Class ExprMatcher
- java.lang.Object
-
- com.tonic.analysis.source.editor.matcher.ExprMatcher
-
public class ExprMatcher extends Object
Composable predicate over expressions, used to select edit targets in the AST.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExprMatcherand(ExprMatcher other)Combines this matcher with another using AND logic.static ExprMatcherany()Matches all expressions.static ExprMatcheranyArrayAccess()Matches all array access expressions.static ExprMatcheranyBinary()Matches all binary expressions.static ExprMatcheranyCast()Matches any cast expression.static ExprMatcheranyFieldAccess()Matches all field access expressions.static ExprMatcheranyInstanceOf()Matches any instanceof expression.static ExprMatcheranyLiteral()Matches all literal expressions.static ExprMatcheranyMethodCall()Matches all method call expressions.static ExprMatcheranyUnary()Matches all unary expressions.static ExprMatcherassignment()Matches binary expressions whose operator assigns.static ExprMatcherbinaryOp(BinaryOperator op)Matches binary expressions with a specific operator.static ExprMatchercast(String targetType)Matches cast expressions to a specific type.static ExprMatchercomparison()Matches binary expressions whose operator is a comparison.static ExprMatchercustom(Predicate<Expression> predicate)Creates a matcher from a custom predicate.static ExprMatchercustom(Predicate<Expression> predicate, String description)Creates a matcher from a custom predicate with a description.static ExprMatcherfieldAccess(String fieldName)Matches field accesses by field name, whatever the owner.static ExprMatcherfieldAccess(String ownerClass, String fieldName)Matches field accesses by owner class and field name.static ExprMatcherinstanceOf(String checkedType)Matches instanceof expressions checking a specific type.booleanmatches(Expression expr)Applies this matcher's predicate.static ExprMatchermethodCall(String methodName)Matches method calls by method name, whatever the owner.static ExprMatchermethodCall(String ownerClass, String methodName)Matches method calls by owner class and method name.static ExprMatchermethodCall(String ownerClass, String methodName, int argCount)Matches method calls by owner class, method name and argument count.static ExprMatchernewArray()Matches new array expressions.static ExprMatchernewExpr(String className)Matches allocations of a specific class.static ExprMatchernone()Matches no expressions.ExprMatchernot()Negates this matcher.static ExprMatcherofType(Class<? extends Expression> type)Matches any expression of a specific node type.ExprMatcheror(ExprMatcher other)Combines this matcher with another using OR logic.StringtoString()static ExprMatcherunaryOp(UnaryOperator op)Matches unary expressions with a specific operator.
-
-
-
Method Detail
-
matches
public boolean matches(Expression expr)
Applies this matcher's predicate.- Parameters:
expr- the expression to test, may be null- Returns:
- true if the predicate accepts it; false if it is null
-
methodCall
public static ExprMatcher methodCall(String methodName)
Matches method calls by method name, whatever the owner.- Parameters:
methodName- the method name to require- Returns:
- the matcher
-
methodCall
public static ExprMatcher methodCall(String ownerClass, String methodName)
Matches method calls by owner class and method name.- Parameters:
ownerClass- the declaring class, in either slashed or dotted formmethodName- the method name to require- Returns:
- the matcher
-
methodCall
public static ExprMatcher methodCall(String ownerClass, String methodName, int argCount)
Matches method calls by owner class, method name and argument count.- Parameters:
ownerClass- the declaring class, in either slashed or dotted formmethodName- the method name to requireargCount- the exact number of arguments to require- Returns:
- the matcher
-
fieldAccess
public static ExprMatcher fieldAccess(String fieldName)
Matches field accesses by field name, whatever the owner.- Parameters:
fieldName- the field name to require- Returns:
- the matcher
-
fieldAccess
public static ExprMatcher fieldAccess(String ownerClass, String fieldName)
Matches field accesses by owner class and field name.- Parameters:
ownerClass- the declaring class, in either slashed or dotted formfieldName- the field name to require- Returns:
- the matcher
-
newExpr
public static ExprMatcher newExpr(String className)
Matches allocations of a specific class.- Parameters:
className- the class name, in either slashed or dotted form- Returns:
- the matcher
-
newArray
public static ExprMatcher newArray()
Matches new array expressions.- Returns:
- the matcher
-
cast
public static ExprMatcher cast(String targetType)
Matches cast expressions to a specific type.- Parameters:
targetType- the cast target, in either slashed or dotted form- Returns:
- the matcher
-
anyCast
public static ExprMatcher anyCast()
Matches any cast expression.- Returns:
- the matcher
-
instanceOf
public static ExprMatcher instanceOf(String checkedType)
Matches instanceof expressions checking a specific type.- Parameters:
checkedType- the type name, in either slashed or dotted form- Returns:
- the matcher
-
anyInstanceOf
public static ExprMatcher anyInstanceOf()
Matches any instanceof expression.- Returns:
- the matcher
-
ofType
public static ExprMatcher ofType(Class<? extends Expression> type)
Matches any expression of a specific node type.- Parameters:
type- the expression class to require- Returns:
- the matcher
-
anyMethodCall
public static ExprMatcher anyMethodCall()
Matches all method call expressions.- Returns:
- the matcher
-
anyFieldAccess
public static ExprMatcher anyFieldAccess()
Matches all field access expressions.- Returns:
- the matcher
-
anyBinary
public static ExprMatcher anyBinary()
Matches all binary expressions.- Returns:
- the matcher
-
anyUnary
public static ExprMatcher anyUnary()
Matches all unary expressions.- Returns:
- the matcher
-
anyLiteral
public static ExprMatcher anyLiteral()
Matches all literal expressions.- Returns:
- the matcher
-
anyArrayAccess
public static ExprMatcher anyArrayAccess()
Matches all array access expressions.- Returns:
- the matcher
-
binaryOp
public static ExprMatcher binaryOp(BinaryOperator op)
Matches binary expressions with a specific operator.- Parameters:
op- the operator to require- Returns:
- the matcher
-
assignment
public static ExprMatcher assignment()
Matches binary expressions whose operator assigns.- Returns:
- the matcher
-
comparison
public static ExprMatcher comparison()
Matches binary expressions whose operator is a comparison.- Returns:
- the matcher
-
unaryOp
public static ExprMatcher unaryOp(UnaryOperator op)
Matches unary expressions with a specific operator.- Parameters:
op- the operator to require- Returns:
- the matcher
-
custom
public static ExprMatcher custom(Predicate<Expression> predicate)
Creates a matcher from a custom predicate.- Parameters:
predicate- the test applied to each expression- Returns:
- the matcher
-
custom
public static ExprMatcher custom(Predicate<Expression> predicate, String description)
Creates a matcher from a custom predicate with a description.- Parameters:
predicate- the test applied to each expressiondescription- the text used bytoString()- Returns:
- the matcher
-
any
public static ExprMatcher any()
Matches all expressions.- Returns:
- the matcher
-
none
public static ExprMatcher none()
Matches no expressions.- Returns:
- the matcher
-
and
public ExprMatcher and(ExprMatcher other)
Combines this matcher with another using AND logic.- Parameters:
other- the matcher to combine with- Returns:
- a matcher accepting only what both accept
-
or
public ExprMatcher or(ExprMatcher other)
Combines this matcher with another using OR logic.- Parameters:
other- the matcher to combine with- Returns:
- a matcher accepting what either one accepts
-
not
public ExprMatcher not()
Negates this matcher.- Returns:
- a matcher accepting everything this one rejects
-
-