use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class ReferencesHandlerTest method testPotentialMatch.
// https://github.com/redhat-developer/vscode-java/issues/2227
@Test
public void testPotentialMatch() throws Exception {
when(preferenceManager.isClientSupportsClassFileContent()).thenReturn(true);
importProjects("eclipse/reference");
IProject referenceProject = WorkspaceHelper.getProject("reference");
URI uri = referenceProject.getFile("src/org/reference/User.java").getRawLocationURI();
String fileURI = ResourceUtils.fixURI(uri);
ReferenceParams param = new ReferenceParams();
param.setPosition(new Position(1, 15));
param.setContext(new ReferenceContext(true));
param.setTextDocument(new TextDocumentIdentifier(fileURI));
List<Location> references = handler.findReferences(param, monitor);
assertEquals(0, references.size());
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class ReferencesHandlerTest method testEmpty.
@Test
public void testEmpty() {
ReferenceParams param = new ReferenceParams();
param.setPosition(new Position(1, 1));
param.setContext(new ReferenceContext(false));
param.setTextDocument(new TextDocumentIdentifier("/foo/bar"));
List<Location> references = handler.findReferences(param, monitor);
assertNotNull(references);
assertTrue("references are not empty", references.isEmpty());
}
use of org.eclipse.lsp4j.TextDocumentIdentifier 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());
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class FormatterHandlerTest method testFormattingOnTypeNewLine.
// typing new_line should format the current line if previous character doesn't close a block
@Test
public void testFormattingOnTypeNewLine() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
"package org.sample;\n" + "\n" + " public class Baz { \n" + // typed \n here
"String name ;\n" + "}\n");
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
// ident == 4 spaces
FormattingOptions options = new FormattingOptions(4, true);
DocumentOnTypeFormattingParams params = new DocumentOnTypeFormattingParams(new Position(3, 28), "\n");
params.setTextDocument(textDocument);
params.setOptions(options);
preferences.setJavaFormatOnTypeEnabled(true);
List<? extends TextEdit> edits = server.onTypeFormatting(params).get();
assertNotNull(edits);
// @formatter:off
String expectedText = "package org.sample;\n" + "\n" + // this part won't be formatted
" public class Baz { \n" + " String name;\n" + "}\n";
// @formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class FormatterHandlerTest method testDocumentFormattingWithTabs.
@Test
public void testDocumentFormattingWithTabs() throws Exception {
javaProject.setOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
"package org.sample;\n\n" + "public class Baz {\n" + " void foo(){\n" + "}\n" + "}\n");
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
// ident == tab
FormattingOptions options = new FormattingOptions(2, false);
DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
List<? extends TextEdit> edits = server.formatting(params).get();
assertNotNull(edits);
// @formatter:off
String expectedText = "package org.sample;\n" + "\n" + "public class Baz {\n" + "\tvoid foo() {\n" + "\t}\n" + "}\n";
// @formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
Aggregations