private void implementGetter(PropertyAdapter adapter) { if (adapter.getReadMethod() != null) { implementGetter(adapter.getReadMethod()); return; } if (adapter.getField() != null) { implementGetter(adapter.getField()); return; } implementNoOpMethod(ConduitMethods.GET, "Expression '%s' for class %s is write-only.", expression, rootType.getName()); }
private Type getGenericType(PropertyAdapter adapter) { Type genericType = null; if (adapter.getField() != null) { genericType = adapter.getField().getGenericType(); } else if (adapter.getReadMethod() != null) { genericType = adapter.getReadMethod().getGenericReturnType(); } else if (adapter.getWriteMethod() != null) { genericType = adapter.getWriteMethod().getGenericParameterTypes()[0]; } else { throw new RuntimeException("Could not find accessor for property " + adapter.getName()); } return genericType == null ? adapter.getType() : genericType; }
private Term buildPropertyAccessTerm(Type activeType, Tree termNode) { String propertyName = termNode.getText(); PropertyAdapter adapter = findPropertyAdapter(activeType, propertyName); // Prefer the accessor over the field if (adapter.getReadMethod() != null) { return buildGetterMethodAccessTerm(activeType, propertyName, adapter.getReadMethod()); } if (adapter.getField() != null) { return buildPublicFieldAccessTerm(activeType, propertyName, adapter.getField()); } throw new RuntimeException(String.format( "Property '%s' of class %s is not readable (it has no read accessor method).", adapter.getName(), adapter.getBeanType().getName())); }
/** * @param classAdapter defines the bean that contains the properties * @param propertyNames the initial set of property names, which will be rebuilt in the correct order */ private void orderProperties(ClassPropertyAdapter classAdapter, List<String> propertyNames) { List<PropertyOrder> properties = CollectionFactory.newList(); for (String name : propertyNames) { PropertyAdapter pa = classAdapter.getPropertyAdapter(name); Method readMethod = pa.getReadMethod(); Location location = readMethod == null ? null : proxyFactory.getMethodLocation(readMethod); int line = location == null ? -1 : location.getLine(); properties.add(new PropertyOrder(name, computeDepth(pa), line)); } Collections.sort(properties); propertyNames.clear(); for (PropertyOrder po : properties) { propertyNames.add(po.propertyName); } }