本文整理汇总了Java中org.eclipse.lsp4j.Range类的典型用法代码示例。如果您正苦于以下问题:Java Range类的具体用法?Java Range怎么用?Java Range使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Range类属于org.eclipse.lsp4j包,在下文中一共展示了Range类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:CodeActionHandlerTest.java
示例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);
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:DocumentTest.java
示例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);
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:FormattingTest.java
示例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))));
}
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:22,代码来源:FindSymbols.java
示例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();
}
}
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:19,代码来源:Lints.java
示例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);
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:15,代码来源:FormattingService.java
示例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);
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:DiagnosticsHandler.java
示例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());
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:CodeActionHandlerTest.java
示例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());
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:CodeActionHandlerTest.java
示例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
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:38,代码来源:CompletionHandlerTest.java
示例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://"));
}
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:WorkspaceSymbolHandlerTest.java
示例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);
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:33,代码来源:FormatterHandlerTest.java
示例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);
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:DocumentLifeCycleHandlerTest.java
示例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);
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:28,代码来源:CodeLensHandlerTest.java
示例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());
}
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:40,代码来源:CodeLensHandlerTest.java
示例16: withoutNull
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
@Test
public void withoutNull() {
final List<? extends Range> input = this.sort(CollectionLiterals.<Range>newArrayList(this.newRange(1, 2, 1, 2), this.newRange(1, 1, 2, 1), this.newRange(1, 1, 1, 2), this.newRange(1, 1, 1, 1),
this.newRange(2, 2, 2, 3)));
Assert.assertEquals(1, input.get(0).getStart().getLine());
Assert.assertEquals(1, input.get(0).getStart().getCharacter());
Assert.assertEquals(1, input.get(0).getEnd().getLine());
Assert.assertEquals(1, input.get(0).getEnd().getCharacter());
Assert.assertEquals(1, input.get(1).getStart().getLine());
Assert.assertEquals(1, input.get(1).getStart().getCharacter());
Assert.assertEquals(1, input.get(1).getEnd().getLine());
Assert.assertEquals(2, input.get(1).getEnd().getCharacter());
Assert.assertEquals(1, input.get(2).getStart().getLine());
Assert.assertEquals(1, input.get(2).getStart().getCharacter());
Assert.assertEquals(2, input.get(2).getEnd().getLine());
Assert.assertEquals(1, input.get(2).getEnd().getCharacter());
Assert.assertEquals(1, input.get(3).getStart().getLine());
Assert.assertEquals(2, input.get(3).getStart().getCharacter());
Assert.assertEquals(1, input.get(3).getEnd().getLine());
Assert.assertEquals(2, input.get(3).getEnd().getCharacter());
Assert.assertEquals(2, input.get(4).getStart().getLine());
Assert.assertEquals(2, input.get(4).getStart().getCharacter());
Assert.assertEquals(2, input.get(4).getEnd().getLine());
Assert.assertEquals(3, input.get(4).getEnd().getCharacter());
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:26,代码来源:RangeComparatorTest.java
示例17: insertInAlphabeticalOrder
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
private Optional<TextEdit> insertInAlphabeticalOrder(String packageName, String className) {
String insertLine = String.format("import %s.%s;\n", packageName, className);
return source.getImports()
.stream()
.filter(i -> qualifiedName(i).compareTo(packageName + "." + className) > 0)
.map(this::startPosition)
.findFirst()
.map(at -> new TextEdit(new Range(at, at), insertLine));
}
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:11,代码来源:RefactorFile.java
示例18: _toExpectation
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
protected String _toExpectation(final DocumentHighlight it) {
String _xblockexpression = null;
{
StringConcatenation _builder = new StringConcatenation();
{
Range _range = it.getRange();
boolean _tripleEquals = (_range == null);
if (_tripleEquals) {
_builder.append("[NaN, NaN]:[NaN, NaN]");
} else {
String _expectation = this.toExpectation(it.getRange());
_builder.append(_expectation);
}
}
final String rangeString = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
{
DocumentHighlightKind _kind = it.getKind();
boolean _tripleEquals_1 = (_kind == null);
if (_tripleEquals_1) {
_builder_1.append("NaN");
} else {
String _expectation_1 = this.toExpectation(it.getKind());
_builder_1.append(_expectation_1);
}
}
_builder_1.append(" ");
_builder_1.append(rangeString);
_xblockexpression = _builder_1.toString();
}
return _xblockexpression;
}
开发者ID:eclipse,项目名称:xtext-core,代码行数:33,代码来源:AbstractLanguageServerTest.java
示例19: checkSends
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
public static void checkSends(final Map<String, SomStructures> structuralProbes,
final SomStructures newProbe, final List<Diagnostic> diagnostics) {
Collection<SomStructures> probes;
synchronized (structuralProbes) {
probes = new ArrayList<>(structuralProbes.values());
}
List<Call> calls = newProbe.getCalls();
for (Call c : calls) {
if (newProbe.defines(c.selector)) {
continue;
}
boolean defined = false;
for (SomStructures p : probes) {
if (p.defines(c.selector)) {
defined = true;
break;
}
}
if (!defined) {
Range r = new Range(pos(c.sections[0].getStartLine(), c.sections[0].getStartColumn()),
pos(c.sections[c.sections.length - 1].getEndLine(),
c.sections[c.sections.length - 1].getEndColumn() + 1));
diagnostics.add(new Diagnostic(r,
"No " + c.selector.getString() + " defined. Might cause run time error.",
DiagnosticSeverity.Warning, LINT_NAME));
}
}
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:32,代码来源:SomLint.java
示例20: toRange
import org.eclipse.lsp4j.Range; //导入依赖的package包/类
public static Range toRange(final SourceSection ss) {
Range range = new Range();
range.setStart(pos(ss.getStartLine(), ss.getStartColumn()));
range.setEnd(pos(ss.getEndLine(), ss.getEndColumn() + 1));
return range;
}
开发者ID:smarr,项目名称:SOMns-vscode,代码行数:7,代码来源:SomAdapter.java
注:本文中的org.eclipse.lsp4j.Range类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论