Class StmtMatcher


  • public class StmtMatcher
    extends Object
    Predicate-based matcher for filtering statements during AST editing.
    • 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 statement
        description - the text used by toString()
        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