Skip to content

Commit

Permalink
fix(spoon): Fix visitor not returning any result because of correct i…
Browse files Browse the repository at this point in the history
…mplemented visitor (#847)
  • Loading branch information
MartinWitt committed Jul 15, 2023
1 parent 62444c5 commit c65ac44
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ public interface BadSmell {

CtType<?> getAffectedType();

default <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
<T> T accept(BadSmellVisitor<T> visitor);

/**
* Fixes the bad smell. Fixing means changing the source code in a way that the bad smell is not present anymore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
*/
public interface BadSmellVisitor<U> extends Visitor<BadSmell, U> {

/**
* Visits a generic bad smell, which is not further specified. This method is called if no other method is more specific.
* @param badSmell the bad smell to visit
* @return the result of the visit
*/
default U visit(BadSmell badSmell) {
return emptyResult();
}

default U visit(IndexOfReplaceableByContains badSmell) {
return emptyResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,4 @@ public List<BadSmell> analyze(String path) {
}
return badSmells;
}

public static void main(String[] args) {
var analyzer = new SpoonAnalyzer();
var badSmells = analyzer.analyze("./assertj-assertions-generator-maven-plugin");
for (BadSmell badSmell : badSmells) {
logger.atInfo().log(badSmell.toString());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.Index_off_replaceable_by_contains;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtType;

Expand Down Expand Up @@ -60,4 +61,9 @@ public void fix() {
public boolean isFixable() {
return true;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.access_static_via_instance;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.declaration.CtType;

Expand Down Expand Up @@ -54,4 +55,9 @@ public void fix() {
public boolean isFixable() {
return true;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.array_can_be_replaced_with_enum_values;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.code.CtNewArray;
import spoon.reflect.declaration.CtType;

Expand Down Expand Up @@ -37,4 +38,9 @@ public CtType<?> getAffectedType() {
public CtNewArray<?> getAffectedElement() {
return affectedElement;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.charset_object_can_be_used;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.declaration.CtType;
Expand Down Expand Up @@ -71,4 +72,9 @@ public String toString() {
return "CharsetObjectCanBeUsed [affectedType=" + affectedType.getQualifiedName() + ", invocation=" + invocation
+ "]";
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.final_static_method;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtType;

Expand Down Expand Up @@ -38,4 +39,9 @@ public CtType<?> getAffectedType() {
public CtMethod<?> getMethod() {
return method;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.innerclass_may_be_static;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.declaration.CtType;

public class InnerClassMayBeStatic implements BadSmell {
Expand Down Expand Up @@ -50,4 +51,9 @@ public void fix() {
public boolean isFixable() {
return true;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.non_protected_constructor_In_abstract_class;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtType;

Expand Down Expand Up @@ -51,4 +52,9 @@ public void fix() {
public boolean isFixable() {
return true;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.private_final_method;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtType;

Expand Down Expand Up @@ -51,4 +52,9 @@ public void fix() {
public boolean isFixable() {
return true;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.size_replaceable_by_is_empty;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtInvocation;
Expand Down Expand Up @@ -62,4 +63,9 @@ public void fix() {
public boolean isFixable() {
return true;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.unnecessary_implements;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.declaration.CtType;
import spoon.reflect.reference.CtTypeReference;

Expand Down Expand Up @@ -63,4 +64,9 @@ public void fix() {
public boolean isFixable() {
return true;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.martinwitt.spoon_analyzer.badsmells.unnecessary_tostring;

import io.github.martinwitt.spoon_analyzer.BadSmell;
import io.github.martinwitt.spoon_analyzer.BadSmellVisitor;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.declaration.CtType;

Expand Down Expand Up @@ -47,4 +48,9 @@ public void fix() {
public boolean isFixable() {
return true;
}

@Override
public <T> T accept(BadSmellVisitor<T> visitor) {
return visitor.visit(this);
}
}

0 comments on commit c65ac44

Please sign in to comment.