Package js.lang

Examples of js.lang.NativeObject


        if (parameterAnnotations == null) {
            parameterAnnotations = new NativeArray(getParameterTypes().length);

            for (String index : annotations.keys()) {
                List<Annotation> container = new ArrayList();
                NativeObject definition = annotations.getProperty(index, new NativeObject());

                for (String name : definition.keys()) {
                    Class type = JSClass.forName(name);

                    container.add((Annotation) Proxy.newProxyInstance(null, new Class[] {type}, new AnnotationProxy(type, definition.getProperty(name))));
                }
                parameterAnnotations.setProperty(index, container);
            }
        }
View Full Code Here


     * {@inheritDoc}
     */
    @Override
    public void clear() {
        size = 0;
        items = new NativeObject();
    }
View Full Code Here

     * @param source
     * @param interceptors
     */
    private static void define(Class source, Table<Method, Annotation> interceptors) {
        try {
            NativeObject prototype = Reflections.getPrototype(source);

            for (Entry<Method, List<Annotation>> entry : interceptors.entrySet()) {
                Method method = entry.getKey();
                List<Annotation> annotations = entry.getValue();

                if (!annotations.isEmpty()) {
                    InterceptorFunction function = new InterceptorFunction(method.getName(), MethodHandles
                            .lookup()
                            .unreflect(method), annotations.toArray(new Annotation[annotations.size()]));
                    prototype.setProperty(Reflections.getPropertyName(method), new NativeFunction(function));
                }
            }
        } catch (Exception e) {
            throw I.quiet(e);
        }
View Full Code Here

    private static <T> List<Class<? extends T>> search(Class<T> type) {
        List<Class<? extends T>> matched = new ArrayList();
        NativeArray extensions = boot.getPropertyAs(NativeArray.class, "extensions");

        for (int i = 0; i < extensions.length(); i++) {
            NativeObject object = (NativeObject) extensions.get(i);

            if (object != null) {
                Class clazz = object.getPropertyAs(Class.class, "$");

                if (((Modifier.INTERFACE | Modifier.ABSTRACT) & clazz.getModifiers()) == 0 && type != clazz && type
                        .isAssignableFrom(clazz)) {
                    matched.add(clazz);
                }
View Full Code Here

                            binds.push(property.name, this);
                        }

                        // rewrite model code to publish their state modification
                        if (rewrites.add(model.type)) {
                            NativeObject prototype = Reflections.getPrototype(model.type);

                            for (Property property : model.properties) {

                                String name = property.name;
                                name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
                                name = (property.model.type == boolean.class ? "is" : "set").concat(name);

                                try {
                                    name = Reflections.getPropertyName(model.type.getMethod(name, property.model.type));

                                    BindingFunction function = new BindingFunction(prototype.getPropertyAs(NativeFunction.class, name), property.name);
                                    prototype.setProperty(name, new NativeFunction(function));
                                } catch (Exception e) {
                                    throw I.quiet(e);
                                }
                            }
                        }
View Full Code Here

        private Property(NativeObject model, String name) {
            this.model = model;
            this.name = name;

            // define getter and setter method
            NativeObject descriptor = NativeObject.getOwnPropertyDescriptor(model, name);

            if (descriptor == null || descriptor.hasProperty("value")) {
                // store initial value
                model.setProperty("$" + name, model.getProperty(name));

                // create property listeners
                NativeObject.defineProperty(model, name, this);
View Full Code Here

        test(new Scriptable() {

            public Object act() {
                String value = "value";

                NativeObject instance = new NativeObject();
                assert instance.getProperty("key") == null;

                instance.setProperty("key", value);
                assert instance.getProperty("key") == value;
                assert instance.getProperty("key").equals(value);

                return instance.getProperty("key");
            }
        });
    }
View Full Code Here

    @Test
    public void propertyNull() throws Exception {
        test(new Scriptable() {

            public Object act() {
                NativeObject instance = new NativeObject();
                assert instance.getProperty("key") == null;

                instance.setProperty("key", null);
                assert instance.getProperty("key") == null;

                return instance.getProperty("key");
            }
        });
    }
View Full Code Here

    @Test
    public void hasProperty() throws Exception {
        test(new Scriptable() {

            public boolean act() {
                NativeObject instance = new NativeObject();
                assert instance.hasProperty("key") == false;
                assert instance.hasProperty("null") == false;

                instance.setProperty("key", "value");
                instance.setProperty("null", null);
                assert instance.hasProperty("key") == true;
                assert instance.hasProperty("null") == true;

                return instance.hasProperty("null");
            }
        });
    }
View Full Code Here

        test(new Scriptable() {

            public boolean act() {
                Object key = "key";

                NativeObject instance = new NativeObject();
                assert instance.hasProperty(key) == false;
                assert instance.getProperty(key) == null;

                Object value = instance.setProperty(key, "value");
                assert instance.hasProperty(key) == true;
                assert instance.getProperty(key) == value;

                boolean result = instance.deleteProperty(key);
                assert instance.hasProperty(key) == false;
                assert instance.getProperty(key) == null;

                return result;
            }
        });
    }
View Full Code Here

TOP

Related Classes of js.lang.NativeObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.