Skip to content

Commit

Permalink
fix(spoon): Make conversion of spoon-analyzer more robust (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt committed Jul 15, 2023
1 parent 3fa3323 commit d45f858
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xyz.keksdose.spoon.code_solver.analyzer.spoon;

import com.google.common.flogger.FluentLogger;
import com.google.common.flogger.StackSize;
import io.github.martinwitt.laughing_train.domain.entity.AnalyzerResult;
import io.github.martinwitt.laughing_train.domain.value.Position;
import io.github.martinwitt.laughing_train.domain.value.RuleId;
Expand Down Expand Up @@ -29,9 +31,17 @@
class AnalyzerResultVisitor implements BadSmellVisitor<AnalyzerResult> {

private static final AnalyzerResultVisitor analyzerResultVisitor = new AnalyzerResultVisitor();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();

public static Optional<AnalyzerResult> toAnalyzerResult(BadSmell badSmell) {
return Optional.ofNullable(badSmell.accept(analyzerResultVisitor));
try {
return Optional.ofNullable(badSmell.accept(analyzerResultVisitor));

} catch (Exception e) {
logger.atWarning().withCause(e).withStackTrace(StackSize.SMALL).log(
"Could not convert bad smell to analyzer result");
return Optional.empty();
}
}

private AnalyzerResultVisitor() {}
Expand Down Expand Up @@ -106,7 +116,7 @@ public AnalyzerResult visit(InnerClassMayBeStatic badSmell) {
CtType<?> clone = badSmell.getAffectedType().clone();
clone.setTypeMembers(new ArrayList<>());
String snippet = clone.toString();
return toSpoonAnalyzerResult(badSmell, badSmell.getAffectedType().getPosition(), snippet);
return toSpoonAnalyzerResult(badSmell, badSmell.getInnerClass().getPosition(), snippet);
}

@Override
Expand Down

0 comments on commit d45f858

Please sign in to comment.