use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class BeanUtils method addExplicitProperties.
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());
}
}
}
}
use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class ClassNodeUtils method hasPossibleStaticProperty.
/**
* Return true if we have a static accessor
*/
public static boolean hasPossibleStaticProperty(ClassNode candidate, String methodName) {
// assume explicit static method call checked first so we can assume a simple check here
if (!methodName.startsWith("get") && !methodName.startsWith("is")) {
return false;
}
String propName = getPropNameForAccessor(methodName);
PropertyNode pNode = getStaticProperty(candidate, propName);
return pNode != null && (methodName.startsWith("get") || boolean_TYPE.equals(pNode.getType()));
}
use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class TupleConstructorASTTransformation method processArgsBlock.
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;
}
use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class ImmutableASTTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
// if (!MY_TYPE.equals(node.getClassNode())) return;
if (!node.getClassNode().getName().endsWith(".Immutable"))
return;
List<PropertyNode> newProperties = new ArrayList<PropertyNode>();
if (parent instanceof ClassNode) {
final List<String> knownImmutableClasses = getKnownImmutableClasses(node);
final List<String> knownImmutables = getKnownImmutables(node);
ClassNode cNode = (ClassNode) parent;
String cName = cNode.getName();
if (!checkNotInterface(cNode, MY_TYPE_NAME))
return;
if (!checkPropertyList(cNode, knownImmutables, "knownImmutables", node, MY_TYPE_NAME, false))
return;
makeClassFinal(cNode);
final List<PropertyNode> pList = getInstanceProperties(cNode);
for (PropertyNode pNode : pList) {
adjustPropertyForImmutability(pNode, newProperties);
}
for (PropertyNode pNode : newProperties) {
cNode.getProperties().remove(pNode);
addProperty(cNode, pNode);
}
final List<FieldNode> fList = cNode.getFields();
for (FieldNode fNode : fList) {
ensureNotPublic(cName, fNode);
}
boolean includeSuperProperties = false;
if (hasAnnotation(cNode, TupleConstructorASTTransformation.MY_TYPE)) {
AnnotationNode tupleCons = cNode.getAnnotations(TupleConstructorASTTransformation.MY_TYPE).get(0);
includeSuperProperties = memberHasValue(tupleCons, "includeSuperProperties", true);
if (unsupportedTupleAttribute(tupleCons, "excludes"))
return;
if (unsupportedTupleAttribute(tupleCons, "includes"))
return;
if (unsupportedTupleAttribute(tupleCons, "includeFields"))
return;
if (unsupportedTupleAttribute(tupleCons, "includeProperties"))
return;
if (unsupportedTupleAttribute(tupleCons, "includeSuperFields"))
return;
if (unsupportedTupleAttribute(tupleCons, "callSuper"))
return;
if (unsupportedTupleAttribute(tupleCons, "force"))
return;
}
createConstructors(cNode, knownImmutableClasses, knownImmutables, includeSuperProperties);
if (!hasAnnotation(cNode, EqualsAndHashCodeASTTransformation.MY_TYPE)) {
createHashCode(cNode, true, false, false, null, null);
createEquals(cNode, false, false, false, null, null);
}
if (!hasAnnotation(cNode, ToStringASTTransformation.MY_TYPE)) {
createToString(cNode, false, false, null, null, false, true);
}
if (memberHasValue(node, MEMBER_ADD_COPY_WITH, true) && !pList.isEmpty() && !hasDeclaredMethod(cNode, COPY_WITH_METHOD, 1)) {
createCopyWith(cNode, pList);
}
}
}
use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class ImmutableASTTransformation method createConstructorOrdered.
private static void createConstructorOrdered(ClassNode cNode, List<PropertyNode> list) {
final MapExpression argMap = new MapExpression();
final Parameter[] orderedParams = new Parameter[list.size()];
int index = 0;
for (PropertyNode pNode : list) {
Parameter param = new Parameter(pNode.getField().getType(), pNode.getField().getName());
orderedParams[index++] = param;
argMap.addMapEntryExpression(constX(pNode.getName()), varX(pNode.getName()));
}
final BlockStatement orderedBody = new BlockStatement();
orderedBody.addStatement(stmt(ctorX(ClassNode.THIS, args(castX(HASHMAP_TYPE, argMap)))));
doAddConstructor(cNode, new ConstructorNode(ACC_PUBLIC, orderedParams, ClassNode.EMPTY_ARRAY, orderedBody));
}
Aggregations