• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TextEdit类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.lsp4j.TextEdit的典型用法代码示例。如果您正苦于以下问题:Java TextEdit类的具体用法?Java TextEdit怎么用?Java TextEdit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TextEdit类属于org.eclipse.lsp4j包,在下文中一共展示了TextEdit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:DocumentTest.java


示例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());
}
 
开发者ID:eclipse,项目名称:lsp4j,代码行数:23,代码来源:EqualityTest.java


示例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() { } }"));
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:22,代码来源:RefactorFileTest.java


示例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() { } }"));
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:22,代码来源:RefactorFileTest.java


示例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() { } }"));
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:21,代码来源:RefactorFileTest.java


示例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;
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:20,代码来源:RefactorFileTest.java


示例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
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:38,代码来源:CompletionHandlerTest.java


示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:FormatterHandlerTest.java


示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:33,代码来源:FormatterHandlerTest.java


示例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());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:AbstractQuickFixTest.java


示例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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:TextEditUtil.java


示例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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:DocumentTest.java


示例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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:26,代码来源:DocumentTest.java


示例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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:DocumentTest.java


示例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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:DocumentTest.java


示例16: _toExpectation

import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
protected String _toExpectation(final WorkspaceEdit it) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("changes :");
  _builder.newLine();
  {
    Set<Map.Entry<String, List<TextEdit>>> _entrySet = it.getChanges().entrySet();
    for(final Map.Entry<String, List<TextEdit>> entry : _entrySet) {
      _builder.append("\t");
      String _lastSegment = org.eclipse.emf.common.util.URI.createURI(entry.getKey()).lastSegment();
      _builder.append(_lastSegment, "\t");
      _builder.append(" : ");
      String _expectation = this.toExpectation(entry.getValue());
      _builder.append(_expectation, "\t");
      _builder.newLineIfNotEmpty();
    }
  }
  _builder.append("documentChanges : ");
  _builder.newLine();
  _builder.append("\t");
  String _expectation_1 = this.toExpectation(it.getDocumentChanges());
  _builder.append(_expectation_1, "\t");
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:25,代码来源:AbstractLanguageServerTest.java


示例17: testFormatting

import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
protected void testFormatting(final Procedure1<? super FormattingConfiguration> configurator) {
  try {
    @Extension
    final FormattingConfiguration configuration = new FormattingConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final FileInfo fileInfo = this.initializeContext(configuration);
    DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
    final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
      String _uri = fileInfo.getUri();
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
      it.setTextDocument(_textDocumentIdentifier);
    };
    DocumentFormattingParams _doubleArrow = ObjectExtensions.<DocumentFormattingParams>operator_doubleArrow(_documentFormattingParams, _function);
    final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.formatting(_doubleArrow);
    String _contents = fileInfo.getContents();
    final Document result = new Document(1, _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[])Conversions.unwrapArray(changes.get(), TextEdit.class)))));
    this.assertEquals(configuration.getExpectedText(), result.getContents());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:23,代码来源:AbstractLanguageServerTest.java


示例18: testRangeFormatting

import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
protected void testRangeFormatting(final Procedure1<? super RangeFormattingConfiguration> configurator) {
  try {
    @Extension
    final RangeFormattingConfiguration configuration = new RangeFormattingConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final FileInfo fileInfo = this.initializeContext(configuration);
    DocumentRangeFormattingParams _documentRangeFormattingParams = new DocumentRangeFormattingParams();
    final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
      String _uri = fileInfo.getUri();
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
      it.setTextDocument(_textDocumentIdentifier);
      it.setRange(configuration.getRange());
    };
    DocumentRangeFormattingParams _doubleArrow = ObjectExtensions.<DocumentRangeFormattingParams>operator_doubleArrow(_documentRangeFormattingParams, _function);
    final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.rangeFormatting(_doubleArrow);
    String _contents = fileInfo.getContents();
    final Document result = new Document(1, _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[])Conversions.unwrapArray(changes.get(), TextEdit.class)))));
    this.assertEquals(configuration.getExpectedText(), result.getContents());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:AbstractLanguageServerTest.java


示例19: applyChanges

import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
public Document applyChanges(final Iterable<? extends TextEdit> changes) {
  String newContent = this.contents;
  for (final TextEdit change : changes) {
    Range _range = change.getRange();
    boolean _tripleEquals = (_range == null);
    if (_tripleEquals) {
      newContent = change.getNewText();
    } else {
      final int start = this.getOffSet(change.getRange().getStart());
      final int end = this.getOffSet(change.getRange().getEnd());
      String _substring = newContent.substring(0, start);
      String _newText = change.getNewText();
      String _plus = (_substring + _newText);
      String _substring_1 = newContent.substring(end);
      String _plus_1 = (_plus + _substring_1);
      newContent = _plus_1;
    }
  }
  return new Document((this.version + 1), newContent);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:21,代码来源:Document.java


示例20: rangeFormatting

import org.eclipse.lsp4j.TextEdit; //导入依赖的package包/类
@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(final DocumentRangeFormattingParams params) {
  final Function1<CancelIndicator, List<? extends TextEdit>> _function = (CancelIndicator cancelIndicator) -> {
    final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
    final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
    FormattingService _get = null;
    if (resourceServiceProvider!=null) {
      _get=resourceServiceProvider.<FormattingService>get(FormattingService.class);
    }
    final FormattingService formatterService = _get;
    if ((formatterService == null)) {
      return CollectionLiterals.<TextEdit>emptyList();
    }
    final Function2<Document, XtextResource, List<? extends TextEdit>> _function_1 = (Document document, XtextResource resource) -> {
      return formatterService.format(document, resource, params, cancelIndicator);
    };
    return this.workspaceManager.<List<? extends TextEdit>>doRead(uri, _function_1);
  };
  return this.requestManager.<List<? extends TextEdit>>runRead(_function);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:21,代码来源:LanguageServerImpl.java



注:本文中的org.eclipse.lsp4j.TextEdit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OpenShiftConfigBuilder类代码示例发布时间:2022-05-23
下一篇:
Java HttpConversionUtil类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap