List of usage examples for com.google.gwt.core.ext.typeinfo JClassType getImplementedInterfaces
JClassType[] getImplementedInterfaces();
From source file:ch.unifr.pai.twice.module.rebind.TWICEModuleGenerator.java
License:Apache License
/** * @param classType/* w w w. j av a 2s.co m*/ * @return the class type of the actual component widget provided through the generic annotation */ private JClassType getGenericClass(JClassType classType) { JClassType clazz = null; for (JClassType intf : classType.getImplementedInterfaces()) { if (intf.getQualifiedSourceName().equals(TWICEModule.class.getName())) { JClassType[] generics = intf.isParameterized().getTypeArgs(); // The twice module has only one generic for (JClassType g : generics) clazz = g; } } return clazz; }
From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private void gatherTypes(JType type, List<JType> types) { nesting++;/*from w w w .j a v a2 s . com*/ // 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. jav a 2 s .com // 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 String createTypeGenerator(JType t) { buffer.setLength(0);//w ww .java 2s . 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.LazyGenerator.java
License:Apache License
public String generate(TreeLogger treeLogger, GeneratorContext generatorContext, String requestedClass) throws UnableToCompleteException { TypeOracle oracle = generatorContext.getTypeOracle(); lazyType = oracle.findType("com.cgxlib.xq.client.Lazy"); lazyBaseType = oracle.findType("com.cgxlib.xq.client.LazyBase"); assert lazyType != null : "Can't find Lazy interface type"; assert lazyBaseType != null : "Can't find LazyBase interface type"; JClassType requestedType = oracle.findType(requestedClass); JClassType targetType = null;/* www . j a v a 2 s . c om*/ JClassType nonLazyType = null; for (JClassType inf : requestedType.getImplementedInterfaces()) { if (inf.isAssignableTo(lazyType)) { nonLazyType = inf.isParameterized().getTypeArgs()[0]; targetType = inf.isParameterized().getTypeArgs()[1]; break; } } if (targetType == null) return null; assert targetType != null : "Parameter of Lazy<T> not found"; String genClass = targetType.getPackage().getName() + "." + targetType.getSimpleSourceName() + getImplSuffix(); SourceWriter sw = getSourceWriter(treeLogger, generatorContext, requestedType.getPackage().getName(), targetType.getSimpleSourceName() + getImplSuffix(), targetType.getQualifiedSourceName()); if (sw != null) { generatePreamble(sw, nonLazyType.getQualifiedSourceName(), treeLogger); sw.indent(); for (JMethod method : targetType.getMethods()) { generateMethod(sw, method, nonLazyType.getQualifiedSourceName(), genClass, treeLogger); } sw.outdent(); generateDoneMethod(sw, nonLazyType, treeLogger); sw.commit(treeLogger); } return genClass; }
From source file:com.ekuefler.supereventbus.rebind.EventRegistrationGenerator.java
License:Apache License
private JClassType getTargetType(JClassType interfaceType, TypeOracle typeOracle) { JClassType[] superTypes = interfaceType.getImplementedInterfaces(); return superTypes[0].isParameterized().getTypeArgs()[0]; }
From source file:com.github.gilbertotorrezan.gwtviews.rebind.PresenterGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { final TypeOracle typeOracle = context.getTypeOracle(); JClassType mainType = typeOracle.findType(typeName); JParameterizedType parameterized = mainType.getImplementedInterfaces()[0].isParameterized(); JClassType viewType = parameterized.getTypeArgs()[0]; final String className = viewType.getQualifiedSourceName(); String name = mainType.getName().substring(mainType.getName().lastIndexOf('.') + 1); name = name.substring(0, name.length() - "Presenter".length()); name = name + "_" + name + "PresenterImpl"; PrintWriter writer = context.tryCreate(logger, viewType.getPackage().getName(), name); if (writer == null) { return viewType.getPackage().getName() + "." + name; }/*from ww w . j a v a 2 s . c om*/ ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(viewType.getPackage().getName(), name); factory.addImplementedInterface(AutoPresenter.class.getName()); factory.addImport(Presenter.class.getPackage().getName() + ".*"); factory.addImport("com.google.gwt.user.client.History"); factory.addImport("com.google.gwt.core.client.GWT"); factory.addImport("com.google.gwt.user.client.ui.Widget"); factory.addImport("javax.annotation.Generated"); factory.addImport("java.util.*"); factory.addAnnotationDeclaration("@Generated(" + "value=\"" + PresenterGenerator.class.getName() + "\", " + "date=\"" + new Date() + "\", " + "comments=\"Generated by GWT-Views project.\")"); View view = viewType.getAnnotation(View.class); ViewContainer viewContainer = viewType.getAnnotation(ViewContainer.class); CachePolicy cache; JClassType injectorType = null; String injectorMethod = null; if (view == null) { cache = CachePolicy.ALWAYS; } else { cache = view.cache(); } if (cache == CachePolicy.SAME_URL) { factory.setSuperclass(CachedPresenter.class.getName()); } SourceWriter sourceWriter = factory.createSourceWriter(context, writer); sourceWriter.println("//AUTO GENERATED FILE BY GWT-VIEWS AT " + getClass().getName() + ". DO NOT EDIT!\n"); if (cache == CachePolicy.ALWAYS) { sourceWriter.println("private Widget view; //the cached view"); } Class<?> injector = view == null ? void.class : view.injector(); if (injector.equals(void.class)) { injector = viewContainer == null ? void.class : viewContainer.injector(); } if (!injector.equals(void.class)) { try { injectorType = typeOracle.findType(injector.getName()); injectorMethod = view != null ? view.injectorMethod() : viewContainer.injectorMethod(); injectorMethod = getInjectorMethod(logger, injectorType, injectorMethod, className); } catch (Exception e) { logger.log(Type.ERROR, "Error loading the injector class \"" + injector.getName() + "\": " + e, e); throw new UnableToCompleteException(); } } if (cache == CachePolicy.SAME_URL) { sourceWriter.println("\n@Override\npublic Widget createNewView(URLToken url) {"); } else { sourceWriter.println("\n@Override\npublic Widget getView(URLToken url) {"); } sourceWriter.indent(); switch (cache) { case NEVER: { sourceWriter.println("//code for the CachePolicy.NEVER:"); printInjectorMethod(sourceWriter, className, injectorType, injectorMethod); } break; case ALWAYS: { sourceWriter.println("//code for the CachePolicy.ALWAYS:"); sourceWriter.println("if (this.view == null) {"); sourceWriter.indent(); printInjectorMethod(sourceWriter, className, injectorType, injectorMethod); sourceWriter.println("this.view = view;"); sourceWriter.outdent(); sourceWriter.println("}"); } break; case SAME_URL: { sourceWriter.println("//code for the CachePolicy.SAME_URL:"); printInjectorMethod(sourceWriter, className, injectorType, injectorMethod); } break; } sourceWriter.println("return view;"); sourceWriter.outdent(); sourceWriter.println("}\n"); sourceWriter.outdent(); sourceWriter.println("}\n"); context.commit(logger, writer); return factory.getCreatedClassName(); }
From source file:com.github.ludorival.dao.gwt.rebind.EntityManagerGenerator.java
License:Apache License
private boolean isBean(JClassType returnType) { if (returnType == null) return false; IsBean anno = returnType.getAnnotation(IsBean.class); if (anno != null) return true; JClassType[] types = returnType.getImplementedInterfaces(); if (types == null) return false; for (JClassType type : types) { if (isBean(type)) return true; }/*from w ww. j a va 2 s. c o m*/ return false; }
From source file:com.github.nmorel.gwtjackson.rebind.CreatorUtils.java
License:Apache License
/** * Browse all the hierarchy of the type and return the first corresponding annotation it found * * @param type type/*from ww w.ja v a 2 s. com*/ * @param annotation annotation to find * @param <T> type of the annotation * @param ignoreType type to ignore when browsing the hierarchy * * @return the annotation if found, null otherwise */ private static <T extends Annotation> Optional<T> findFirstEncounteredAnnotationsOnAllHierarchy( RebindConfiguration configuration, JClassType type, Class<T> annotation, Optional<JClassType> ignoreType) { JClassType currentType = type; while (null != currentType) { Optional<JClassType> mixin = configuration.getMixInAnnotations(currentType); if (mixin.isPresent() && mixin.get().isAnnotationPresent(annotation)) { return Optional.of(mixin.get().getAnnotation(annotation)); } if (currentType.isAnnotationPresent(annotation)) { return Optional.of(currentType.getAnnotation(annotation)); } for (JClassType interf : currentType.getImplementedInterfaces()) { if (!ignoreType.isPresent() || !ignoreType.get().equals(interf)) { Optional<T> annot = findFirstEncounteredAnnotationsOnAllHierarchy(configuration, interf, annotation); if (annot.isPresent()) { return annot; } } } currentType = currentType.getSuperclass(); if (ignoreType.isPresent() && ignoreType.get().equals(currentType)) { currentType = null; } } return Optional.absent(); }
From source file:com.github.nmorel.gwtjackson.rebind.ObjectMapperCreator.java
License:Apache License
/** * Extract the type to map from the interface. * * @param interfaceClass the interface//from w ww. ja v a2s . c o m * * @return the extracted type to map * @throws UnableToCompleteException if we don't find the type */ private JClassType extractMappedType(JClassType interfaceClass) throws UnableToCompleteException { JClassType intf = interfaceClass.isInterface(); if (intf == null) { logger.log(TreeLogger.Type.ERROR, "Expected " + interfaceClass + " to be an interface."); throw new UnableToCompleteException(); } JClassType[] intfs = intf.getImplementedInterfaces(); for (JClassType t : intfs) { if (t.getQualifiedSourceName().equals(OBJECT_MAPPER_CLASS)) { return extractParameterizedType(OBJECT_MAPPER_CLASS, t.isParameterized()); } else if (t.getQualifiedSourceName().equals(OBJECT_READER_CLASS)) { return extractParameterizedType(OBJECT_READER_CLASS, t.isParameterized()); } else if (t.getQualifiedSourceName().equals(OBJECT_WRITER_CLASS)) { return extractParameterizedType(OBJECT_WRITER_CLASS, t.isParameterized()); } } logger.log(TreeLogger.Type.ERROR, "Expected " + interfaceClass + " to extend one of the following interface : " + OBJECT_MAPPER_CLASS + ", " + OBJECT_READER_CLASS + " or " + OBJECT_WRITER_CLASS); throw new UnableToCompleteException(); }