本文整理汇总了Java中org.eclipse.lsp4j.Range类的典型用法代码示例。如果您正苦于以下问题:Java Range类的具体用法?Java Range怎么用?Java Range使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Range类属于org.eclipse.lsp4j包,在下文中一共展示了Range类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCodeAction_exception
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void testCodeAction_exception() throws JavaModelException {
URI uri = project.getFile("nopackage/Test.java").getRawLocationURI();
ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
try {
cu.becomeWorkingCopy(new NullProgressMonitor());
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(uri.toString()));
final Range range = new Range();
range.setStart(new Position(0, 17));
range.setEnd(new Position(0, 17));
params.setRange(range);
CodeActionContext context = new CodeActionContext();
context.setDiagnostics(Collections.emptyList());
params.setContext(context);
List<? extends Command> commands = server.codeAction(params).join();
Assert.assertNotNull(commands);
Assert.assertEquals(0, commands.size());
} finally {
cu.discardWorkingCopy();
}
}
示例2: change
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
private TextEdit change(final Position startPos, final Position endPos, final String newText) {
TextEdit _textEdit = new TextEdit();
final Procedure1<TextEdit> _function = (TextEdit it) -> {
if ((startPos != null)) {
Range _range = new Range();
final Procedure1<Range> _function_1 = (Range it_1) -> {
it_1.setStart(startPos);
it_1.setEnd(endPos);
};
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
it.setRange(_doubleArrow);
}
it.setNewText(newText);
};
return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function);
}
示例3: testRangeFormattingService
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void testRangeFormattingService() {
final Procedure1<RangeFormattingConfiguration> _function = (RangeFormattingConfiguration it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
it.setModel(_builder.toString());
Range _range = new Range();
final Procedure1<Range> _function_1 = (Range it_1) -> {
Position _position = new Position(0, 0);
it_1.setStart(_position);
Position _position_1 = new Position(0, 17);
it_1.setEnd(_position_1);
};
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
it.setRange(_doubleArrow);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type Foo{");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("int bar");
_builder_1.newLine();
_builder_1.append("} type Bar{Foo foo}");
it.setExpectedText(_builder_1.toString());
};
this.testRangeFormatting(_function);
}
示例4: findPath
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
private static Optional<Location> findPath(TreePath path, Trees trees) {
CompilationUnitTree compilationUnit = path.getCompilationUnit();
long start = trees.getSourcePositions().getStartPosition(compilationUnit, path.getLeaf());
long end = trees.getSourcePositions().getEndPosition(compilationUnit, path.getLeaf());
if (start == Diagnostic.NOPOS) return Optional.empty();
if (end == Diagnostic.NOPOS) end = start;
int startLine = (int) compilationUnit.getLineMap().getLineNumber(start);
int startColumn = (int) compilationUnit.getLineMap().getColumnNumber(start);
int endLine = (int) compilationUnit.getLineMap().getLineNumber(end);
int endColumn = (int) compilationUnit.getLineMap().getColumnNumber(end);
return Optional.of(
new Location(
compilationUnit.getSourceFile().toUri().toString(),
new Range(
new Position(startLine - 1, startColumn - 1),
new Position(endLine - 1, endColumn - 1))));
}
示例5: convert
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
static Optional<Diagnostic> convert(javax.tools.Diagnostic<? extends JavaFileObject> error) {
if (error.getStartPosition() != javax.tools.Diagnostic.NOPOS) {
Range range = position(error);
Diagnostic diagnostic = new Diagnostic();
DiagnosticSeverity severity = severity(error.getKind());
diagnostic.setSeverity(severity);
diagnostic.setRange(range);
diagnostic.setCode(error.getCode());
diagnostic.setMessage(error.getMessage(null));
return Optional.of(diagnostic);
} else {
LOG.warning("Skipped " + error.getMessage(Locale.getDefault()));
return Optional.empty();
}
}
示例6: toTextEdit
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
protected TextEdit toTextEdit(final Document document, final String formattedText, final int startOffset, final int length) {
TextEdit _textEdit = new TextEdit();
final Procedure1<TextEdit> _function = (TextEdit it) -> {
it.setNewText(formattedText);
Range _range = new Range();
final Procedure1<Range> _function_1 = (Range it_1) -> {
it_1.setStart(document.getPosition(startOffset));
it_1.setEnd(document.getPosition((startOffset + length)));
};
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
it.setRange(_doubleArrow);
};
return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function);
}
示例7: convertRange
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@SuppressWarnings("restriction")
private static Range convertRange(IProblem problem) {
Position start = new Position();
Position end = new Position();
start.setLine(problem.getSourceLineNumber()-1);// VSCode is 0-based
end.setLine(problem.getSourceLineNumber()-1);
if(problem instanceof DefaultProblem){
DefaultProblem dProblem = (DefaultProblem)problem;
start.setCharacter(dProblem.getSourceColumnNumber() - 1);
int offset = 0;
if (dProblem.getSourceStart() != -1 && dProblem.getSourceEnd() != -1) {
offset = dProblem.getSourceEnd() - dProblem.getSourceStart() + 1;
}
end.setCharacter(dProblem.getSourceColumnNumber() - 1 + offset);
}
return new Range(start, end);
}
示例8: testCodeAction_removeUnusedImport
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void testCodeAction_removeUnusedImport() throws Exception{
ICompilationUnit unit = getWorkingCopy(
"src/java/Foo.java",
"import java.sql.*; \n" +
"public class Foo {\n"+
" void foo() {\n"+
" }\n"+
"}\n");
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
final Range range = getRange(unit, "java.sql");
params.setRange(range);
params.setContext(new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UnusedImport), range))));
List<? extends Command> commands = server.codeAction(params).join();
Assert.assertNotNull(commands);
Assert.assertEquals(2, commands.size());
Command c = commands.get(0);
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
}
示例9: testCodeAction_removeUnterminatedString
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void testCodeAction_removeUnterminatedString() throws Exception{
ICompilationUnit unit = getWorkingCopy(
"src/java/Foo.java",
"public class Foo {\n"+
" void foo() {\n"+
"String s = \"some str\n" +
" }\n"+
"}\n");
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
final Range range = getRange(unit, "some str");
params.setRange(range);
params.setContext(new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UnterminatedString), range))));
List<? extends Command> commands = server.codeAction(params).join();
Assert.assertNotNull(commands);
Assert.assertEquals(1, commands.size());
Command c = commands.get(0);
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
}
示例10: testCompletion_import_package
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void testCompletion_import_package() throws JavaModelException{
ICompilationUnit unit = getWorkingCopy(
"src/java/Foo.java",
"import java.sq \n" +
"public class Foo {\n"+
" void foo() {\n"+
" }\n"+
"}\n");
int[] loc = findCompletionLocation(unit, "java.sq");
CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
assertNotNull(list);
assertEquals(1, list.getItems().size());
CompletionItem item = list.getItems().get(0);
// Check completion item
assertNull(item.getInsertText());
assertEquals("java.sql",item.getLabel());
assertEquals(CompletionItemKind.Module, item.getKind() );
assertEquals("999999215", item.getSortText());
assertNull(item.getTextEdit());
CompletionItem resolvedItem = server.resolveCompletionItem(item).join();
assertNotNull(resolvedItem);
TextEdit te = item.getTextEdit();
assertNotNull(te);
assertEquals("java.sql.*;",te.getNewText());
assertNotNull(te.getRange());
Range range = te.getRange();
assertEquals(0, range.getStart().getLine());
assertEquals(7, range.getStart().getCharacter());
assertEquals(0, range.getEnd().getLine());
//Not checking the range end character
}
示例11: testWorkspaceSearch
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void testWorkspaceSearch() {
String query = "Abstract";
List<SymbolInformation> results = handler.search(query, monitor);
assertNotNull(results);
assertEquals("Found " + results.size() + " results", 33, results.size());
Range defaultRange = JDTUtils.newRange();
for (SymbolInformation symbol : results) {
assertNotNull("Kind is missing", symbol.getKind());
assertNotNull("ContainerName is missing", symbol.getContainerName());
assertTrue(symbol.getName().startsWith(query));
Location location = symbol.getLocation();
assertEquals(defaultRange, location.getRange());
//No class in the workspace project starts with Abstract, so everything comes from the JDK
assertTrue("Unexpected uri "+ location.getUri(), location.getUri().startsWith("jdt://"));
}
}
示例12: testRangeFormatting
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void testRangeFormatting() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java",
//@formatter:off
"package org.sample;\n" +
" public class Baz {\n"+
"\tvoid foo(){\n" +
" }\n"+
" }\n"
//@formatter:on
);
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
Range range = new Range(new Position(2, 0), new Position(3, 5));// range around foo()
DocumentRangeFormattingParams params = new DocumentRangeFormattingParams(range);
params.setTextDocument(textDocument);
params.setOptions(new FormattingOptions(3, true));// ident == 3 spaces
List<? extends TextEdit> edits = server.rangeFormatting(params).get();
//@formatter:off
String expectedText =
"package org.sample;\n" +
" public class Baz {\n"+
" void foo() {\n" +
" }\n"+
" }\n";
//@formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
示例13: changeDocument
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
private void changeDocument(ICompilationUnit cu, String content, int version, Range range, int length) throws JavaModelException {
DidChangeTextDocumentParams changeParms = new DidChangeTextDocumentParams();
VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier();
textDocument.setUri(JDTUtils.toURI(cu));
textDocument.setVersion(version);
changeParms.setTextDocument(textDocument);
TextDocumentContentChangeEvent event = new TextDocumentContentChangeEvent();
if (range != null) {
event.setRange(range);
event.setRangeLength(length);
}
event.setText(content);
List<TextDocumentContentChangeEvent> contentChanges = new ArrayList<>();
contentChanges.add(event);
changeParms.setContentChanges(contentChanges);
lifeCycleHandler.didChange(changeParms);
}
示例14: testGetCodeLensSymbols
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void testGetCodeLensSymbols() throws Exception {
String payload = createCodeLensSymbolsRequest("src/java/Foo.java");
CodeLensParams codeLensParams = getParams(payload);
String uri = codeLensParams.getTextDocument().getUri();
assertFalse(uri.isEmpty());
//when
List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);
//then
assertEquals("Found " + result, 3, result.size());
CodeLens cl = result.get(0);
Range r = cl.getRange();
//CodeLens on main method
assertRange(7, 20, 24, r);
cl = result.get(1);
r = cl.getRange();
// CodeLens on foo method
assertRange(14, 13, 16, r);
cl = result.get(2);
r = cl.getRange();
//CodeLens on Foo type
assertRange(5, 13, 16, r);
}
示例15: testResolveImplementationsCodeLense
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testResolveImplementationsCodeLense() {
String source = "src/java/IFoo.java";
String payload = createCodeLensImplementationsRequest(source, 5, 17, 21);
CodeLens lens = getParams(payload);
Range range = lens.getRange();
assertRange(5, 17, 21, range);
CodeLens result = handler.resolve(lens, monitor);
assertNotNull(result);
//Check if command found
Command command = result.getCommand();
assertNotNull(command);
assertEquals("2 implementations", command.getTitle());
assertEquals("java.show.implementations", command.getCommand());
//Check codelens args
List<Object> args = command.getArguments();
assertEquals(3, args.size());
//Check we point to the Bar class
String sourceUri = args.get(0).toString();
assertTrue(sourceUri.endsWith("IFoo.java"));
//CodeLens position
Map<String, Object> map = (Map<String, Object>) args.get(1);
assertEquals(5.0, map.get("line"));
assertEquals(17.0, map.get("character"));
//Reference location
List<Location> locations = (List<Location>) args.get(2);
assertEquals(2, locations.size());
Location loc = locations.get(0);
assertTrue(loc.getUri().endsWith("src/java/Foo2.java"));
assertRange(5, 13, 17, loc.getRange());
}