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

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

Introduction

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

Prototype

JClassType[] getNestedTypes();

Source Link

Usage

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

License:Apache License

private void gatherTypes(JType type, List<JType> types) {
    nesting++;// w w w .  ja va 2s  .  c om
    // came here from a type that has no super class
    if (type == null) {
        nesting--;
        return;
    }
    // package info
    if (type.getQualifiedSourceName().contains("-")) {
        nesting--;
        return;
    }

    // not visible
    if (!isVisible(type)) {
        nesting--;
        return;
    }

    // filter reflection scope based on configuration in gwt xml module
    boolean keep = false;
    String name = type.getQualifiedSourceName();
    try {
        ConfigurationProperty prop;
        keep |= !name.contains(".");
        prop = context.getPropertyOracle().getConfigurationProperty("artemis.reflect.include");
        for (String s : prop.getValues())
            keep |= name.contains(s);
        prop = context.getPropertyOracle().getConfigurationProperty("artemis.reflect.exclude");
        for (String s : prop.getValues())
            keep &= !name.equals(s);
    } catch (BadPropertyValueException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (!keep) {
        nesting--;
        return;
    }

    // already visited this type
    if (types.contains(type.getErasedType())) {
        nesting--;
        return;
    }
    types.add(type.getErasedType());
    out(type.getErasedType().getQualifiedSourceName(), nesting);

    if (type instanceof JPrimitiveType) {
        // nothing to do for a primitive type
        nesting--;
        return;
    } else {
        // gather fields
        JClassType c = (JClassType) type;
        JField[] fields = c.getFields();
        if (fields != null) {
            for (JField field : fields) {
                gatherTypes(field.getType().getErasedType(), types);
            }
        }

        // gather super types & interfaces
        gatherTypes(c.getSuperclass(), types);
        JClassType[] interfaces = c.getImplementedInterfaces();
        if (interfaces != null) {
            for (JClassType i : interfaces) {
                gatherTypes(i.getErasedType(), types);
            }
        }

        // gather method parameter & return types
        JMethod[] methods = c.getMethods();
        if (methods != null) {
            for (JMethod m : methods) {
                gatherTypes(m.getReturnType().getErasedType(), types);
                if (m.getParameterTypes() != null) {
                    for (JType p : m.getParameterTypes()) {
                        gatherTypes(p.getErasedType(), types);
                    }
                }
            }
        }

        // gather inner classes
        JClassType[] inner = c.getNestedTypes();
        if (inner != null) {
            for (JClassType i : inner) {
                gatherTypes(i.getErasedType(), types);
            }
        }
    }
    nesting--;
}

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

License:Apache License

private void gatherTypes(JType type, List<JType> types) {
    nesting++;//from   w  w w.ja v a  2  s.  co  m
    // came here from a type that has no super class
    if (type == null) {
        nesting--;
        return;
    }
    // package info
    if (type.getQualifiedSourceName().contains("-")) {
        nesting--;
        return;
    }

    // not visible
    if (!isVisible(type)) {
        nesting--;
        return;
    }

    // filter reflection scope based on configuration in gwt xml module
    boolean keep = false;
    String name = type.getQualifiedSourceName();
    try {
        ConfigurationProperty prop;
        keep |= !name.contains(".");
        prop = context.getPropertyOracle().getConfigurationProperty("gdx.reflect.include");
        for (String s : prop.getValues())
            keep |= name.contains(s);
        prop = context.getPropertyOracle().getConfigurationProperty("gdx.reflect.exclude");
        for (String s : prop.getValues())
            keep &= !name.equals(s);
    } catch (BadPropertyValueException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (!keep) {
        nesting--;
        return;
    }

    // already visited this type
    if (types.contains(type.getErasedType())) {
        nesting--;
        return;
    }
    types.add(type.getErasedType());
    out(type.getErasedType().getQualifiedSourceName(), nesting);

    if (type instanceof JPrimitiveType) {
        // nothing to do for a primitive type
        nesting--;
        return;
    } else {
        // gather fields
        JClassType c = (JClassType) type;
        JField[] fields = c.getFields();
        if (fields != null) {
            for (JField field : fields) {
                gatherTypes(field.getType().getErasedType(), types);
            }
        }

        // gather super types & interfaces
        gatherTypes(c.getSuperclass(), types);
        JClassType[] interfaces = c.getImplementedInterfaces();
        if (interfaces != null) {
            for (JClassType i : interfaces) {
                gatherTypes(i.getErasedType(), types);
            }
        }

        // gather method parameter & return types
        JMethod[] methods = c.getMethods();
        if (methods != null) {
            for (JMethod m : methods) {
                gatherTypes(m.getReturnType().getErasedType(), types);
                if (m.getParameterTypes() != null) {
                    for (JType p : m.getParameterTypes()) {
                        gatherTypes(p.getErasedType(), types);
                    }
                }
            }
        }

        // gather inner classes
        JClassType[] inner = c.getNestedTypes();
        if (inner != null) {
            for (JClassType i : inner) {
                gatherTypes(i.getErasedType(), types);
            }
        }
    }
    nesting--;
}

From source file:org.jboss.errai.bus.server.util.RebindUtil.java

License:Apache License

private static void doVisit(JClassType type, GeneratorContext context, TreeLogger logger, SourceWriter writer,
        RebindVisitor visitor) {//from w ww .  j  av  a  2  s . co m
    visitor.visit(type, context, logger, writer);
    for (JClassType declaredClass : type.getNestedTypes()) {
        visitor.visit(declaredClass, context, logger, writer);
    }
}

From source file:org.parallax3d.parallax.platforms.gwt.generator.SourceBundleFactoryGenerator.java

License:Open Source License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {

    PrintWriter pw = context.tryCreate(logger, "org.parallax3d.parallax.platforms.gwt.preloader",
            "SourceBundleFactoryImpl");

    if (pw != null) {
        // write package, imports, whatever
        pw.append("package org.parallax3d.parallax.platforms.gwt.preloader;");
        pw.append("import org.parallax3d.parallax.system.SourceBundle;");
        pw.append("import org.parallax3d.parallax.system.SourceBundleFactory;");
        pw.append("import com.google.gwt.core.client.GWT;");
        pw.append("import org.parallax3d.parallax.system.FastMap;");

        // iterates over all the classes to find those with EntryPointWidget annotation
        TypeOracle oracle = context.getTypeOracle();
        JPackage[] packages = oracle.getPackages();

        System.out.println(" Start classpath text bundles generation ");

        FastMap<JClassType> genClasses = new FastMap<>();
        for (JPackage pack : packages) {
            for (JClassType classtype : pack.getTypes()) {
                for (JClassType nestedClass : classtype.getNestedTypes()) {
                    String cls = generateStaticInstance(oracle, logger, context, nestedClass);
                    if (cls != null)
                        genClasses.put(cls, nestedClass);
                }/*from  w  ww .  j  ava 2 s  .  c o  m*/

                String cls = generateStaticInstance(oracle, logger, context, classtype);
                if (cls != null)
                    genClasses.put(cls, classtype);
            }
        }

        System.out.println("   " + genClasses.size() + " bundles have been generated");

        // import generated classes
        for (String genClass : genClasses.keySet())
            pw.append("import " + genClass + ";");

        // the class
        pw.append("public class SourceBundleFactoryImpl implements SourceBundleFactory {");

        pw.append("   private static final FastMap<SourceBundle> MAP = new FastMap<SourceBundle>(){{");

        for (Map.Entry<String, JClassType> entry : genClasses.entrySet())
            pw.append("      put(\"" + entry.getValue().getQualifiedSourceName() + "\", new " + entry.getKey()
                    + "() );");

        pw.append("   }};");

        // get method
        pw.append("   public <T> T get(Class<? extends SourceBundle> classLiteral) {");
        pw.append("       if (MAP.containsKey(classLiteral.getCanonicalName())) {");
        pw.append("           return (T) MAP.get(classLiteral.getCanonicalName());");
        pw.append("       }");
        pw.append("       return null;");
        pw.append("   }"); // method
        pw.append("}"); // class

        context.commit(logger, pw);
    }

    // return the name of the generated class
    return "org.parallax3d.parallax.platforms.gwt.preloader.SourceBundleFactoryImpl";
}