public final class Criterias
extends java.lang.Object
A.CRITERIA or by
importing this class directly.
class AddPropertyToInnerClass extends AbstractClassNodeTransformer {
AddPropertyToInnerClass(final SourceUnit sourceUnit) {
super(sourceUnit,
A.CRITERIA.byClassNodeNameContains('AddTransformerSpecExample$Input'))
}
}
In this case the constructor receives as second argument a criteria
to apply the transformation only over a specific inner class.
Although criterias were targeted for transformers they could be also
used in any other transformation.
List finders = classNode
.getMethods()
.findAll(and(byMethodNodeNameStartsWith('find'),
byMethodNodeNameContains('By')))
This last example could be a normal case in a local transformation
where you are interested in checking the existence of a certain
node in order to take a decision during the transformation.| Constructor and Description |
|---|
Criterias() |
| Modifier and Type | Method and Description |
|---|---|
static Closure<java.lang.Boolean> |
and(Closure<java.lang.Boolean>... fns)
Combines two
Closure expressions returning a boolean. |
static <T extends AnnotatedNode> |
byAnnotation(java.lang.Class annotationClazz)
Criteria to find those annotated nodes with an annotation with
a
Class. |
static <T extends AnnotatedNode> |
byAnnotationSimpleName(java.lang.String annotationName)
Criteria to find those annotated nodes with an annotation with
a
Class with a name as the passed argument. |
static <T extends ClassNode> |
byClassNodeNameContains(java.lang.String term)
Criteria to find those classes with a name containing the term
passed as parameter
|
static <T extends ClassNode> |
byClassNodeNameEndsWith(java.lang.String term)
Criteria to find those classes with a name containing the term
passed as parameter at the end.
|
static <T extends ClassNode> |
byClassNodeNameStartsWith(java.lang.String term)
Criteria to find those classes with a name containing the term
passed as parameter at the beginning.
|
static <T extends Expression> |
byExprAny()
This criteria will make the transformer to process every
Expression |
static <T extends Expression> |
byExprBinaryUsingToken(int tokenType)
Checks that a given
BinaryExpression uses a specific
token type. |
static Closure<java.lang.Boolean> |
byExprMethodCallByArgs(java.lang.Class... argTypes)
This method returns a criteria to look for
MethodCallExpression with arguments with the types specified
as parameters |
static <T extends Expression> |
byExprMethodCallByName(java.lang.String name)
This method returns a criteria to look for
MethodCallExpression
with a name equals to the name passed as parameter |
static <T extends MethodNode> |
byMethodNodeName(java.lang.String methodName)
Criteria to find those methods with a specific name
|
static <T extends MethodNode> |
byMethodNodeNameContains(java.lang.String term)
Criteria to find those methods with a name containing the term
passed as parameter
|
static <T extends MethodNode> |
byMethodNodeNameEndsWith(java.lang.String suffix)
Criteria to find those methods with a name containing the term
passed as parameter at the end.
|
static <T extends MethodNode> |
byMethodNodeNameStartsWith(java.lang.String prefix)
Criteria to find those methods with a name containing the term
passed as parameter at the beginning.
|
static <T extends Statement> |
byStmtByType(java.lang.Class<T> stmtClass)
This method returns a criteria to look for
Statement
with a specific type |
static Closure<java.lang.Boolean> |
or(Closure<java.lang.Boolean>... fns)
Combines two
Closure expressions returning a boolean. |
public static <T extends AnnotatedNode> Closure<java.lang.Boolean> byAnnotation(java.lang.Class annotationClazz)
Class.
annotationClazz - the type of the annotationpublic static <T extends AnnotatedNode> Closure<java.lang.Boolean> byAnnotationSimpleName(java.lang.String annotationName)
Class with a name as the passed argument. This name
should be the same as using Class.getSimpleName()
Class as argument
cause the package (type information) won't be available for
earlier CompilePhaseannotationName - the simple name of the Class of the annotation used as markeropublic static <T extends MethodNode> Closure<java.lang.Boolean> byMethodNodeName(java.lang.String methodName)
methodName - the name returned by MethodNode.getName()AbstractMethodNodeTransformer constructorpublic static <T extends MethodNode> Closure<java.lang.Boolean> byMethodNodeNameContains(java.lang.String term)
term - the term contained in the MethodNode nameAbstractMethodNodeTransformer constructorpublic static <T extends MethodNode> Closure<java.lang.Boolean> byMethodNodeNameEndsWith(java.lang.String suffix)
suffix - the term at the end of the MethodNode nameAbstractMethodNodeTransformer constructorpublic static <T extends MethodNode> Closure<java.lang.Boolean> byMethodNodeNameStartsWith(java.lang.String prefix)
prefix - at the beginning of the MethodNode nameAbstractMethodNodeTransformer constructorpublic static <T extends ClassNode> Closure<java.lang.Boolean> byClassNodeNameContains(java.lang.String term)
term - the term contained in the ClassNode nameAbstractClassNodeTransformer constructorpublic static <T extends ClassNode> Closure<java.lang.Boolean> byClassNodeNameEndsWith(java.lang.String term)
term - the term at the end of the ClassNode nameAbstractClassNodeTransformer constructorpublic static <T extends ClassNode> Closure<java.lang.Boolean> byClassNodeNameStartsWith(java.lang.String term)
term - at the beginning of the ClassNode nameAbstractClassNodeTransformer constructorpublic static <T extends Expression> Closure<java.lang.Boolean> byExprMethodCallByName(java.lang.String name)
MethodCallExpression
with a name equals to the name passed as parametername - the method namepublic static Closure<java.lang.Boolean> byExprMethodCallByArgs(java.lang.Class... argTypes)
MethodCallExpression with arguments with the types specified
as parametersargTypes - the classes of every parameterpublic static <T extends Expression> Closure<java.lang.Boolean> byExprAny()
Expressionpublic static <T extends Expression> Closure<java.lang.Boolean> byExprBinaryUsingToken(int tokenType)
BinaryExpression uses a specific
token type. The token type is an `int` value. You can use
Types where all token types are declared.public static <T extends Statement> Closure<java.lang.Boolean> byStmtByType(java.lang.Class<T> stmtClass)
Statement
with a specific typestmtClass - the type Classpublic static Closure<java.lang.Boolean> or(Closure<java.lang.Boolean>... fns)
Closure expressions returning a boolean.
The result will be a function that returns true if the
parameter passed makes any of the former functions to return
true.
AST
def even = { x -> x % 2 == 0 }
def positive = { y -> y > 0 }
def evenOrPositive = or(even, positive)fns - functions to combineClosurepublic static Closure<java.lang.Boolean> and(Closure<java.lang.Boolean>... fns)
Closure expressions returning a boolean.
The result will be a function that returns true only if the
parameter passed makes all of the former functions to return
true.
AST
def even = { x -> x % 2 == 0 }
def positive = { y -> y > 0 }
def evenAndPositive = and(even, positive)fns - functions to combineClosure