本文整理汇总了Java中org.eclipse.lsp4j.TextEdit类的典型用法代码示例。如果您正苦于以下问题:Java TextEdit类的具体用法?Java TextEdit怎么用?Java TextEdit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextEdit类属于org.eclipse.lsp4j包,在下文中一共展示了TextEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: change
import org.eclipse.lsp4j.TextEdit; //导入依赖的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);
}
示例2: testEquals
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test public void testEquals() {
Assert.assertEquals(new TextDocumentIdentifier("foo"), new TextDocumentIdentifier("foo"));
Assert.assertNotEquals(new TextDocumentIdentifier("foo"), new TextDocumentIdentifier("bar"));
CompletionItem e1 = new CompletionItem();
e1.setAdditionalTextEdits(new ArrayList<>());
e1.getAdditionalTextEdits().add(new TextEdit(new Range(new Position(1,1), new Position(1,1)), "foo"));
CompletionItem e2 = new CompletionItem();
e2.setAdditionalTextEdits(new ArrayList<>());
e2.getAdditionalTextEdits().add(new TextEdit(new Range(new Position(1,1), new Position(1,1)), "foo"));
CompletionItem e3 = new CompletionItem();
e3.setAdditionalTextEdits(new ArrayList<>());
e3.getAdditionalTextEdits().add(new TextEdit(new Range(new Position(1,1), new Position(1,2)), "foo"));
Assert.assertEquals(e1, e2);
Assert.assertNotEquals(e1, e3);
Assert.assertEquals(e1.hashCode(), e2.hashCode());
Assert.assertNotEquals(e1.hashCode(), e3.hashCode());
}
示例3: addImportToExisting
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test
public void addImportToExisting() {
String before =
"package org.javacs;\n"
+ "\n"
+ "import java.util.List;\n"
+ "\n"
+ "public class Example { void main() { } }";
List<TextEdit> edits = addImport(before, "org.javacs", "Foo");
String after = applyEdits(before, edits);
assertThat(
after,
equalTo(
"package org.javacs;\n"
+ "\n"
+ "import java.util.List;\n"
+ "import org.javacs.Foo;\n"
+ "\n"
+ "public class Example { void main() { } }"));
}
示例4: addImportAtBeginning
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test
public void addImportAtBeginning() {
String before =
"package org.javacs;\n"
+ "\n"
+ "import org.javacs.Foo;\n"
+ "\n"
+ "public class Example { void main() { } }";
List<TextEdit> edits = addImport(before, "java.util", "List");
String after = applyEdits(before, edits);
assertThat(
after,
equalTo(
"package org.javacs;\n"
+ "\n"
+ "import java.util.List;\n"
+ "import org.javacs.Foo;\n"
+ "\n"
+ "public class Example { void main() { } }"));
}
示例5: importAlreadyExists
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test
public void importAlreadyExists() {
String before =
"package org.javacs;\n"
+ "\n"
+ "import java.util.List;\n"
+ "\n"
+ "public class Example { void main() { } }";
List<TextEdit> edits = addImport(before, "java.util", "List");
String after = applyEdits(before, edits);
assertThat(
after,
equalTo(
"package org.javacs;\n"
+ "\n"
+ "import java.util.List;\n"
+ "\n"
+ "public class Example { void main() { } }"));
}
示例6: addImport
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
private List<TextEdit> addImport(String content, String packageName, String className) {
List<TextEdit> result = new ArrayList<>();
JavacHolder compiler =
JavacHolder.create(
Collections.singleton(Paths.get("src/test/test-project/workspace/src")),
Collections.emptySet());
BiConsumer<JavacTask, CompilationUnitTree> doRefactor =
(task, tree) -> {
List<TextEdit> edits =
new RefactorFile(task, tree).addImport(packageName, className);
result.addAll(edits);
};
compiler.compileBatch(
Collections.singletonMap(FAKE_FILE, Optional.of(content)), doRefactor);
return result;
}
示例7: testCompletion_import_package
import org.eclipse.lsp4j.TextEdit; //导入依赖的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
}
示例8: testJavaFormatEnable
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test
public void testJavaFormatEnable() throws Exception {
String text =
//@formatter:off
"package org.sample ;\n\n" +
" public class Baz { String name;}\n";
//@formatter:on"
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", text);
preferenceManager.getPreferences().setJavaFormatEnabled(false);
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
FormattingOptions options = new FormattingOptions(4, true);// ident == 4 spaces
DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
List<? extends TextEdit> edits = server.formatting(params).get();
assertNotNull(edits);
String newText = TextEditUtil.apply(unit, edits);
assertEquals(text, newText);
}
示例9: testRangeFormatting
import org.eclipse.lsp4j.TextEdit; //导入依赖的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);
}
示例10: evaluateCodeActionCommand
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
private String evaluateCodeActionCommand(Command c)
throws BadLocationException, JavaModelException {
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
Assert.assertNotNull(c.getArguments());
Assert.assertTrue(c.getArguments().get(0) instanceof WorkspaceEdit);
WorkspaceEdit we = (WorkspaceEdit) c.getArguments().get(0);
Iterator<Entry<String, List<TextEdit>>> editEntries = we.getChanges().entrySet().iterator();
Entry<String, List<TextEdit>> entry = editEntries.next();
assertNotNull("No edits generated", entry);
assertEquals("More than one resource modified", false, editEntries.hasNext());
ICompilationUnit cu = JDTUtils.resolveCompilationUnit(entry.getKey());
assertNotNull("CU not found: " + entry.getKey(), cu);
Document doc = new Document();
doc.set(cu.getSource());
return TextEditUtil.apply(doc, entry.getValue());
}
示例11: apply
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
public static String apply(Document doc, Collection<? extends TextEdit> edits) throws BadLocationException {
Assert.isNotNull(doc);
Assert.isNotNull(edits);
List<TextEdit> sortedEdits = new ArrayList<>(edits);
sortByLastEdit(sortedEdits);
String text = doc.get();
for (int i = sortedEdits.size() - 1; i >= 0; i--) {
TextEdit te = sortedEdits.get(i);
Range r = te.getRange();
if (r != null && r.getStart() != null && r.getEnd() != null) {
int start = getOffset(doc, r.getStart());
int end = getOffset(doc, r.getEnd());
text = text.substring(0, start)
+ te.getNewText()
+ text.substring(end, text.length());
}
}
return text;
}
示例12: testUpdate_01
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test
public void testUpdate_01() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hello world");
_builder.newLine();
_builder.append("foo");
_builder.newLine();
_builder.append("bar");
_builder.newLine();
String _normalize = this.normalize(_builder);
Document _document = new Document(1, _normalize);
final Procedure1<Document> _function = (Document it) -> {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hello world");
_builder_1.newLine();
_builder_1.append("bar");
_builder_1.newLine();
TextEdit _change = this.change(this.position(1, 0), this.position(2, 0), "");
Assert.assertEquals(this.normalize(_builder_1), it.applyChanges(
Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change))).getContents());
};
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
示例13: testUpdate_02
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test
public void testUpdate_02() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hello world");
_builder.newLine();
_builder.append("foo");
_builder.newLine();
_builder.append("bar");
_builder.newLine();
String _normalize = this.normalize(_builder);
Document _document = new Document(1, _normalize);
final Procedure1<Document> _function = (Document it) -> {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hello world");
_builder_1.newLine();
_builder_1.append("future");
_builder_1.newLine();
_builder_1.append("bar");
_builder_1.newLine();
TextEdit _change = this.change(this.position(1, 1), this.position(1, 3), "uture");
Assert.assertEquals(this.normalize(_builder_1), it.applyChanges(
Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change))).getContents());
};
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
示例14: testUpdate_03
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test
public void testUpdate_03() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hello world");
_builder.newLine();
_builder.append("foo");
_builder.newLine();
_builder.append("bar");
String _normalize = this.normalize(_builder);
Document _document = new Document(1, _normalize);
final Procedure1<Document> _function = (Document it) -> {
TextEdit _change = this.change(this.position(0, 0), this.position(2, 3), "");
Assert.assertEquals("", it.applyChanges(
Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change))).getContents());
};
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
示例15: testUpdate_nonIncrementalChange
import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Test
public void testUpdate_nonIncrementalChange() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hello world");
_builder.newLine();
_builder.append("foo");
_builder.newLine();
_builder.append("bar");
String _normalize = this.normalize(_builder);
Document _document = new Document(1, _normalize);
final Procedure1<Document> _function = (Document it) -> {
TextEdit _change = this.change(null, null, " foo ");
Assert.assertEquals(" foo ", it.applyChanges(
Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change))).getContents());
};
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}