Package com.tonic.analysis.source.editor
Class Replacement
- java.lang.Object
-
- com.tonic.analysis.source.editor.Replacement
-
public abstract class Replacement extends Object
The action an editor handler returns for a visited AST node: keep, replace, remove, or insert.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReplacement.TypeThe kind of action a replacement performs.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExpressiongetExpression()StatementgetStatement()List<Statement>getStatements()Replacement.TypegetType()static ReplacementinsertAfter(Statement... stmts)Creates a replacement that inserts statements after the current statement.static ReplacementinsertAfter(List<Statement> stmts)Creates a replacement that inserts statements after the current statement.static ReplacementinsertBefore(Statement... stmts)Creates a replacement that inserts statements before the current statement.static ReplacementinsertBefore(List<Statement> stmts)Creates a replacement that inserts statements before the current statement.booleanisInsert()booleanisKeep()booleanisRemove()booleanisReplace()static Replacementkeep()static Replacementremove()static Replacementwith(Expression newExpr)Creates a replacement that substitutes a new expression for the visited one.static Replacementwith(Statement newStmt)Creates a replacement that substitutes a new statement for the visited one.static ReplacementwithBlock(Statement... stmts)Creates a replacement that substitutes multiple statements for the visited one.static ReplacementwithBlock(List<Statement> stmts)Creates a replacement that substitutes multiple statements for the visited one.
-
-
-
Method Detail
-
getType
public Replacement.Type getType()
- Returns:
- the type
-
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
-
-