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

Java TextChange类代码示例

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

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



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

示例1: getAdditionalProposalInfo

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
  StringBuffer buf = new StringBuffer();
  try {
    TextChange change = getTextChange();
    change.setKeepPreviewEdits(true);
    IDocument previewDocument = change.getPreviewDocument(monitor);
    TextEdit rootEdit = change.getPreviewEdit(change.getEdit());

    EditAnnotator ea = new EditAnnotator(buf, previewDocument);
    rootEdit.accept(ea);
    ea.unchangedUntil(previewDocument.getLength()); // Final pre-existing region
  } catch (CoreException e) {
    JavaPlugin.log(e);
  }
  return buf.toString();
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:CUCorrectionProposal.java


示例2: checkCompilationofDeclaringCu

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
private RefactoringStatus checkCompilationofDeclaringCu() throws CoreException {
  ICompilationUnit cu = getCu();
  TextChange change = fChangeManager.get(cu);
  String newCuSource = change.getPreviewContent(new NullProgressMonitor());
  CompilationUnit newCUNode =
      new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
          .parse(newCuSource, cu, true, false, null);
  IProblem[] problems =
      RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fBaseCuRewrite.getRoot());
  RefactoringStatus result = new RefactoringStatus();
  for (int i = 0; i < problems.length; i++) {
    IProblem problem = problems[i];
    if (shouldReport(problem, newCUNode))
      result.addEntry(
          new RefactoringStatusEntry(
              (problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING),
              problem.getMessage(),
              new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:ChangeSignatureProcessor.java


示例3: addReferenceUpdates

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
  SearchResultGroup[] grouped = getOccurrences();
  for (int i = 0; i < grouped.length; i++) {
    SearchResultGroup group = grouped[i];
    SearchMatch[] results = group.getSearchResults();
    ICompilationUnit cu = group.getCompilationUnit();
    TextChange change = manager.get(cu);
    for (int j = 0; j < results.length; j++) {
      SearchMatch match = results[j];
      if (!(match instanceof MethodDeclarationMatch)) {
        ReplaceEdit replaceEdit = createReplaceEdit(match, cu);
        String editName = RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
        addTextEdit(change, editName, replaceEdit);
      }
    }
  }
  pm.done();
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:RenameNonVirtualMethodProcessor.java


示例4: getEditChangeOffsetUpdates

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
/**
 * @param change
 * @return Map &lt;Integer oldOffset, Integer updatedOffset&gt;
 */
private static Map<Integer, Integer> getEditChangeOffsetUpdates(TextChange change) {
  TextEditChangeGroup[] editChanges = change.getTextEditChangeGroups();
  Map<Integer, Integer> offsetUpdates = new HashMap<Integer, Integer>(editChanges.length);
  for (int i = 0; i < editChanges.length; i++) {
    TextEditChangeGroup editChange = editChanges[i];
    IRegion oldRegion = editChange.getRegion();
    if (oldRegion == null) continue;
    IRegion updatedRegion =
        TextEdit.getCoverage(change.getPreviewEdits(editChange.getTextEdits()));
    if (updatedRegion == null) continue;

    offsetUpdates.put(new Integer(oldRegion.getOffset()), new Integer(updatedRegion.getOffset()));
  }
  return offsetUpdates;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:RenameAnalyzeUtil.java


示例5: addTextEditFromRewrite

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
private static TextChange addTextEditFromRewrite(
    TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException {
  try {
    ITextFileBuffer buffer = RefactoringFileBuffers.acquire(cu);
    TextEdit resultingEdits =
        rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true));
    TextChange textChange = manager.get(cu);
    if (textChange instanceof TextFileChange) {
      TextFileChange tfc = (TextFileChange) textChange;
      tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE);
    }
    String message = RefactoringCoreMessages.DeleteChangeCreator_1;
    TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits);
    return textChange;
  } finally {
    RefactoringFileBuffers.release(cu);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:DeleteChangeCreator.java


示例6: getSingleChange

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
public Change getSingleChange(IFile[] alreadyTouchedFiles) {
  Collection<TextChange> values = fChanges.values();
  if (values.size() == 0) return null;

  CompositeChange result =
      new CompositeChange(RefactoringCoreMessages.QualifiedNameSearchResult_change_name);
  result.markAsSynthetic();
  List<IFile> files = Arrays.asList(alreadyTouchedFiles);
  for (Iterator<TextChange> iter = values.iterator(); iter.hasNext(); ) {
    TextFileChange change = (TextFileChange) iter.next();
    if (!files.contains(change.getFile())) {
      result.add(change);
    }
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:QualifiedNameSearchResult.java


示例7: getAllChanges

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
/**
 * Returns all text changes managed by this instance.
 *
 * @return all text changes managed by this instance
 */
public TextChange[] getAllChanges() {
  Set<ICompilationUnit> cuSet = fMap.keySet();
  ICompilationUnit[] cus = cuSet.toArray(new ICompilationUnit[cuSet.size()]);
  // sort by cu name:
  Arrays.sort(
      cus,
      new Comparator<ICompilationUnit>() {
        public int compare(ICompilationUnit o1, ICompilationUnit o2) {
          String name1 = o1.getElementName();
          String name2 = o2.getElementName();
          return name1.compareTo(name2);
        }
      });

  TextChange[] textChanges = new TextChange[cus.length];
  for (int i = 0; i < cus.length; i++) {
    textChanges[i] = fMap.get(cus[i]);
  }
  return textChanges;
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:TextChangeManager.java


示例8: addToTextChangeMap

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
private void addToTextChangeMap(Change change) {
  if (change instanceof TextChange) {
    Object element = ((TextChange) change).getModifiedElement();
    if (element != null) {
      fTextChangeMap.put(element, change);
    }
    // check if we have a subclass of TextFileChange. If so also put the change
    // under the file resource into the hash table if possible.
    if (change instanceof TextFileChange && !change.getClass().equals(TextFileChange.class)) {
      IFile file = ((TextFileChange) change).getFile();
      fTextChangeMap.put(file, change);
    }
  } else if (change instanceof CompositeChange) {
    Change[] children = ((CompositeChange) change).getChildren();
    for (int i = 0; i < children.length; i++) {
      addToTextChangeMap(children[i]);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ProcessorBasedRefactoring.java


示例9: testCreateChange

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
public void testCreateChange() {
  GWTRefactoringSupport support = new DummyGWTRefactoringSupport();
  support.setUpdateReferences(true);

  IType refactorTestType = refactorTestClass.getCompilationUnit().findPrimaryType();
  support.setOldElement(refactorTestType);

  RefactoringParticipant participant = new DummyRefactoringParticipant();
  IRefactoringChangeFactory changeFactory = new DefaultChangeFactory();
  CompositeChange change = support.createChange(participant, changeFactory);

  // Return value should contain one child change
  Change[] changeChildren = change.getChildren();
  assertEquals(1, changeChildren.length);

  // Root edit should contain two child edits, one for each JSNI ref
  TextChange childChange = (TextChange) changeChildren[0];
  TextEdit changeEdit = childChange.getEdit();
  assertEquals(2, changeEdit.getChildrenSize());
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:21,代码来源:GWTRefactoringSupportTest.java


示例10: moveTextEditGroupsIntoChange

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
/**
 * Moves the given text edit groups (and its text edits) into the given
 * change.
 */
public static void moveTextEditGroupsIntoChange(
    TextEditBasedChangeGroup[] groups, TextChange textChange) {
  for (TextEditBasedChangeGroup changeGroup : groups) {
    TextEditGroup group = changeGroup.getTextEditGroup();
    for (TextEdit edit : group.getTextEdits()) {
      if (edit.getParent() != null) {
        edit.getParent().removeChild(edit);
      }

      textChange.addEdit(edit);
    }

    // We must create a new change group since it doesn't have API to change
    // the parent change
    TextEditBasedChangeGroup newChangeGroup = new TextEditBasedChangeGroup(
        textChange, group);
    newChangeGroup.setEnabled(changeGroup.isEnabled());
    textChange.addChangeGroup(newChangeGroup);
  }
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:25,代码来源:TextEditUtilities.java


示例11: getAdditionalProposalInfo

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
	StringBuffer buf= new StringBuffer();
	try {
		TextChange change= getTextChange();
		change.setKeepPreviewEdits(true);
		IDocument previewDocument= change.getPreviewDocument(monitor);
		TextEdit rootEdit= change.getPreviewEdit(change.getEdit());

		EditAnnotator ea= new EditAnnotator(buf, previewDocument);
		rootEdit.accept(ea);
		ea.unchangedUntil(previewDocument.getLength()); // Final pre-existing region
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return buf.toString();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:18,代码来源:CUCorrectionProposal.java


示例12: getEditChangeOffsetUpdates

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
/**
 *
 * @param change
 * @return Map &lt;Integer oldOffset, Integer updatedOffset&gt;
 */
private static Map<Integer, Integer> getEditChangeOffsetUpdates(TextChange change) {
	TextEditChangeGroup[] editChanges= change.getTextEditChangeGroups();
	Map<Integer, Integer> offsetUpdates= new HashMap<Integer, Integer>(editChanges.length);
	for (int i= 0; i < editChanges.length; i++) {
		TextEditChangeGroup editChange= editChanges[i];
		IRegion oldRegion= editChange.getRegion();
		if (oldRegion == null)
			continue;
		IRegion updatedRegion= TextEdit.getCoverage(change.getPreviewEdits(editChange.getTextEdits()));
		if (updatedRegion == null)
			continue;

		offsetUpdates.put(new Integer(oldRegion.getOffset()), new Integer(updatedRegion.getOffset()));
	}
	return offsetUpdates;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:RenameAnalyzeUtil.java


示例13: addTextEditFromRewrite

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException {
	try {
		ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu);
		TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true));
		TextChange textChange= manager.get(cu);
		if (textChange instanceof TextFileChange) {
			TextFileChange tfc= (TextFileChange) textChange;
			tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE);
		}
		String message= RefactoringCoreMessages.DeleteChangeCreator_1;
		TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits);
		return textChange;
	} finally {
		RefactoringFileBuffers.release(cu);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:DeleteChangeCreator.java


示例14: addFields

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的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


示例15: removeFields

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的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


示例16: insert

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
/**
  * Inserts the given key value pairs into this model at appropriate
  * positions. Records all required text changes in the given change
  *
  * @param keyValuePairs the key value pairs to insert
  * @param change the change to use to record text changes
  */
 public void insert(KeyValuePair[] keyValuePairs, TextChange change) {

     ArrayList<KeyValuePair> sorted= new ArrayList<KeyValuePair>(Arrays.asList(keyValuePairs));
     Collections.sort(sorted, new Comparator<KeyValuePair>() {
public int compare(KeyValuePair p1, KeyValuePair p2) {
	return Collator.getInstance().compare(p1.fKey, p2.fKey);
}
     });

     for (int i = 0; i < sorted.size(); i++) {
         KeyValuePair curr= sorted.get(i);
InsertEdit insertEdit= insert(curr);

         String message= Messages.format(NLSMessages.NLSPropertyFileModifier_add_entry, BasicElementLabels.getJavaElementName(curr.getKey()));
TextChangeCompatibility.addTextEdit(change, message, insertEdit);
     }
 }
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:PropertyFileDocumentModel.java


示例17: removeKeys

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
public static Change removeKeys(IPath propertyFilePath, List<String> keys) throws CoreException {

		String name= Messages.format(NLSMessages.NLSPropertyFileModifier_remove_from_property_file, BasicElementLabels.getPathLabel(propertyFilePath, false));
		TextChange textChange= new TextFileChange(name, getPropertyFile(propertyFilePath));
		textChange.setTextType("properties"); //$NON-NLS-1$

		PropertyFileDocumentModel model= new PropertyFileDocumentModel(textChange.getCurrentDocument(new NullProgressMonitor()));

		for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
			String key= iterator.next();
			TextEdit edit= model.remove(key);
			if (edit != null) {
				TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, BasicElementLabels.getJavaElementName(key)), edit);
			}

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


示例18: addReplaceEdits

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
private static void addReplaceEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) {
	for (int i= 0; i < substitutions.length; i++) {
		NLSSubstitution substitution= substitutions[i];
		if (doReplace(substitution, newKeyToSubstMap, oldKeyToSubstMap)) {
			KeyValuePair initialPair= new KeyValuePair(substitution.getInitialKey(), substitution.getInitialValue());

			String key= PropertyFileDocumentModel.escape(substitution.getKey(), false);
			String value= PropertyFileDocumentModel.escape(substitution.getValue(), true) + model.getLineDelimiter();
			KeyValuePair newPair= new KeyValuePair(key, value);
			TextEdit edit= model.replace(initialPair, newPair);
			if (edit != null) {
				TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_replace_entry, BasicElementLabels.getJavaElementName(substitution.getKey())), edit);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:NLSPropertyFileModifier.java


示例19: addInsertEdits

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的package包/类
private static void addInsertEdits(TextChange textChange, NLSSubstitution[] substitutions, Map<String, NLSSubstitution> newKeyToSubstMap, Map<String, NLSSubstitution> oldKeyToSubstMap, PropertyFileDocumentModel model) {
	ArrayList<KeyValuePair> keyValuePairsToAdd= new ArrayList<KeyValuePair>();

	for (int i= 0; i < substitutions.length; i++) {
		NLSSubstitution substitution= substitutions[i];

		if (doInsert(substitution, newKeyToSubstMap, oldKeyToSubstMap)) {
			String value= PropertyFileDocumentModel.escape(substitution.getValueNonEmpty(), true) + model.getLineDelimiter();
			String key= PropertyFileDocumentModel.escape(substitution.getKey(), false);
			keyValuePairsToAdd.add(new KeyValuePair(key, value));
		}
	}

	if (keyValuePairsToAdd.size() > 0) {
		model.insert(keyValuePairsToAdd.toArray(new KeyValuePair[keyValuePairsToAdd.size()]), textChange);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:NLSPropertyFileModifier.java


示例20: addAccessor

import org.eclipse.ltk.core.refactoring.TextChange; //导入依赖的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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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