Refine search
if (c != null && (isVisible(c.getSuperclass()))) superClass = c.getSuperclass().getErasedType().getQualifiedSourceName() + ".class"; String assignables = null; String interfaces = null; 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 + "), "); 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; logger.log(Type.INFO, c.getName() + " can't be instantiated. Constructors not generated");
if (setterName != null || field.isDefaultAccess() || field.isProtected() || field.isPublic()) { JsonProperty jsonPropertyAnnotation = getAnnotation(field, JsonProperty.class); String name = field.getName(); String jsonName = name; String expression = locator.decodeExpression(field.getType(), objectGetter, style); boolean isShort = field.getType().isPrimitive() == JPrimitiveType.SHORT; String defaultValue = getDefaultValue(field); getLogger().log(DEBUG, "private field gets ignored: " + field.getEnclosingType().getQualifiedSourceName() + "." + field.getName());
if (type.getQualifiedSourceName().contains("-")) { nesting--; return; String name = type.getQualifiedSourceName(); try { ConfigurationProperty prop; if (types.contains(type.getErasedType())) { nesting--; return; JField[] fields = c.getFields(); if (fields != null) { for (JField field : fields) { gatherTypes(field.getType().getErasedType(), types); gatherTypes(c.getSuperclass(), types); JClassType[] interfaces = c.getImplementedInterfaces(); if (interfaces != null) { for (JClassType i : interfaces) { 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);
public static JField findField(final TreeLogger logger, final JClassType type, final String name, final boolean declared) { for (final JField field : type.getFields()) { if (field.getName().equals(name)) { if (declared){ if (!field.getEnclosingType().getQualifiedSourceName().equals(type.getQualifiedSourceName())) { logger.log(Type.TRACE, "Field with same name and different enclosing type skipped because declared-only field was requested;\n" +field.getEnclosingType().getQualifiedSourceName()+" != "+type.getQualifiedSourceName()); continue; } } else { if (!field.isPublic()) { logger.log(Type.TRACE, "Non-public field " +field.getEnclosingType().getName()+"."+ field.getName() + " skipped because declared=false."); continue; } } return field; } } return declared || type.getSuperclass() == null ? null: findField(logger, type.getSuperclass(), name, declared); }
declaredConstructors.clear(); declaredFields.clear(); final String typeName = type.getQualifiedSourceName(); for (JField field : type.getFields()) { if (field.getName().equals("serialVersionUID")) continue; if (field.getEnclosingType().getQualifiedSourceName().equals(typeName)) { GwtRetention retention = field.getAnnotation(GwtRetention.class); if (retention == null) retention = strategy.fieldRetention(); declaredFields.put(field.getName(), new ReflectionUnit<JField>(field, retention)); for (JMethod method : type.getMethods()) { if (method.getEnclosingType().getQualifiedSourceName().equals(typeName)) { GwtRetention retention = method.getAnnotation(GwtRetention.class); if (retention == null) retention = strategy.methodRetention(); declaredMethods.put(method.getJsniSignature(), new ReflectionUnit<JMethod>(method, retention)); if (!uniqueNames.add(method.getName())) { overloadedMethods.add(method.getName());
public String getOrMakeFieldFactory(TreeLogger logger, GeneratorContext ctx, com.google.gwt.core.ext.typeinfo.JField field, com.google.gwt.core.ext.typeinfo.JType classType, ReflectionManifest manifest, boolean declaredOnly) throws UnableToCompleteException { // get cached manifest for this type String clsName = classType.getQualifiedSourceName(); TypeOracle oracle = ctx.getTypeOracle(); String name = field.getName(); JClassType cls = oracle.findType(clsName); if (cls == null) { logger.log(Type.ERROR, "Unable to find enclosing class "+clsName); throw new UnableToCompleteException(); } String fieldFactoryName = getFieldFactoryName(cls, name); JClassType factory; 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; }
protected String toStringExpression(JParameter arg) throws UnableToCompleteException { Attribute attribute = getAnnotation(arg, Attribute.class); if (attribute != null) { if (arg.getType().isClass().getField(attribute.value()) != null && arg.getType().isClass().getField(attribute.value()).isPublic()) { return "(" + arg.getName() + "." + attribute.value() + "+ \"\")"; } String publicGetter = "get" + attribute.value().substring(0, 1).toUpperCase() + attribute.value().substring(1); for (JMethod jMethod : arg.getType().isClass().getMethods()) { if (jMethod.getName().equals(publicGetter)) { return "(" + arg.getName() + "." + publicGetter + "()" + "+ \"\")"; } } getLogger().log(ERROR, "Neither public argument " + attribute.value() + " nor public getter " + publicGetter + " found!"); throw new UnableToCompleteException(); } return toStringExpression(arg.getType(), arg.getName()); }
if ( !useJsni ) { if ( useMethod ) { return new Accessor( CodeBlock.builder().add( beanName + "." + method.get().getName() + "()" ).build() ); } else { return new Accessor( CodeBlock.builder().add( beanName + "." + field.get().getName() ).build() ); final JClassType enclosingType; if ( useMethod ) { fieldType = method.get().getReturnType(); enclosingType = method.get().getEnclosingType(); } else { fieldType = field.get().getType(); enclosingType = field.get().getEnclosingType(); jsniCode.addStatement( "return bean.@$L::$L()()", enclosingType.getQualifiedSourceName(), method.get().getName() ); } else { jsniCode.addStatement( "return bean.@$L::$L", enclosingType.getQualifiedSourceName(), field.get().getName() );
@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()]); }
private String getElementTypes (JField f) { StringBuilder b = new StringBuilder(); JParameterizedType params = f.getType().isParameterized(); if (params != null) { JClassType[] typeArgs = params.getTypeArgs(); b.append("new Class[] {"); for (JClassType typeArg : typeArgs) { if (typeArg.isWildcard() != null) b.append("null"); else if (!isVisible(typeArg)) b.append("null"); else if (typeArg.isClassOrInterface() != null) b.append(typeArg.isClassOrInterface().getQualifiedSourceName()).append(".class"); else if (typeArg.isParameterized() != null) b.append(typeArg.isParameterized().getQualifiedBinaryName()).append(".class"); else b.append("null"); b.append(", "); } b.append("}"); return b.toString(); } return "null"; }
/** * Method is used to determine is mapping/binding is one to one * e.g. One value to single value component - String <-> TextBox * @return true if binding is one to one * false otherwise * @throws UnableToCompleteException */ private Class<? extends Annotation> getFieldBindingType(JField field) throws UnableToCompleteException { if (!((field.getType()) instanceof JClassType)) { logger.log(Type.ERROR, "Only class type bindings are allowed. Cannot provide binding to " + field.getType() + " type"); throw new UnableToCompleteException(); } JClassType classType = (JClassType)field.getType(); BindingComponent bindingComponent = getBindingComponent(classType); if (bindingComponent == null) { logger.log(Type.ERROR, "Unable to find binding component for " + (classType == null ? "null" : classType.getQualifiedSourceName()) + ". Did you forgot to create an adapter provider?"); throw new UnableToCompleteException(); } return bindingComponent.bindingType; }
for (JField field : enclosingType.getFields()) { if (!field.isStatic()) { continue; } else if (field.isPublic()) { } else if (field.isProtected() || field.isPrivate()) { continue; } else if (!enclosingType.getPackage().equals( writer.getOwnerClass().getOwnerType().getPackage())) { + field.getName(), field.getName());
private static JType findType( TreeLogger logger, PropertyAccessors fieldAccessors, JacksonTypeOracle typeOracle, boolean getterAutoDetected, boolean setterAutoDetected, boolean fieldAutoDetected ) throws UnableToCompleteException { JType type; if ( getterAutoDetected && fieldAccessors.getGetter().isPresent() ) { type = fieldAccessors.getGetter().get().getReturnType(); } else if ( setterAutoDetected && fieldAccessors.getSetter().isPresent() ) { type = fieldAccessors.getSetter().get().getParameters()[0].getType(); } else if ( fieldAutoDetected && fieldAccessors.getField().isPresent() ) { type = fieldAccessors.getField().get().getType(); } else if ( fieldAccessors.getParameter().isPresent() ) { type = fieldAccessors.getParameter().get().getType(); } else { logger.log( Type.ERROR, "Cannot find the type of the property " + fieldAccessors.getPropertyName() ); throw new UnableToCompleteException(); } Optional<Annotation> jd = fieldAccessors.getAnnotation( "com.fasterxml.jackson.databind.annotation.JsonDeserialize" ); if ( jd.isPresent() ) { return typeOracle.replaceType( logger, type, jd.get() ); } return type; }
public String generateFieldMapperGenerator(TypeOracle oracle, JField targetWidget, JType targetType, JField targetEntityMember, JField targetEntityField) { InputStream istream = this.getClass().getResourceAsStream("TextBoxFMGenerator.mv"); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("typeOracle", oracle); vars.put("targetWidget", targetWidget.getType().isClassOrInterface().getQualifiedSourceName()); vars.put("targetType", targetType.isClassOrInterface().getQualifiedSourceName()); vars.put("fieldType", targetEntityMember.getType().isClassOrInterface().getQualifiedSourceName()); vars.put("fieldName", targetEntityMember.getName()); return (String) TemplateRuntime.eval(istream, null, new MapVariableResolverFactory(vars), null); }
public static int getModifiers(JField field) { int mod; if (field.isPublic()) mod = Modifier.PUBLIC; else if (field.isPrivate()) mod = Modifier.PRIVATE; else if (field.isProtected()) mod = Modifier.PROTECTED; else mod = 0;//Package Protected if (field.isFinal()) mod |= Modifier.FINAL; if (field.isStatic()) mod |= Modifier.STATIC; if (field.isTransient()) mod |= Modifier.TRANSIENT; if (field.isVolatile()) mod |= Modifier.VOLATILE; return mod; }
public static List<Injection> getInjectedFields(JClassType dType) { List<Injection> injects = new ArrayList<Injection>(); for (JField f : dType.getFields()) { if(f.isAnnotationPresent(NgInjected.class)) { JClassType pType = f.getType().isClassOrInterface(); if (pType != null) { NgInject pInject = pType.getAnnotation(NgInject.class); if (pInject != null) { injects.add(Injection.create(pType, f.getName(),pInject.name())); } } } } return injects; } }
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; }
private List<JField> getOrderedFields(List<JField> fields, JConstructor creator) throws UnableToCompleteException { List<JField> orderedFields = new ArrayList<JField>(); for (JParameter param : creator.getParameters()) { JsonProperty prop = getAnnotation(param, JsonProperty.class); if (prop != null) { for (JField field : fields) { if (field.getName().equals(prop.value())) { orderedFields.add(field); } } } else { getLogger().log(ERROR, "a constructor annotated with @JsonCreator requires that all paramaters are annotated with " + "@JsonProperty."); throw new UnableToCompleteException(); } } return orderedFields; }
@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() + "'"; } };
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(); }