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


Java CompilationUnitChange.addTextEditGroup方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.refactoring.CompilationUnitChange.addTextEditGroup方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnitChange.addTextEditGroup方法的具体用法?Java CompilationUnitChange.addTextEditGroup怎么用?Java CompilationUnitChange.addTextEditGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.refactoring.CompilationUnitChange的用法示例。


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

示例1: replaceDuplicates

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
private void replaceDuplicates(CompilationUnitChange result, int modifiers) {
	int numberOf = getNumberOfDuplicates();
	if (numberOf == 0 || !fReplaceDuplicates) {
		return;
	}
	String label = null;
	if (numberOf == 1) {
		label = Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_single, BasicElementLabels.getJavaElementName(fMethodName));
	} else {
		label = Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_multi, BasicElementLabels.getJavaElementName(fMethodName));
	}

	TextEditGroup description = new TextEditGroup(label);
	result.addTextEditGroup(description);

	for (Match duplicate : fDuplicates) {
		if (!duplicate.isInvalidNode()) {
			if (isDestinationReachable(duplicate.getEnclosingMethod())) {
				ASTNode[] callNodes = createCallNodes(duplicate, modifiers);
				ASTNode[] duplicateNodes = duplicate.getNodes();
				for (int i = 0; i < duplicateNodes.length; i++) {
					ASTNode parent = duplicateNodes[i].getParent();
					if (parent instanceof ParenthesizedExpression) {
						duplicateNodes[i] = parent;
					}
				}
				new StatementRewrite(fRewriter, duplicateNodes).replace(callNodes, description);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:32,代码来源:ExtractMethodRefactoring.java

示例2: createChange

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
	final String NN = ""; //$NON-NLS-1$
	if (pm == null) {
		pm = new NullProgressMonitor();
	}
	pm.beginTask(NN, 2);
	try {
		final CompilationUnitChange result = new CompilationUnitChange(getName(), fCUnit);
		if (fLeaveDirty) {
			result.setSaveMode(TextFileChange.LEAVE_DIRTY);
		}
		MultiTextEdit root = new MultiTextEdit();
		result.setEdit(root);
		fRewriter = ASTRewrite.create(fAnalyzer.getEnclosingBodyDeclaration().getAST());
		fRewriter.setTargetSourceRangeComputer(new SelectionAwareSourceRangeComputer(fAnalyzer.getSelectedNodes(), fCUnit.getBuffer(), fSelection.getOffset(), fSelection.getLength()));
		fImportRewrite = StubUtility.createImportRewrite(fRootNode, true);

		fLinkedProposalModel = new LinkedProposalModel();

		fScope = CodeScopeBuilder.perform(fAnalyzer.getEnclosingBodyDeclaration(), fSelection).findScope(fSelection.getOffset(), fSelection.getLength());
		fScope.setCursor(fSelection.getOffset());

		fSelectedNodes = fAnalyzer.getSelectedNodes();

		createTryCatchStatement(fCUnit.getBuffer(), fCUnit.findRecommendedLineSeparator());

		if (fImportRewrite.hasRecordedChanges()) {
			TextEdit edit = fImportRewrite.rewriteImports(null);
			root.addChild(edit);
			result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] { edit }));
		}
		TextEdit change = fRewriter.rewriteAST();
		root.addChild(change);
		result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] { change }));
		return result;
	} finally {
		pm.done();
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:41,代码来源:SurroundWithTryCatchRefactoring.java

示例3: createChange

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
/** {@inheritDoc} */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
  String label = fChangeDescription;
  CompilationUnitChange result = new CompilationUnitChange(label, fUnit);
  result.setEdit(fEdit);
  result.addTextEditGroup(
      new CategorizedTextEditGroup(
          label, new GroupCategorySet(new GroupCategory(label, label, label))));
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:TextEditFix.java

示例4: replaceDuplicates

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
private void replaceDuplicates(CompilationUnitChange result, int modifiers) {
  int numberOf = getNumberOfDuplicates();
  if (numberOf == 0 || !fReplaceDuplicates) return;
  String label = null;
  if (numberOf == 1)
    label =
        Messages.format(
            RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_single,
            BasicElementLabels.getJavaElementName(fMethodName));
  else
    label =
        Messages.format(
            RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_multi,
            BasicElementLabels.getJavaElementName(fMethodName));

  TextEditGroup description = new TextEditGroup(label);
  result.addTextEditGroup(description);

  for (int d = 0; d < fDuplicates.length; d++) {
    SnippetFinder.Match duplicate = fDuplicates[d];
    if (!duplicate.isInvalidNode()) {
      if (isDestinationReachable(duplicate.getEnclosingMethod())) {
        ASTNode[] callNodes = createCallNodes(duplicate, modifiers);
        ASTNode[] duplicateNodes = duplicate.getNodes();
        for (int i = 0; i < duplicateNodes.length; i++) {
          ASTNode parent = duplicateNodes[i].getParent();
          if (parent instanceof ParenthesizedExpression) {
            duplicateNodes[i] = parent;
          }
        }
        new StatementRewrite(fRewriter, duplicateNodes).replace(callNodes, description);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:36,代码来源:ExtractMethodRefactoring.java

示例5: updateType

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
private void updateType(CompilationUnit cu, Type oldType, CompilationUnitChange unitChange,
						ASTRewrite unitRewriter, String typeName) {

	String oldName= fSelectionTypeBinding.getName();
	String[] keys= { BasicElementLabels.getJavaElementName(oldName), BasicElementLabels.getJavaElementName(typeName)};
	String description= Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_typeChange, keys);
	TextEditGroup gd= new TextEditGroup(description);
	AST	ast= cu.getAST();

	ASTNode nodeToReplace= oldType;
	if (fSelectionTypeBinding.isParameterizedType() && !fSelectionTypeBinding.isRawType()){
		if (oldType.isSimpleType()){
			nodeToReplace= oldType.getParent();
		}
	}

    //TODO handle types other than simple & parameterized (e.g., arrays)
	Assert.isTrue(fSelectedType.isClass() || fSelectedType.isInterface());

	Type newType= null;
	if (!fSelectedType.isParameterizedType()){
		newType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeName));
	} else {
		newType= createParameterizedType(ast, fSelectedType);
	}

	unitRewriter.replace(nodeToReplace, newType, gd);
	unitChange.addTextEditGroup(gd);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:ChangeTypeRefactoring.java

示例6: createEdits

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
private void createEdits() {
	TextEdit declarationEdit= createRenameEdit(fTempDeclarationNode.getName().getStartPosition());
	TextEdit[] allRenameEdits= getAllRenameEdits(declarationEdit);

	TextEdit[] allUnparentedRenameEdits= new TextEdit[allRenameEdits.length];
	TextEdit unparentedDeclarationEdit= null;

	fChange= new CompilationUnitChange(RefactoringCoreMessages.RenameTempRefactoring_rename, fCu);
	MultiTextEdit rootEdit= new MultiTextEdit();
	fChange.setEdit(rootEdit);
	fChange.setKeepPreviewEdits(true);

	for (int i= 0; i < allRenameEdits.length; i++) {
		if (fIsComposite) {
			// Add a copy of the text edit (text edit may only have one
			// parent) to keep problem reporting code clean
			TextChangeCompatibility.addTextEdit(fChangeManager.get(fCu), RefactoringCoreMessages.RenameTempRefactoring_changeName, allRenameEdits[i].copy(), fCategorySet);

			// Add a separate copy for problem reporting
			allUnparentedRenameEdits[i]= allRenameEdits[i].copy();
			if (allRenameEdits[i].equals(declarationEdit))
				unparentedDeclarationEdit= allUnparentedRenameEdits[i];
		}
		rootEdit.addChild(allRenameEdits[i]);
		fChange.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.RenameTempRefactoring_changeName, allRenameEdits[i]));
	}

	// store information for analysis
	if (fIsComposite) {
		fLocalAnalyzePackage= new RenameAnalyzeUtil.LocalAnalyzePackage(unparentedDeclarationEdit, allUnparentedRenameEdits);
	} else
		fLocalAnalyzePackage= new RenameAnalyzeUtil.LocalAnalyzePackage(declarationEdit, allRenameEdits);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:RenameLocalVariableProcessor.java

示例7: replaceDuplicates

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
private void replaceDuplicates(CompilationUnitChange result, int modifiers) {
	int numberOf= getNumberOfDuplicates();
	if (numberOf == 0 || !fReplaceDuplicates)
		return;
	String label= null;
	if (numberOf == 1)
		label= Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_single, BasicElementLabels.getJavaElementName(fMethodName));
	else
		label= Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_multi, BasicElementLabels.getJavaElementName(fMethodName));

	TextEditGroup description= new TextEditGroup(label);
	result.addTextEditGroup(description);

	for (int d= 0; d < fDuplicates.length; d++) {
		SnippetFinder.Match duplicate= fDuplicates[d];
		if (!duplicate.isInvalidNode()) {
			if (isDestinationReachable(duplicate.getEnclosingMethod())) {
				ASTNode[] callNodes= createCallNodes(duplicate, modifiers);
				ASTNode[] duplicateNodes= duplicate.getNodes();
				for (int i= 0; i < duplicateNodes.length; i++) {
					ASTNode parent= duplicateNodes[i].getParent();
					if (parent instanceof ParenthesizedExpression) {
						duplicateNodes[i]= parent;
					}
				}
				new StatementRewrite(fRewriter, duplicateNodes).replace(callNodes, description);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:31,代码来源:ExtractMethodRefactoring.java

示例8: createChange

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
	final String NN= ""; //$NON-NLS-1$
	if (pm == null) pm= new NullProgressMonitor();
	pm.beginTask(NN, 2);
	try {
		final CompilationUnitChange result= new CompilationUnitChange(getName(), fCUnit);
		if (fLeaveDirty)
			result.setSaveMode(TextFileChange.LEAVE_DIRTY);
		MultiTextEdit root= new MultiTextEdit();
		result.setEdit(root);
		fRewriter= ASTRewrite.create(fAnalyzer.getEnclosingBodyDeclaration().getAST());
		fRewriter.setTargetSourceRangeComputer(new SelectionAwareSourceRangeComputer(
			fAnalyzer.getSelectedNodes(), fCUnit.getBuffer(), fSelection.getOffset(), fSelection.getLength()));
		fImportRewrite= StubUtility.createImportRewrite(fRootNode, true);

		fLinkedProposalModel= new LinkedProposalModel();

		fScope= CodeScopeBuilder.perform(fAnalyzer.getEnclosingBodyDeclaration(), fSelection).
			findScope(fSelection.getOffset(), fSelection.getLength());
		fScope.setCursor(fSelection.getOffset());

		fSelectedNodes= fAnalyzer.getSelectedNodes();

		createTryCatchStatement(fCUnit.getBuffer(), fCUnit.findRecommendedLineSeparator());

		if (fImportRewrite.hasRecordedChanges()) {
			TextEdit edit= fImportRewrite.rewriteImports(null);
			root.addChild(edit);
			result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] {edit} ));
		}
		TextEdit change= fRewriter.rewriteAST();
		root.addChild(change);
		result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] {change} ));
		return result;
	} finally {
		pm.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:40,代码来源:SurroundWithTryCatchRefactoring.java

示例9: createChange

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
	String label= fChangeDescription;
	CompilationUnitChange result= new CompilationUnitChange(label, fUnit);
	result.setEdit(fEdit);
	result.addTextEditGroup(new CategorizedTextEditGroup(label, new GroupCategorySet(new GroupCategory(label, label, label))));
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:TextEditFix.java

示例10: createChange

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Override
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
	TextEdit edit = createLambdaConversionTextEdit(compilationUnit, progressMonitor);
	CompilationUnitChange result= new CompilationUnitChange(TEXT_EDIT_GROUP_NAME, (ICompilationUnit) compilationUnit.getJavaElement());
	if (null == edit) {
		return result;
	}
	result.setEdit(edit);
	result.addTextEditGroup(textEditGroup);
	return result;
}
 
开发者ID:vogellacompany,项目名称:codemodify,代码行数:12,代码来源:LambdaConverterFix.java

示例11: replaceDuplicates

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
private void replaceDuplicates(CompilationUnitChange result, int modifiers) {
	int numberOf= getNumberOfDuplicates();
	if (numberOf == 0 || !fReplaceDuplicates)
		return;
	String label= null;
	if (numberOf == 1)
		label= Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_single, BasicElementLabels.getJavaElementName(fMethodName));
	else
		label= Messages.format(RefactoringCoreMessages.ExtractMethodRefactoring_duplicates_multi, BasicElementLabels.getJavaElementName(fMethodName));

	TextEditGroup description= new TextEditGroup(label);
	result.addTextEditGroup(description);

	for (int d= 0; d < fDuplicates.length; d++) {
		SnippetFinder.Match duplicate= fDuplicates[d];
		if (!duplicate.isMethodBody()) {
			if (isDestinationReachable(duplicate.getEnclosingMethod())) {
				ASTNode[] callNodes= createCallNodes(duplicate, modifiers);
				ASTNode[] duplicateNodes= duplicate.getNodes();
				for (int i= 0; i < duplicateNodes.length; i++) {
					ASTNode parent= duplicateNodes[i].getParent();
					if (parent instanceof ParenthesizedExpression) {
						duplicateNodes[i]= parent;
					}
				}
				new StatementRewrite(fRewriter, duplicateNodes).replace(callNodes, description);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:31,代码来源:ExtractMethodRefactoring.java

示例12: createEdits

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
private void createEdits() {
  TextEdit declarationEdit = createRenameEdit(fTempDeclarationNode.getName().getStartPosition());
  TextEdit[] allRenameEdits = getAllRenameEdits(declarationEdit);

  TextEdit[] allUnparentedRenameEdits = new TextEdit[allRenameEdits.length];
  TextEdit unparentedDeclarationEdit = null;

  fChange = new CompilationUnitChange(RefactoringCoreMessages.RenameTempRefactoring_rename, fCu);
  MultiTextEdit rootEdit = new MultiTextEdit();
  fChange.setEdit(rootEdit);
  fChange.setKeepPreviewEdits(true);

  for (int i = 0; i < allRenameEdits.length; i++) {
    if (fIsComposite) {
      // Add a copy of the text edit (text edit may only have one
      // parent) to keep problem reporting code clean
      TextChangeCompatibility.addTextEdit(
          fChangeManager.get(fCu),
          RefactoringCoreMessages.RenameTempRefactoring_changeName,
          allRenameEdits[i].copy(),
          fCategorySet);

      // Add a separate copy for problem reporting
      allUnparentedRenameEdits[i] = allRenameEdits[i].copy();
      if (allRenameEdits[i].equals(declarationEdit))
        unparentedDeclarationEdit = allUnparentedRenameEdits[i];
    }
    rootEdit.addChild(allRenameEdits[i]);
    fChange.addTextEditGroup(
        new TextEditGroup(
            RefactoringCoreMessages.RenameTempRefactoring_changeName, allRenameEdits[i]));
  }

  // store information for analysis
  if (fIsComposite) {
    fLocalAnalyzePackage =
        new RenameAnalyzeUtil.LocalAnalyzePackage(
            unparentedDeclarationEdit, allUnparentedRenameEdits);
  } else
    fLocalAnalyzePackage =
        new RenameAnalyzeUtil.LocalAnalyzePackage(declarationEdit, allRenameEdits);
}
 
开发者ID:eclipse,项目名称:che,代码行数:43,代码来源:RenameLocalVariableProcessor.java

示例13: addAllChangesFor

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
/**
 * Add all changes necessary on the <code>ICompilationUnit</code> in the given <code>
 * SearchResultGroup</code> to implement the refactoring transformation to the given <code>
 * CompilationUnitChange</code>.
 *
 * @param rg the <code>SearchResultGroup</code> for which changes should be created
 * @param unitHandle
 * @param unitChange the CompilationUnitChange object for the compilation unit in question
 * @return <code>true</code> iff a change has been added
 * @throws CoreException
 */
private boolean addAllChangesFor(
    SearchResultGroup rg, ICompilationUnit unitHandle, CompilationUnitChange unitChange)
    throws CoreException {
  //		ICompilationUnit	unitHandle= rg.getCompilationUnit();
  Assert.isTrue(rg == null || rg.getCompilationUnit() == unitHandle);
  CompilationUnit unit = getASTFor(unitHandle);
  ASTRewrite unitRewriter = ASTRewrite.create(unit.getAST());
  MultiTextEdit root = new MultiTextEdit();
  boolean someChange = false;

  unitChange.setEdit(root);
  fImportRewriter = StubUtility.createImportRewrite(unit, true);

  // First create the factory method
  if (unitHandle.equals(fFactoryUnitHandle)) {
    TextEditGroup factoryGD =
        new TextEditGroup(RefactoringCoreMessages.IntroduceFactory_addFactoryMethod);

    createFactoryChange(unitRewriter, unit, factoryGD);
    unitChange.addTextEditGroup(factoryGD);
    someChange = true;
  }

  // Now rewrite all the constructor calls to use the factory method
  if (rg != null)
    if (replaceConstructorCalls(rg, unit, unitRewriter, unitChange)) someChange = true;

  // Finally, make the constructor private, if requested.
  if (shouldProtectConstructor() && isConstructorUnit(unitHandle)) {
    TextEditGroup declGD =
        new TextEditGroup(RefactoringCoreMessages.IntroduceFactory_protectConstructor);

    if (protectConstructor(unit, unitRewriter, declGD)) {
      unitChange.addTextEditGroup(declGD);
      someChange = true;
    }
  }

  if (someChange) {
    root.addChild(unitRewriter.rewriteAST());
    root.addChild(fImportRewriter.rewriteImports(null));
  }

  return someChange;
}
 
开发者ID:eclipse,项目名称:che,代码行数:57,代码来源:IntroduceFactoryRefactoring.java

示例14: createChange

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
  final String NN = ""; // $NON-NLS-1$
  if (pm == null) pm = new NullProgressMonitor();
  pm.beginTask(NN, 2);
  try {
    final CompilationUnitChange result = new CompilationUnitChange(getName(), fCUnit);
    if (fLeaveDirty) result.setSaveMode(TextFileChange.LEAVE_DIRTY);
    MultiTextEdit root = new MultiTextEdit();
    result.setEdit(root);
    fRewriter = ASTRewrite.create(fAnalyzer.getEnclosingBodyDeclaration().getAST());
    fRewriter.setTargetSourceRangeComputer(
        new SelectionAwareSourceRangeComputer(
            fAnalyzer.getSelectedNodes(),
            fCUnit.getBuffer(),
            fSelection.getOffset(),
            fSelection.getLength()));
    fImportRewrite = StubUtility.createImportRewrite(fRootNode, true);

    fLinkedProposalModel = new LinkedProposalModel();

    fScope =
        CodeScopeBuilder.perform(fAnalyzer.getEnclosingBodyDeclaration(), fSelection)
            .findScope(fSelection.getOffset(), fSelection.getLength());
    fScope.setCursor(fSelection.getOffset());

    fSelectedNodes = fAnalyzer.getSelectedNodes();

    createTryCatchStatement(fCUnit.getBuffer(), fCUnit.findRecommendedLineSeparator());

    if (fImportRewrite.hasRecordedChanges()) {
      TextEdit edit = fImportRewrite.rewriteImports(null);
      root.addChild(edit);
      result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] {edit}));
    }
    TextEdit change = fRewriter.rewriteAST();
    root.addChild(change);
    result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] {change}));
    return result;
  } finally {
    pm.done();
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:44,代码来源:SurroundWithTryCatchRefactoring.java

示例15: addAllChangesFor

import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
/**
	 * Add all changes necessary on the <code>ICompilationUnit</code> in the given
	 * <code>SearchResultGroup</code> to implement the refactoring transformation
	 * to the given <code>CompilationUnitChange</code>.
	 * @param rg the <code>SearchResultGroup</code> for which changes should be created
	 * @param unitHandle
	 * @param unitChange the CompilationUnitChange object for the compilation unit in question
	 * @return <code>true</code> iff a change has been added
	 * @throws CoreException
	 */
	private boolean addAllChangesFor(SearchResultGroup rg, ICompilationUnit	unitHandle, CompilationUnitChange unitChange) throws CoreException {
//		ICompilationUnit	unitHandle= rg.getCompilationUnit();
		Assert.isTrue(rg == null || rg.getCompilationUnit() == unitHandle);
		CompilationUnit		unit= getASTFor(unitHandle);
		ASTRewrite			unitRewriter= ASTRewrite.create(unit.getAST());
		MultiTextEdit		root= new MultiTextEdit();
		boolean				someChange= false;

		unitChange.setEdit(root);
		fImportRewriter= StubUtility.createImportRewrite(unit, true);

		// First create the factory method
		if (unitHandle.equals(fFactoryUnitHandle)) {
			TextEditGroup	factoryGD= new TextEditGroup(RefactoringCoreMessages.IntroduceFactory_addFactoryMethod);

			createFactoryChange(unitRewriter, unit, factoryGD);
			unitChange.addTextEditGroup(factoryGD);
			someChange= true;
		}

		// Now rewrite all the constructor calls to use the factory method
		if (rg != null)
			if (replaceConstructorCalls(rg, unit, unitRewriter, unitChange))
				someChange= true;

		// Finally, make the constructor private, if requested.
		if (shouldProtectConstructor() && isConstructorUnit(unitHandle)) {
			TextEditGroup	declGD= new TextEditGroup(RefactoringCoreMessages.IntroduceFactory_protectConstructor);

			if (protectConstructor(unit, unitRewriter, declGD)) {
				unitChange.addTextEditGroup(declGD);
				someChange= true;
			}
		}

		if (someChange) {
			root.addChild(unitRewriter.rewriteAST());
			root.addChild(fImportRewriter.rewriteImports(null));
		}

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


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