Example usage for com.google.gwt.core.ext.typeinfo JClassType isPublic

List of usage examples for com.google.gwt.core.ext.typeinfo JClassType isPublic

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JClassType isPublic.

Prototype

boolean isPublic();

Source Link

Usage

From source file:cc.alcina.framework.entity.gwtsynth.ClientReflectionGenerator.java

License:Apache License

private boolean ignore(JClassType jClassType, ReflectionAction reflectionAction) {
    return (jClassType.isAbstract() && jClassType.isEnum() == null) || (jClassType.isInterface() != null)
            || !jClassType.isPublic() || filter.omitForModule(jClassType, reflectionAction);
}

From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private String createTypeGenerator(JType t) {
    buffer.setLength(0);//from  w w w .  j  a  va2  s. co  m
    String varName = "t";
    if (t instanceof JPrimitiveType)
        varName = "p";
    int id = nextId();
    typeNames2typeIds.put(t.getErasedType().getQualifiedSourceName(), id);
    pb("Type " + varName + " = new Type();");
    pb(varName + ".name = \"" + t.getErasedType().getQualifiedSourceName() + "\";");
    pb(varName + ".id = " + id + ";");
    pb(varName + ".clazz = " + t.getErasedType().getQualifiedSourceName() + ".class;");
    if (t instanceof JClassType) {
        JClassType c = (JClassType) t;
        if (isVisible(c.getSuperclass()))
            pb(varName + ".superClass = " + c.getSuperclass().getErasedType().getQualifiedSourceName()
                    + ".class;");
        if (c.getFlattenedSupertypeHierarchy() != null) {
            pb("Set<Class> " + varName + "Assignables = new HashSet<Class>();");
            for (JType i : c.getFlattenedSupertypeHierarchy()) {
                if (!isVisible(i))
                    continue;
                pb(varName + "Assignables.add(" + i.getErasedType().getQualifiedSourceName() + ".class);");
            }
            pb(varName + ".assignables = " + varName + "Assignables;");
        }
        if (c.isInterface() != null)
            pb(varName + ".isInterface = true;");
        if (c.isEnum() != null)
            pb(varName + ".isEnum = true;");
        if (c.isArray() != null)
            pb(varName + ".isArray = true;");
        if (c.isMemberType())
            pb(varName + ".isMemberClass = true;");
        pb(varName + ".isStatic = " + c.isStatic() + ";");
        pb(varName + ".isAbstract = " + c.isAbstract() + ";");

        if (c.getFields() != null) {
            pb(varName + ".fields = new Field[] {");
            for (JField f : c.getFields()) {
                String enclosingType = getType(c);
                String fieldType = getType(f.getType());
                int setter = nextId();
                int getter = nextId();
                String elementType = getElementTypes(f);
                String annotations = getAnnotations(f.getDeclaredAnnotations());

                pb("new Field(\"" + f.getName() + "\", " + enclosingType + ", " + fieldType + ", " + f.isFinal()
                        + ", " + f.isDefaultAccess() + ", " + f.isPrivate() + ", " + f.isProtected() + ", "
                        + f.isPublic() + ", " + f.isStatic() + ", " + f.isTransient() + ", " + f.isVolatile()
                        + ", " + getter + ", " + setter + ", " + elementType + ", " + annotations + "), ");

                SetterGetterStub stub = new SetterGetterStub();
                stub.name = f.getName();
                stub.enclosingType = enclosingType;
                stub.type = fieldType;
                stub.isStatic = f.isStatic();
                stub.isFinal = f.isFinal();
                if (enclosingType != null && fieldType != null) {
                    stub.getter = getter;
                    stub.setter = setter;
                }
                setterGetterStubs.add(stub);
            }
            pb("};");
        }

        printMethods(c, varName, "Method", c.getMethods());
        if (c.isPublic() && !c.isAbstract() && (c.getEnclosingType() == null || c.isStatic())) {
            printMethods(c, varName, "Constructor", c.getConstructors());
        } else {
            logger.log(Type.INFO, c.getName() + " can't be instantiated. Constructors not generated");
        }

        if (c.isArray() != null) {
            pb(varName + ".componentType = " + getType(c.isArray().getComponentType()) + ";");
        }
        if (c.isEnum() != null) {
            JEnumConstant[] enumConstants = c.isEnum().getEnumConstants();
            if (enumConstants != null) {
                pb(varName + ".enumConstants = new Object[" + enumConstants.length + "];");
                for (int i = 0; i < enumConstants.length; i++) {
                    pb(varName + ".enumConstants[" + i + "] = " + c.getErasedType().getQualifiedSourceName()
                            + "." + enumConstants[i].getName() + ";");
                }
            }
        }

        Annotation[] annotations = c.getDeclaredAnnotations();
        if (annotations != null && annotations.length > 0) {
            pb(varName + ".annotations = " + getAnnotations(annotations) + ";");
        }
    } else if (t.isAnnotation() != null) {
        pb(varName + ".isAnnotation = true;");
    } else {
        pb(varName + ".isPrimitive = true;");
    }

    pb("types.put(\"" + t.getErasedType().getQualifiedSourceName() + "\", " + varName + ");");
    return buffer.toString();
}

From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private String createTypeGenerator(JType t) {
    buffer.setLength(0);/*from   w ww  .  j  ava  2  s. c  om*/
    int id = nextTypeId++;
    typeNames2typeIds.put(t.getErasedType().getQualifiedSourceName(), id);
    JClassType c = t.isClass();

    String name = t.getErasedType().getQualifiedSourceName();
    String superClass = null;
    if (c != null && (isVisible(c.getSuperclass())))
        superClass = c.getSuperclass().getErasedType().getQualifiedSourceName() + ".class";
    String assignables = null;
    String interfaces = null;

    if (c != null && c.getFlattenedSupertypeHierarchy() != null) {
        assignables = "new HashSet<Class>(Arrays.asList(";
        boolean used = false;
        for (JType i : c.getFlattenedSupertypeHierarchy()) {
            if (!isVisible(i) || i.equals(t)
                    || "java.lang.Object".equals(i.getErasedType().getQualifiedSourceName()))
                continue;
            if (used)
                assignables += ", ";
            assignables += i.getErasedType().getQualifiedSourceName() + ".class";
            used = true;
        }
        if (used)
            assignables += "))";
        else
            assignables = null;
    }

    if (c == null) {
        // if it's not a class, it may be an interface instead
        c = t.isInterface();
    }

    if (c != null && c.getImplementedInterfaces() != null) {
        interfaces = "new HashSet<Class>(Arrays.asList(";
        boolean used = false;
        for (JType i : c.getImplementedInterfaces()) {
            if (!isVisible(i) || i.equals(t))
                continue;
            if (used)
                interfaces += ", ";
            interfaces += i.getErasedType().getQualifiedSourceName() + ".class";
            used = true;
        }
        if (used)
            interfaces += "))";
        else
            interfaces = null;
    }

    String varName = "c" + id;
    pb("private static Type " + varName + ";");
    pb("private static Type " + varName + "() {");
    pb("if(" + varName + "!=null) return " + varName + ";");
    pb(varName + " = new Type(\"" + name + "\", " + id + ", " + name + ".class, " + superClass + ", "
            + assignables + ", " + interfaces + ");");

    if (c != null) {
        if (c.isEnum() != null)
            pb(varName + ".isEnum = true;");
        if (c.isArray() != null)
            pb(varName + ".isArray = true;");
        if (c.isMemberType())
            pb(varName + ".isMemberClass = true;");
        if (c.isInterface() != null) {
            pb(varName + ".isInterface = true;");
        } else {
            pb(varName + ".isStatic = " + c.isStatic() + ";");
            pb(varName + ".isAbstract = " + c.isAbstract() + ";");
        }

        if (c.getFields() != null && c.getFields().length > 0) {
            pb(varName + ".fields = new Field[] {");
            for (JField f : c.getFields()) {
                String enclosingType = getType(c);
                String fieldType = getType(f.getType());
                int setterGetter = nextSetterGetterId++;
                String elementType = getElementTypes(f);
                String annotations = getAnnotations(f.getDeclaredAnnotations());

                pb("    new Field(\"" + f.getName() + "\", " + enclosingType + ", " + fieldType + ", "
                        + f.isFinal() + ", " + f.isDefaultAccess() + ", " + f.isPrivate() + ", "
                        + f.isProtected() + ", " + f.isPublic() + ", " + f.isStatic() + ", " + f.isTransient()
                        + ", " + f.isVolatile() + ", " + setterGetter + ", " + setterGetter + ", " + elementType
                        + ", " + annotations + "), ");

                SetterGetterStub stub = new SetterGetterStub();
                stub.name = f.getName();
                stub.enclosingType = enclosingType;
                stub.type = fieldType;
                stub.isStatic = f.isStatic();
                stub.isFinal = f.isFinal();
                if (enclosingType != null && fieldType != null) {
                    stub.getter = setterGetter;
                    stub.setter = setterGetter;
                }
                setterGetterStubs.add(stub);
            }
            pb("};");
        }

        createTypeInvokables(c, varName, "Method", c.getMethods());
        if (c.isPublic() && !c.isAbstract() && (c.getEnclosingType() == null || c.isStatic())) {
            createTypeInvokables(c, varName, "Constructor", c.getConstructors());
        } else {
            logger.log(Type.INFO, c.getName() + " can't be instantiated. Constructors not generated");
        }

        if (c.isArray() != null) {
            pb(varName + ".componentType = " + getType(c.isArray().getComponentType()) + ";");
        }
        if (c.isEnum() != null) {
            JEnumConstant[] enumConstants = c.isEnum().getEnumConstants();
            if (enumConstants != null) {
                pb(varName + ".enumConstants = new Object[" + enumConstants.length + "];");
                for (int i = 0; i < enumConstants.length; i++) {
                    pb(varName + ".enumConstants[" + i + "] = " + c.getErasedType().getQualifiedSourceName()
                            + "." + enumConstants[i].getName() + ";");
                }
            }
        }

        Annotation[] annotations = c.getDeclaredAnnotations();
        if (annotations != null && annotations.length > 0) {
            pb(varName + ".annotations = " + getAnnotations(annotations) + ";");
        }
    } else if (t.isAnnotation() != null) {
        pb(varName + ".isAnnotation = true;");
    } else {
        pb(varName + ".isPrimitive = true;");
    }

    pb("return " + varName + ";");
    pb("}");
    return buffer.toString();
}

From source file:com.cgxlib.xq.rebind.JsonBuilderGenerator.java

License:Apache License

private void generateCreateMethod(SourceWriter sw, TreeLogger logger) {
    sw.println("public <T extends " + JsonBuilder.class.getName() + "> T create(Class<T> clz) {");
    sw.indent();//from ww  w .j  a v a2s.  c  o  m
    ArrayList<JClassType> types = new ArrayList<JClassType>();
    for (JClassType t : oracle.getTypes()) {
        if (t.isInterface() != null && t.isAssignableTo(jsonBuilderType)) {
            if (t.isPublic()) {
                sw.println("if (clz == " + t.getQualifiedSourceName() + ".class) return GWT.<T>create("
                        + t.getQualifiedSourceName() + ".class);");
            } else {
                logger.log(Type.WARN, t.getQualifiedSourceName() + " is not public");
            }
            types.add(t);
        }
    }
    sw.println("return null;");
    sw.outdent();
    sw.println("}");
    sw.println("public " + IsProperties.class.getName() + " create(String s) {");
    sw.indent();
    sw.println("return (" + IsProperties.class.getName() + ")" + JsUtils.class.getName() + ".parseJSON(s);");
    sw.outdent();
    sw.println("}");
    sw.println("public " + IsProperties.class.getName() + " create() {");
    sw.indent();
    sw.println("return " + Properties.class.getName() + ".create();");
    sw.outdent();
    sw.println("}");
}

From source file:com.github.nmorel.gwtjackson.rebind.CreatorUtils.java

License:Apache License

public static ImmutableList<JClassType> filterSubtypesForSerialization(TreeLogger logger,
        RebindConfiguration configuration, JClassType type) {
    boolean filterOnlySupportedType = isObjectOrSerializable(type);

    ImmutableList.Builder<JClassType> builder = ImmutableList.builder();
    if (type.getSubtypes().length > 0) {
        for (JClassType subtype : type.getSubtypes()) {
            if (null == subtype.isAnnotation() && subtype.isPublic()
                    && (!filterOnlySupportedType
                            || configuration.isTypeSupportedForSerialization(logger, subtype))
                    && !findFirstEncounteredAnnotationsOnAllHierarchy(configuration,
                            subtype.isClassOrInterface(), JsonIgnoreType.class, Optional.of(type))
                                    .isPresent()) {
                builder.add(subtype);/*from  ww  w .  ja  v a 2 s .  co m*/
            }
        }
    }
    return builder.build();
}

From source file:com.github.nmorel.gwtjackson.rebind.CreatorUtils.java

License:Apache License

public static ImmutableList<JClassType> filterSubtypesForDeserialization(TreeLogger logger,
        RebindConfiguration configuration, JClassType type) {
    boolean filterOnlySupportedType = isObjectOrSerializable(type);

    ImmutableList.Builder<JClassType> builder = ImmutableList.builder();
    if (type.getSubtypes().length > 0) {
        for (JClassType subtype : type.getSubtypes()) {
            if ((null == subtype.isInterface() && !subtype.isAbstract()
                    && (!subtype.isMemberType() || subtype.isStatic())) && null == subtype.isAnnotation()
                    && subtype.isPublic()
                    && (!filterOnlySupportedType || (configuration.isTypeSupportedForDeserialization(logger,
                            subtype)/*from ww w.  j  a  v a 2  s. co  m*/
                            // EnumSet and EnumMap are not supported in subtype deserialization because we can't know the enum to use.
                            && !EnumSet.class.getCanonicalName().equals(subtype.getQualifiedSourceName())
                            && !EnumMap.class.getCanonicalName().equals(subtype.getQualifiedSourceName())))
                    && !findFirstEncounteredAnnotationsOnAllHierarchy(configuration,
                            subtype.isClassOrInterface(), JsonIgnoreType.class, Optional.of(type))
                                    .isPresent()) {
                builder.add(subtype);
            }
        }
    }
    return builder.build();
}

From source file:com.google.web.bindery.autobean.gwt.rebind.AutoBeanFactoryGenerator.java

License:Apache License

/**
 * Write an instance initializer block to populate the creators map.
 *///from  w  ww. ja  v  a2 s. c o m
private void writeDynamicMethods(SourceWriter sw) {
    List<JClassType> privatePeers = new ArrayList<JClassType>();
    sw.println("@Override protected void initializeCreatorMap(%s map) {",
            JsniCreatorMap.class.getCanonicalName());
    sw.indent();
    for (AutoBeanType type : model.getAllTypes()) {
        if (type.isNoWrap()) {
            continue;
        }
        String classLiteralAccessor;
        JClassType peer = type.getPeerType();
        String peerName = ModelUtils.ensureBaseType(peer).getQualifiedSourceName();
        if (peer.isPublic()) {
            classLiteralAccessor = peerName + ".class";
        } else {
            privatePeers.add(peer);
            classLiteralAccessor = "classLit_" + peerName.replace('.', '_') + "()";
        }
        // map.add(Foo.class, getConstructors_com_foo_Bar());
        sw.println("map.add(%s, getConstructors_%s());", classLiteralAccessor, peerName.replace('.', '_'));
    }
    sw.outdent();
    sw.println("}");

    /*
     * Create a native method for each peer type that isn't public since Java
     * class literal references are scoped.
     */
    for (JClassType peer : privatePeers) {
        String peerName = ModelUtils.ensureBaseType(peer).getQualifiedSourceName();
        sw.println("private native Class<?> classLit_%s() /*-{return @%s::class;}-*/;",
                peerName.replace('.', '_'), peerName);
    }

    /*
     * Create a method that returns an array containing references to the
     * constructors.
     */
    String factoryJNIName = context.getTypeOracle().findType(AutoBeanFactory.class.getCanonicalName())
            .getJNISignature();
    for (AutoBeanType type : model.getAllTypes()) {
        String peerName = ModelUtils.ensureBaseType(type.getPeerType()).getQualifiedSourceName();
        String peerJNIName = ModelUtils.ensureBaseType(type.getPeerType()).getJNISignature();
        /*-
         * private native JsArray<JSO> getConstructors_com_foo_Bar() {
         *   return [
         *     BarProxyImpl::new(ABFactory),
         *     BarProxyImpl::new(ABFactory, DelegateType)
         *   ];
         * }
         */
        sw.println("private native %s<%s> getConstructors_%s() /*-{", JsArray.class.getCanonicalName(),
                JavaScriptObject.class.getCanonicalName(), peerName.replace('.', '_'));
        sw.indent();
        sw.println("return [");
        if (type.isSimpleBean()) {
            sw.indentln("@%s::new(%s),", type.getQualifiedSourceName(), factoryJNIName);
        } else {
            sw.indentln(",");
        }
        sw.indentln("@%s::new(%s%s)", type.getQualifiedSourceName(), factoryJNIName, peerJNIName);
        sw.println("];");
        sw.outdent();
        sw.println("}-*/;");
    }
}

From source file:com.google.web.bindery.autobean.gwt.rebind.model.AutoBeanFactoryModel.java

License:Apache License

private void processClassArrayAnnotation(Class<?>[] classes, Collection<JClassType> accumulator) {
    for (Class<?> clazz : classes) {
        JClassType category = oracle.findType(clazz.getCanonicalName());
        if (category == null) {
            poison("Could not find @%s type %s in the TypeOracle", Category.class.getSimpleName(),
                    clazz.getCanonicalName());
            continue;
        } else if (!category.isPublic()) {
            poison("Category type %s is not public", category.getQualifiedSourceName());
            continue;
        } else if (!category.isStatic() && category.isMemberType()) {
            poison("Category type %s must be static", category.getQualifiedSourceName());
            continue;
        }//www.  j  av a  2s  .com
        accumulator.add(category);
    }
}

From source file:com.gwtent.gen.reflection.ReflectAllInOneCreator.java

License:Apache License

private boolean addClassIfNotExists(JClassType classType, Reflectable setting) {
    //Add next line we can make sure we just append normal class type, always get from TypeOracle
    //not JParameterizedType or JTypeParameter etc...
    //RC2 we support ParameterizedType now.
    if (classType != null && classType.isParameterized() == null) {
        //         System.out.println("addClassIfNotExists: " + classType.getQualifiedSourceName());
        classType = this.typeOracle.findType(classType.getQualifiedSourceName());

    }//from ww  w .j a v  a  2s .  c  om

    //we just process public classes
    if ((classType == null) || (classType.isPrivate()) || (classType.isProtected())
            || (GeneratorHelper.isSystemClass(classType) && !classType.isPublic()))
        return false;

    //no need java.lang.class
    if (classType.getQualifiedSourceName().equals("java.lang.Class"))
        return false;

    if (candidateList.indexOf(classType.getErasedType()) < 0) {
        candidateList.add(classType.getErasedType());
        candidates.put(classType.getErasedType(), setting);
        return true;
    }

    return false;
}

From source file:com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory.java

License:Apache License

private void writeSuperClasses(SplittingSourceWriter w, ConnectorBundle bundle) {
    List<JClassType> needsSuperclass = new ArrayList<JClassType>(bundle.getNeedsSuperclass());
    // Emit in hierarchy order to ensure superclass is defined when
    // referenced
    Collections.sort(needsSuperclass, new Comparator<JClassType>() {

        @Override/*from w  w  w  .  j a  v  a 2s .co m*/
        public int compare(JClassType type1, JClassType type2) {
            int depthDiff = getDepth(type1) - getDepth(type2);
            if (depthDiff != 0) {
                return depthDiff;
            } else {
                // Just something to get a stable compare
                return type1.getName().compareTo(type2.getName());
            }
        }

        private int getDepth(JClassType type) {
            int depth = 0;
            while (type != null) {
                depth++;
                type = type.getSuperclass();
            }
            return depth;
        }
    });

    for (JClassType jClassType : needsSuperclass) {
        JClassType superclass = jClassType.getSuperclass();
        while (superclass != null && !superclass.isPublic()) {
            superclass = superclass.getSuperclass();
        }
        String classLiteralString;
        if (superclass == null) {
            classLiteralString = "null";
        } else {
            classLiteralString = getClassLiteralString(superclass);
        }
        w.println("store.setSuperClass(%s, %s);", getClassLiteralString(jClassType), classLiteralString);
    }
}