@Override public MetaClass getDeclaringClass() { return GWTClass.newInstance(oracle, field.getEnclosingType()); }
@Override public MetaClass getDeclaringClass() { return GWTClass.newInstance(oracle, field.getEnclosingType()); }
@Override public String getDeclaringClassName() { return field.getEnclosingType().getName(); }
@Override public String getDeclaringClassName() { return field.getEnclosingType().getName(); }
private static void logFinalField(TreeLogger logger, GeneratorContext context, JField field) { TreeLogger.Type logLevel; if (Shared.shouldSuppressNonStaticFinalFieldWarnings(logger, context)) { logLevel = TreeLogger.DEBUG; } else if (isManuallySerializable(field.getEnclosingType())) { // If the type has a custom serializer, assume the programmer knows best. logLevel = TreeLogger.DEBUG; } else { logLevel = TreeLogger.WARN; } logger.branch(logLevel, "Field '" + field + "' will not be serialized because it is final"); }
private static void logFinalField(TreeLogger logger, GeneratorContext context, JField field) { TreeLogger.Type logLevel; if (Shared.shouldSuppressNonStaticFinalFieldWarnings(logger, context)) { logLevel = TreeLogger.DEBUG; } else if (isManuallySerializable(field.getEnclosingType())) { // If the type has a custom serializer, assume the programmer knows best. logLevel = TreeLogger.DEBUG; } else { logLevel = TreeLogger.WARN; } logger.branch(logLevel, "Field '" + field + "' will not be serialized because it is final"); }
@Override public MetaField[] getFields() { final List<MetaField> fields = Lists.newArrayList(); JClassType type = getEnclosedMetaObject().isClass(); while (type != null) { for (final JField field : type.getFields()) { // In GWT 2.7 java.lang.Object contains two public fields castableTypeMap and typeMarker that we don't want. if (field.isPublic() && !field.getEnclosingType().getQualifiedSourceName().equals("java.lang.Object")) { fields.add(new GWTField(oracle, field)); } } type = type.getSuperclass(); } return fields.toArray(new MetaField[fields.size()]); }
@Override public MetaField[] getFields() { final List<MetaField> fields = Lists.newArrayList(); JClassType type = getEnclosedMetaObject().isClass(); while (type != null) { for (final JField field : type.getFields()) { // In GWT 2.7 java.lang.Object contains two public fields castableTypeMap and typeMarker that we don't want. if (field.isPublic() && !field.getEnclosingType().getQualifiedSourceName().equals("java.lang.Object")) { fields.add(new GWTField(oracle, field)); } } type = type.getSuperclass(); } return fields.toArray(new MetaField[fields.size()]); }
/** * * @param field * @return the name for the setter for the specified field or null if a * setter can't be found. */ private String getSetterName(JField field) { String fieldName = "set" + getMiddleNameForPrefixingAsAccessorMutator(field.getName()); JClassType type = field.getEnclosingType(); if (exists(type, field, fieldName, true)) { return fieldName; } return null; }
/** * * @param field * @return the name for the setter for the specified field or null if a * setter can't be found. */ private String getSetterName(JField field) { String fieldName = "set" + getMiddleNameForPrefixingAsAccessorMutator(field.getName()); JClassType type = field.getEnclosingType(); if (exists(type, field, fieldName, true)) { return fieldName; } return null; }
private boolean includeField(JField field, Set<Class<? extends Annotation>> mustHaveAnnotations) { if (mustHaveAnnotations.isEmpty()) { return true; } for (Class<? extends Annotation> a : mustHaveAnnotations) { if (field.isAnnotationPresent(a)) { return true; } } logger.debug("Skipping field %s in %s as it is not annotated with any of %s", field.getName(), field .getEnclosingType().getParameterizedQualifiedSourceName(), mustHaveAnnotations); return false; }
@Override public String toString() { JType type = field.getType(); JClassType enclosingType = field.getEnclosingType(); return "'" + type.getParameterizedQualifiedSourceName() + "' is reachable from field '" + field.getName() + "' of type '" + enclosingType.getParameterizedQualifiedSourceName() + "'"; } };
@Override public String toString() { JType type = field.getType(); JClassType enclosingType = field.getEnclosingType(); return "'" + type.getParameterizedQualifiedSourceName() + "' is reachable from field '" + field.getName() + "' of type '" + enclosingType.getParameterizedQualifiedSourceName() + "'"; } };
private Annotation getAnnotation(final PropertyDescriptor ppropertyDescription, final boolean useField, final Class<? extends Annotation> expectedAnnotationClass) { Annotation annotation = null; if (useField) { final JField field = beanType.findField(ppropertyDescription.getPropertyName()); if (field.getEnclosingType().equals(beanType)) { annotation = field.getAnnotation(expectedAnnotationClass); } } else { final JMethod method = beanType.findMethod(asGetter(ppropertyDescription), NO_ARGS); if (method.getEnclosingType().equals(beanType)) { annotation = method.getAnnotation(expectedAnnotationClass); } } return annotation; }
private Annotation getAnnotation(PropertyDescriptor p, boolean useField, Class<? extends Annotation> expectedAnnotationClass) { Annotation annotation = null; if (useField) { JField field = beanType.findField(p.getPropertyName()); if (field.getEnclosingType().equals(beanType)) { annotation = field.getAnnotation(expectedAnnotationClass); } } else { JMethod method = beanType.findMethod(asGetter(p), NO_ARGS); if (method.getEnclosingType().equals(beanType)) { annotation = method.getAnnotation(expectedAnnotationClass); } } return annotation; }
protected boolean skipField(JField field, Set<Class<? extends Annotation>> annotationsToSkip) { if (field.isTransient() || field.isStatic()) { logger.debug("Skipping %s field %s in %s", field.isTransient() ? "transient" : "static", field.getName(), field.getEnclosingType().getParameterizedQualifiedSourceName()); return true; } for (Class<? extends Annotation> a : annotationsToSkip) { if (field.isAnnotationPresent(a)) { logger.debug("Skipping field %s in %s as it is annotated with @%s", field.getName(), field .getEnclosingType().getParameterizedQualifiedSourceName(), a.getClass().getName()); return true; } } return false; }
private Annotation getAnnotation(PropertyDescriptor p, boolean useField, Class<? extends Annotation> expectedAnnotationClass) { Annotation annotation = null; if (useField) { JField field = beanType.findField(p.getPropertyName()); if (field.getEnclosingType().equals(beanType)) { annotation = field.getAnnotation(expectedAnnotationClass); } } else { JMethod method = beanType.findMethod(asGetter(p), NO_ARGS); if (method.getEnclosingType().equals(beanType)) { annotation = method.getAnnotation(expectedAnnotationClass); } } return annotation; }
public String getOrMakeFieldFactory(final TreeLogger logger, final ReflectionGeneratorContext ctx, final com.google.gwt.core.ext.typeinfo.JField field, final com.google.gwt.core.ext.typeinfo.JType classType, final ReflectionManifest manifest, final boolean declaredOnly) throws UnableToCompleteException { // get cached manifest for this type final String clsName = classType.getQualifiedSourceName(); final TypeOracle oracle = ctx.getTypeOracle(); final String name = field.getName(); final JClassType cls = oracle.findType(clsName); if (cls == null) { logger.log(Type.ERROR, "Unable to find enclosing class "+clsName); throw new UnableToCompleteException(); } final String fieldFactoryName = FieldGenerator.getFieldFactoryName(cls, name); JClassType factory; final String pkgName = field.getEnclosingType().getPackage().getName(); factory = oracle.findType(pkgName, fieldFactoryName); if (factory == null) { return generateFieldFactory(logger, ctx, field, fieldFactoryName, manifest); } else { return (pkgName.length()==0?"":pkgName+".")+ fieldFactoryName; } }
public JMethodCall getFieldProvider(final TreeLogger logger, final ReflectionGeneratorContext ctx, final com.google.gwt.core.ext.typeinfo.JField field, final JClassLiteral classLit, final boolean declaredOnly) throws UnableToCompleteException { final String clsName = classLit.getRefType().getName(); final ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ctx.getGeneratorContext()); final String factoryCls = getOrMakeFieldFactory(logger, ctx, field, field.getEnclosingType(), manifest, declaredOnly); ctx.finish(logger); final UnifyAstView ast = ctx.getAst(); final JDeclaredType factory = ast.searchForTypeBySource(factoryCls); // pull out the static accessor method for (final JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Field subclass "+factoryCls); throw new UnableToCompleteException(); }
public JMethodCall getFieldProvider(TreeLogger logger, UnifyAstView ast, com.google.gwt.core.ext.typeinfo.JField field, JClassLiteral classLit, boolean declaredOnly) throws UnableToCompleteException { String clsName = classLit.getRefType().getName(); ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ast.getGeneratorContext()); String factoryCls = getOrMakeFieldFactory(logger, ast.getRebindPermutationOracle().getGeneratorContext(), field, field.getEnclosingType(), manifest, declaredOnly); ast.getGeneratorContext().finish(logger); JDeclaredType factory = ast.searchForTypeBySource(factoryCls); // pull out the static accessor method for (JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Field subclass "+factoryCls); throw new UnableToCompleteException(); }