Skip to content

Commit 365d396

Browse files
committed
Fix AbstractQuickFixTest.evaluateCodeActions(ICompilationUnit) logic.
- Code actions belonging to diagnostics need to be resolved by setting the invocation range for the particular diagnostic in the evalutation request Signed-off-by: Roland Grunberg <[email protected]>
1 parent 2f37f45 commit 365d396

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractQuickFixTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,8 @@ public void assertEquivalent(Either<Command, CodeAction> action) throws Exceptio
225225
}
226226
}
227227

228-
protected Range getRange(ICompilationUnit cu, IProblem[] problems) throws JavaModelException {
229-
if (problems.length == 0) {
230-
return new Range(new Position(), new Position());
231-
}
232-
IProblem problem = problems[0];
233-
return JDTUtils.toRange(cu, problem.getSourceStart(), 0);
228+
protected Range getRange(ICompilationUnit cu, IProblem problem) throws JavaModelException {
229+
return (problem == null) ? new Range(new Position(), new Position()) : JDTUtils.toRange(cu, problem.getSourceStart(), 0);
234230
}
235231

236232
protected void setIgnoredCommands(String... ignoredCommands) {
@@ -246,12 +242,21 @@ protected void setOnly(String... onlyKinds) {
246242
}
247243

248244
protected List<Either<Command, CodeAction>> evaluateCodeActions(ICompilationUnit cu) throws JavaModelException {
249-
245+
List<Either<Command, CodeAction>> result = new ArrayList<>();
250246
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
251247
IProblem[] problems = astRoot.getProblems();
252-
253-
Range range = getRange(cu, problems);
254-
return evaluateCodeActions(cu, range);
248+
if (problems.length == 0) {
249+
Range range = getRange(cu, null);
250+
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, range);
251+
result.addAll(codeActions);
252+
} else {
253+
for (IProblem problem : problems) {
254+
Range range = getRange(cu, problem);
255+
List<Either<Command, CodeAction>> codeActions = evaluateCodeActions(cu, range);
256+
result.addAll(codeActions);
257+
}
258+
}
259+
return result;
255260
}
256261

257262
protected List<Either<Command, CodeAction>> evaluateCodeActions(ICompilationUnit cu, Range range) throws JavaModelException {

org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractSelectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected int[] getSelection(String source) {
2626
}
2727

2828
@Override
29-
protected Range getRange(ICompilationUnit cu, IProblem[] problems) throws JavaModelException {
29+
protected Range getRange(ICompilationUnit cu, IProblem problem) throws JavaModelException {
3030
return CodeActionUtil.getRange(cu);
3131
}
3232
}

org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/ExtractFieldTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public void testExtractToField_standaloneStatement() throws Exception {
537537
protected void failHelper(ICompilationUnit cu) throws OperationCanceledException, CoreException {
538538
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
539539
IProblem[] problems = astRoot.getProblems();
540-
Range range = getRange(cu, problems);
540+
Range range = getRange(cu, problems.length > 0 ? problems[0] : null);
541541
int start = DiagnosticsHelper.getStartOffset(cu, range);
542542
int end = DiagnosticsHelper.getEndOffset(cu, range);
543543
ExtractFieldRefactoring refactoring = new ExtractFieldRefactoring(astRoot, start, end - start);
@@ -549,7 +549,7 @@ protected void failHelper(ICompilationUnit cu) throws OperationCanceledException
549549
protected boolean helper(ICompilationUnit cu, InitializeScope initializeIn, String expected) throws Exception {
550550
CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
551551
IProblem[] problems = astRoot.getProblems();
552-
Range range = getRange(cu, problems);
552+
Range range = getRange(cu, problems.length > 0 ? problems[0] : null);
553553
int start = DiagnosticsHelper.getStartOffset(cu, range);
554554
int end = DiagnosticsHelper.getEndOffset(cu, range);
555555
ExtractFieldRefactoring refactoring = new ExtractFieldRefactoring(astRoot, start, end - start);

0 commit comments

Comments
 (0)