final Map<String, JType> unfilledRequiredParams = new HashMap<String, JType>(); final OwnerFieldClass ownerFieldClass = OwnerFieldClass.getFieldClass(type, writer.getLogger(), context); if (creator == null) { creator = ownerFieldClass.getUiConstructor(); unfilledRequiredParams.remove(key); } else { JMethod setter = ownerFieldClass.getSetter(key); JParameter[] params = setter == null ? null : setter.getParameters(); unfilledRequiredParams.remove(propertyName); } else { JMethod setter = ownerFieldClass.getSetter(propertyName); if (setter != null) { String n = attribute.getName(); String addMethod = ADD_PROPERTY_TO_SETTER_MAP.get(propertyName); JType stringType = writer.getOracle().findType(String.class.getName()); if (ownerFieldClass.getRawType().findMethod(addMethod, new JType[]{stringType}) != null) { String n = attribute.getName(); String[] value = elem.consumeStringArrayAttribute(n);
public void parse(final XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { this.fieldName = fieldName; this.writer = writer; OwnerFieldClass ownerFieldClass = OwnerFieldClass.getFieldClass(type, writer.getLogger(), uiBinderCtx); uiChildMethods = ownerFieldClass.getUiChildMethods(); // Parse children. elem.consumeChildElements(new Interpreter<Boolean>() { public Boolean interpretElement(XMLElement child) throws UnableToCompleteException { if (isValidChildElement(elem, child)) { handleChild(child); return true; } return false; } }); }
/** * Finds all setters in the class, and puts them in the {@link #setters} * field. * * @param fieldType the type of the field */ private void findSetters(JClassType fieldType) { // Pass one - get all setter methods Map<String, Collection<JMethod>> allSetters = findAllSetters(fieldType); // Pass two - disambiguate ambiguousSetters = new HashSet<String>(); for (String propertyName : allSetters.keySet()) { Collection<JMethod> propertySetters = allSetters.get(propertyName); JMethod setter = disambiguateSetters(propertyName, propertySetters); setters.put(propertyName, setter); } if (ambiguousSetters.size() == 0) { ambiguousSetters = null; } }
/** * Default constructor. This is package-visible for testing only. * * @param forType the type of the field class * @param logger * @throws UnableToCompleteException if the class is not valid */ OwnerFieldClass(JClassType forType, MortalLogger logger) throws UnableToCompleteException { this.rawType = forType; this.logger = logger; findUiConstructor(forType); findSetters(forType); findUiChildren(forType); }
/** * Gets the type associated with this field. */ public JClassType getRawType() { // This shorten getType().getRawType() and make tests easier. return getType().getRawType(); }
final Map<String, JType> unfilledRequiredParams = new HashMap<String, JType>(); final OwnerFieldClass ownerFieldClass = OwnerFieldClass.getFieldClass(type, writer.getLogger(), context); if (creator == null) { creator = ownerFieldClass.getUiConstructor(); unfilledRequiredParams.remove(key); } else { JMethod setter = ownerFieldClass.getSetter(key); JParameter[] params = setter == null ? null : setter.getParameters(); unfilledRequiredParams.remove(propertyName); } else { JMethod setter = ownerFieldClass.getSetter(propertyName); if (setter == null) { writer.die(elem, "Class %s has no appropriate set%s() method",
allSetters = findAllSetters(superClass); } else { if (!isSetterMethod(method)) { continue; addSetter(allSetters, beanPropertyName, method); + propertyName.substring(1); if (!legacyPropertyName.equals(beanPropertyName)) { addSetter(allSetters, legacyPropertyName, method);
/** * Constructor. * * @param field the field of the owner class * @param logger * @param context */ public OwnerField(JField field, MortalLogger logger, UiBinderContext context) throws UnableToCompleteException { this.name = field.getName(); // Get the field type and ensure it's a class or interface JClassType fieldClassType = field.getType().isClassOrInterface(); if (fieldClassType == null) { logger.die("Type for field " + name + " is not a class: " + field.getType().getSimpleSourceName()); } this.fieldType = OwnerFieldClass.getFieldClass(fieldClassType, logger, context); // Get the UiField annotation and process it UiField annotation = field.getAnnotation(UiField.class); if (annotation == null) { logger.die("Field " + name + " is not annotated with @UiField"); } isProvided = annotation.provided(); }
/** * Gets or creates the descriptor for the given field class. * * @param forType the field type to get a descriptor for * @param logger TODO * @param context * @return the descriptor */ public static OwnerFieldClass getFieldClass(JClassType forType, MortalLogger logger, UiBinderContext context) throws UnableToCompleteException { OwnerFieldClass clazz = context.getOwnerFieldClass(forType); if (clazz == null) { clazz = new OwnerFieldClass(forType, logger); context.putOwnerFieldClass(forType, clazz); } return clazz; }
/** * Gets the type associated with this field. */ public JClassType getRawType() { // This shorten getType().getRawType() and make tests easier. return getType().getRawType(); }
/** * Default constructor. This is package-visible for testing only. * * @param forType the type of the field class * @param logger * @throws UnableToCompleteException if the class is not valid */ OwnerFieldClass(JClassType forType, MortalLogger logger) throws UnableToCompleteException { this.rawType = forType; this.logger = logger; findUiConstructor(forType); findSetters(forType); findUiChildren(forType); }
/** * Constructor. * * @param field the field of the owner class * @param logger * @param context */ public OwnerField(JField field, MortalLogger logger, UiBinderContext context) throws UnableToCompleteException { this.name = field.getName(); // Get the field type and ensure it's a class or interface JClassType fieldClassType = field.getType().isClassOrInterface(); if (fieldClassType == null) { logger.die("Type for field " + name + " is not a class: " + field.getType().getSimpleSourceName()); } this.fieldType = OwnerFieldClass.getFieldClass(fieldClassType, logger, context); // Get the UiField annotation and process it UiField annotation = field.getAnnotation(UiField.class); if (annotation == null) { logger.die("Field " + name + " is not annotated with @UiField"); } isProvided = annotation.provided(); }
/** * Gets or creates the descriptor for the given field class. * * @param forType the field type to get a descriptor for * @param logger TODO * @param context * @return the descriptor */ public static OwnerFieldClass getFieldClass(JClassType forType, MortalLogger logger, UiBinderContext context) throws UnableToCompleteException { OwnerFieldClass clazz = context.getOwnerFieldClass(forType); if (clazz == null) { clazz = new OwnerFieldClass(forType, logger); context.putOwnerFieldClass(forType, clazz); } return clazz; }
final Map<String, JType> unfilledRequiredParams = new HashMap<String, JType>(); final OwnerFieldClass ownerFieldClass = OwnerFieldClass.getFieldClass(type, writer.getLogger(), context); if (creator == null) { creator = ownerFieldClass.getUiConstructor(); unfilledRequiredParams.remove(key); } else { JMethod setter = ownerFieldClass.getSetter(key); JParameter[] params = setter == null ? null : setter.getParameters(); unfilledRequiredParams.remove(propertyName); } else { JMethod setter = ownerFieldClass.getSetter(propertyName); if (setter != null) { String n = attribute.getName(); String addMethod = ADD_PROPERTY_TO_SETTER_MAP.get(propertyName); JType stringType = writer.getOracle().findType(String.class.getName()); if (ownerFieldClass.getRawType().findMethod(addMethod, new JType[]{stringType}) != null) { String n = attribute.getName(); String[] value = elem.consumeStringArrayAttribute(n);
@Override public String toString() { return String.format("%s.%s#%s", fieldType.getRawType().getPackage(), fieldType.getRawType().getName(), name); } }
public void parse(final XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { this.fieldName = fieldName; this.writer = writer; OwnerFieldClass ownerFieldClass = OwnerFieldClass.getFieldClass(type, writer.getLogger(), uiBinderCtx); uiChildMethods = ownerFieldClass.getUiChildMethods(); // Parse children. elem.consumeChildElements(new Interpreter<Boolean>() { public Boolean interpretElement(XMLElement child) throws UnableToCompleteException { if (isValidChildElement(elem, child)) { handleChild(child); return true; } return false; } }); }
/** * Finds all setters in the class, and puts them in the {@link #setters} * field. * * @param fieldType the type of the field */ private void findSetters(JClassType fieldType) { // Pass one - get all setter methods Multimap<String, JMethod> allSetters = findAllSetters(fieldType); // Pass two - disambiguate ambiguousSetters = new HashSet<String>(); for (String propertyName : allSetters.keySet()) { Collection<JMethod> propertySetters = allSetters.get(propertyName); JMethod setter = disambiguateSetters(propertyName, propertySetters); setters.put(propertyName, setter); } if (ambiguousSetters.size() == 0) { ambiguousSetters = null; } }
@Override public String toString() { return String.format("%s.%s#%s", fieldType.getRawType().getPackage(), fieldType.getRawType().getName(), name); } }
public void parse(final XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { this.fieldName = fieldName; this.writer = writer; OwnerFieldClass ownerFieldClass = OwnerFieldClass.getFieldClass(type, writer.getLogger(), uiBinderCtx); uiChildMethods = ownerFieldClass.getUiChildMethods(); // Parse children. elem.consumeChildElements(new Interpreter<Boolean>() { public Boolean interpretElement(XMLElement child) throws UnableToCompleteException { if (isValidChildElement(elem, child)) { handleChild(child); return true; } return false; } }); }
/** * Checks whether the given owner field name is a LazyDomElement or not. */ public boolean isOwnerFieldLazyDomElement(String fieldName) { OwnerField ownerField = ownerClass.getUiField(fieldName); if (ownerField == null) { return false; } return lazyDomElementClass.isAssignableFrom(ownerField.getType().getRawType()); }