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


Java MultiTextEdit类代码示例

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


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

示例1: toTextEdit

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
/**
	 * Add the necessary text edits to the accumulating result. Optionally return the offset of the alias.
	 */
	private AliasLocation toTextEdit(QualifiedName qualifiedName, String optionalAlias, int insertionOffset,
			MultiTextEdit result) {
		QualifiedName moduleName = qualifiedName.skipLast(1);
		// the following code for enhancing existing ImportDeclarations makes use of the Xtext serializer, which is not
		// yet compatible with fragments in Xtext grammars (as of Xtext 2.9.1) -> deactivated for now
// @formatter:off
//		String moduleNameAsString = unquoted(syntacticModuleName(moduleName));
//		for (ImportDeclaration existing : existingImports) {
//			String importedModuleName = existing.getModule().getQualifiedName();
//			if (moduleNameAsString.equals(importedModuleName)) {
//				return enhanceExistingImportDeclaration(existing, qualifiedName, optionalAlias, result);
//			}
//		}
// @formatter:on
		return addNewImportDeclaration(moduleName, qualifiedName, optionalAlias, insertionOffset, result);
	}
 
开发者ID:eclipse,项目名称:n4js,代码行数:20,代码来源:ImportRewriter.java

示例2: enhanceExistingImportDeclaration

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
@SuppressWarnings({ "unused", "deprecation" })
private AliasLocation enhanceExistingImportDeclaration(ImportDeclaration importDeclaration,
		QualifiedName qualifiedName,
		String optionalAlias, MultiTextEdit result) {

	addImportSpecifier(importDeclaration, qualifiedName, optionalAlias);
	ICompositeNode replaceMe = NodeModelUtils.getNode(importDeclaration);
	int offset = replaceMe.getOffset();
	AliasLocationAwareBuffer observableBuffer = new AliasLocationAwareBuffer(
			optionalAlias,
			offset,
			grammarAccess);

	try {
		serializer.serialize(
				importDeclaration,
				observableBuffer,
				SaveOptions.newBuilder().noValidation().getOptions());
	} catch (IOException e) {
		throw new RuntimeException("Should never happen since we write into memory", e);
	}
	result.addChild(new ReplaceEdit(offset, replaceMe.getLength(), observableBuffer.toString()));
	return observableBuffer.getAliasLocation();
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:25,代码来源:ImportRewriter.java

示例3: removeComment

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
private void removeComment(IDocument doc, int offset) {
	try {
		IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
		undoMgr.beginCompoundChange();

		ITypedRegion par = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, offset, false);
		int beg = par.getOffset();
		int len = par.getLength();

		String comment = doc.get(beg, len);
		int eLen = markerLen(comment);
		int bLen = eLen + 1;

		MultiTextEdit edit = new MultiTextEdit();
		edit.addChild(new DeleteEdit(beg, bLen));
		edit.addChild(new DeleteEdit(beg + len - eLen, eLen));
		edit.apply(doc);
		undoMgr.endCompoundChange();
	} catch (MalformedTreeException | BadLocationException e) {
		Log.error("Failure removing comment " + e.getMessage());
	}
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:23,代码来源:ToggleHiddenCommentHandler.java

示例4: toTextEdit

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
private static void toTextEdit(CodeEdit codeEdit, IDocument document, MultiTextEdit textEdit)
		throws TypeScriptException {
	String newText = codeEdit.getNewText();
	int startLine = codeEdit.getStart().getLine();
	int startOffset = codeEdit.getStart().getOffset();
	int endLine = codeEdit.getEnd().getLine();
	int endOffset = codeEdit.getEnd().getOffset();
	int start = DocumentUtils.getPosition(document, startLine, startOffset);
	int end = DocumentUtils.getPosition(document, endLine, endOffset);
	int length = end - start;
	if (newText.isEmpty()) {
		if (length > 0) {
			textEdit.addChild(new DeleteEdit(start, length));
		}
	} else {
		if (length > 0) {
			textEdit.addChild(new ReplaceEdit(start, length, newText));
		} else if (length == 0) {
			textEdit.addChild(new InsertEdit(start, newText));
		}
	}
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:23,代码来源:DocumentUtils.java

示例5: createTextEditProcessor

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
private TextEditProcessor createTextEditProcessor(
    IDocument document, int flags, TextEditBasedChangeGroup[] changes) {
  if (fEdit == null) return new TextEditProcessor(document, new MultiTextEdit(0, 0), flags);
  List includes = new ArrayList(0);
  for (int c = 0; c < changes.length; c++) {
    TextEditBasedChangeGroup change = changes[c];
    Assert.isTrue(change.getTextEditChange() == this);
    if (change.isEnabled()) {
      includes.addAll(Arrays.asList(change.getTextEditGroup().getTextEdits()));
    }
  }
  fCopier = new TextEditCopier(fEdit);
  TextEdit copiedEdit = fCopier.perform();
  boolean keep = getKeepPreviewEdits();
  if (keep) flags = flags | TextEdit.UPDATE_REGIONS;
  LocalTextEditProcessor result = new LocalTextEditProcessor(document, copiedEdit, flags);
  result.setIncludes(
      mapEdits((TextEdit[]) includes.toArray(new TextEdit[includes.size()]), fCopier));
  if (!keep) fCopier = null;
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:TextChange.java

示例6: testPerform

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
public void testPerform() throws CoreException {
  // Create a dummy change for updating references in RefactorTest.java
  // to the class R to its new name 'RRR'
  ICompilationUnit cu = refactorTestClass.getCompilationUnit();
  GWTRefactoringSupport support = new DummyRefactoringSupport();
  JsniReferenceChangeFactory factory = new JsniReferenceChangeFactory(support);
  IJsniReferenceChange jsniChange = factory.createChange(cu);

  // Add one dummy edit to the change
  TextEdit oldRootEdit = new MultiTextEdit();
  oldRootEdit.addChild(new ReplaceEdit(252, 0, ""));
  ((TextFileChange)jsniChange).setEdit(oldRootEdit);

  // Perform the change (this should replace the original edits with new ones
  // with the correct offsets).
  ((TextFileChange)jsniChange).perform(new NullProgressMonitor());

  // Verify that the change still has one edit
  TextEdit newRootEdit = ((TextFileChange)jsniChange).getEdit();
  assertEquals(1, newRootEdit.getChildrenSize());
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:22,代码来源:JsniReferenceChangeTest.java

示例7: createMethodContent

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
/**
 * Creates the method content of the moved method.
 *
 * @param document
 *            the document representing the source compilation unit
 * @param declaration
 *            the source method declaration
 * @param rewrite
 *            the ast rewrite to use
 * @return the string representing the moved method body
 * @throws BadLocationException
 *             if an offset into the document is invalid
 */
protected String createMethodContent(final IDocument document, final MethodDeclaration declaration, final ASTRewrite rewrite) throws BadLocationException {
	Assert.isNotNull(document);
	Assert.isNotNull(declaration);
	Assert.isNotNull(rewrite);
	final IRegion range= new Region(declaration.getStartPosition(), declaration.getLength());
	final RangeMarker marker= new RangeMarker(range.getOffset(), range.getLength());
	final IJavaProject project= fMethod.getJavaProject();
	final TextEdit[] edits= rewrite.rewriteAST(document, project.getOptions(true)).removeChildren();
	for (int index= 0; index < edits.length; index++)
		marker.addChild(edits[index]);
	final MultiTextEdit result= new MultiTextEdit();
	result.addChild(marker);
	final TextEditProcessor processor= new TextEditProcessor(document, new MultiTextEdit(0, document.getLength()), TextEdit.UPDATE_REGIONS);
	processor.getRoot().addChild(result);
	processor.performEdits();
	final IRegion region= document.getLineInformation(document.getLineOfOffset(marker.getOffset()));
	return Strings.changeIndent(document.get(marker.getOffset(), marker.getLength()), Strings.computeIndentUnits(document.get(region.getOffset(), region.getLength()), project), project, "", TextUtilities.getDefaultLineDelimiter(document)); //$NON-NLS-1$
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:32,代码来源:MoveInstanceMethodProcessor.java

示例8: addFields

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
public static Change addFields(ICompilationUnit cu, List<String> fields) throws CoreException {
	AccessorClassModifier sourceModification= new AccessorClassModifier(cu);
	String message= Messages.format(NLSMessages.AccessorClassModifier_add_fields_to_accessor, BasicElementLabels.getFileName(cu));

	TextChange change= new CompilationUnitChange(message, cu);
	MultiTextEdit multiTextEdit= new MultiTextEdit();
	change.setEdit(multiTextEdit);

	for (int i= 0; i < fields.size(); i++) {
		String field= fields.get(i);
		NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null);
		sourceModification.addKey(substitution, change);
	}

	if (change.getChangeGroups().length == 0)
		return null;

	change.addEdit(sourceModification.getTextEdit());

	return change;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:AccessorClassModifier.java

示例9: removeFields

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
public static Change removeFields(ICompilationUnit cu, List<String> fields) throws CoreException {
	AccessorClassModifier sourceModification= new AccessorClassModifier(cu);
	String message= Messages.format(NLSMessages.AccessorClassModifier_remove_fields_from_accessor, BasicElementLabels.getFileName(cu));

	TextChange change= new CompilationUnitChange(message, cu);
	MultiTextEdit multiTextEdit= new MultiTextEdit();
	change.setEdit(multiTextEdit);

	for (int i= 0; i < fields.size(); i++) {
		String field= fields.get(i);
		NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null);
		sourceModification.removeKey(substitution, change);
	}

	if (change.getChangeGroups().length == 0)
		return null;

	change.addEdit(sourceModification.getTextEdit());

	return change;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:AccessorClassModifier.java

示例10: addAccessor

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
private void addAccessor(NLSSubstitution sub, TextChange change, String accessorName) {
	if (sub.getState() == NLSSubstitution.EXTERNALIZED) {
		NLSElement element= sub.getNLSElement();
		Region position= element.getPosition();
		String[] args= {sub.getValueNonEmpty(), BasicElementLabels.getJavaElementName(sub.getKey())};
		String text= Messages.format(NLSMessages.NLSSourceModifier_externalize, args);

		String resourceGetter= createResourceGetter(sub.getKey(), accessorName);

		TextEdit edit= new ReplaceEdit(position.getOffset(), position.getLength(), resourceGetter);
		if (fIsEclipseNLS && element.getTagPosition() != null) {
			MultiTextEdit multiEdit= new MultiTextEdit();
			multiEdit.addChild(edit);
			Region tagPosition= element.getTagPosition();
			multiEdit.addChild(new DeleteEdit(tagPosition.getOffset(), tagPosition.getLength()));
			edit= multiEdit;
		}
		TextChangeCompatibility.addTextEdit(change, text, edit);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:NLSSourceModifier.java

示例11: isPacked

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
/**
 * Returns true if the given <code>edit</code> is minimal.
 * <p>
 * That is if:
 * <ul>
 * <li><b>true</b> if <code>edit</code> is a leaf</li>
 * <li>if <code>edit</code> is a inner node then <b>true</b> if
 *   <ul>
 *   <li><code>edit</code> has same size as all its children</li>
 *   <li><code>isPacked</code> is <b>true</b> for all children</li>
 *   </ul>
 * </li>
 * </ul>
 * </p>
 *
 * @param edit the edit to verify
 * @return true if edit is minimal
 * @since 3.4
 */
public static boolean isPacked(TextEdit edit) {
	if (!(edit instanceof MultiTextEdit))
		return true;

	if (!edit.hasChildren())
		return true;

	TextEdit[] children= edit.getChildren();
	if (edit.getOffset() != children[0].getOffset())
		return false;

	if (edit.getExclusiveEnd() != children[children.length - 1].getExclusiveEnd())
		return false;

	for (int i= 0; i < children.length; i++) {
		if (!isPacked(children[i]))
			return false;
	}

	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:41,代码来源:TextEditUtil.java

示例12: fixEmptyVariables

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables) throws MalformedTreeException, BadLocationException {
	IDocument doc= new Document(buffer.getString());
	int nLines= doc.getNumberOfLines();
	MultiTextEdit edit= new MultiTextEdit();
	HashSet<Integer> removedLines= new HashSet<Integer>();
	for (int i= 0; i < variables.length; i++) {
		TemplateVariable position= findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
		if (position == null || position.getLength() > 0) {
			continue;
		}
		int[] offsets= position.getOffsets();
		for (int k= 0; k < offsets.length; k++) {
			int line= doc.getLineOfOffset(offsets[k]);
			IRegion lineInfo= doc.getLineInformation(line);
			int offset= lineInfo.getOffset();
			String str= doc.get(offset, lineInfo.getLength());
			if (Strings.containsOnlyWhitespaces(str) && nLines > line + 1 && removedLines.add(new Integer(line))) {
				int nextStart= doc.getLineOffset(line + 1);
				edit.addChild(new DeleteEdit(offset, nextStart - offset));
			}
		}
	}
	edit.apply(doc, 0);
	return doc.get();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:StubUtility.java

示例13: removeAndInsertNew

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
private void removeAndInsertNew(IBuffer buffer, int contentOffset, int contentEnd, ArrayList stringsToInsert, MultiTextEdit resEdit) {
	int pos= contentOffset;
	for (int i= 0; i < stringsToInsert.size(); i++) {
		String curr= (String) stringsToInsert.get(i);
		int idx= findInBuffer(buffer, curr, pos, contentEnd);
		if (idx != -1) {
			if (idx != pos) {
				resEdit.addChild(new DeleteEdit(pos, idx - pos));
			}
			pos= idx + curr.length();
		} else {
			resEdit.addChild(new InsertEdit(pos, curr));
		}
	}
	if (pos < contentEnd) {
		resEdit.addChild(new DeleteEdit(pos, contentEnd - pos));
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:ImportRewriteAnalyzer.java

示例14: createChange

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm)
	throws CoreException, OperationCanceledException
{
	if (editsPerFiles.isEmpty())
		return null;

	pm.beginTask("Searching for references.", editsPerFiles.size());
	final CompositeChange changes = new CompositeChange("Update mapper element ID");
	int workCount = 0;
	for (Entry<IFile, List<ReplaceEdit>> editsPerFile : editsPerFiles.entrySet())
	{
		IFile file = editsPerFile.getKey();
		TextChange change = new TextFileChange(file.getName(), file);
		TextEdit editRoot = new MultiTextEdit();
		change.setEdit(editRoot);
		for (ReplaceEdit edit : editsPerFile.getValue())
		{
			editRoot.addChild(edit);
		}
		changes.add(change);
		pm.worked(++workCount);
	}
	pm.done();
	return changes;
}
 
开发者ID:mybatis,项目名称:mybatipse,代码行数:27,代码来源:ElementRenameRefactoring.java

示例15: applyGenerateProperties

import org.eclipse.text.edits.MultiTextEdit; //导入依赖的package包/类
private IDocument applyGenerateProperties(MockupGeneratePropertiesRequestProcessor requestProcessor)
        throws BadLocationException, MalformedTreeException, MisconfigurationException {
    IDocument refactoringDoc = new Document(data.source);
    MultiTextEdit multi = new MultiTextEdit();
    for (GeneratePropertiesRequest req : requestProcessor.getRefactoringRequests()) {
        SelectionState state = req.getSelectionState();

        if (state.isGetter()) {
            multi.addChild(new GetterMethodEdit(req).getEdit());
        }
        if (state.isSetter()) {
            multi.addChild(new SetterMethodEdit(req).getEdit());
        }
        if (state.isDelete()) {
            multi.addChild(new DeleteMethodEdit(req).getEdit());
        }
        multi.addChild(new PropertyEdit(req).getEdit());
    }
    multi.apply(refactoringDoc);
    return refactoringDoc;
}
 
开发者ID:fabioz,项目名称:Pydev,代码行数:22,代码来源:GeneratePropertiesTestCase.java


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