public class ClassNodeUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
addDeclaredMethodsFromAllInterfaces(ClassNode cNode,
Map<String,MethodNode> methodsMap)
Adds methods from interfaces and parent interfaces.
|
static void |
addDeclaredMethodsFromInterfaces(ClassNode cNode,
Map<String,MethodNode> methodsMap)
Adds methods from all interfaces.
|
static void |
addGeneratedConstructor(ClassNode classNode,
ConstructorNode consNode)
Add a method that is marked as
@Generated . |
static ConstructorNode |
addGeneratedConstructor(ClassNode classNode,
int modifiers,
Parameter[] parameters,
ClassNode[] exceptions,
Statement code)
Add a method that is marked as
@Generated . |
static void |
addGeneratedInnerClass(ClassNode cNode,
ClassNode inner)
Add an inner class that is marked as
@Generated . |
static void |
addGeneratedMethod(ClassNode cNode,
MethodNode mNode)
Add a method and mark it as
@Generated . |
static MethodNode |
addGeneratedMethod(ClassNode cNode,
String name,
int modifiers,
ClassNode returnType,
Parameter[] parameters,
ClassNode[] exceptions,
Statement code)
Return an existing method if one exists or else create a new method and mark it as
@Generated . |
static String |
formatTypeName(ClassNode cNode)
Formats a type name into a human readable version.
|
static Map<String,MethodNode> |
getDeclaredMethodsFromInterfaces(ClassNode cNode)
Gets methods from all interfaces.
|
static Map<String,MethodNode> |
getDeclaredMethodsFromSuper(ClassNode cNode)
Add methods from the super class.
|
static FieldNode |
getField(ClassNode classNode,
String fieldName)
Return the (potentially inherited) field of the classnode.
|
static String |
getPropNameForAccessor(String accessorName)
Returns the property name, e.g.
|
static PropertyNode |
getStaticProperty(ClassNode cNode,
String propName)
Detect whether a static property with the given name is within the class
or a super class.
|
static boolean |
hasExplicitConstructor(AbstractASTTransformation xform,
ClassNode cNode)
Determine if an explicit (non-generated) constructor is in the class.
|
static boolean |
hasNoArgConstructor(ClassNode cNode) |
static boolean |
hasPossibleStaticMethod(ClassNode cNode,
String name,
Expression arguments,
boolean trySpread)
Returns true if the given method has a possibly matching static method with the given name and arguments.
|
static boolean |
hasPossibleStaticProperty(ClassNode cNode,
String methodName)
Return true if we have a static accessor
|
static boolean |
hasStaticProperty(ClassNode cNode,
String propName) |
static boolean |
isInnerClass(ClassNode cNode)
Detect whether a given ClassNode is a inner class (non-static).
|
static boolean |
isValidAccessorName(String accessorName)
Detect whether the given accessor name starts with "get", "set" or "is" followed by at least one character.
|
static boolean |
samePackageName(ClassNode first,
ClassNode second)
Determine if the given ClassNode values have the same package name.
|
public static String formatTypeName(ClassNode cNode)
cNode
- the type to formatpublic static MethodNode addGeneratedMethod(ClassNode cNode, String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)
@Generated
.public static void addGeneratedMethod(ClassNode cNode, MethodNode mNode)
@Generated
.ClassNode.addMethod(MethodNode)
public static void addGeneratedInnerClass(ClassNode cNode, ClassNode inner)
@Generated
.ModuleNode.addClass(ClassNode)
public static ConstructorNode addGeneratedConstructor(ClassNode classNode, int modifiers, Parameter[] parameters, ClassNode[] exceptions, Statement code)
@Generated
.public static void addGeneratedConstructor(ClassNode classNode, ConstructorNode consNode)
@Generated
.public static Map<String,MethodNode> getDeclaredMethodsFromSuper(ClassNode cNode)
cNode
- The ClassNodepublic static void addDeclaredMethodsFromInterfaces(ClassNode cNode, Map<String,MethodNode> methodsMap)
cNode
- The ClassNodemethodsMap
- A map of existing methods to alterpublic static Map<String,MethodNode> getDeclaredMethodsFromInterfaces(ClassNode cNode)
cNode
- The ClassNodepublic static void addDeclaredMethodsFromAllInterfaces(ClassNode cNode, Map<String,MethodNode> methodsMap)
cNode
- The ClassNodemethodsMap
- A map of existing methods to alterpublic static boolean hasPossibleStaticMethod(ClassNode cNode, String name, Expression arguments, boolean trySpread)
cNode
- the ClassNode of interestname
- the name of the method of interestarguments
- the arguments to match againsttrySpread
- whether to try to account for SpreadExpressions within the argumentspublic static boolean hasPossibleStaticProperty(ClassNode cNode, String methodName)
public static String getPropNameForAccessor(String accessorName)
accessorName
- the accessor name of interest, e.g. getAgepublic static boolean isValidAccessorName(String accessorName)
accessorName
- the accessor name of interest, e.g. getAgepublic static PropertyNode getStaticProperty(ClassNode cNode, String propName)
cNode
- the ClassNode of interestpropName
- the property namepublic static boolean isInnerClass(ClassNode cNode)
cNode
- the ClassNode of interestpublic static boolean hasNoArgConstructor(ClassNode cNode)
public static boolean hasExplicitConstructor(AbstractASTTransformation xform, ClassNode cNode)
xform
- if non null, add an error if an explicit constructor is foundcNode
- the type of the containing classpublic static boolean samePackageName(ClassNode first, ClassNode second)
first
- a ClassNodesecond
- a ClassNodeNullPointerException
- if either of the given nodes are null