diff --git a/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/analyzer/qodana/rules/ToArrayCallWithZeroLengthArrayArgument.java b/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/analyzer/qodana/rules/ToArrayCallWithZeroLengthArrayArgument.java index 870e433fd..69332cb6d 100644 --- a/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/analyzer/qodana/rules/ToArrayCallWithZeroLengthArrayArgument.java +++ b/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/analyzer/qodana/rules/ToArrayCallWithZeroLengthArrayArgument.java @@ -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; @@ -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); @@ -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 filterMatches(List findLineOnly) { return findLineOnly.stream()