use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_classMethodOverride.
private void testCompletion_classMethodOverride(String projectName, boolean supportSnippets, boolean overridesSuperClass) throws Exception {
if (project == null || !projectName.equals(project.getName())) {
importProjects("eclipse/" + projectName);
project = WorkspaceHelper.getProject(projectName);
}
mockClientPreferences(supportSnippets, true);
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + " toStr" + "}\n");
int[] loc = findCompletionLocation(unit, " toStr");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
List<CompletionItem> filtered = list.getItems().stream().filter((item) -> {
return item.getDetail() != null && item.getDetail().startsWith("Override method in");
}).collect(Collectors.toList());
assertFalse("No override proposals", filtered.isEmpty());
CompletionItem oride = filtered.get(0);
assertEquals("toString", oride.getInsertText());
assertNull(oride.getTextEdit());
oride = server.resolveCompletionItem(oride).join();
assertNotNull(oride.getTextEdit());
String text = oride.getTextEdit().getNewText();
StringBuilder expectedText = new StringBuilder();
if (overridesSuperClass) {
expectedText.append("@Override\n");
}
expectedText.append("public String toString() {\n\t");
if (supportSnippets) {
expectedText.append("${0:");
}
expectedText.append("return super.toString();");
if (supportSnippets) {
expectedText.append("}");
}
expectedText.append("\n}");
assertEquals(expectedText.toString(), text);
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_AnonymousDeclarationType.
@Test
public void testCompletion_AnonymousDeclarationType() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + " public static void main(String[] args) {\n" + " new Runnable()\n" + " }\n" + "}\n");
waitForBackgroundJobs();
int[] loc = findCompletionLocation(unit, "Runnable(");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
CompletionItem ci = list.getItems().stream().filter(item -> item.getLabel().startsWith("Runnable() Anonymous Inner Type")).findFirst().orElse(null);
assertNotNull(ci);
assertEquals("Runnable", ci.getInsertText());
assertEquals(CompletionItemKind.Class, ci.getKind());
assertEquals("999999372", ci.getSortText());
assertNull(ci.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem.getTextEdit());
assertTextEdit(2, 20, 22, "(){\n" + "\n" + " @Override\n" + " public void run() {\n" + " ${0}\n" + " }\n" + "}", resolvedItem.getTextEdit());
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_methodOverrideWithException.
@Test
public void testCompletion_methodOverrideWithException() throws Exception {
ICompilationUnit unit = getWorkingCopy(// @formatter:off
"src/org/sample/Test.java", "package org.sample;\n\n" + "public class Test extends Baz {\n" + " dele" + "}\n");
// @formatter:on
int[] loc = findCompletionLocation(unit, " dele");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
List<CompletionItem> filtered = list.getItems().stream().filter((item) -> {
return item.getDetail() != null && item.getDetail().startsWith("Override method in");
}).collect(Collectors.toList());
assertEquals("No override proposals", filtered.size(), 1);
CompletionItem oride = filtered.get(0);
assertEquals("deleteSomething", oride.getInsertText());
assertNull(oride.getTextEdit());
oride = server.resolveCompletionItem(oride).join();
assertNotNull(oride.getTextEdit());
String text = oride.getTextEdit().getNewText();
String expectedText = "@Override\n" + "protected void deleteSomething() throws IOException {\n" + "\t${0:super.deleteSomething();}\n" + "}";
assertEquals(expectedText, text);
assertEquals("Missing required imports", 4, oride.getAdditionalTextEdits().size());
assertTextEdit(0, 19, 19, "\n\n", oride.getAdditionalTextEdits().get(0));
assertTextEdit(0, 19, 19, "import java.io.IOException;", oride.getAdditionalTextEdits().get(1));
assertTextEdit(0, 19, 19, "\n\n", oride.getAdditionalTextEdits().get(2));
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testStaticImports2.
@Test
public void testStaticImports2() throws Exception {
PreferenceManager.getPrefs(null).setJavaCompletionFavoriteMembers(Collections.emptyList());
ICompilationUnit unit = getWorkingCopy("src/test1/B.java", // @formatter:off
"package test1;\n" + "\n" + "public class B {\n" + " public void bar() {\n" + " /* */fo\n" + " }\n" + // conflicting method, no static import possible
" public void foo(int x) {\n" + " }\n" + "}\n");
// @formatter:on
int[] loc = findCompletionLocation(unit, "/* */fo");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
assertTrue(list.getItems().size() > 0);
for (CompletionItem it : list.getItems()) {
if ("foo() : void".equals(it.getLabel())) {
fail("there is a proposal for foo()");
}
}
}
use of org.eclipse.lsp4j.CompletionList in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testCompletion_AnonymousDeclarationType5.
@Test
public void testCompletion_AnonymousDeclarationType5() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + " public static void main(String[] args) {\n" + " run(\"name\", new Runnable(");
waitForBackgroundJobs();
int[] loc = findCompletionLocation(unit, "Runnable(");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
CompletionItem ci = list.getItems().stream().filter(item -> item.getLabel().startsWith("Runnable() Anonymous Inner Type")).findFirst().orElse(null);
assertNotNull(ci);
assertEquals("Runnable", ci.getInsertText());
assertEquals(CompletionItemKind.Class, ci.getKind());
assertEquals("999999372", ci.getSortText());
assertNull(ci.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem.getTextEdit());
assertTextEdit(2, 33, 33, "(){\n" + "\n" + " @Override\n" + " public void run() {\n" + " ${0}\n" + " }\n" + "}", resolvedItem.getTextEdit());
}
Aggregations