Search in sources :

Example 26 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelp_parameterTypes.

@Test
public void testSignatureHelp_parameterTypes() 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 static void main(String[] args) {\n");
    buf.append("		 new RuntimeException(new Exception(),)\n");
    buf.append("	}\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 3, 40);
    assertNotNull(help);
    assertEquals(4, help.getSignatures().size());
    assertNull(help.getActiveParameter());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SignatureHelp(org.eclipse.lsp4j.SignatureHelp) Test(org.junit.Test)

Example 27 with SignatureHelp

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

the class SignatureHelpHandlerTest method testStringLiteral.

private void testStringLiteral(ICompilationUnit cu, int line, int character) {
    SignatureHelp help = getSignatureHelp(cu, line, character);
    assertNotNull(help);
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=575149
    // assertEquals(1, help.getSignatures().size());
    assertNotNull(help.getActiveParameter());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().equals("foo(String p, int x) : void"));
}
Also used : SignatureHelp(org.eclipse.lsp4j.SignatureHelp)

Example 28 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelp_parameterObject.

@Test
public void testSignatureHelp_parameterObject() 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 static void main(String[] args) {\n");
    buf.append("		 Object foo = new Object();\n");
    buf.append("		 System.err.println(foo);\n");
    buf.append("	}\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 4, 23);
    assertNotNull(help);
    assertEquals(10, help.getSignatures().size());
    assertNotNull(help.getActiveParameter());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().matches("println\\(Object \\w+\\) : 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 29 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelp_constructorParameters.

@Test
public void testSignatureHelp_constructorParameters() 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(\"t\", )\n");
    buf.append("   }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 3, 31);
    assertNotNull(help);
    assertEquals(4, help.getSignatures().size());
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().matches("RuntimeException\\(String \\w+, Throwable \\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 30 with SignatureHelp

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

the class SignatureHelpHandlerTest method testSignatureHelp_binary.

@Test
public void testSignatureHelp_binary() 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 bar(String s) { System.out.println(  }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
    SignatureHelp help = getSignatureHelp(cu, 2, 50);
    assertNotNull(help);
    assertTrue(help.getSignatures().size() >= 10);
    assertTrue(help.getSignatures().get(help.getActiveSignature()).getLabel().equals("println() : void"));
    SignatureHelp help2 = getSignatureHelp(cu, 2, 49);
    assertEquals(help.getSignatures().size(), help2.getSignatures().size());
    assertEquals(help.getActiveSignature(), help2.getActiveSignature());
}
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