Package io.codemodder.ast
Class ASTTransforms
java.lang.Object
io.codemodder.ast.ASTTransforms
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addImportIfMissing
(com.github.javaparser.ast.CompilationUnit cu, Class<?> clazz) Add an import in alphabetical order.static void
addImportIfMissing
(com.github.javaparser.ast.CompilationUnit cu, String className) Add an import in alphabetical order.static void
addStatementAfterStatement
(com.github.javaparser.ast.stmt.Statement existingStatement, com.github.javaparser.ast.stmt.Statement newStatement) Adds anStatement
after anotherStatement
.static void
addStatementBeforeStatement
(com.github.javaparser.ast.stmt.Statement existingStatement, com.github.javaparser.ast.stmt.Statement newStatement) Adds anStatement
before anotherStatement
.static void
addStaticImportIfMissing
(com.github.javaparser.ast.CompilationUnit cu, String method) static com.github.javaparser.ast.stmt.TryStmt
combineResources
(com.github.javaparser.ast.stmt.TryStmt innerTry) Given aTryStmt
without any finally and catch clauses, and that is the first statement of a try with resources block, merge the two try statements into one.static void
removeImportIfUnused
(com.github.javaparser.ast.CompilationUnit cu, String className) Remove an import if we can't find references to it in the code.static com.github.javaparser.ast.stmt.TryStmt
splitResources
(com.github.javaparser.ast.stmt.TryStmt stmt, int index) Given aTryStmt
split its resources into two nestedTryStmt
s.static com.github.javaparser.ast.stmt.TryStmt
wrapIntoResource
(com.github.javaparser.ast.stmt.ExpressionStmt stmt, com.github.javaparser.ast.expr.VariableDeclarationExpr vdecl, LocalScope scope) Given a local variable declarationstmt
, wherevdecl
is a single initialized declaration of a variablev
with scopescope
,v
is never assigned in its scope, then wrap the declaration into as a resource of a try stmt.
-
Constructor Details
-
ASTTransforms
public ASTTransforms()
-
-
Method Details
-
addImportIfMissing
public static void addImportIfMissing(com.github.javaparser.ast.CompilationUnit cu, String className) Add an import in alphabetical order. -
addImportIfMissing
Add an import in alphabetical order. -
addStaticImportIfMissing
public static void addStaticImportIfMissing(com.github.javaparser.ast.CompilationUnit cu, String method) -
addStatementBeforeStatement
public static void addStatementBeforeStatement(com.github.javaparser.ast.stmt.Statement existingStatement, com.github.javaparser.ast.stmt.Statement newStatement) Adds anStatement
before anotherStatement
. SingleStatement
s in the body of For/Do/While/If/Labeled Statements are replaced with aBlockStmt
containing both statements. -
addStatementAfterStatement
public static void addStatementAfterStatement(com.github.javaparser.ast.stmt.Statement existingStatement, com.github.javaparser.ast.stmt.Statement newStatement) Adds anStatement
after anotherStatement
. SingleStatement
s in the body of For/Do/While/If/Labeled Statements are replaced with aBlockStmt
containing both statements. -
wrapIntoResource
public static com.github.javaparser.ast.stmt.TryStmt wrapIntoResource(com.github.javaparser.ast.stmt.ExpressionStmt stmt, com.github.javaparser.ast.expr.VariableDeclarationExpr vdecl, LocalScope scope) Given a local variable declarationstmt
, wherevdecl
is a single initialized declaration of a variablev
with scopescope
,v
is never assigned in its scope, then wrap the declaration into as a resource of a try stmt. -
splitResources
public static com.github.javaparser.ast.stmt.TryStmt splitResources(com.github.javaparser.ast.stmt.TryStmt stmt, int index) Given aTryStmt
split its resources into two nestedTryStmt
s. -
combineResources
public static com.github.javaparser.ast.stmt.TryStmt combineResources(com.github.javaparser.ast.stmt.TryStmt innerTry) Given aTryStmt
without any finally and catch clauses, and that is the first statement of a try with resources block, merge the two try statements into one. -
removeImportIfUnused
public static void removeImportIfUnused(com.github.javaparser.ast.CompilationUnit cu, String className) Remove an import if we can't find references to it in the code.
-