Package io.codemodder.ast
Class ASTTransforms
java.lang.Object
io.codemodder.ast.ASTTransforms
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddImportIfMissing(com.github.javaparser.ast.CompilationUnit cu, Class<?> clazz) Add an import in alphabetical order.static voidaddImportIfMissing(com.github.javaparser.ast.CompilationUnit cu, String className) Add an import in alphabetical order.static voidaddStatementAfterStatement(com.github.javaparser.ast.stmt.Statement existingStatement, com.github.javaparser.ast.stmt.Statement newStatement) Adds anStatementafter anotherStatement.static voidaddStatementBeforeStatement(com.github.javaparser.ast.stmt.Statement existingStatement, com.github.javaparser.ast.stmt.Statement newStatement) Adds anStatementbefore anotherStatement.static voidaddStaticImportIfMissing(com.github.javaparser.ast.CompilationUnit cu, String method) static com.github.javaparser.ast.stmt.TryStmtcombineResources(com.github.javaparser.ast.stmt.TryStmt innerTry) Given aTryStmtwithout 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 voidremoveImportIfUnused(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.TryStmtsplitResources(com.github.javaparser.ast.stmt.TryStmt stmt, int index) Given aTryStmtsplit its resources into two nestedTryStmts.static com.github.javaparser.ast.stmt.TryStmtwrapIntoResource(com.github.javaparser.ast.stmt.ExpressionStmt stmt, com.github.javaparser.ast.expr.VariableDeclarationExpr vdecl, LocalScope scope) Given a local variable declarationstmt, wherevdeclis a single initialized declaration of a variablevwith scopescope,vis 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 anStatementbefore anotherStatement. SingleStatements in the body of For/Do/While/If/Labeled Statements are replaced with aBlockStmtcontaining both statements. -
addStatementAfterStatement
public static void addStatementAfterStatement(com.github.javaparser.ast.stmt.Statement existingStatement, com.github.javaparser.ast.stmt.Statement newStatement) Adds anStatementafter anotherStatement. SingleStatements in the body of For/Do/While/If/Labeled Statements are replaced with aBlockStmtcontaining 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, wherevdeclis a single initialized declaration of a variablevwith scopescope,vis 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 aTryStmtsplit its resources into two nestedTryStmts. -
combineResources
public static com.github.javaparser.ast.stmt.TryStmt combineResources(com.github.javaparser.ast.stmt.TryStmt innerTry) Given aTryStmtwithout 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.
-