Search in sources :

Example 6 with SignatureHelp

use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.

the class SignatureHelpHandlerTest method testSignatureHelp_javadocOriginal.

// See https://github.com/redhat-developer/vscode-java/issues/1258
@Test
public void testSignatureHelp_javadocOriginal() throws JavaModelException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package test1;\n");
    buf.append("import java.util.LinkedList;\n");
    buf.append("import org.sample.MyList;\n");
    buf.append("public class E {\n\n");
    buf.append("	void test() {\n");
    buf.append("		MyList<String> l = new LinkedList<>();\n");
    buf.append("		l.add(\n");
    buf.append("	}\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    int[] loc = findCompletionLocation(cu, "l.add(");
    SignatureHelp help = getSignatureHelp(cu, loc[0], loc[1]);
    assertNotNull(help);
    assertEquals(2, help.getSignatures().size());
    SignatureInformation signature = help.getSignatures().get(help.getActiveSignature());
    assertTrue(signature.getLabel().equals("add(String e) : boolean"));
    String documentation = signature.getDocumentation().getLeft();
    assertEquals(" Test ", documentation);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SignatureInformation(org.eclipse.lsp4j.SignatureInformation) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Test(org.junit.Test)

Example 7 with SignatureHelp

use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.

the class SignatureHelpHandlerTest method testSignatureHelp_multipleMethods.

@Test
public void testSignatureHelp_multipleMethods() throws JavaModelException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("   public int foo(String s) { }\n");
    buf.append("   public int foo(int s) { }\n");
    buf.append("   public int foo(int s, String s) { }\n");
    buf.append("   public int bar(String s) { this.foo(2,  ) }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 5, 42);
    assertNotNull(help);
    assertEquals(3, help.getSignatures().size());
    assertEquals((Integer) 1, help.getActiveParameter());
    assertEquals(help.getSignatures().get(help.getActiveSignature()).getLabel(), "foo(int s, String s) : int");
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Test(org.junit.Test)

Example 8 with SignatureHelp

use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.

the class SignatureHelpHandlerTest method testSignatureHelpConstructor.

// https://github.com/redhat-developer/vscode-java/issues/2097
@Test
public void testSignatureHelpConstructor() throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IType type = javaProject.findType("test1.SignatureHelp2097");
    ICompilationUnit cu = type.getCompilationUnit();
    SignatureHelp help = getSignatureHelp(cu, 9, 51);
    assertNotNull(help);
    assertEquals(1, help.getSignatures().size());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().equals("SignatureHelp2097(String name)"));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaProject(org.eclipse.jdt.core.IJavaProject) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 9 with SignatureHelp

use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.

the class SignatureHelpHandlerTest method testAssertEquals.

private void testAssertEquals(ICompilationUnit cu, int line, int character) {
    SignatureHelp help = getSignatureHelp(cu, line, character);
    assertNotNull(help);
    assertEquals(12, help.getSignatures().size());
    assertNotNull(help.getActiveParameter());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().equals("assertEquals(long expected, long actual) : void"));
}
Also used : SignatureHelp(org.eclipse.lsp4j.SignatureHelp)

Example 10 with SignatureHelp

use of org.eclipse.lsp4j.SignatureHelp in project eclipse.jdt.ls by eclipse.

the class SignatureHelpHandlerTest method testSignatureHelp_varargs.

@Test
public void testSignatureHelp_varargs() throws JavaModelException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package test1;\n");
    buf.append("import java.util.Arrays;\n");
    buf.append("public class E {\n");
    buf.append("	public static void main(String[] args) {\n");
    buf.append("		Arrays.asList(1,2,3);\n");
    buf.append("		demo(\"1\", \"2\",\"3\" )\n");
    buf.append("	}\n");
    buf.append("	public static void demo (String s, String... s2) {\n");
    buf.append("	}\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 4, 21);
    assertNotNull(help);
    assertEquals(1, help.getSignatures().size());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().startsWith("asList(T... "));
    help = getSignatureHelp(cu, 5, 19);
    assertNotNull(help);
    assertEquals(1, help.getSignatures().size());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().equals("demo(String s, String... s2) : void"));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Test(org.junit.Test)

Aggregations

SignatureHelp (org.eclipse.lsp4j.SignatureHelp)31 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)23 Test (org.junit.Test)21 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)17 SignatureInformation (org.eclipse.lsp4j.SignatureInformation)7 IJavaProject (org.eclipse.jdt.core.IJavaProject)5 IType (org.eclipse.jdt.core.IType)4 ArrayList (java.util.ArrayList)3 CoreException (org.eclipse.core.runtime.CoreException)2 CompletionProposal (org.eclipse.jdt.core.CompletionProposal)2 InternalCompletionProposal (org.eclipse.jdt.internal.codeassist.InternalCompletionProposal)2 SignatureHelpRequestor (org.eclipse.jdt.ls.core.internal.contentassist.SignatureHelpRequestor)2 ParameterInformation (org.eclipse.lsp4j.ParameterInformation)2 Joiner (com.google.common.base.Joiner)1 Objects (com.google.common.base.Objects)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Inject (com.google.inject.Inject)1