Package io.codemodder.codemods
Class RemoveUnusedLocalVariableCodemod
java.lang.Object
io.codemodder.javaparser.JavaParserChanger
io.codemodder.providers.sonar.SonarPluginJavaParserChanger<com.github.javaparser.ast.body.VariableDeclarator>
io.codemodder.codemods.RemoveUnusedLocalVariableCodemod
- All Implemented Interfaces:
io.codemodder.CodeChanger
@Codemod(id="sonar:java/remove-unused-local-variable-s1481",
reviewGuidance=MERGE_WITHOUT_REVIEW,
executionPriority=HIGH)
public final class RemoveUnusedLocalVariableCodemod
extends io.codemodder.providers.sonar.SonarPluginJavaParserChanger<com.github.javaparser.ast.body.VariableDeclarator>
Codemod to remove unused local variables which expression is a variable or just a Literal
expression like a single boolean, char, double, integer, long, null, string or a text block
string. We are not considering create object expression, method call expressions, condition
expressions, etc. because all of them have an expression node and that expression node could
result in a method call expression where a process could be performed and deleting it could
result on some unexpected behaviors.
-
Field Summary
Fields inherited from class io.codemodder.javaparser.JavaParserChanger
reporter
-
Constructor Summary
ConstructorsConstructorDescriptionRemoveUnusedLocalVariableCodemod
(io.codemodder.providers.sonar.RuleIssues issues) -
Method Summary
Modifier and TypeMethodDescriptionboolean
onIssueFound
(io.codemodder.CodemodInvocationContext context, com.github.javaparser.ast.CompilationUnit cu, com.github.javaparser.ast.body.VariableDeclarator variableDeclarator, io.codemodder.providers.sonar.api.Issue issue) Methods inherited from class io.codemodder.providers.sonar.SonarPluginJavaParserChanger
shouldRun, visit
Methods inherited from class io.codemodder.javaparser.JavaParserChanger
dependenciesRequired, getDescription, getIndividualChangeDescription, getReferences, getSummary
-
Constructor Details
-
RemoveUnusedLocalVariableCodemod
@Inject public RemoveUnusedLocalVariableCodemod(@ProvidedSonarScan(ruleId="java:S1481") io.codemodder.providers.sonar.RuleIssues issues)
-
-
Method Details
-
onIssueFound
public boolean onIssueFound(io.codemodder.CodemodInvocationContext context, com.github.javaparser.ast.CompilationUnit cu, com.github.javaparser.ast.body.VariableDeclarator variableDeclarator, io.codemodder.providers.sonar.api.Issue issue) - Specified by:
onIssueFound
in classio.codemodder.providers.sonar.SonarPluginJavaParserChanger<com.github.javaparser.ast.body.VariableDeclarator>
-