| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ANNOTATION_VALUE |
| Constructor and Description |
|---|
NodeUtils() |
| Modifier and Type | Method and Description |
|---|---|
void |
addAfterCodeBlock(MethodNode methodNode,
Statement statement)
Adds the statement passed as argument after the current method code
|
void |
addAroundCodeBlock(MethodNode methodNode,
Statement before,
Statement after)
Adds two different statements to be executed before and after the current
method code
|
void |
addBeforeCodeBlock(MethodNode methodNode,
Statement statement)
Adds the statement passed as argument before the current method code
|
void |
addCheckTo(MethodNode methodNode)
Adds checks to the method node passed as parameter
|
void |
addImport(ClassNode classNode,
java.lang.Class clazz)
Adds an import to the
ModuleNode containing the ClassNode passed as first argument. |
void |
addImport(ClassNode classNode,
java.lang.Class clazz,
java.lang.String alias)
Adds an import to the
ModuleNode containing the ClassNode passed as first argument. |
void |
addImport(ClassNode classNode,
java.lang.String clazz)
Adds an import to the
ModuleNode containing the ClassNode passed as first argument. |
void |
addImport(ClassNode classNode,
java.lang.String clazz,
java.lang.String alias)
Adds an import to the
ModuleNode containing the ClassNode passed as first argument. |
void |
addInterfaces(ClassNode classNode,
java.lang.Class... interfaces)
Makes the
ClassNode to implement the interfaces passed
as arguments
IMPORTANT: Dont use this method at any CompilePhase
before SEMANTIC_ANALYSIS. |
void |
addInterfaces(ClassNode classNode,
ClassNode... interfaces)
Makes the
ClassNode to implement the interfaces passed
as arguments. |
void |
addMethod(ClassNode classNode,
MethodNode methodNode)
Adds the method to the class node passed as first argument
|
void |
addMethodIfNotPresent(ClassNode classNode,
MethodNode methodNode)
Adds a method to the class node passed as first argument only
if it wasn't present in the first place
|
void |
addProperty(ClassNode classNode,
PropertyNode propertyNode)
Adds the property to the class node passed as first argument
|
void |
addPropertyIfNotPresent(ClassNode classNode,
PropertyNode propertyNode)
Adds a property to the class node passed as first argument only
if it wasn't present in the first place
|
java.util.List<MethodNode> |
findAllMethodByName(ClassNode classNode,
java.lang.String methodName)
Returns all
MethodNode found with a given name in a
specific ClassNode |
MethodNode |
findMethodByName(ClassNode classNode,
java.lang.String methodName)
Returns the first
MethodNode found with a given name in
a specific ClassNode |
<T> T |
get(AnnotationNode annotationNode,
java.lang.Class<T> clazz)
Returns the value of a given annotation member.
|
<T> T |
get(AnnotationNode annotationNode,
java.lang.String name,
java.lang.Class<T> clazz)
Returns the value of a member of the
AnnotationNode passed as first parameter with the name
passed as second parameter. |
AnnotationNode |
getAnnotationFrom(ClassNode classNode,
ClassNode annotationType)
Gets a given annotation node from the
ClassNode passed as first argument. |
AnnotationNode |
getAnnotationFrom(ClassNode classNode,
java.lang.String simpleName)
Retrieves an annotation with a specific simple name.
|
BlockStatement |
getCodeBlock(MethodNode methodNode)
Utility method to make your transformation code more compile
static compliant when getting a method node code block.
|
<T> T |
getFirstNodeAs(ASTNode[] nodes,
java.lang.Class<T> clazz)
Returns the first node of the list passed as parameter with the expected type T
|
java.util.List<FieldNode> |
getInstancePropertyFields(ClassNode classNode)
Returns all properties from a given
ClassNode passed as
argument |
<T> T |
getLastNodeAs(ASTNode[] nodes,
java.lang.Class<T> clazz)
Returns the last node of the list passed as parameter with the expected type T
|
java.lang.String |
getStringValue(AnnotationNode annotationNode)
Returns the
String representation of the member "value" of the annotation
passed as parameter |
java.lang.Boolean |
hasFieldOfType(ClassNode node,
java.lang.String qualifiedName)
Returns whether if the
ClassNode passed as first
parameter has any field with the type matching the qualified
name passed as second parameter. |
java.lang.Boolean |
isOrExtends(ClassNode child,
java.lang.Class parent)
Returns true if the classNode passed as first argument is of type `clazz` or that class extends
the other class, false otherwise
|
java.lang.Boolean |
isOrExtends(ClassNode child,
ClassNode parent)
Returns true if the classNode passed as first argument is of type `clazz` or that class extends
the other class, false otherwise
|
java.lang.Boolean |
isOrExtends(ClassNode child,
java.lang.String parent)
Returns true if the classNode passed as first argument is of type `clazz` or that class extends
the other class, false otherwise
|
java.lang.Boolean |
isOrExtendsUnsafe(ClassNode child,
ClassNode parent)
Returns true if the classNode passed as first argument is of type `clazz` or that class extends
the other class, false otherwise.
|
java.lang.Boolean |
isOrImplements(java.lang.Class child,
java.lang.Class parent)
Returns true if the classNode passed as first argument is of type `clazz` or that class implements
`parent`, false otherwise
|
java.lang.Boolean |
isOrImplements(ClassNode child,
java.lang.Class parent)
Returns true if the classNode passed as first argument is of type `clazz` or that class implements
`parent`, false otherwise
|
java.lang.Boolean |
isOrImplements(ClassNode child,
java.lang.String parent)
Returns true if the classNode passed as first argument is of type `clazz` or that class implements
`parent`, false otherwise
|
void |
removeAnnotation(AnnotatedNode annotated,
AnnotationNode annotation)
It removes the
AnnotationNode from a given AnnotatedNode |
public static final java.lang.String ANNOTATION_VALUE
public void addCheckTo(MethodNode methodNode)
methodNode - the node we want to add the checks topublic <T> T getFirstNodeAs(ASTNode[] nodes, java.lang.Class<T> clazz)
T - the expected typenodes - a list of nodesclazz - the type of the expected valuepublic <T> T getLastNodeAs(ASTNode[] nodes, java.lang.Class<T> clazz)
T - the expected typenodes - a list of nodesclazz - the type of the expected valuepublic java.lang.String getStringValue(AnnotationNode annotationNode)
String representation of the member "value" of the annotation
passed as parameterannotationNode - The node we want the value fromStringpublic <T> T get(AnnotationNode annotationNode, java.lang.Class<T> clazz)
T - The expected return typeannotationNode - The node we want the member value fromclazz - the type of value expectedpublic <T> T get(AnnotationNode annotationNode, java.lang.String name, java.lang.Class<T> clazz)
AnnotationNode passed as first parameter with the name
passed as second parameter. The third parameter is the expected type for the member. There are
a set of rules before trying to convert values to the Class passed as third parameter:
ClassExpression a String with the qualified name will be returnedConstantExpression the raw value will be returnedPropertyExpression the value will be converted to StringClassannotationNode - the annotation we want a member value fromname - the name of the member we want the value fromclazz - the clazz of the expected valuepublic void addProperty(ClassNode classNode, PropertyNode propertyNode)
classNode - the class we want to add the property topropertyNode - the property we want to addpublic void addPropertyIfNotPresent(ClassNode classNode, PropertyNode propertyNode)
classNode - the class we want to add the property topropertyNode - the property we want to addpublic void addMethod(ClassNode classNode, MethodNode methodNode)
classNode - the class we want to add the method tomethodNode - the method we want to addpublic void addMethodIfNotPresent(ClassNode classNode, MethodNode methodNode)
classNode - the class we want to add the method tomethodNode - the method we want to addpublic void addInterfaces(ClassNode classNode, java.lang.Class... interfaces)
ClassNode to implement the interfaces passed
as arguments
CompilePhase
before SEMANTIC_ANALYSIS. Classes may have not been set at this
point.classNode - The class we want to add the interfaces tointerfaces - the interfaces we want the class node to be
implementingpublic void addInterfaces(ClassNode classNode, ClassNode... interfaces)
ClassNode to implement the interfaces passed
as arguments.public java.util.List<FieldNode> getInstancePropertyFields(ClassNode classNode)
ClassNode passed as
argumentpublic AnnotationNode getAnnotationFrom(ClassNode classNode, ClassNode annotationType)
ClassNode passed as first argument.classNode - the class node annotated with the annotation we're looking forannotationType - the annotation class nodepublic AnnotationNode getAnnotationFrom(ClassNode classNode, java.lang.String simpleName)
classNode - the class node annotated with the annotation we're looking forsimpleName - the annotation type simple namepublic void removeAnnotation(AnnotatedNode annotated, AnnotationNode annotation)
AnnotationNode from a given AnnotatedNodeannotated - the AnnotatedNode to remove the annotation fromannotation - the AnnotationNode you want to removepublic java.lang.Boolean hasFieldOfType(ClassNode node, java.lang.String qualifiedName)
ClassNode passed as first
parameter has any field with the type matching the qualified
name passed as second parameter.node - The node under testqualifiedName - The qualified name of the typepublic java.lang.Boolean isOrImplements(java.lang.Class child,
java.lang.Class parent)
child - the Class we are checkingparent - the Class we are testing againstpublic java.lang.Boolean isOrImplements(ClassNode child, java.lang.Class parent)
child - the ClassNode we are checkingparent - the Class we are testing againstpublic java.lang.Boolean isOrImplements(ClassNode child, java.lang.String parent)
child - the ClassNode we are checkingparent - the qualified name of the Class we are testing againstpublic java.lang.Boolean isOrExtends(ClassNode child, java.lang.Class parent)
child - the ClassNode we are checkingparent - the Class we are testing againstpublic java.lang.Boolean isOrExtends(ClassNode child, ClassNode parent)
public java.lang.Boolean isOrExtends(ClassNode child, java.lang.String parent)
child - the ClassNode we are checkingparent - the qualified name of the class we are testing againstpublic java.lang.Boolean isOrExtendsUnsafe(ClassNode child, ClassNode parent)
public MethodNode findMethodByName(ClassNode classNode, java.lang.String methodName)
MethodNode found with a given name in
a specific ClassNodeclassNode - the ClassNode the method should be foundmethodName - the method nameMethodNode if foundpublic java.util.List<MethodNode> findAllMethodByName(ClassNode classNode, java.lang.String methodName)
MethodNode found with a given name in a
specific ClassNodeclassNode - the ClassNode the method should be foundmethodName - the method nameMethodNode if foundpublic void addImport(ClassNode classNode, java.lang.Class clazz)
ModuleNode containing the ClassNode passed as first argument.classNode - the ClassNode where the import will be addedclazz - the type Class of the importpublic void addImport(ClassNode classNode, java.lang.String clazz)
ModuleNode containing the ClassNode passed as first argument.classNode - the ClassNode where the import will be addedclazz - the string representing the qualified class of the importpublic void addImport(ClassNode classNode, java.lang.Class clazz, java.lang.String alias)
ModuleNode containing the ClassNode passed as first argument.classNode - the ClassNode where the import will be addedclazz - the type Class of the importalias - an alias to avoid class collisionspublic void addImport(ClassNode classNode, java.lang.String clazz, java.lang.String alias)
ModuleNode containing the ClassNode passed as first argument.classNode - the ClassNode where the import will be addedclazz - the string representing the qualified class of the importalias - an alias to avoid class collisionspublic BlockStatement getCodeBlock(MethodNode methodNode)
BlockStatement.methodNode - the method we want the code fromBlockStatementpublic void addBeforeCodeBlock(MethodNode methodNode, Statement statement)
statement - the statement to be executed before current codepublic void addAfterCodeBlock(MethodNode methodNode, Statement statement)
statement - the statement to be executed after current codepublic void addAroundCodeBlock(MethodNode methodNode, Statement before, Statement after)
before - to be executed beforeafter - to be executed after