use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class BindableASTTransformation method addListenerToProperty.
private void addListenerToProperty(SourceUnit source, AnnotationNode node, ClassNode declaringClass, FieldNode field) {
String fieldName = field.getName();
for (PropertyNode propertyNode : declaringClass.getProperties()) {
if (propertyNode.getName().equals(fieldName)) {
if (field.isStatic()) {
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException("@groovy.beans.Bindable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source));
} else {
if (needsPropertyChangeSupport(declaringClass, source)) {
addPropertyChangeSupport(declaringClass);
}
createListenerSetter(declaringClass, propertyNode);
}
return;
}
}
//noinspection ThrowableInstanceNeverThrown
source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(new SyntaxException("@groovy.beans.Bindable must be on a property, not a field. Try removing the private, protected, or public modifier.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source));
}
use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class BindableASTTransformation method addListenerToClass.
private void addListenerToClass(SourceUnit source, ClassNode classNode) {
if (needsPropertyChangeSupport(classNode, source)) {
addPropertyChangeSupport(classNode);
}
for (PropertyNode propertyNode : classNode.getProperties()) {
FieldNode field = propertyNode.getField();
// look to see if per-field handlers will catch this one...
if (hasBindableAnnotation(field) || ((field.getModifiers() & Opcodes.ACC_FINAL) != 0) || field.isStatic() || VetoableASTTransformation.hasVetoableAnnotation(field)) {
// VetoableASTTransformation will handle both @Bindable and @Vetoable
continue;
}
createListenerSetter(classNode, propertyNode);
}
}
use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class GeneralUtils method getAllProperties.
public static List<PropertyNode> getAllProperties(ClassNode type) {
ClassNode node = type;
List<PropertyNode> result = new ArrayList<PropertyNode>();
while (node != null) {
result.addAll(node.getProperties());
node = node.getSuperClass();
}
return result;
}
use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class BeanUtils method addPseudoProperties.
private static void addPseudoProperties(ClassNode cNode, List<PropertyNode> result, Set<String> names, boolean includeStatic, boolean includePseudoGetters, boolean includeSuperProperties) {
if (!includePseudoGetters)
return;
List<MethodNode> methods = cNode.getAllDeclaredMethods();
ClassNode node = cNode.getSuperClass();
if (includeSuperProperties) {
while (node != null) {
for (MethodNode next : node.getAllDeclaredMethods()) {
if (!next.isPrivate()) {
methods.add(next);
}
}
node = node.getSuperClass();
}
}
for (MethodNode mNode : methods) {
if (!includeStatic && mNode.isStatic())
continue;
String name = mNode.getName();
if ((name.length() <= 3 && !name.startsWith(IS_PREFIX)) || name.equals("getClass") || name.equals("getMetaClass") || name.equals("getDeclaringClass")) {
// Optimization: skip invalid propertyNames
continue;
}
if (mNode.getDeclaringClass() != cNode && mNode.isPrivate()) {
// skip private super methods
continue;
}
int paramCount = mNode.getParameters().length;
ClassNode returnType = mNode.getReturnType();
if (paramCount == 0) {
if (name.startsWith(GET_PREFIX)) {
// Simple getter
String propName = decapitalize(name.substring(3));
if (!names.contains(propName)) {
result.add(new PropertyNode(propName, mNode.getModifiers(), returnType, cNode, null, mNode.getCode(), null));
names.add(propName);
}
} else {
if (name.startsWith(IS_PREFIX) && returnType.equals(ClassHelper.boolean_TYPE)) {
// boolean getter
String propName = decapitalize(name.substring(2));
if (!names.contains(propName)) {
names.add(propName);
result.add(new PropertyNode(propName, mNode.getModifiers(), returnType, cNode, null, mNode.getCode(), null));
}
}
}
}
}
}
use of org.codehaus.groovy.ast.PropertyNode in project groovy by apache.
the class BeanUtils method getAllProperties.
/**
* Get all properties including JavaBean pseudo properties matching getter conventions.
*
* @param type the ClassNode
* @param includeSuperProperties whether to include super properties
* @param includeStatic whether to include static properties
* @param includePseudoGetters whether to include JavaBean pseudo (getXXX/isYYY) properties with no corresponding field
* @return the list of found property nodes
*/
public static List<PropertyNode> getAllProperties(ClassNode type, boolean includeSuperProperties, boolean includeStatic, boolean includePseudoGetters) {
// TODO add generics support so this can be used for @EAHC
// TODO add an includePseudoSetters so this can be used for @TupleConstructor
ClassNode node = type;
List<PropertyNode> result = new ArrayList<PropertyNode>();
Set<String> names = new HashSet<String>();
while (node != null) {
addExplicitProperties(node, result, names, includeStatic);
if (!includeSuperProperties)
break;
node = node.getSuperClass();
}
addPseudoProperties(type, result, names, includeStatic, includePseudoGetters, includeSuperProperties);
return result;
}
Aggregations