public class GeneralUtils extends Object
Modifier and Type | Field and Description |
---|---|
static Token |
AND |
static Token |
ASSIGN |
static Token |
CMP |
static Token |
EQ |
static Token |
LT |
static Token |
NE |
static Token |
OR |
Constructor and Description |
---|
GeneralUtils() |
public static final Token ASSIGN
public static final Token EQ
public static final Token NE
public static final Token LT
public static final Token AND
public static final Token OR
public static final Token CMP
public static BinaryExpression andX(Expression lhv, Expression rhv)
public static ArgumentListExpression args(Expression... expressions)
public static ArgumentListExpression args(List<Expression> expressions)
public static ArgumentListExpression args(Parameter[] parameters)
public static ArgumentListExpression args(String... names)
public static Statement assignNullS(Expression target)
public static Statement assignS(Expression target, Expression value)
public static Expression assignX(Expression target, Expression value)
public static Expression attrX(Expression oe, Expression prop)
public static BinaryExpression binX(Expression left, Token token, Expression right)
public static BlockStatement block(VariableScope scope, Statement... stmts)
public static BlockStatement block(VariableScope scope, List<Statement> stmts)
public static BlockStatement block(Statement... stmts)
public static BooleanExpression boolX(Expression expr)
public static MethodCallExpression callSuperX(String methodName)
public static MethodCallExpression callSuperX(String methodName, Expression args)
public static MethodCallExpression callThisX(String methodName)
public static MethodCallExpression callThisX(String methodName, Expression args)
public static MethodCallExpression callX(Expression receiver, String methodName)
public static MethodCallExpression callX(Expression receiver, String methodName, Expression args)
public static MethodCallExpression callX(Expression receiver, Expression method, Expression args)
public static StaticMethodCallExpression callX(ClassNode receiver, String methodName)
public static StaticMethodCallExpression callX(ClassNode receiver, String methodName, Expression args)
public static CastExpression castX(ClassNode type, Expression expression)
public static CastExpression castX(ClassNode type, Expression expression, boolean ignoreAutoboxing)
public static CatchStatement catchS(Parameter variable, Statement code)
public static ClassExpression classX(ClassNode clazz)
public static ClassExpression classX(Class clazz)
public static ClosureExpression closureX(Parameter[] params, Statement code)
public static ClosureExpression closureX(Statement code)
public static BinaryExpression cmpX(Expression lhv, Expression rhv)
lhv
- expression for the value to compare fromrhv
- expression for the value value to compare topublic static ConstantExpression constX(Object val)
public static ConstantExpression constX(Object val, boolean keepPrimitive)
public static ConstructorCallExpression ctorX(ClassNode type, Expression args)
public static ConstructorCallExpression ctorX(ClassNode type)
public static Statement ctorSuperS()
public static Statement ctorSuperS(Expression args)
public static ConstructorCallExpression ctorSuperX()
public static ConstructorCallExpression ctorSuperX(Expression args)
public static Statement ctorThisS()
public static Statement ctorThisS(Expression args)
public static ConstructorCallExpression ctorThisX()
public static ConstructorCallExpression ctorThisX(Expression args)
public static Statement declS(Expression target, Expression init)
public static DeclarationExpression declX(Expression target, Expression init)
public static MapEntryExpression entryX(Expression key, Expression value)
public static BinaryExpression eqX(Expression lhv, Expression rhv)
public static BooleanExpression equalsNullX(Expression argExpr)
public static FieldExpression fieldX(FieldNode fieldNode)
public static FieldExpression fieldX(ClassNode owner, String fieldName)
public static Expression findArg(String argName)
public static List<MethodNode> getAllMethods(ClassNode type)
public static List<PropertyNode> getAllProperties(ClassNode type)
public static List<FieldNode> getInstanceNonPropertyFields(ClassNode cNode)
public static List<String> getInstanceNonPropertyFieldNames(ClassNode cNode)
public static List<PropertyNode> getInstanceProperties(ClassNode cNode)
public static Set<ClassNode> getInterfacesAndSuperInterfaces(ClassNode type)
public static List<PropertyNode> getAllProperties(Set<String> names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly)
public static List<PropertyNode> getAllProperties(Set<String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly)
public static List<PropertyNode> getAllProperties(Set<String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly, boolean reverse, boolean allNames, boolean includeStatic)
public static Expression getterThisX(ClassNode annotatedNode, PropertyNode pNode)
propX(Expression, Expression)
but will make sure that if the property
being accessed is defined inside the classnode provided as a parameter, then a getter call is generated
instead of a field access.annotatedNode
- the class node where the property node is accessed frompNode
- the property being accessedpublic static Expression getterX(ClassNode annotatedNode, Expression receiver, PropertyNode pNode)
propX(Expression, Expression)
but will make sure that if the property
being accessed is defined inside the classnode provided as a parameter, then a getter call is generated
instead of a field access.annotatedNode
- the class node where the property node is accessed fromreceiver
- the object having the propertypNode
- the property being accessedpublic static BinaryExpression hasClassX(Expression instance, ClassNode cNode)
public static BinaryExpression hasEqualFieldX(FieldNode fNode, Expression other)
public static BinaryExpression hasEqualPropertyX(ClassNode annotatedNode, PropertyNode pNode, VariableExpression other)
@Deprecated public static BinaryExpression hasEqualPropertyX(PropertyNode pNode, Expression other)
public static BooleanExpression hasSameFieldX(FieldNode fNode, Expression other)
public static BooleanExpression hasSamePropertyX(PropertyNode pNode, Expression other)
@Deprecated public static Statement ifElseS$$bridge(Expression cond, Statement thenStmt, Statement elseStmt)
public static IfStatement ifElseS(Expression cond, Statement thenStmt, Statement elseStmt)
@Deprecated public static Statement ifS$$bridge(Expression cond, Expression trueExpr)
public static IfStatement ifS(Expression cond, Expression trueExpr)
@Deprecated public static Statement ifS$$bridge(Expression cond, Statement trueStmt)
public static IfStatement ifS(Expression cond, Statement trueStmt)
public static Expression indexX(Expression target, Expression value)
public static BooleanExpression isInstanceOfX(Expression objectExpression, ClassNode cNode)
public static BooleanExpression isNullX(Expression expr)
equalsNullX(Expression)
public static BooleanExpression isOneX(Expression expr)
public static BooleanExpression isTrueX(Expression argExpr)
public static BooleanExpression isZeroX(Expression expr)
public static ListExpression listX(List<Expression> args)
public static ListExpression list2args(List args)
public static ListExpression classList2args(List<String> args)
public static VariableExpression localVarX(String name)
public static VariableExpression localVarX(String name, ClassNode type)
public static BinaryExpression ltX(Expression lhv, Expression rhv)
public static MapExpression mapX(List<MapEntryExpression> expressions)
public static BinaryExpression neX(Expression lhv, Expression rhv)
public static BooleanExpression notNullX(Expression argExpr)
public static NotExpression notX(Expression expr)
public static ConstantExpression nullX()
public static BinaryExpression orX(Expression lhv, Expression rhv)
public static Parameter param(ClassNode type, String name, Expression initialExpression)
public static BinaryExpression plusX(Expression lhv, Expression rhv)
public static Expression propX(Expression owner, String property)
public static Expression propX(Expression owner, Expression property)
public static PropertyExpression propX(Expression owner, Expression property, boolean safe)
public static Statement returnS(Expression expr)
public static Statement safeExpression(Expression fieldExpr, Expression expression)
public static BooleanExpression sameX(Expression self, Expression other)
public static Statement stmt(Expression expr)
public static TernaryExpression ternaryX(Expression cond, Expression trueExpr, Expression elseExpr)
public static PropertyExpression thisPropX(boolean implicit, String property)
public static ThrowStatement throwS(Expression expr)
public static TryCatchStatement tryCatchS(Statement tryStatement)
public static TryCatchStatement tryCatchS(Statement tryStatement, Statement finallyStatement)
public static VariableExpression varX(String name)
public static VariableExpression varX(Variable variable)
public static VariableExpression varX(String name, ClassNode type)
public static void copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied)
RetentionPolicy.RUNTIME
and RetentionPolicy.CLASS
.
Annotations with GeneratedClosure
members are not supported at present.
public static void copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied, boolean includeGenerated)
RetentionPolicy.RUNTIME
and RetentionPolicy.CLASS
.
Generated
annotations will be copied if includeGenerated
is true.
Annotations with GeneratedClosure
members are not supported at present.
public static Statement createConstructorStatementDefault(FieldNode fNode)
public static String getGetterName(PropertyNode pNode)
public static String convertASTToSource(ReaderSource readerSource, ASTNode expression) throws Exception
readerSource
- a sourceexpression
- an expression. Can't be nullIllegalArgumentException
- when expression is nullException
- when closure can't be read from sourcepublic static boolean copyStatementsWithSuperAdjustment(ClosureExpression pre, BlockStatement body)
public static boolean hasDeclaredMethod(ClassNode cNode, String name, int argsCount)
public static boolean isDefaultVisibility(int modifiers)
@Deprecated public static String makeDescriptorWithoutReturnType(MethodNode mn)