Skip to content

Commit

Permalink
fix: use startline only for matching (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Oct 29, 2022
1 parent eb16bf4 commit 4f1b492
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import spoon.reflect.declaration.CtType;
import xyz.keksdose.spoon.code_solver.analyzer.PositionScanner;
import xyz.keksdose.spoon.code_solver.api.analyzer.AnalyzerResult;
import xyz.keksdose.spoon.code_solver.api.analyzer.Position;
import xyz.keksdose.spoon.code_solver.history.Change;
import xyz.keksdose.spoon.code_solver.history.ChangeListener;
import xyz.keksdose.spoon.code_solver.history.MarkdownString;
Expand Down Expand Up @@ -44,7 +45,8 @@ public void refactor(ChangeListener listener, CtType<?> type) {
if (!isSameType(type, Path.of(result.filePath()))) {
return;
}
for (CtNewArray<?> toArrayCall : filterMatches(PositionScanner.findLineOnly(type, result.position()))) {
for (CtNewArray<?> toArrayCall :
filterMatches(PositionScanner.findLineOnly(type, toStartLinePosition(result.position())))) {
var dimensionExpression = toArrayCall.getDimensionExpressions().get(0);
var zeroExpression = dimensionExpression.getFactory().createLiteral(0);
dimensionExpression.replace(zeroExpression);
Expand All @@ -55,6 +57,10 @@ public void refactor(ChangeListener listener, CtType<?> type) {
}
}

private Position toStartLinePosition(Position position) {
return new Position(position.startLine(), 0, 0, 0, 0, 0);
}

@SuppressWarnings("rawtypes")
private List<CtNewArray> filterMatches(List<CtElement> findLineOnly) {
return findLineOnly.stream()
Expand Down

0 comments on commit 4f1b492

Please sign in to comment.