JField[] fields = c.getFields(); if (fields != null) { for (JField field : fields) {
JField[] fields = c.getFields(); if (fields != null) { for (JField field : fields) {
/** * Returns the set of fields that are serializable for a given class type. * This method does not consider any superclass fields. * * @param context the context * @param classType the class for which we want serializable fields * @return array of fields that meet the serialization criteria */ public static JField[] getSerializableFields(GeneratorContext context, JClassType classType) { assert (classType != null); List<JField> fields = new ArrayList<JField>(); JField[] declFields = classType.getFields(); assert (declFields != null); for (JField field : declFields) { if (SerializableTypeOracleBuilder .shouldConsiderForSerialization(TreeLogger.NULL, context, field)) { fields.add(field); } } Collections.sort(fields, FIELD_COMPARATOR); return fields.toArray(new JField[fields.size()]); }
/** * Returns the set of fields that are serializable for a given class type. * This method does not consider any superclass fields. * * @param context the context * @param classType the class for which we want serializable fields * @return array of fields that meet the serialization criteria */ public static JField[] getSerializableFields(GeneratorContext context, JClassType classType) { assert (classType != null); List<JField> fields = new ArrayList<JField>(); JField[] declFields = classType.getFields(); assert (declFields != null); for (JField field : declFields) { if (SerializableTypeOracleBuilder .shouldConsiderForSerialization(TreeLogger.NULL, context, field)) { fields.add(field); } } Collections.sort(fields, FIELD_COMPARATOR); return fields.toArray(new JField[fields.size()]); }
@Override public MetaField[] getDeclaredFields() { final JClassType type = getEnclosedMetaObject().isClass(); if (type != null) { return Arrays.stream(type.getFields()).map(f -> new GWTField(oracle, f)).toArray(s -> new MetaField[s]); } return new MetaField[0]; }
@Override public MetaField[] getDeclaredFields() { final JClassType type = getEnclosedMetaObject().isClass(); if (type != null) { return Arrays.stream(type.getFields()).map(f -> new GWTField(oracle, f)).toArray(s -> new MetaField[s]); } return new MetaField[0]; }
public static Collection<JField> listFields(JClassType type, Class<? extends Annotation> annotationClass) { Collection<JField> methodAnnoted = Lists.newArrayList(); JField[] fields = type.getFields(); for (JField field : fields) { Annotation annotation = field.getAnnotation(annotationClass); if (annotation != null) { methodAnnoted.add(field); } } // Recurse to superclass JClassType superclass = type.getSuperclass(); if (superclass != null) { methodAnnoted.addAll(InjectCreatorUtil.listFields(superclass, annotationClass)); } return methodAnnoted; }
public static Collection<JField> listFields(JClassType type, Class<? extends Annotation> annotationClass) { Collection<JField> methodAnnoted = Lists.newArrayList(); JField[] fields = type.getFields(); for (JField field : fields) { Annotation annotation = field.getAnnotation(annotationClass); if (annotation != null) { methodAnnoted.add(field); } } // Recurse to superclass JClassType superclass = type.getSuperclass(); if (superclass != null) { methodAnnoted.addAll(InjectCreatorUtil.listFields(superclass, annotationClass)); } return methodAnnoted; }
/** * Returns all fields of the type considering inheritance * @return */ public Set<JField> getAllFields(){ LinkedHashSet<JField> fields = new LinkedHashSet<JField>(); JClassType currentType = type; while(currentType.getSuperclass()!=null){ for(JField field : currentType.getFields()){ if (fieldsContain(field, fields)==false) fields.add(field); } currentType = currentType.getSuperclass(); } return fields; }
private JMethod[] retrieveMethodsFromBeanIfNeeded(JMethod[] methods) { if (methods == null || methods.length == 0) { List<JMethod> listOfMethods = new LinkedList<JMethod>(); JDummyClassType dummy = new JDummyClassType(); Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>(); com.google.gwt.dev.javac.typemodel.JTypeParameter[] jtypeParameters = new com.google.gwt.dev.javac.typemodel.JTypeParameter[0]; for (JField field : beanType.getFields()) { if (!field.isTransient() && !field.isStatic()) { JMethod method = JMethodInstancer.instanceMethod(dummy, field.getName(), annotations, jtypeParameters); listOfMethods.add(method); } } methods = listOfMethods.toArray(methods); } return methods; }
private void generateFields(SourceWriter sourceWriter, JClassType classType) throws UnableToCompleteException { for (JField field : classType.getFields()) { BindingField bindingFieldAnnotation = field.getAnnotation(BindingField.class); if (bindingFieldAnnotation != null) { IBindingCreator<? extends Annotation> bindingGenerator = BindingCreatorFactory .getBindingCreator(field); if (bindingGenerator != null) { bindingGenerator.generateFields(field, bindingFieldAnnotation); } } } }
@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()]); }
@Test public void doParse_unhandledFieldTypeRecursion() { Set<? extends JClassType> ownerTypeParentFieldTypeSubField1TypeFlattenedSupertypeHierarchy = Collections.singleton(ownerTypeParentFieldTypeSubField1Type); doReturn(ownerTypeParentFieldTypeSubField1TypeFlattenedSupertypeHierarchy) .when(ownerTypeParentFieldTypeSubField1Type).getFlattenedSupertypeHierarchy(); when(ownerTypeParentFieldTypeSubField1Type.getFields()).thenReturn(new JField[] { ownerTypeParentField }); assertThrows(UnableToCompleteException.class, () -> tested.doParse(ownerType, new ArrayList<>(), ".", "IdPrefix")); //$NON-NLS-1$ //$NON-NLS-2$ }
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; } }
@Test public void doParse_handledFieldTypeRecursion() throws UnableToCompleteException { Set<? extends JClassType> ownerTypeParentFieldTypeSubField1TypeFlattenedSupertypeHierarchy = Collections.singleton(ownerTypeParentFieldTypeSubField1Type); doReturn(ownerTypeParentFieldTypeSubField1TypeFlattenedSupertypeHierarchy) .when(ownerTypeParentFieldTypeSubField1Type).getFlattenedSupertypeHierarchy(); when(ownerTypeParentFieldTypeSubField1Type.getFields()).thenReturn(new JField[] { ownerTypeParentField }); stubFieldIdAnnotation(ownerTypeParentField, "", false); //$NON-NLS-1$ tested.doParse(ownerType, new ArrayList<JClassType>(), ".", "IdPrefix"); //$NON-NLS-1$ //$NON-NLS-2$ List<ElementIdStatement> expected = Arrays.asList( getExpectedStatement("ownerTypeParentField", "IdPrefix_ownerTypeParentField"), //$NON-NLS-1$ //$NON-NLS-2$ getExpectedStatement("ownerTypeField1", "IdPrefix_ownerTypeField1"), //$NON-NLS-1$ //$NON-NLS-2$ getExpectedStatement("ownerTypeField2", "IdPrefix_ownerTypeField2")); //$NON-NLS-1$ //$NON-NLS-2$ assertThat(tested.statements.size(), is(equalTo(expected.size()))); assertThat(tested.statements.containsAll(expected), is(equalTo(true))); }
private Set<String> getEditorFieldCleanupExpressions() { Set<String> result = new LinkedHashSet<>(); for (JClassType typeCandidate : model.getEditorType().getFlattenedSupertypeHierarchy()) { JClassType classType = typeCandidate.isClass(); if (classType != null) { for (JField field : classType.getFields()) { JClassType fieldClassOrInterfaceType = field.getType().isClassOrInterface(); if (fieldClassOrInterfaceType != null // field type assignable to HasCleanup .. && fieldClassOrInterfaceType.isAssignableTo(hasCleanupType) // .. but not assignable to Model && !fieldClassOrInterfaceType.isAssignableTo(baseModelType)) { result.add(String.format( "getEditor().%s", //$NON-NLS-1$ field.getName())); } } } } return result; }
private static void parseFields( TreeLogger logger, JClassType type, Map<String, PropertyAccessorsBuilder> propertiesMap, boolean mixin ) { if ( type.getQualifiedSourceName().equals( "java.lang.Object" ) ) { return; } for ( JField field : type.getFields() ) { if ( field.isStatic() ) { continue; } String fieldName = field.getName(); PropertyAccessorsBuilder property = propertiesMap.get( fieldName ); if ( null == property ) { property = new PropertyAccessorsBuilder( fieldName ); propertiesMap.put( fieldName, property ); } if ( property.getField().isPresent() && !mixin ) { // we found an other field with the same name on a superclass. we ignore it logger.log( Type.INFO, "A field with the same name as '" + field .getName() + "' has already been found on child class" ); } else { property.addField( field, mixin ); } } }