Search in sources :

Example 1 with LinkLocation

use of org.eclipse.jdt.ls.core.internal.handlers.FindLinksHandler.LinkLocation in project eclipse.jdt.ls by eclipse.

the class FindLinksHandlerTest method testFindSuperMethod.

@Test
public void testFindSuperMethod() throws JavaModelException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    // @formatter:off
    ICompilationUnit unitA = pack1.createCompilationUnit("A.java", "package test1;\n" + "\n" + "public class A {\n" + "	public void run() {\n" + "	}\n" + "}", true, null);
    // @formatter:on
    // @formatter:off
    ICompilationUnit unitB = pack1.createCompilationUnit("B.java", "package test1;\n" + "\n" + "public class B extends A {\n" + "	public void run() {\n" + "	}\n" + "}", true, null);
    // @formatter:on
    String uri = JDTUtils.toURI(unitB);
    List<? extends Location> response = FindLinksHandler.findLinks("superImplementation", new TextDocumentPositionParams(new TextDocumentIdentifier(uri), new Position(3, 14)), new NullProgressMonitor());
    assertTrue(response != null && response.size() == 1);
    LinkLocation location = (LinkLocation) response.get(0);
    assertEquals("test1.A.run", location.displayName);
    assertEquals("method", location.kind);
    assertEquals(JDTUtils.toURI(unitA), location.getUri());
    Range range = location.getRange();
    assertEquals(3, range.getStart().getLine());
    assertEquals(13, range.getStart().getCharacter());
    assertEquals(3, range.getEnd().getLine());
    assertEquals(16, range.getEnd().getCharacter());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) LinkLocation(org.eclipse.jdt.ls.core.internal.handlers.FindLinksHandler.LinkLocation) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 2 with LinkLocation

use of org.eclipse.jdt.ls.core.internal.handlers.FindLinksHandler.LinkLocation in project eclipse.jdt.ls by eclipse.

the class FindLinksHandlerTest method testFindNearestSuperMethod.

@Test
public void testFindNearestSuperMethod() throws JavaModelException {
    IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
    // @formatter:off
    ICompilationUnit unitA = pack1.createCompilationUnit("A.java", "package test1;\n" + "\n" + "public class A {\n" + "	public void run() {\n" + "	}\n" + "}", true, null);
    // @formatter:on
    // @formatter:off
    ICompilationUnit unitB = pack1.createCompilationUnit("B.java", "package test1;\n" + "\n" + "public class B extends A {\n" + "}", true, null);
    // @formatter:on
    // @formatter:off
    ICompilationUnit unitC = pack1.createCompilationUnit("C.java", "package test1;\n" + "\n" + "public class C extends B {\n" + "	public void run() {\n" + "	}\n" + "}", true, null);
    // @formatter:on
    String uri = JDTUtils.toURI(unitC);
    List<? extends Location> response = FindLinksHandler.findLinks("superImplementation", new TextDocumentPositionParams(new TextDocumentIdentifier(uri), new Position(3, 14)), new NullProgressMonitor());
    assertTrue(response != null && response.size() == 1);
    LinkLocation location = (LinkLocation) response.get(0);
    assertEquals("test1.A.run", location.displayName);
    assertEquals("method", location.kind);
    assertEquals(JDTUtils.toURI(unitA), location.getUri());
    Range range = location.getRange();
    assertEquals(3, range.getStart().getLine());
    assertEquals(13, range.getStart().getCharacter());
    assertEquals(3, range.getEnd().getLine());
    assertEquals(16, range.getEnd().getCharacter());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) LinkLocation(org.eclipse.jdt.ls.core.internal.handlers.FindLinksHandler.LinkLocation) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 LinkLocation (org.eclipse.jdt.ls.core.internal.handlers.FindLinksHandler.LinkLocation)2 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)2 Position (org.eclipse.lsp4j.Position)2 Range (org.eclipse.lsp4j.Range)2 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)2 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)2 Test (org.junit.Test)2