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


Java TextChange类代码示例

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


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


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