Class StmtMatcher
- java.lang.Object
-
- com.tonic.analysis.source.editor.matcher.StmtMatcher
-
public class StmtMatcher extends Object
Predicate-based matcher for filtering statements during AST editing.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StmtMatcherand(StmtMatcher other)Combines this matcher with another using AND logic.static StmtMatcherany()Matches all statements.static StmtMatcheranyLoop()Matches any loop statement (for, while, do-while, for-each).static StmtMatcherassignmentStmt()Matches expression statements containing an assignment.static StmtMatcherblockStmt()Matches block statements.static StmtMatcherbreakStmt()Matches break statements.static StmtMatchercontinueStmt()Matches continue statements.static StmtMatchercustom(Predicate<Statement> predicate)Creates a matcher from a custom predicate.static StmtMatchercustom(Predicate<Statement> predicate, String description)Creates a matcher from a custom predicate with description.static StmtMatcherdoWhileStmt()Matches do-while statements.static StmtMatcherexprStmt()Matches expression statements.static StmtMatcherforEachStmt()Matches for-each statements.static StmtMatcherforStmt()Matches for statements.static StmtMatcherifElseStmt()Matches if statements with an else branch.static StmtMatcherifOnlyStmt()Matches if statements without an else branch.static StmtMatcherifStmt()Matches if statements.static StmtMatcherlabeledStmt()Matches labeled statements.booleanmatches(Statement stmt)Tests if this matcher matches the given statement.static StmtMatchermethodCallStmt()Matches expression statements containing a method call.static StmtMatchernone()Matches no statements.StmtMatchernot()Negates this matcher.static StmtMatcherofType(Class<? extends Statement> type)Matches any statement of a specific type.StmtMatcheror(StmtMatcher other)Combines this matcher with another using OR logic.static StmtMatcherreturnStmt()Matches return statements.static StmtMatcherreturnWithValue()Matches return statements with a value.static StmtMatcherswitchStmt()Matches switch statements.static StmtMatchersynchronizedStmt()Matches synchronized statements.static StmtMatcherthrowStmt()Matches throw statements.StringtoString()static StmtMatchertryCatchStmt()Matches try-catch statements.static StmtMatchervarDeclStmt()Matches variable declaration statements.static StmtMatchervoidReturn()Matches void return statements.static StmtMatcherwhileStmt()Matches while statements.static StmtMatcherwithLabel(String label)Matches statements with a specific label.
-
-
-
Method Detail
-
matches
public boolean matches(Statement stmt)
Tests if this matcher matches the given statement.- Parameters:
stmt- the statement to test, null is never matched- Returns:
- true when the predicate accepts the statement
-
ofType
public static StmtMatcher ofType(Class<? extends Statement> type)
Matches any statement of a specific type.- Parameters:
type- the statement class an instance must belong to- Returns:
- a matcher accepting instances of that class
-
returnStmt
public static StmtMatcher returnStmt()
Matches return statements.- Returns:
- a matcher accepting any return
-
returnWithValue
public static StmtMatcher returnWithValue()
Matches return statements with a value.- Returns:
- a matcher accepting non-void returns
-
voidReturn
public static StmtMatcher voidReturn()
Matches void return statements.- Returns:
- a matcher accepting returns without a value
-
throwStmt
public static StmtMatcher throwStmt()
Matches throw statements.- Returns:
- a matcher accepting throws
-
ifStmt
public static StmtMatcher ifStmt()
Matches if statements.- Returns:
- a matcher accepting any if
-
ifElseStmt
public static StmtMatcher ifElseStmt()
Matches if statements with an else branch.- Returns:
- a matcher accepting ifs that carry an else
-
ifOnlyStmt
public static StmtMatcher ifOnlyStmt()
Matches if statements without an else branch.- Returns:
- a matcher accepting ifs with no else
-
anyLoop
public static StmtMatcher anyLoop()
Matches any loop statement (for, while, do-while, for-each).- Returns:
- a matcher accepting all four loop forms
-
forStmt
public static StmtMatcher forStmt()
Matches for statements.- Returns:
- a matcher accepting counted for loops
-
whileStmt
public static StmtMatcher whileStmt()
Matches while statements.- Returns:
- a matcher accepting while loops
-
doWhileStmt
public static StmtMatcher doWhileStmt()
Matches do-while statements.- Returns:
- a matcher accepting do-while loops
-
forEachStmt
public static StmtMatcher forEachStmt()
Matches for-each statements.- Returns:
- a matcher accepting enhanced for loops
-
tryCatchStmt
public static StmtMatcher tryCatchStmt()
Matches try-catch statements.- Returns:
- a matcher accepting try statements
-
switchStmt
public static StmtMatcher switchStmt()
Matches switch statements.- Returns:
- a matcher accepting switch statements
-
synchronizedStmt
public static StmtMatcher synchronizedStmt()
Matches synchronized statements.- Returns:
- a matcher accepting synchronized blocks
-
blockStmt
public static StmtMatcher blockStmt()
Matches block statements.- Returns:
- a matcher accepting braced blocks
-
exprStmt
public static StmtMatcher exprStmt()
Matches expression statements.- Returns:
- a matcher accepting expression statements
-
varDeclStmt
public static StmtMatcher varDeclStmt()
Matches variable declaration statements.- Returns:
- a matcher accepting local declarations
-
breakStmt
public static StmtMatcher breakStmt()
Matches break statements.- Returns:
- a matcher accepting breaks
-
continueStmt
public static StmtMatcher continueStmt()
Matches continue statements.- Returns:
- a matcher accepting continues
-
labeledStmt
public static StmtMatcher labeledStmt()
Matches labeled statements.- Returns:
- a matcher accepting labeled statements
-
withLabel
public static StmtMatcher withLabel(String label)
Matches statements with a specific label.- Parameters:
label- the label a statement must carry- Returns:
- a matcher accepting statements labeled that way
-
methodCallStmt
public static StmtMatcher methodCallStmt()
Matches expression statements containing a method call.- Returns:
- a matcher accepting expression statements whose expression is a call
-
assignmentStmt
public static StmtMatcher assignmentStmt()
Matches expression statements containing an assignment.- Returns:
- a matcher accepting expression statements whose expression assigns
-
custom
public static StmtMatcher custom(Predicate<Statement> predicate)
Creates a matcher from a custom predicate.- Parameters:
predicate- the test to apply to each statement- Returns:
- a matcher backed by the predicate, described as "custom"
-
custom
public static StmtMatcher custom(Predicate<Statement> predicate, String description)
Creates a matcher from a custom predicate with description.- Parameters:
predicate- the test to apply to each statementdescription- the text used bytoString()- Returns:
- a matcher backed by the predicate
-
any
public static StmtMatcher any()
Matches all statements.- Returns:
- a matcher that always accepts
-
none
public static StmtMatcher none()
Matches no statements.- Returns:
- a matcher that never accepts
-
and
public StmtMatcher and(StmtMatcher other)
Combines this matcher with another using AND logic.- Parameters:
other- the matcher that must also accept- Returns:
- a matcher accepting only what both accept
-
or
public StmtMatcher or(StmtMatcher other)
Combines this matcher with another using OR logic.- Parameters:
other- the alternative matcher- Returns:
- a matcher accepting what either accepts
-
not
public StmtMatcher not()
Negates this matcher.- Returns:
- a matcher accepting exactly what this one rejects
-
-