当前位置: 首页>>代码示例>>Java>>正文


Java WorkspaceEdit类代码示例

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


WorkspaceEdit类属于org.eclipse.lsp4j包,在下文中一共展示了WorkspaceEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: organizeImportsInCompilationUnit

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
public void organizeImportsInCompilationUnit(ICompilationUnit unit, WorkspaceEdit rootEdit) {
	try {
		InnovationContext context = new InnovationContext(unit, 0, unit.getBuffer().getLength() - 1);
		CUCorrectionProposal proposal = new CUCorrectionProposal("OrganizeImports", unit, IProposalRelevance.ORGANIZE_IMPORTS) {
			@Override
			protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
				CompilationUnit astRoot = context.getASTRoot();
				OrganizeImportsOperation op = new OrganizeImportsOperation(unit, astRoot, true, false, true, null);
				editRoot.addChild(op.createTextEdit(null));
			}
		};

		addWorkspaceEdit(unit, proposal, rootEdit);
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Problem organize imports ", e);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:18,代码来源:OrganizeImportsCommand.java

示例2: testOrganizeImportsUnused

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
@Test
public void testOrganizeImportsUnused() throws CoreException, BadLocationException {

	IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);

	StringBuilder buf = new StringBuilder();
	buf.append("package test1;\n");
	buf.append("\n");
	buf.append("import java.util.ArrayList;\n");
	buf.append("\n");
	buf.append("public class E {\n");
	buf.append("}\n");

	ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

	buf = new StringBuilder();
	buf.append("package test1;\n");
	buf.append("\n");
	buf.append("public class E {\n");
	buf.append("}\n");

	WorkspaceEdit rootEdit = new WorkspaceEdit();
	command.organizeImportsInCompilationUnit(cu, rootEdit);
	assertEquals(getOrganizeImportResult(cu, rootEdit), buf.toString());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:OrganizeImportsCommandTest.java

示例3: testRenameSystemLibrary

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
@Test
public void testRenameSystemLibrary() throws JavaModelException {
	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);

	String[] codes = {
			"package test1;\n",
			"public class E {\n",
			"   public int bar() {\n",
			"		String str = new String();\n",
			"   	str.len|*gth();\n",
			"   }\n",
			"}\n"
	};
	StringBuilder builder = new StringBuilder();
	Position pos = mergeCode(builder, codes);
	ICompilationUnit cu = pack1.createCompilationUnit("E.java", builder.toString(), false, null);

	WorkspaceEdit edit = getRenameEdit(cu, pos, "newname");
	assertNotNull(edit);
	assertEquals(edit.getChanges().size(), 0);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:RenameHandlerTest.java

示例4: evaluateCodeActionCommand

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的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

示例5: doTest

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
protected void doTest(final String fileName, final Position position) {
  try {
    TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileName);
    final RenameParams params = new RenameParams(_textDocumentIdentifier, position, "Tescht");
    final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("changes :");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("MyType1.testlang : Tescht [[0, 5] .. [0, 9]]");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("Tescht [[1, 4] .. [1, 8]]");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("MyType2.testlang : Tescht [[1, 4] .. [1, 8]]");
    _builder.newLine();
    _builder.append("documentChanges : ");
    _builder.newLine();
    this.assertEquals(_builder.toString(), this.toExpectation(workspaceEdit));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:25,代码来源:RenameTest.java

示例6: _toExpectation

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的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

示例7: rename

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
@Override
public CompletableFuture<WorkspaceEdit> rename(final RenameParams params) {
  final Function1<CancelIndicator, WorkspaceEdit> _function = (CancelIndicator cancelIndicator) -> {
    WorkspaceEdit _xblockexpression = null;
    {
      final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
      final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
      IRenameService _get = null;
      if (resourceServiceProvider!=null) {
        _get=resourceServiceProvider.<IRenameService>get(IRenameService.class);
      }
      final IRenameService renameService = _get;
      if ((renameService == null)) {
        return new WorkspaceEdit();
      }
      _xblockexpression = renameService.rename(this.workspaceManager, params, cancelIndicator);
    }
    return _xblockexpression;
  };
  return this.requestManager.<WorkspaceEdit>runRead(_function);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:22,代码来源:LanguageServerImpl.java

示例8: testMapConversion

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
@Test
public void testMapConversion() {
  Map<String, List<TextEdit>> changes =
      Collections.singletonMap(
          "anURL",
          Arrays.asList(
              new TextEdit(new Range(new Position(0, 1), new Position(3, 4)), "blabla")));
  WorkspaceEdit edit = new WorkspaceEdit();
  edit.setChanges(changes);

  WorkspaceEditDto originalDto = new WorkspaceEditDto(edit);
  Assert.assertTrue(reflectionEquals(originalDto, edit));
  String jsonString = originalDto.toJson();
  WorkspaceEditDto convertedDto = WorkspaceEditDto.fromJson(jsonString);
  Assert.assertTrue(reflectionEquals(originalDto, convertedDto));
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:DtoConversionTest.java

示例9: organizeImportsInProject

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
/**
 * Organize imports when select a project.
 *
 * @param proj
 *            the target project
 * @return
 */
public WorkspaceEdit organizeImportsInProject(IProject proj) {
	WorkspaceEdit rootEdit = new WorkspaceEdit();
	HashSet<IJavaElement> result = new HashSet<>();

	collectCompilationUnits(JavaCore.create(proj), result, null);
	for (IJavaElement elem : result) {
		if (elem.getElementType() == IJavaElement.COMPILATION_UNIT) {
			organizeImportsInCompilationUnit((ICompilationUnit) elem, rootEdit);
		}
	}
	return rootEdit;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:OrganizeImportsCommand.java

示例10: organizeImportsInDirectory

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
/**
 * Organize imports underlying a directory
 *
 * @param folderUri
 *            Selected folder URI
 * @param proj
 *            the folder associated project
 * @return
 * @throws CoreException
 */
public WorkspaceEdit organizeImportsInDirectory(String folderUri, IProject proj) throws CoreException {
	WorkspaceEdit rootEdit = new WorkspaceEdit();
	IPackageFragment fragment = null;
	if (JDTUtils.toURI(folderUri) != null) {
		fragment = JDTUtils.resolvePackage(folderUri);
	}
	// Select an individual package
	if (fragment != null) {
		organizeImportsInPackageFragment(fragment, rootEdit);
	} else if (proj != null) {
		// Search the packages under the selected folder:
		IJavaProject javaProject = JavaCore.create(proj);
		IPath rootPath = ResourceUtils.filePathFromURI(folderUri);
		IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
		HashSet<IJavaElement> result = new HashSet<>();
		for (IPackageFragmentRoot root : roots) {
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
				String packageRoot = root.getResource().getLocation().toString();
				if (packageRoot.toLowerCase().indexOf(rootPath.toString().toLowerCase()) >= 0) {
					collectCompilationUnits(javaProject, result, null);
				}
			}
		}
		for (IJavaElement elem : result) {
			if (elem.getElementType() == IJavaElement.COMPILATION_UNIT) {
				organizeImportsInCompilationUnit((ICompilationUnit) elem, rootEdit);
			}
		}
	}
	return rootEdit;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:42,代码来源:OrganizeImportsCommand.java

示例11: organizeImportsInFile

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
public WorkspaceEdit organizeImportsInFile(String fileUri) {
	WorkspaceEdit rootEdit = new WorkspaceEdit();
	ICompilationUnit unit = null;
	if (JDTUtils.toURI(fileUri) != null) {
		unit = JDTUtils.resolveCompilationUnit(fileUri);
	}
	if (unit == null) {
		return rootEdit;
	}
	organizeImportsInCompilationUnit(unit, rootEdit);
	return rootEdit;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:13,代码来源:OrganizeImportsCommand.java

示例12: organizeImportsInPackageFragment

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
public void organizeImportsInPackageFragment(IPackageFragment fragment, WorkspaceEdit rootEdit) throws CoreException {
	HashSet<IJavaElement> result = new HashSet<>();
	collectCompilationUnits(fragment.getParent(), result, fragment.getElementName());
	for (IJavaElement elem : result) {
		if (elem.getElementType() == IJavaElement.COMPILATION_UNIT) {
			organizeImportsInCompilationUnit((ICompilationUnit) elem, rootEdit);
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:10,代码来源:OrganizeImportsCommand.java

示例13: renameOccurrences

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
@Override
public void renameOccurrences(WorkspaceEdit edit, String newName, IProgressMonitor monitor) throws CoreException {
	super.renameOccurrences(edit, newName, monitor);

	IType t = (IType) fElement;
	IMethod[] methods = t.getMethods();

	for (IMethod method : methods) {
		if (method.isConstructor()) {
			TextEdit replaceEdit = new ReplaceEdit(method.getNameRange().getOffset(), method.getNameRange().getLength(), newName);
			convert(edit, t.getCompilationUnit(), replaceEdit);
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:15,代码来源:RenameTypeProcessor.java

示例14: renameOccurrences

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
public void renameOccurrences(WorkspaceEdit edit, String newName, IProgressMonitor monitor) throws CoreException {
	if (fElement == null || !canRename()) {
		return;
	}

	IJavaElement[] elementsToSearch = null;

	if (fElement instanceof IMethod) {
		elementsToSearch = RippleMethodFinder.getRelatedMethods((IMethod) fElement, monitor, null);
	} else {
		elementsToSearch = new IJavaElement[] { fElement };
	}

	SearchPattern pattern = createOccurrenceSearchPattern(elementsToSearch);
	if (pattern == null) {
		return;
	}
	SearchEngine engine = new SearchEngine();
	engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), new SearchRequestor() {

		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			Object o = match.getElement();
			if (o instanceof IJavaElement) {
				IJavaElement element = (IJavaElement) o;
				ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
				if (compilationUnit == null) {
					return;
				}
				TextEdit replaceEdit = collectMatch(match, element, compilationUnit, newName);
				if (replaceEdit != null) {
					convert(edit, compilationUnit, replaceEdit);
				}
			}
		}
	}, monitor);

}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:39,代码来源:RenameProcessor.java

示例15: convert

import org.eclipse.lsp4j.WorkspaceEdit; //导入依赖的package包/类
protected void convert(WorkspaceEdit root, ICompilationUnit unit, TextEdit edits) {
	TextEditConverter converter = new TextEditConverter(unit, edits);
	String uri = JDTUtils.toURI(unit);
	Map<String, List<org.eclipse.lsp4j.TextEdit>> changes = root.getChanges();
	if (changes.containsKey(uri)) {
		changes.get(uri).addAll(converter.convert());
	} else {
		changes.put(uri, converter.convert());
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:RenameProcessor.java


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