Package org.codehaus.groovy.ast.tools
Class BeanUtils
java.lang.Object
org.codehaus.groovy.ast.tools.BeanUtils
Utility methods for discovering and working with bean properties on
ClassNode instances.
This utility supports JavaBean property conventions including:
- Explicit properties defined via the
@Propertyannotation - Pseudo-properties from getter methods following JavaBean naming conventions (getXxx, isXxx)
- Pseudo-properties from setter methods following JavaBean naming conventions (setXxx)
- Inherited properties from superclasses and interfaces
- Static property filtering
Commonly used in AST transformation and type checking to analyze class structure and generate property access patterns.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddPseudoProperties(ClassNode origType, ClassNode cNode, List<PropertyNode> result, Set<String> names, boolean includeStatic, boolean includePseudoGetters, boolean includePseudoSetters) Adds pseudo-properties for getters and setters to a property list.static voidaddPseudoProperties(ClassNode origType, ClassNode cNode, List<PropertyNode> result, Set<String> names, boolean includeStatic, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses) Adds pseudo-properties for getters and setters to a property list, optionally traversing superclasses.static List<PropertyNode>getAllProperties(ClassNode type, boolean includeSuperProperties, boolean includeStatic, boolean includePseudoGetters) Discovers all properties in a class, optionally including inherited and pseudo-properties.static List<PropertyNode>getAllProperties(ClassNode type, boolean includeSuperProperties, boolean includeStatic, boolean includePseudoGetters, boolean includePseudoSetters, boolean superFirst) Discovers all properties in a class, optionally including both getter and setter pseudo-properties.
-
Method Details
-
getAllProperties
public static List<PropertyNode> getAllProperties(ClassNode type, boolean includeSuperProperties, boolean includeStatic, boolean includePseudoGetters) Discovers all properties in a class, optionally including inherited and pseudo-properties. Pseudo-properties are derived from getter methods following JavaBean naming conventions.- Parameters:
type- theClassNodeto analyzeincludeSuperProperties- whether to include properties from superclassesincludeStatic- whether to include static propertiesincludePseudoGetters- whether to include pseudo-properties created from getXxx/isXxx methods- Returns:
- a list of all discovered
PropertyNodes, may be empty - See Also:
-
getAllProperties
public static List<PropertyNode> getAllProperties(ClassNode type, boolean includeSuperProperties, boolean includeStatic, boolean includePseudoGetters, boolean includePseudoSetters, boolean superFirst) Discovers all properties in a class, optionally including both getter and setter pseudo-properties. Pseudo-properties include JavaBean getters (getXxx/isXxx) and setters (setXxx) without corresponding fields.- Parameters:
type- theClassNodeto analyzeincludeSuperProperties- whether to include properties from superclassesincludeStatic- whether to include static propertiesincludePseudoGetters- whether to include pseudo-properties from getter methodsincludePseudoSetters- whether to include pseudo-properties from setter methodssuperFirst- whether to list superclass properties before current class properties- Returns:
- a list of all discovered
PropertyNodes, with order controlled by superFirst, may be empty
-
addPseudoProperties
public static void addPseudoProperties(ClassNode origType, ClassNode cNode, List<PropertyNode> result, Set<String> names, boolean includeStatic, boolean includePseudoGetters, boolean includePseudoSetters) Adds pseudo-properties for getters and setters to a property list. Pseudo-properties are created from methods following JavaBean naming conventions but without corresponding field declarations.- Parameters:
origType- the original type being analyzed (used for access checks)cNode- the class node to scan for getter/setter methodsresult- the list to accumulate discovered pseudo-propertiesnames- a set tracking property names already discovered (to prevent duplicates)includeStatic- whether to include static methodsincludePseudoGetters- whether to add properties from getter methodsincludePseudoSetters- whether to add properties from setter methods
-
addPseudoProperties
public static void addPseudoProperties(ClassNode origType, ClassNode cNode, List<PropertyNode> result, Set<String> names, boolean includeStatic, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses) Adds pseudo-properties for getters and setters to a property list, optionally traversing superclasses. Pseudo-properties are created from methods following JavaBean naming conventions but without corresponding field declarations. Methods marked with@Internalare skipped.- Parameters:
origType- the original type being analyzed (used for access checks)cNode- the class node to scan for getter/setter methodsresult- the list to accumulate discovered pseudo-propertiesnames- a set tracking property names already discovered (to prevent duplicates)includeStatic- whether to include static methodsincludePseudoGetters- whether to add properties from getXxx/isXxx getter methodsincludePseudoSetters- whether to add properties from setXxx setter methodstraverseSuperClasses- whether to include inherited methods from superclasses
-