Search in sources :

Example 11 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelp_double.

// https://github.com/eclipse/eclipse.jdt.ls/issues/1980
@Test
public void testSignatureHelp_double() 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 E(String s) {\n");
    buf.append("        this.unique(\n");
    buf.append("    }\n");
    buf.append("    public void unique(double d) {}\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 3, 20);
    assertNotNull(help);
    assertEquals(1, help.getSignatures().size());
    assertEquals((Integer) 0, help.getActiveParameter());
    assertEquals(help.getSignatures().get(help.getActiveSignature()).getLabel(), "unique(double d) : void");
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Test(org.junit.Test)

Example 12 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelpMethod.

// https://github.com/redhat-developer/vscode-java/issues/2097
@Test
public void testSignatureHelpMethod() throws Exception {
    IJavaProject javaProject = JavaCore.create(project);
    IType type = javaProject.findType("test1.SignatureHelp2097");
    IType resultType = javaProject.findType("test1.Result", new NullProgressMonitor());
    assertNotNull(resultType);
    ICompilationUnit cu = type.getCompilationUnit();
    SignatureHelp help = getSignatureHelp(cu, 14, 42);
    assertNotNull(help);
    assertEquals(1, help.getSignatures().size());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().equals("success(Boolean flag) : Boolean"));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) 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 13 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelp_constructorParameters3.

@Test
public void testSignatureHelp_constructorParameters3() throws JavaModelException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package test1;\n");
    buf.append("import java.text.StringCharacterIterator;\n");
    buf.append("public class E {\n");
    buf.append("   public void bar() {\n");
    buf.append("     new StringCharacterIterator(\"\", 0,  , 2);\n");
    buf.append("   }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 4, 39);
    assertNotNull(help);
    assertEquals(3, help.getSignatures().size());
    // StringCharacterIterator(String arg0, int arg1, int arg2, int arg3)
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().matches("StringCharacterIterator\\(String \\w+, int \\w+, int \\w+, int \\w+\\)"));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Test(org.junit.Test)

Example 14 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelp_constructor.

@Test
public void testSignatureHelp_constructor() 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 void bar() {\n");
    buf.append("     new RuntimeException()\n");
    buf.append("   }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 3, 26);
    assertNotNull(help);
    assertEquals(4, help.getSignatures().size());
    assertEquals(help.getSignatures().get(help.getActiveSignature()).getLabel(), "RuntimeException()");
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Test(org.junit.Test)

Example 15 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelp_varargs2.

@Test
public void testSignatureHelp_varargs2() throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IType type = javaProject.findType("test1.Varargs");
    ICompilationUnit cu = type.getCompilationUnit();
    SignatureHelp help = getSignatureHelp(cu, 4, 16);
    assertNotNull(help);
    assertEquals(2, help.getSignatures().size());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().equals("run(Class<?> clazz, String... args) : void"));
}
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)

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