List of usage examples for com.google.gwt.core.ext.typeinfo JClassType isStatic
boolean isStatic();
From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private String createTypeGenerator(JType t) { buffer.setLength(0);//from w ww. j av a 2 s . c o 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);//ww w. j ava 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.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)// w ww .j a v a 2 s .c om // 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.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; }/*from w w w. ja v a 2 s . c o m*/ accumulator.add(category); } }
From source file:com.totsp.gwt.freezedry.rebind.SerializableTypeOracleBuilder.java
License:Apache License
/** * Case 1: Type is automatically serializable a) All fields must be * serializable b) All subtypes must be serializable unless we allow subtypes * that are not serializable c) If inherited automatic serialization * superclass must be serializable/*from w ww.j av a 2s. co m*/ * * Case 2: Type is manually serializable a) CSF must be valid b) All * automatically and manually serializable fields must be serializable c) Any * field that is not manually or automatically serializable is okay * * Case 3: Type is neither automatically or manually serializable a) If type * has at least one automatically or manually serializable subtype then we are * okay. b) If type has no serializable subtypes then: i) context is * automatically serializable => error ii) context is manually serializable => * warning iii) context is neither manually nor automatically serializable => * warning. */ private void checkClassOrInterface(TreeLogger logger, JClassType type, boolean validateSubtypes) { if (type == stringClass) { // we know that it is serializable return; } if (type == typeOracle.getJavaLangObject()) { // Object is never serializable setUnserializableAndLog(logger, inManualSerializationContext() ? TreeLogger.WARN : TreeLogger.ERROR, "In order to produce smaller client-side code, 'Object' is not allowed; consider using a more specific type", type); return; } JClassType superclass = type.getSuperclass(); if (superclass != null) { MetaTypeInfo smti = getMetaTypeInfo(superclass); if (smti.qualifiesForSerialization()) { checkType(logger.branch(TreeLogger.DEBUG, "Analyzing superclass:", null), superclass, false); } else { logger.branch(TreeLogger.DEBUG, "Not analyzing superclass '" + superclass.getParameterizedQualifiedSourceName() + "' because it is not assignable to '" + IsSerializable.class.getName() + "' or '" + Serializable.class.getName() + "' nor does it have a custom field serializer", null); } } MetaTypeInfo mti = getMetaTypeInfo(type); if (mti.qualifiesForManualSerialization()) { List failures = CustomFieldSerializerValidator.validate(streamReaderClass, streamWriterClass, mti.getManualSerializer(), type); if (!failures.isEmpty()) { setUnserializableAndLog(logger, TreeLogger.ERROR, failures, type); return; } mti.setSerializable(true); checkFields(logger, type); } else if (mti.qualifiesForAutoSerialization()) { if (type.isLocalType()) { setUnserializableAndLog(logger, TreeLogger.WARN, "Is a local type, it will be excluded from the set of serializable types", type); return; } if (type.isMemberType() && !type.isStatic()) { setUnserializableAndLog(logger, TreeLogger.WARN, "Is nested but not static, it will be excluded from the set of serializable types", type); return; } if (type.isClass() != null && !type.isDefaultInstantiable()) { setUnserializableAndLog(logger, TreeLogger.ERROR, "Was not default instantiable (it must have a zero-argument public constructor or no constructors at all)", type); return; } if (type.isAbstract() && type.getSubtypes().length == 0) { setUnserializableAndLog(logger, TreeLogger.ERROR, "Is abstract and it has no serializable subtypes", type); return; } getMetaTypeInfo(type).setSerializable(true); checkMethods(logger, type); checkFields(logger, type); } if (validateSubtypes) { int nSubtypes = 0; int nSerializableSubtypes = 0; JClassType[] subtypes = type.getSubtypes(); if (subtypes.length > 0) { TreeLogger localLogger = logger.branch(TreeLogger.DEBUG, "Analyzing subclasses:", null); for (int i = 0; i < subtypes.length; ++i) { JClassType subtype = subtypes[i]; MetaTypeInfo smti = getMetaTypeInfo(subtype); if (smti.qualifiesForSerialization()) { checkType(localLogger, subtype, false); ++nSubtypes; if (smti.isSerializable()) { ++nSerializableSubtypes; } else { localLogger.branch(TreeLogger.DEBUG, subtype.getParameterizedQualifiedSourceName() + " is not serializable", null); if (subtype.isLocalType() || subtype.isMemberType() && !subtype.isStatic()) { --nSubtypes; } } } else { localLogger.branch(TreeLogger.DEBUG, "Not analyzing subclass '" + subtype.getParameterizedQualifiedSourceName() + "' because it is not assignable to '" + IsSerializable.class.getName() + "' or '" + Serializable.class.getName() + "' nor does it have a custom field serializer", null); } } } if (mti.qualifiesForAutoSerialization()) { if (nSerializableSubtypes < nSubtypes) { if (!allowUnserializableSubtypesOfAutoSerializableTypes || nSerializableSubtypes == 0) { setUnserializableAndLog(logger, TreeLogger.ERROR, "Not all subtypes are serializable", type); } } } else if (!mti.qualifiesForManualSerialization() && nSerializableSubtypes == 0) { /* * The type does not qualify for either serialization and it has no * serializable subtypes; this is only an error if we are not in the * context of a custom field serializer */ String message = MessageFormat.format( "Type ''{0}'' is not assignable to IsSerializable or java.io.Serializable, it does not have a custom field serializer and it does not have any serializable subtypes", new String[] { type.getParameterizedQualifiedSourceName() }); setUnserializableAndLog(logger, inManualSerializationContext() ? TreeLogger.WARN : TreeLogger.ERROR, message, type); } } }
From source file:com.totsp.gwt.freezedry.rebind.SerializableTypeOracleBuilder.java
License:Apache License
private void logReasonsForUnserializability(TreeLogger logger, JType type) { TreeLogger.Type logType;//from w w w . ja va2 s . c o m MetaTypeInfo mti = getMetaTypeInfo(type); boolean autoSerializable = mti.qualifiesForAutoSerialization(); if (inManualSerializationContext() && !autoSerializable) { logType = TreeLogger.WARN; } else { logType = TreeLogger.ERROR; if (autoSerializable) { JClassType classOrInterface = type.isClassOrInterface(); if (classOrInterface.isLocalType() || (classOrInterface.isMemberType() && !classOrInterface.isStatic())) { logType = TreeLogger.WARN; } } } if (logType == TreeLogger.ERROR) { validationFailed = true; } Set /* <String> */ reasons = mti.getFailures(); Iterator iter = reasons.iterator(); while (iter.hasNext()) { logger.branch(logType, (String) iter.next(), null); } }
From source file:org.gwtportlets.portlet.rebind.WidgetFactoryHelperCreator.java
License:Open Source License
public WidgetFactoryHelperCreator(TreeLogger logger, TypeOracle typeOracle, SourceWriter sw) throws NotFoundException { this.logger = logger; this.typeOracle = typeOracle; this.sw = sw; widgetFactory = typeOracle.getType(WIDGET_FACTORY); containerFactory = typeOracle.getType(CONTAINER_FACTORY); int c = 0;/*from ww w . j a v a 2s . c o m*/ for (JClassType t : typeOracle.getTypes()) { if (t.isClass() != null && !t.isAbstract() && t.isDefaultInstantiable() && t.isStatic() && implementsWidgetFactory(t)) { widgetFactoryMap.put(t, c++); } } }