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; }
@Override public MetaField[] getFields() { final JClassType type = getEnclosedMetaObject().isClassOrInterface(); if (type == null) { return null; } return fromFieldArray(oracle, type.getFields()); }
/** * @param srcWriter * @param type * @param parentVariable * @param added * @param iocContainerVariable * @param configurations */ private static void injectFields( SourcePrinter srcWriter, JClassType type, String parentVariable, Set<String> added, String iocContainerVariable, Map<String, IocConfig<?>> configurations) { for (JField field : type.getFields()) { String fieldName = field.getName(); if (!added.contains(fieldName)) { added.add(fieldName); JType fieldType = field.getType(); if ((fieldType.isPrimitive() == null)) { String injectionExpression = getFieldInjectionExpression(field, iocContainerVariable, configurations); if (injectionExpression != null) { if (JClassUtils.isPropertyVisibleToWrite(type, field, false)) { if (JClassUtils.hasSetMethod(field, type)) { String setterMethodName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); JMethod method = type.findMethod(setterMethodName, new JType[] {field.getType()}); if (method.getAnnotation(Inject.class) == null) // Annotated methods are handled apart { srcWriter.println( fieldType.getQualifiedSourceName() + " field_" + fieldName + " = " + injectionExpression + ";"); srcWriter.println( parentVariable + "." + setterMethodName + "(field_" + fieldName + ");"); } } else { srcWriter.println( parentVariable + "." + fieldName + " = " + injectionExpression + ";"); } } else { throw new IoCException( "IoC Error Field [" + field.getName() + "] from class [" + type.getQualifiedSourceName() + "] is not a writeable property."); } } } } } }