private SortedSet<JClassType> computeOperableTypes(ResourceContext context) { TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType baseInterface = typeOracle.findType(CssResource.class.getCanonicalName()); SortedSet<JClassType> toReturn = new TreeSet<>(new JClassOrderComparator()); JClassType[] cssResourceSubtypes = baseInterface.getSubtypes(); for (JClassType type : cssResourceSubtypes) { if (type.isInterface() != null) { toReturn.add(type); } } return toReturn; }
new JClassOrderComparator()); JClassType[] cssResourceSubtypes = baseInterface.getSubtypes(); for (JClassType type : cssResourceSubtypes) { if (type.isInterface() != null) {
public static boolean isLeaf(JClassType source) { return !(source.getSubtypes() != null && source.getSubtypes().length > 0); }
public static boolean isLeaf(JClassType source) { return !(source.getSubtypes() != null && source.getSubtypes().length > 0); }
/** * Given a SVG tag name, return the corresponding * {@link org.vectomatic.dom.svg.OMSVGElement} subclass. */ private JClassType findSvgDomElementTypeForTag(String tag) { JClassType elementClass = oracle.findType(OMSVGElement.class.getName()); JClassType[] types = elementClass.getSubtypes(); for (JClassType type : types) { TagName annotation = type.getAnnotation(TagName.class); if (annotation != null) { for (String annotationTag : annotation.value()) { if (annotationTag.equals(tag)) { return type; } } } } return elementClass; } // laaglu
/** * Given a SVG tag name, return the corresponding * {@link org.vectomatic.dom.svg.OMSVGElement} subclass. */ private JClassType findSvgDomElementTypeForTag(String tag) { JClassType elementClass = oracle.findType(OMSVGElement.class.getName()); JClassType[] types = elementClass.getSubtypes(); for (JClassType type : types) { TagName annotation = type.getAnnotation(TagName.class); if (annotation != null) { for (String annotationTag : annotation.value()) { if (annotationTag.equals(tag)) { return type; } } } } return elementClass; } // laaglu
private SortedSet<JClassType> computeOperableTypes(ResourceContext context) { TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType baseInterface = typeOracle.findType(CssResource.class.getCanonicalName()); SortedSet<JClassType> toReturn = new TreeSet<>(new JClassOrderComparator()); JClassType[] cssResourceSubtypes = baseInterface.getSubtypes(); for (JClassType type : cssResourceSubtypes) { if (type.isInterface() != null) { toReturn.add(type); } } return toReturn; }
/** * Given a DOM tag name, return the corresponding JSO subclass. */ private JClassType findDomElementTypeForTag(String tag) { JClassType elementClass = oracle.findType("com.google.gwt.dom.client.Element"); JClassType[] types = elementClass.getSubtypes(); for (JClassType type : types) { TagName annotation = type.getAnnotation(TagName.class); if (annotation != null) { for (String annotationTag : annotation.value()) { if (annotationTag.equals(tag)) { return type; } } } } return elementClass; }
/** * Given a DOM tag name, return the corresponding JSO subclass. */ private JClassType findDomElementTypeForTag(String tag) { JClassType elementClass = oracle.findType("com.google.gwt.dom.client.Element"); JClassType[] types = elementClass.getSubtypes(); for (JClassType type : types) { TagName annotation = type.getAnnotation(TagName.class); if (annotation != null) { for (String annotationTag : annotation.value()) { if (annotationTag.equals(tag)) { return type; } } } } return elementClass; }
private SortedSet<JClassType> computeOperableTypes(ResourceContext context) { TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType baseInterface = typeOracle.findType(CssResource.class.getCanonicalName()); SortedSet<JClassType> toReturn = new TreeSet<JClassType>(new JClassOrderComparator()); JClassType[] cssResourceSubtypes = baseInterface.getSubtypes(); for (JClassType type : cssResourceSubtypes) { if (type.isInterface() != null) { toReturn.add(type); } } return toReturn; }
/** * Given a DOM tag name, return the corresponding JSO subclass. */ private JClassType findDomElementTypeForTag(String tag) { JClassType elementClass = oracle.findType("com.google.gwt.dom.client.Element"); JClassType[] types = elementClass.getSubtypes(); for (JClassType type : types) { TagName annotation = type.getAnnotation(TagName.class); if (annotation != null) { for (String annotationTag : annotation.value()) { if (annotationTag.equals(tag)) { return type; } } } } return elementClass; }
/** * Given a DOM tag name, return the corresponding JSO subclass. */ private JClassType findDomElementTypeForTag(String tag) { JClassType elementClass = oracle.findType("com.google.gwt.dom.client.Element"); JClassType[] types = elementClass.getSubtypes(); for (JClassType type : types) { TagName annotation = type.getAnnotation(TagName.class); if (annotation != null) { for (String annotationTag : annotation.value()) { if (annotationTag.equals(tag)) { return type; } } } } return elementClass; }
/** * Returns the immediate subtypes of the erased class argument. */ public static List<JClassType> getImmediateSubtypes(JClassType clazz) { List<JClassType> immediateSubtypes = new ArrayList<JClassType>(); clazz = clazz.getErasedType(); for (JClassType subclass : clazz.getSubtypes()) { JClassType superclass = subclass.getSuperclass(); if (superclass != null) { superclass = superclass.getErasedType(); } if (superclass == clazz || clazz.isInterface() != null && directlyImplementsInterface(subclass, clazz)) { immediateSubtypes.add(subclass); } } return immediateSubtypes; }
/** * Returns the immediate subtypes of the erased class argument. */ public static List<JClassType> getImmediateSubtypes(JClassType clazz) { List<JClassType> immediateSubtypes = new ArrayList<JClassType>(); clazz = clazz.getErasedType(); for (JClassType subclass : clazz.getSubtypes()) { JClassType superclass = subclass.getSuperclass(); if (superclass != null) { superclass = superclass.getErasedType(); } if (superclass == clazz || clazz.isInterface() != null && directlyImplementsInterface(subclass, clazz)) { immediateSubtypes.add(subclass); } } return immediateSubtypes; }
@Override public Set<JType> findStorageTypes() throws UnableToCompleteException{ Set<JType> serializables = new HashSet<>(); JClassType remoteSvcIntf = typeOracle.findType(RemoteService.class.getName()); JClassType[] remoteSvcTypes = remoteSvcIntf.getSubtypes(); for(JClassType remoteSvcType : remoteSvcTypes){ for(JMethod method : remoteSvcType.getMethods()){ JType type = method.getReturnType(); if(JPrimitiveType.VOID != type){ addIfIsValidType(serializables, type); } for(JType param : method.getParameterTypes()){ addIfIsValidType(serializables, param); } } } return serializables; }
@Override public Set<JType> findStorageTypes() { Set<JType> serializables = new HashSet<>(); JClassType keyProviderIntf = typeOracle.findType(StorageKeyProvider.class.getName()); JClassType[] keyProviderTypes = keyProviderIntf.getSubtypes(); for (JClassType keyProviderType : keyProviderTypes) { for (JMethod method : keyProviderType.getMethods()) { if(method.isStatic() || method.getParameters().length > 1){ continue; } JParameterizedType storageKeyType = method.getReturnType().isParameterized(); if (storageKeyType != null) { JClassType type = storageKeyType.getTypeArgs()[0]; addIfIsValidType(serializables, type); } } } return serializables; } }
/** * <p>filterSubtypesForSerialization</p> * * @param logger a {@link com.google.gwt.core.ext.TreeLogger} object. * @param configuration a {@link com.github.nmorel.gwtjackson.rebind.RebindConfiguration} object. * @param type a {@link com.google.gwt.core.ext.typeinfo.JClassType} object. * @return a {@link com.google.gwt.thirdparty.guava.common.collect.ImmutableList} object. */ 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 ); } } } return builder.build(); }
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { initialized = true; this.logger = logger; this.context = context; JClassType type = null; try { type = context.getTypeOracle().getType( IDomainObject.class.getName()); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, "Cannot find class", e); throw new UnableToCompleteException(); } JClassType[] types = type.getSubtypes(); try { logger.log(Type.INFO, "Enable " + typeName + " for introspection"); return doGenerate(typeName, types); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, null, e); throw new UnableToCompleteException(); } }
@Override protected void doGenerate(SourceWriter sourceWriter) throws UnableToCompleteException { JClassType adapterProviderClassType = typeOracle.findType(getAdapterProviderBaseClass().getCanonicalName()); JClassType[] adapterProviders = adapterProviderClassType.getSubtypes(); sourceWriter.println("public void registerAllAdapters() {"); sourceWriter.indent(); for (JClassType adapterProviderImplementationClassType : adapterProviders) { if (!adapterProviderImplementationClassType.isAbstract()) { boolean found = false; for (JConstructor constructor :adapterProviderImplementationClassType.getConstructors()) { if (constructor.getParameters().length == 0) { found = true; } } if (found) { sourceWriter.println(BeanAdapterFactory.class.getSimpleName() + ".addProvider(new " + adapterProviderImplementationClassType.getQualifiedSourceName() + "());"); } } } sourceWriter.indent(); sourceWriter.println("}"); }
private void writeSubtypes( SourceWriter sourceWriter, JClassType classType, String variableName, int nameIndex, int writeType, int depth ) { // Avoid going too deep if ( depth > MAXIMUM_DEPTH ) { return; } // For each subclass... for ( JClassType subtype : classType.getSubtypes() ) { // ...write its subclass-level properties... writeProperties( sourceWriter, subtype, variableName, nameIndex, true, classType, writeType, depth ); } // ...and for the base class write every superclass JClassType typeTraversal = classType; while ( typeTraversal != null ) { writeProperties( sourceWriter, typeTraversal, variableName, nameIndex, false, classType, writeType, depth ); typeTraversal = typeTraversal.getSuperclass(); } // ...or error for an unknown property sourceWriter.println(); sourceWriter.println( "// Unknown" ); sourceWriter.println(); sourceWriter.println( "throw new RuntimeException( \"Unknown property '\" + names[" + nameIndex + "] + \"' of " + classType.getParameterizedQualifiedSourceName() + "\" );" ); }