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 voidmergeConcatenatedLiterals(com.github.javaparser.ast.expr.Expression e) Given a string expression, merge any literals that are directly concatenated.static com.github.javaparser.ast.expr.ExpressionremoveEmptyStringConcatenation(com.github.javaparser.ast.expr.BinaryExpr binexp) Removes concatenation with empty strings.static voidremoveEmptyStringConcatenation(com.github.javaparser.ast.Node subtree) Removes all concatenations with empty strings in the given subtree.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 voidremoveUnusedLocalVariables(com.github.javaparser.ast.Node subtree) Removes unused variables.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. -
removeEmptyStringConcatenation
public static com.github.javaparser.ast.expr.Expression removeEmptyStringConcatenation(com.github.javaparser.ast.expr.BinaryExpr binexp) Removes concatenation with empty strings. For example, in : ``` String a = "some string"; String b = ""; a + "" + b; ``` The expression `a + "" + b` would be reduced to `a`. Returns the expression without the empty concatenations. -
removeEmptyStringConcatenation
public static void removeEmptyStringConcatenation(com.github.javaparser.ast.Node subtree) Removes all concatenations with empty strings in the given subtree. -
removeUnusedLocalVariables
public static void removeUnusedLocalVariables(com.github.javaparser.ast.Node subtree) Removes unused variables. -
mergeConcatenatedLiterals
public static void mergeConcatenatedLiterals(com.github.javaparser.ast.expr.Expression e) Given a string expression, merge any literals that are directly concatenated. This transform will recurse over any Names referenced.
-