diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractQuickFixTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractQuickFixTest.java index dfb3490601..3f5d6fff86 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractQuickFixTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractQuickFixTest.java @@ -225,12 +225,8 @@ public void assertEquivalent(Either action) throws Exceptio } } - protected Range getRange(ICompilationUnit cu, IProblem[] problems) throws JavaModelException { - if (problems.length == 0) { - return new Range(new Position(), new Position()); - } - IProblem problem = problems[0]; - return JDTUtils.toRange(cu, problem.getSourceStart(), 0); + protected Range getRange(ICompilationUnit cu, IProblem problem) throws JavaModelException { + return (problem == null) ? new Range(new Position(), new Position()) : JDTUtils.toRange(cu, problem.getSourceStart(), 0); } protected void setIgnoredCommands(String... ignoredCommands) { @@ -246,12 +242,21 @@ protected void setOnly(String... onlyKinds) { } protected List> evaluateCodeActions(ICompilationUnit cu) throws JavaModelException { - + List> result = new ArrayList<>(); CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null); IProblem[] problems = astRoot.getProblems(); - - Range range = getRange(cu, problems); - return evaluateCodeActions(cu, range); + if (problems.length == 0) { + Range range = getRange(cu, null); + List> codeActions = evaluateCodeActions(cu, range); + result.addAll(codeActions); + } else { + for (IProblem problem : problems) { + Range range = getRange(cu, problem); + List> codeActions = evaluateCodeActions(cu, range); + result.addAll(codeActions); + } + } + return result; } protected List> evaluateCodeActions(ICompilationUnit cu, Range range) throws JavaModelException { diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractSelectionTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractSelectionTest.java index 49d4a41af3..c39d943d9b 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractSelectionTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/correction/AbstractSelectionTest.java @@ -26,7 +26,7 @@ protected int[] getSelection(String source) { } @Override - protected Range getRange(ICompilationUnit cu, IProblem[] problems) throws JavaModelException { + protected Range getRange(ICompilationUnit cu, IProblem problem) throws JavaModelException { return CodeActionUtil.getRange(cu); } } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/ExtractFieldTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/ExtractFieldTest.java index 898ddfe9a3..a0cf06036e 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/ExtractFieldTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/ExtractFieldTest.java @@ -537,7 +537,7 @@ public void testExtractToField_standaloneStatement() throws Exception { protected void failHelper(ICompilationUnit cu) throws OperationCanceledException, CoreException { CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null); IProblem[] problems = astRoot.getProblems(); - Range range = getRange(cu, problems); + Range range = getRange(cu, problems.length > 0 ? problems[0] : null); int start = DiagnosticsHelper.getStartOffset(cu, range); int end = DiagnosticsHelper.getEndOffset(cu, range); ExtractFieldRefactoring refactoring = new ExtractFieldRefactoring(astRoot, start, end - start); @@ -549,7 +549,7 @@ protected void failHelper(ICompilationUnit cu) throws OperationCanceledException protected boolean helper(ICompilationUnit cu, InitializeScope initializeIn, String expected) throws Exception { CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null); IProblem[] problems = astRoot.getProblems(); - Range range = getRange(cu, problems); + Range range = getRange(cu, problems.length > 0 ? problems[0] : null); int start = DiagnosticsHelper.getStartOffset(cu, range); int end = DiagnosticsHelper.getEndOffset(cu, range); ExtractFieldRefactoring refactoring = new ExtractFieldRefactoring(astRoot, start, end - start);