Class Replacement


  • public abstract class Replacement
    extends Object
    The action an editor handler returns for a visited AST node: keep, replace, remove, or insert.
    • Method Detail

      • isKeep

        public boolean isKeep()
        Returns:
        true if this replacement leaves the node unchanged
      • isReplace

        public boolean isReplace()
        Returns:
        true if this replacement substitutes an expression, statement, or block
      • isRemove

        public boolean isRemove()
        Returns:
        true if this replacement removes the node entirely
      • isInsert

        public boolean isInsert()
        Returns:
        true if this replacement inserts a node before or after the original
      • keep

        public static Replacement keep()
        Returns:
        the shared replacement that keeps the original node unchanged
      • with

        public static Replacement with​(Expression newExpr)
        Creates a replacement that substitutes a new expression for the visited one.
        Parameters:
        newExpr - the expression to substitute
        Returns:
        the expression replacement
        Throws:
        IllegalArgumentException - if newExpr is null
      • with

        public static Replacement with​(Statement newStmt)
        Creates a replacement that substitutes a new statement for the visited one.
        Parameters:
        newStmt - the statement to substitute
        Returns:
        the statement replacement
        Throws:
        IllegalArgumentException - if newStmt is null
      • withBlock

        public static Replacement withBlock​(Statement... stmts)
        Creates a replacement that substitutes multiple statements for the visited one.
        Parameters:
        stmts - the statements to substitute
        Returns:
        the block replacement
        Throws:
        IllegalArgumentException - if stmts is null or empty
      • withBlock

        public static Replacement withBlock​(List<Statement> stmts)
        Creates a replacement that substitutes multiple statements for the visited one.
        Parameters:
        stmts - the statements to substitute
        Returns:
        the block replacement
        Throws:
        IllegalArgumentException - if stmts is null or empty
      • remove

        public static Replacement remove()
        Returns:
        the shared replacement that removes the node entirely
      • insertBefore

        public static Replacement insertBefore​(Statement... stmts)
        Creates a replacement that inserts statements before the current statement.
        Parameters:
        stmts - the statements to insert
        Returns:
        the insert-before replacement
        Throws:
        IllegalArgumentException - if stmts is null or empty
      • insertBefore

        public static Replacement insertBefore​(List<Statement> stmts)
        Creates a replacement that inserts statements before the current statement.
        Parameters:
        stmts - the statements to insert
        Returns:
        the insert-before replacement
        Throws:
        IllegalArgumentException - if stmts is null or empty
      • insertAfter

        public static Replacement insertAfter​(Statement... stmts)
        Creates a replacement that inserts statements after the current statement.
        Parameters:
        stmts - the statements to insert
        Returns:
        the insert-after replacement
        Throws:
        IllegalArgumentException - if stmts is null or empty
      • insertAfter

        public static Replacement insertAfter​(List<Statement> stmts)
        Creates a replacement that inserts statements after the current statement.
        Parameters:
        stmts - the statements to insert
        Returns:
        the insert-after replacement
        Throws:
        IllegalArgumentException - if stmts is null or empty
      • getExpression

        public Expression getExpression()
        Returns:
        the replacement expression, or null unless the type is REPLACE_EXPR
      • getStatement

        public Statement getStatement()
        Returns:
        the replacement statement, or null unless the type is REPLACE_STMT
      • getStatements

        public List<Statement> getStatements()
        Returns:
        the replacement statements, or an empty list unless the type is REPLACE_BLOCK, INSERT_BEFORE, or INSERT_AFTER