Example usage for com.google.gwt.core.ext.typeinfo JType getQualifiedSourceName

List of usage examples for com.google.gwt.core.ext.typeinfo JType getQualifiedSourceName

Introduction

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

Prototype

String getQualifiedSourceName();

Source Link

Document

Returns a type name as it would be specified in Java source, with the package name included.

Usage

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

License:Apache License

private void generateLookups() {
    p("Map<String, Type> types = new HashMap<String, Type>();");

    TypeOracle typeOracle = context.getTypeOracle();
    JPackage[] packages = typeOracle.getPackages();

    // gather all types from wanted packages
    for (JPackage p : packages) {
        for (JClassType t : p.getTypes()) {
            gatherTypes(t.getErasedType(), types);
        }/*  w ww. j a va2 s  .c o m*/
    }

    gatherTypes(typeOracle.findType("java.util.List").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.ArrayList").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.HashMap").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.Map").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.String").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Boolean").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Byte").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Long").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Character").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Short").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Integer").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Float").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.CharSequence").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Double").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Object").getErasedType(), types);

    // sort the types so the generated output will be stable between runs
    Collections.sort(types, new Comparator<JType>() {
        public int compare(JType o1, JType o2) {
            return o1.getQualifiedSourceName().compareTo(o2.getQualifiedSourceName());
        }
    });

    // generate Type lookup generator methods.
    int id = 0;
    for (JType t : types) {
        String typeGen = createTypeGenerator(t);
        p("private void c" + (id++) + "() {");
        p(typeGen);
        p("}\n");
    }

    // generate constructor that calls all the type generators
    // that populate the map.
    p("public " + simpleName + "() {");
    for (int i = 0; i < id; i++) {
        p("c" + i + "();");
    }
    p("}");

    // sort the stubs so the generated output will be stable between runs
    Collections.sort(setterGetterStubs, new Comparator<SetterGetterStub>() {
        @Override
        public int compare(SetterGetterStub o1, SetterGetterStub o2) {
            return new Integer(o1.setter).compareTo(o2.setter);
        }
    });

    // generate field setters/getters
    for (SetterGetterStub stub : setterGetterStubs) {
        String stubSource = generateSetterGetterStub(stub);
        if (stubSource.equals(""))
            stub.unused = true;
        p(stubSource);
    }

    // sort the stubs so the generated output will be stable between runs
    Collections.sort(methodStubs, new Comparator<MethodStub>() {
        @Override
        public int compare(MethodStub o1, MethodStub o2) {
            return new Integer(o1.methodId).compareTo(o2.methodId);
        }
    });

    // generate methods
    for (MethodStub stub : methodStubs) {
        String stubSource = generateMethodStub(stub);
        if (stubSource.equals(""))
            stub.unused = true;
        p(stubSource);
    }

    logger.log(Type.INFO, types.size() + " types reflected");
}

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

License:Apache License

private void gatherTypes(JType type, List<JType> types) {
    nesting++;/*  w  ww  .j  av  a2s.  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.artemis.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private void newArrayC() {
    p("public Object newArray (Class componentType, int size) {");
    p("   Type t = forName(componentType.getName().replace('$', '.'));");
    p("   if (t != null) {");
    SwitchedCodeBlock pc = new SwitchedCodeBlock("t.id");
    for (JType type : types) {
        if (type.getQualifiedSourceName().equals("void"))
            continue;
        if (type.getQualifiedSourceName().endsWith("Void"))
            continue;
        String arrayType = type.getErasedType().getQualifiedSourceName() + "[size]";
        if (arrayType.contains("[]")) {
            arrayType = type.getErasedType().getQualifiedSourceName();
            arrayType = arrayType.replaceFirst("\\[\\]", "[size]") + "[]";
        }//from   w  w w.j  a  v  a2 s  .  co  m
        pc.add(typeNames2typeIds.get(type.getQualifiedSourceName()), "return new " + arrayType + ";");
    }
    pc.print();
    p("   }");
    p("   throw new RuntimeException(\"Couldn't create array with element type \" + componentType.getName());");
    p("}");
}

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

License:Apache License

private void generateLookups() {
    TypeOracle typeOracle = context.getTypeOracle();
    JPackage[] packages = typeOracle.getPackages();

    // gather all types from wanted packages
    for (JPackage p : packages) {
        for (JClassType t : p.getTypes()) {
            gatherTypes(t.getErasedType(), types);
        }//  www .j  av  a  2s .  c  om
    }

    // gather all types from explicitly requested packages
    try {
        ConfigurationProperty prop = context.getPropertyOracle()
                .getConfigurationProperty("gdx.reflect.include");
        for (String s : prop.getValues()) {
            JClassType type = typeOracle.findType(s);
            if (type != null)
                gatherTypes(type.getErasedType(), types);
        }
    } catch (BadPropertyValueException e) {
    }

    gatherTypes(typeOracle.findType("java.util.List").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.ArrayList").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.HashMap").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.util.Map").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.String").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Boolean").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Byte").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Long").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Character").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Short").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Integer").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Float").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.CharSequence").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Double").getErasedType(), types);
    gatherTypes(typeOracle.findType("java.lang.Object").getErasedType(), types);

    // sort the types so the generated output will be stable between runs
    Collections.sort(types, new Comparator<JType>() {
        public int compare(JType o1, JType o2) {
            return o1.getQualifiedSourceName().compareTo(o2.getQualifiedSourceName());
        }
    });

    // generate Type lookup generator methods.
    for (JType t : types) {
        p(createTypeGenerator(t));
    }

    // generate reusable parameter objects
    parameterInitialization();

    // sort the stubs so the generated output will be stable between runs
    Collections.sort(setterGetterStubs, new Comparator<SetterGetterStub>() {
        @Override
        public int compare(SetterGetterStub o1, SetterGetterStub o2) {
            return new Integer(o1.setter).compareTo(o2.setter);
        }
    });

    // generate field setters/getters
    for (SetterGetterStub stub : setterGetterStubs) {
        String stubSource = generateSetterGetterStub(stub);
        if (stubSource.equals(""))
            stub.unused = true;
        p(stubSource);
    }

    // sort the stubs so the generated output will be stable between runs
    Collections.sort(methodStubs, new Comparator<MethodStub>() {
        @Override
        public int compare(MethodStub o1, MethodStub o2) {
            return new Integer(o1.methodId).compareTo(o2.methodId);
        }
    });

    // generate methods
    for (MethodStub stub : methodStubs) {
        String stubSource = generateMethodStub(stub);
        if (stubSource.equals(""))
            stub.unused = true;
        p(stubSource);
    }

    logger.log(Type.INFO, types.size() + " types reflected");
}

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 .java2  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:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private void newArrayC() {
    p("public Object newArray (Type t, int size) {");
    p("    if (t != null) {");
    SwitchedCodeBlock pc = new SwitchedCodeBlock("t.id");
    for (JType type : types) {
        if (type.getQualifiedSourceName().equals("void"))
            continue;
        if (type.getQualifiedSourceName().endsWith("Void"))
            continue;
        String arrayType = type.getErasedType().getQualifiedSourceName() + "[size]";
        if (arrayType.contains("[]")) {
            arrayType = type.getErasedType().getQualifiedSourceName();
            arrayType = arrayType.replaceFirst("\\[\\]", "[size]") + "[]";
        }//from w ww .  j  a  va 2  s.  c  o  m
        pc.add(typeNames2typeIds.get(type.getQualifiedSourceName()), "return new " + arrayType + ";");
    }
    pc.print();
    p("    }");
    p("    throw new RuntimeException(\"Couldn't create array\");");
    p("}");
}

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

License:Apache License

public void generateMethod(SourceWriter sw, JMethod method, String name, TreeLogger logger)
        throws UnableToCompleteException {
    String ifaceName = method.getEnclosingType().getQualifiedSourceName();

    String retType = method.getReturnType().getParameterizedQualifiedSourceName();
    sw.print("public final " + retType + " " + method.getName());
    JParameter[] params = method.getParameters();
    if (params.length == 0) {
        JArrayType arr = method.getReturnType().isArray();
        JParameterizedType list = method.getReturnType().isParameterized();

        sw.println("() {");
        sw.indent();/*from  w w w.  j ava 2s. co  m*/
        if (retType.matches("(java.lang.Boolean|boolean)")) {
            sw.println("return p.getBoolean(\"" + name + "\");");
        } else if (retType.matches("java.util.Date")) {
            sw.println("return new Date(java.lang.Long.parseLong(p.getStr(\"" + name + "\")));");
        } else if (method.getReturnType().isPrimitive() != null) {
            sw.println("return (" + retType + ")p.getFloat(\"" + name + "\");");
        } else if (retType.equals("java.lang.Character")) {
            sw.println("return (char) p.getFloat(\"" + name + "\");");
        } else if (retType.equals("java.lang.Byte")) {
            sw.println("return (byte) p.getFloat(\"" + name + "\");");
        } else if (retType.equals("java.lang.Integer")) {
            sw.println("return (int) p.getFloat(\"" + name + "\");");
        } else if (retType.equals("java.lang.Float")) {
            sw.println("return p.getFloat(\"" + name + "\");");
        } else if (retType.equals("java.lang.Double")) {
            sw.println("return (double) p.getFloat(\"" + name + "\");");
        } else if (retType.equals("java.lang.Long")) {
            sw.println("return (long) p.getFloat(\"" + name + "\");");
        } else if (retType.equals("java.lang.Byte")) {
            sw.println("return (byte) p.getFloat(\"" + name + "\");");
        } else if (isTypeAssignableTo(method.getReturnType(), stringType)) {
            sw.println("return p.getStr(\"" + name + "\");");
        } else if (isTypeAssignableTo(method.getReturnType(), jsonBuilderType)) {
            String q = method.getReturnType().getQualifiedSourceName();
            sw.println("return " + "((" + q + ")GWT.create(" + q + ".class))" + ".load(getPropertiesBase(\""
                    + name + "\"));");
        } else if (isTypeAssignableTo(method.getReturnType(), settingsType)) {
            String q = method.getReturnType().getQualifiedSourceName();
            sw.println("return " + "((" + q + ")getPropertiesBase(\"" + name + "\"));");
        } else if (retType.equals(Properties.class.getName())) {
            sw.println("return getPropertiesBase(\"" + name + "\");");
        } else if (isTypeAssignableTo(method.getReturnType(), jsType)) {
            sw.println("return p.getJavaScriptObject(\"" + name + "\");");
        } else if (isTypeAssignableTo(method.getReturnType(), functionType)) {
            sw.println("return p.getFunction(\"" + name + "\");");
        } else if (arr != null || list != null) {
            JType type = arr != null ? arr.getComponentType() : list.getTypeArgs()[0];
            boolean buildType = isTypeAssignableTo(type, jsonBuilderType);
            String t = type.getQualifiedSourceName();
            sw.println("JsArrayMixed a = p.getArray(\"" + name + "\");");
            sw.println("int l = a == null ? 0 : a.length();");
            String ret;
            if (buildType) {
                sw.println(t + "[] r = new " + t + "[l];");
                sw.println("JsObjectArray<?> a1 = p.getArray(\"" + name + "\").cast();");
                sw.println("int l1 = r.length;");
                sw.println("for (int i = 0 ; i < l1 ; i++) {");
                sw.println("  Object w = a1.get(i);");
                sw.println("  " + t + " instance = GWT.create(" + t + ".class);");
                sw.println("  r[i] = instance.load(w);");
                sw.println("}");
                ret = "r";
            } else {
                ret = "getArrayBase(\"" + name + "\", new " + t + "[l], " + t + ".class)";
            }
            if (arr != null) {
                sw.println("return " + ret + ";");
            } else {
                sw.println("return Arrays.asList(" + ret + ");");
            }
        } else if (method.getReturnType().isEnum() != null) {
            sw.println("return " + method.getReturnType().getQualifiedSourceName() + ".valueOf(p.getStr(\""
                    + name + "\"));");
        } else {
            sw.println("System.err.println(\"JsonBuilderGenerator WARN: unknown return type " + retType + " "
                    + ifaceName + "." + name + "()\"); ");
            // We return the object because probably the user knows how to handle it
            sw.println("return p.get(\"" + name + "\");");
        }
        sw.outdent();
        sw.println("}");
    } else if (params.length == 1) {
        JType type = params[0].getType();
        JArrayType arr = type.isArray();
        JParameterizedType list = type.isParameterized();

        sw.print("(" + type.getParameterizedQualifiedSourceName() + " a)");
        sw.println("{");
        sw.indent();
        if (arr != null || list != null) {
            String a = "a";
            if (list != null) {
                a = "a.toArray(new " + list.getTypeArgs()[0].getQualifiedSourceName() + "[0])";
            }
            sw.println("setArrayBase(\"" + name + "\", " + a + ");");
        } else if (type.getParameterizedQualifiedSourceName().matches("java.util.Date")) {
            sw.println("p.setNumber(\"" + name + "\", a.getTime());");
        } else if (type.getParameterizedQualifiedSourceName().matches(
                "(java.lang.(Character|Long|Double|Integer|Float|Byte)|(char|long|double|int|float|byte))")) {
            sw.println("p.setNumber(\"" + name + "\", a);");
        } else if (type.getParameterizedQualifiedSourceName().matches("(java.lang.Boolean|boolean)")) {
            sw.println("p.setBoolean(\"" + name + "\", a);");
        } else if (type.getParameterizedQualifiedSourceName().matches("com.cgxlib.xq.client.Function")) {
            sw.println("p.setFunction(\"" + name + "\", a);");
        } else if (type.isEnum() != null) {
            sw.println("p.set(\"" + name + "\", a.name());");
        } else {
            sw.println("set(\"" + name + "\", a);");
        }
        if (!"void".equals(retType)) {
            if (isTypeAssignableTo(method.getReturnType(), method.getEnclosingType())) {
                sw.println("return this;");
            } else {
                sw.println("return null;");
            }
        }
        sw.outdent();
        sw.println("}");
    }
}

From source file:com.ekuefler.supereventbus.rebind.EventRegistrationWriter.java

License:Apache License

private String getFirstParameterType(JMethod method) {
    // If the parameter type is primitive, box it
    JType type = method.getParameterTypes()[0];
    if (type.isPrimitive() != null) {
        if (type.isPrimitive() == JPrimitiveType.BOOLEAN) {
            return Boolean.class.getName();
        } else if (type.isPrimitive() == JPrimitiveType.BYTE) {
            return Byte.class.getName();
        } else if (type.isPrimitive() == JPrimitiveType.CHAR) {
            return Character.class.getName();
        } else if (type.isPrimitive() == JPrimitiveType.DOUBLE) {
            return Double.class.getName();
        } else if (type.isPrimitive() == JPrimitiveType.FLOAT) {
            return Float.class.getName();
        } else if (type.isPrimitive() == JPrimitiveType.INT) {
            return Integer.class.getName();
        } else if (type.isPrimitive() == JPrimitiveType.LONG) {
            return Long.class.getName();
        } else if (type.isPrimitive() == JPrimitiveType.SHORT) {
            return Short.class.getName();
        }//from  w ww. ja v  a 2  s.  co  m
    }

    // Otherwise return the fully-qualified type name
    return type.getQualifiedSourceName();
}

From source file:com.github.gilbertotorrezan.gwtviews.rebind.PresenterGenerator.java

License:Open Source License

private String getInjectorMethod(TreeLogger logger, JClassType injector, String injectorMethod,
        String className) throws UnableToCompleteException {
    if (injectorMethod != null && !injectorMethod.isEmpty()) {
        try {/* w w w.j a v  a2s .  co m*/
            injector.getMethod(injectorMethod, new JType[0]);
        } catch (NotFoundException e) {
            logger.log(Type.WARN, "The injector method \"" + injectorMethod + "\" was not found on class "
                    + injector.getQualifiedSourceName());
            //a compiler error will be trigged if the method really doesn't exist
        }
        return injectorMethod;
    } else {
        String methodName = null;
        JMethod[] methods = injector.getInheritableMethods();
        for (JMethod method : methods) {
            JType returnType = method.getReturnType();
            if (returnType.getQualifiedSourceName().equals(className)) {
                if (methodName != null) {
                    logger.log(Type.ERROR, "The injector " + injector.getName()
                            + " has more than one method with " + className
                            + " as return type. Use the \"injectorMethod\" property to specify which one should be used.");
                    throw new UnableToCompleteException();
                }
                methodName = method.getName();
            }
        }
        if (methodName == null) {
            logger.log(Type.INFO, "The injector " + injector.getName() + " has no methods with " + className
                    + " as return type. The View will not be injected.");
            return null;
        }
        return methodName;
    }
}

From source file:com.github.ludorival.dao.gwt.rebind.EntityManagerGenerator.java

License:Apache License

private BeanMetadata create(GeneratorContext context, TreeLogger logger, String packageName, JClassType type,
        Class<?> classAdapter, IsEntity anno) throws TypeOracleException {
    String beanName = anno == null || anno.aliasName().isEmpty() ? type.getName() : anno.aliasName();
    Source implementation = null;
    JClassType implType = type;/*from   w  ww  .  j  a  va2s  . c  om*/
    TypeOracle typeOracle = context.getTypeOracle();
    if (type.isInterface() != null) {
        implType = null;
        JClassType[] types = type.getSubtypes();
        log(logger, Type.DEBUG, "Get all sub types of %s : %s", type, Arrays.toString(types));
        if (types != null && types.length > 0) {
            for (JClassType jClassType : types) {
                if (isInstantiable(jClassType, logger)) {
                    implType = jClassType;
                    implementation = new Source(implType.getPackage().getName(), implType.getName());
                    break;
                }

            }

        }
        if (implType == null) {
            log(logger, Type.ERROR, "The type %s has not valid subtypes " + "%s !", type,
                    Arrays.toString(types));
            return null;
        }
    }
    if (!implType.isDefaultInstantiable())
        return null;
    String prefix = classAdapter.getSimpleName().replace("Adapter", "");
    boolean isEntity = anno != null;
    String className = prefix + beanName;
    if (parseOnlyInterface && implType != type)
        className += "Light";
    PrintWriter writer = context.tryCreate(logger, packageName, className);
    if (writer == null) {
        return new BeanMetadata(type, className, implementation, isEntity);
    }

    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, className);
    logger.log(Type.DEBUG, "Create Entity " + factory.getCreatedClassName());

    factory.setSuperclass(classAdapter.getSimpleName() + "<" + type.getName() + ">");
    factory.addImport(RuntimeException.class.getName());
    factory.addImport(classAdapter.getName());
    factory.addImport(type.getQualifiedSourceName());
    if (isEntity) {
        factory.addImport(ArrayList.class.getName());
        factory.addImport(Collection.class.getName());
    }
    factory.addImport(HashMap.class.getName());
    factory.addImport(Property.class.getName());
    factory.addImport(Property.class.getName() + ".Kind");
    factory.addImport(Index.class.getName());
    factory.addImport(implType.getQualifiedSourceName());

    factory.addImport("javax.annotation.Generated");
    factory.addAnnotationDeclaration("@Generated(" + "value=\"" + AdapterEntity.class.getName() + "\", "
            + "date=\"" + new Date() + "\", " + "comments=\"Generated by DAO-GWT project.\")");

    SourceWriter sourceWriter = factory.createSourceWriter(context, writer);

    sourceWriter.println("//AUTO GENERATED FILE BY DAO-GWT " + getClass().getName() + ". DO NOT EDIT!\n");

    sourceWriter.println("private static HashMap<String,Property<%s,?>> PROPERTIES = "
            + "new HashMap<String,Property<%s,?>>();", type.getName(), type.getName());
    if (isEntity) {
        factory.addImport(ArrayList.class.getName());
        factory.addImport(Index.class.getName());
        sourceWriter.println("private static Collection<Index> INDEXES = " + "new ArrayList<Index>();");

    }
    sourceWriter.println("static {");
    sourceWriter.indent();
    JClassType interfaz = type != implType ? type : null;
    JMethod[] methods = parseOnlyInterface ? type.getInheritableMethods() : implType.getInheritableMethods();
    for (JMethod method : methods) {
        String name = method.getName();
        //Check if the method has a IsIgnored annotation before to continue
        IsIgnored ignored = method.getAnnotation(IsIgnored.class);
        if (ignored != null) {

            log(logger, Type.DEBUG, EXPLICITELY_IGNORED, name, implType);
            continue;
        }
        boolean startsWithGet = name.startsWith("get");
        boolean startsWithIs = name.startsWith("is");
        if (!startsWithGet && !startsWithIs) {
            log(logger, Type.DEBUG, IGNORE_METHOD, name, implType);
            continue;
        }

        //check no parameters
        if (method.getParameterTypes().length != 0) {
            log(logger, Type.WARN, NO_PARAMETER_GETTER, name, implType);
            continue;
        }
        //check return type
        JType returnType = method.getReturnType();
        if (returnType == null || returnType.getQualifiedSourceName().equals(Void.class.getName())
                || returnType.getQualifiedSourceName().equals(void.class.getName())) {
            log(logger, Type.DEBUG, VOID_GETTER, name + "" + returnType, implType);
            continue;
        }
        //change the format of the name getXyy ==> xyy
        String getterSetter = name;
        if (startsWithGet)
            getterSetter = name.substring(3);
        else if (startsWithIs)
            getterSetter = name.substring(2);
        name = getterSetter.substring(0, 1).toLowerCase() + getterSetter.substring(1);
        // check if the getter has an annotation
        IsIndexable indexable = method.getAnnotation(IsIndexable.class);
        boolean isIndexable = indexable != null;
        if (isIndexable && !isEntity)
            log(logger, Type.WARN, ONLY_ENTITY_FOR_INDEX, name, implType, IsEntity.class);

        isIndexable = isIndexable && isEntity;//only entity can defined indexable element

        String indexName = isIndexable ? indexable.aliasName() : "";
        String[] compositeIndexes = isIndexable ? indexable.compoundWith() : new String[0];
        Kind kind = null;
        JType typeOfCollection = null;
        String typeOfCollectionString = "null";

        if (!isPrimitive(returnType)) {

            //load complex properties except Key
            if (returnType.isEnum() != null) {
                kind = Kind.ENUM;
            } else {
                boolean isPrimitive = false;
                boolean isEnum = false;
                JParameterizedType pType = returnType.isParameterized();
                JType collection = typeOracle.parse(Collection.class.getName());

                if (pType != null && pType.getRawType().isAssignableTo(collection.isClassOrInterface())) {
                    JClassType[] types = pType.getTypeArgs();
                    kind = Kind.COLLECTION_OF_PRIMITIVES;
                    if (types.length > 1) {
                        log(logger, Type.DEBUG, CANNOT_PROCESS_PARAMETERIZED_TYPE, returnType, implType);
                        continue;
                    }
                    typeOfCollection = types[0];
                    typeOfCollectionString = typeOfCollection.getQualifiedSourceName() + ".class";
                    log(logger, Type.DEBUG, "The type of the collection is %s", typeOfCollectionString);
                    isPrimitive = isPrimitive(typeOfCollection);
                    isEnum = typeOfCollection.isEnum() != null;
                }
                if (!isPrimitive) {

                    if (isEnum && kind != null) {
                        kind = Kind.COLLECTION_OF_ENUMS;
                    } else {
                        JClassType classType = typeOfCollection != null ? typeOfCollection.isClassOrInterface()
                                : returnType.isClassOrInterface();
                        boolean isBean = isBean(classType);
                        if (isBean) {
                            log(logger, Type.DEBUG, "The property %s is well a type %s", name, classType);
                            if (kind == null)
                                kind = Kind.BEAN;
                            else
                                kind = Kind.COLLECTION_OF_BEANS;
                        } else {
                            log(logger, Type.DEBUG, "The property %s has not a bean type %s", name, classType);
                            continue;
                        }
                    }

                }
            }

        }
        assert kind != null;

        boolean isMemo = method.getAnnotation(IsMemo.class) != null;
        String oldName = "null";
        OldName oldNameAnno = method.getAnnotation(OldName.class);
        if (oldNameAnno != null)
            oldName = "\"" + oldNameAnno.value() + "\"";
        //create a property
        if (kind == Kind.BEAN || kind == Kind.COLLECTION_OF_BEANS)
            factory.addImport(returnType.getQualifiedSourceName());
        String valueType = "";
        JClassType classType = returnType.isClassOrInterface();
        JPrimitiveType primitiveType = returnType.isPrimitive();
        if (classType != null)
            valueType = classType.getQualifiedSourceName();
        else if (primitiveType != null) {
            valueType = primitiveType.getQualifiedBoxedSourceName();
        }

        sourceWriter.println("{ //Property %s", name);
        sourceWriter.indent();
        sourceWriter.print("Index index =");
        if (isIndexable) {
            if (indexName.isEmpty())
                indexName = name;
            sourceWriter.println("new Index(\"%s\",\"%s\",new String[]{%s});", indexName, name,
                    String.join(",", compositeIndexes));
        } else
            sourceWriter.println("null;");
        boolean useKeyAsString = anno != null ? (name.equals(anno.keyName()) ? anno.useKeyAsString() : false)
                : false;

        KeyOf keyOf = method.getAnnotation(KeyOf.class);
        if (keyOf != null) {
            IsEntity isEntity2 = keyOf.entity().getAnnotation(IsEntity.class);
            if (isEntity2 == null) {
                log(logger, Type.ERROR, AdapterEntityManager.KEY_OF_NO_ENTITY, method, keyOf, keyOf.entity(),
                        IsEntity.class);
                continue;
            }
            useKeyAsString = isEntity2.useKeyAsString();
        }
        boolean isHidden = isHidden(method, interfaz);
        sourceWriter.println(
                "Property<%s,%s> property = new Property<%s,%s>(\"%s\",%s,%s.class,%s,%s,%s,%s,index,%s){",
                type.getName(), valueType, type.getName(), valueType, name, oldName,
                returnType.getQualifiedSourceName(), typeOfCollectionString,
                kind != null ? "Kind." + kind.name() : "null", useKeyAsString + "", isMemo + "", isHidden + "");
        sourceWriter.indent();
        sourceWriter.println("@Override");
        sourceWriter.println("public %s get(%s instance){", valueType, type.getName());
        sourceWriter.indent();

        sourceWriter.println("return ((%s)instance).%s();", implType.getName(),
                startsWithGet ? "get" + getterSetter : "is" + getterSetter);
        sourceWriter.outdent();
        sourceWriter.println("}");

        sourceWriter.println("@Override");
        sourceWriter.println("public void set(%s instance, %s value){", type.getName(), valueType);
        sourceWriter.indent();

        if (getSetter(implType, getterSetter, returnType) != null)
            sourceWriter.println("((%s)instance).%s(value);", implType.getName(), "set" + getterSetter);
        else {
            logger.log(Type.WARN, " Not found setter for " + getterSetter);
            sourceWriter.println("throw new RuntimeException(\"No such setter " + getterSetter + " \");");
        }

        sourceWriter.outdent();
        sourceWriter.println("}");
        sourceWriter.outdent();
        sourceWriter.println("};");
        sourceWriter.println("PROPERTIES.put(\"%s\",property);", name);
        if (!oldName.equals("null")) {
            sourceWriter.println("PROPERTIES.put(%s,property);", oldName);
        }
        if (isIndexable)
            sourceWriter.println("INDEXES.add(index);");
        sourceWriter.outdent();
        sourceWriter.println("}");

        log(logger, Type.DEBUG, SUCCESSFUL_ADD_PROPERTY, name + ":" + valueType, implType);

    }
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println();
    sourceWriter.println("public %s(){", className);
    sourceWriter.indent();

    /*
     * boolean asyncReady,
       boolean autoGeneratedFlag,
       String keyName,
       boolean useKeyAsString,
       Class<T> type,Class<? extends T> implType,
       Map<String, Property<T,?>> mapAllProperties, Collection<Index> indexes) {
    super(type,implType,mapAllProperties);
     */
    if (isEntity)
        sourceWriter
                .println(String.format("super(\"%s\",%s,%s,\"%s\",%s,%s.class,%s.class,PROPERTIES,INDEXES);",
                        anno.aliasName().isEmpty() ? type.getName() : anno.aliasName(), anno.asyncReady(),
                        anno.autoGeneratedKey(), anno.keyName(), anno.useKeyAsString(), type.getName(),
                        implType.getName()));
    else {
        sourceWriter.println(
                String.format("super(%s.class,%s.class,PROPERTIES);", type.getName(), implType.getName()));

    }
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println();
    sourceWriter.println("@Override");
    sourceWriter.println("public %s newInstance(){", type.getName());
    sourceWriter.indent();
    sourceWriter.println("return new %s();", implType.getName());
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.outdent();
    sourceWriter.println("}");
    context.commit(logger, writer);

    return new BeanMetadata(type, className, implementation, isEntity);
}