@Override public void visitProperty(PropertyNode node) { addNode(properties, node.getName(), node); super.visitProperty(node); }
public PropertyNode getProperty(String name) { for (PropertyNode pn : getProperties()) { if (pn.getName().equals(name)) return pn; } return null; }
private static void addExplicitProperties(ClassNode cNode, List<PropertyNode> result, Set<String> names, boolean includeStatic) { for (PropertyNode pNode : cNode.getProperties()) { if (includeStatic || !pNode.isStatic()) { if (!names.contains(pNode.getName())) { result.add(pNode); names.add(pNode.getName()); } } } }
public static List<String> getInstancePropertyNames(ClassNode cNode) { List<PropertyNode> pList = BeanUtils.getAllProperties(cNode, false, false, true); List<String> result = new ArrayList<String>(pList.size()); for (PropertyNode pNode : pList) { result.add(pNode.getName()); } return result; }
public static String getGetterName(PropertyNode pNode) { return "get" + Verifier.capitalize(pNode.getName()); }
private static String getName(ASTNode node) { if (node instanceof FieldNode) return ((FieldNode) node).getName(); if (node instanceof PropertyNode) return ((PropertyNode) node).getName(); return node.getText(); }
private static String getterName(ClassNode annotatedNode, PropertyNode pNode) { String getterName = "get" + MetaClassHelper.capitalize(pNode.getName()); boolean existingExplicitGetter = annotatedNode.getMethod(getterName, Parameter.EMPTY_ARRAY) != null; if (ClassHelper.boolean_TYPE.equals(pNode.getOriginType()) && !existingExplicitGetter) { getterName = "is" + MetaClassHelper.capitalize(pNode.getName()); } return getterName; }
protected List<PropertyInfo> getPropertyInfoFromClassNode(BuilderASTTransformation transform, AnnotationNode anno, ClassNode cNode, List<String> includes, List<String> excludes, boolean allNames, boolean allProperties) { List<PropertyInfo> props = new ArrayList<PropertyInfo>(); List<String> seen = new ArrayList<String>(); for (PropertyNode pNode : BeanUtils.getAllProperties(cNode, false, false, allProperties)) { if (shouldSkip(pNode.getName(), excludes, includes, allNames)) continue; props.add(new PropertyInfo(pNode.getName(), pNode.getType())); seen.add(pNode.getName()); } for (FieldNode fNode : getFields(transform, anno, cNode)) { if (seen.contains(fNode.getName()) || shouldSkip(fNode.getName(), excludes, includes, allNames)) continue; props.add(new PropertyInfo(fNode.getName(), fNode.getType())); } return props; }
private static String getRefDescriptor(ASTNode ref) { if (ref instanceof FieldNode) { FieldNode f = (FieldNode) ref; return "the field "+f.getName()+" "; } else if (ref instanceof PropertyNode) { PropertyNode p = (PropertyNode) ref; return "the property "+p.getName()+" "; } else if (ref instanceof ConstructorNode) { return "the constructor "+ref.getText()+" "; } else if (ref instanceof MethodNode) { return "the method "+ref.getText()+" "; } else if (ref instanceof ClassNode) { return "the super class "+ref+" "; } return "<unknown with class "+ref.getClass()+"> "; }
private static void processProps(AbstractASTTransformation xform, AnnotationNode anno, ClassNode cNode, PropertyHandler handler, boolean allNames, List<String> excludes, List<String> includes, List<PropertyNode> superList, Parameter map, BlockStatement inner) { for (PropertyNode pNode : superList) { String name = pNode.getName(); if (shouldSkipUndefinedAware(name, excludes, includes, allNames)) continue; Statement propInit = handler.createPropInit(xform, anno, cNode, pNode, map); if (propInit != null) { inner.addStatement(propInit); } } }
private void createListenerSetter(ClassNode classNode, PropertyNode propertyNode) { String setterName = "set" + MetaClassHelper.capitalize(propertyNode.getName()); if (classNode.getMethods(setterName).isEmpty()) { Statement setterBlock = createBindableStatement(propertyNode, fieldX(propertyNode.getField())); // create method void <setter>(<type> fieldName) createSetterMethod(classNode, propertyNode, setterName, setterBlock); } else { wrapSetterMethod(classNode, propertyNode.getName()); } }
/** * Creates a statement body similar to: * <code>this.fireVetoableChange("field", field, field = value)</code> * * @param propertyNode the field node for the property * @param fieldExpression a field expression for setting the property value * @return the created statement */ protected Statement createConstrainedStatement(PropertyNode propertyNode, Expression fieldExpression) { return stmt(callThisX("fireVetoableChange", args(constX(propertyNode.getName()), fieldExpression, varX("value")))); }
/** * This method is similar to {@link #propX(Expression, Expression)} but will make sure that if the property * being accessed is defined inside the classnode provided as a parameter, then a getter call is generated * instead of a field access. * @param annotatedNode the class node where the property node is accessed from * @param receiver the object having the property * @param pNode the property being accessed * @return a method call expression or a property expression */ public static Expression getterX(ClassNode annotatedNode, Expression receiver, PropertyNode pNode) { ClassNode owner = pNode.getDeclaringClass(); if (annotatedNode.equals(owner)) { return callX(receiver, getterName(annotatedNode, pNode)); } return propX(receiver, pNode.getName()); }
/** * Creates a statement body similar to: * <code>this.firePropertyChange("field", field, field = value)</code> * * @param propertyNode the field node for the property * @param fieldExpression a field expression for setting the property value * @return the created statement */ protected Statement createBindableStatement(PropertyNode propertyNode, Expression fieldExpression) { // create statementBody return stmt(callThisX("firePropertyChange", args(constX(propertyNode.getName()), fieldExpression, assignX(fieldExpression, varX("value"))))); }
private static void addProperty(ClassNode cNode, PropertyNode pNode) { final FieldNode fn = pNode.getField(); cNode.getFields().remove(fn); cNode.addProperty(pNode.getName(), pNode.getModifiers() | ACC_FINAL, pNode.getType(), pNode.getInitialExpression(), pNode.getGetterBlock(), pNode.getSetterBlock()); final FieldNode newfn = cNode.getField(fn.getName()); cNode.getFields().remove(newfn); cNode.addField(fn); }
/** * This method is similar to {@link #propX(Expression, Expression)} but will make sure that if the property * being accessed is defined inside the classnode provided as a parameter, then a getter call is generated * instead of a field access. * @param annotatedNode the class node where the property node is accessed from * @param pNode the property being accessed * @return a method call expression or a property expression */ public static Expression getterThisX(ClassNode annotatedNode, PropertyNode pNode) { ClassNode owner = pNode.getDeclaringClass(); if (annotatedNode.equals(owner)) { return callThisX(getterName(annotatedNode, pNode)); } return propX(new VariableExpression("this"), pNode.getName()); }
private void checkComparable(PropertyNode pNode) { if (pNode.getType().implementsInterface(COMPARABLE_TYPE) || isPrimitiveType(pNode.getType()) || hasAnnotation(pNode.getType(), MY_TYPE)) { return; } addError("Error during " + MY_TYPE_NAME + " processing: property '" + pNode.getName() + "' must be Comparable", pNode); }
private static BlockStatement processArgsBlock(ClassNode cNode, VariableExpression namedArgs) { BlockStatement block = new BlockStatement(); for (PropertyNode pNode : cNode.getProperties()) { if (pNode.isStatic()) continue; // if namedArgs.containsKey(propertyName) setProperty(propertyName, namedArgs.get(propertyName)); Statement ifStatement = ifS( callX(namedArgs, "containsKey", constX(pNode.getName())), assignS(varX(pNode), propX(namedArgs, pNode.getName()))); block.addStatement(ifStatement); } block.addStatement(stmt(callX(CHECK_METHOD_TYPE, "checkPropNames", args(varX("this"), namedArgs)))); return block; }
private static Statement createCompareMethodBody(PropertyNode property, boolean reversed) { String propName = property.getName(); return block( // if (arg0 == arg1) return 0; ifS(eqX(varX(ARG0), varX(ARG1)), returnS(constX(0))), // if (arg0 != null && arg1 == null) return -1; ifS(andX(notNullX(varX(ARG0)), equalsNullX(varX(ARG1))), returnS(constX(-1))), // if (arg0 == null && arg1 != null) return 1; ifS(andX(equalsNullX(varX(ARG0)), notNullX(varX(ARG1))), returnS(constX(1))), // return arg0.prop <=> arg1.prop; returnS(compareExpr(propX(varX(ARG0), propName), propX(varX(ARG1), propName), reversed)) ); }