本文整理汇总了Java中org.eclipse.jdt.core.refactoring.CompilationUnitChange.setEdit方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnitChange.setEdit方法的具体用法?Java CompilationUnitChange.setEdit怎么用?Java CompilationUnitChange.setEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.refactoring.CompilationUnitChange
的用法示例。
在下文中一共展示了CompilationUnitChange.setEdit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAddImportChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
static CompilationUnitChange createAddImportChange(
ICompilationUnit cu, Name name, String fullyQualifiedName) throws CoreException {
String[] args = {
BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)),
BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName))
};
String label =
Messages.format(
CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description, args);
CompilationUnitChange cuChange = new CompilationUnitChange(label, cu);
ImportRewrite importRewrite =
StubUtility.createImportRewrite((CompilationUnit) name.getRoot(), true);
importRewrite.addImport(fullyQualifiedName);
cuChange.setEdit(importRewrite.rewriteImports(null));
return cuChange;
}
示例2: cloneCompilationUnitChangeWithDifferentCu
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
/**
* Destructively clones a {@link CompilationUnitChange} where the cloned
* change will have a different compilation unit. This does not update text
* regions or anything more than setting the change properties and moving text
* edits from the old to new change.
*
* @param originalChange the original change, this change's internal state
* will likely become invalid (its text edits will be moved to the
* new change)
* @param cu the compilation unit to be used for the new
* {@link CompilationUnitChange}
* @return the cloned {@link CompilationUnitChange}
*/
public static CompilationUnitChange cloneCompilationUnitChangeWithDifferentCu(
TextFileChange originalChange, ICompilationUnit cu) {
CompilationUnitChange newChange = new CompilationUnitChange(
originalChange.getName(), cu);
newChange.setEdit(originalChange.getEdit());
newChange.setEnabledShallow(originalChange.isEnabled());
newChange.setKeepPreviewEdits(originalChange.getKeepPreviewEdits());
newChange.setSaveMode(originalChange.getSaveMode());
newChange.setTextType(originalChange.getTextType());
// Copy the changes over
TextEditUtilities.moveTextEditGroupsIntoChange(
originalChange.getChangeGroups(), newChange);
return newChange;
}
示例3: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
CompositeChange changes = new CompositeChange("Rename method change");
for (ICompilationUnit unit : map.keySet()) {
TextEdit newEdit = map.get(unit).getAstRewrite().rewriteAST();
TextChange existingChange = getTextChange(unit);
if (existingChange == null) {
CompilationUnitChange change = new CompilationUnitChange("change", unit);
change.setEdit(newEdit);
changes.add(change);
} else {
TextEdit existingEdit = existingChange.getEdit();
if (existingEdit.covers(newEdit)) {
mergeEdits(existingEdit, newEdit);
} else {
existingEdit.addChild(newEdit);
}
}
}
return changes;
}
示例4: 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();
}
}
示例5: createAddImportChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
static CompilationUnitChange createAddImportChange(ICompilationUnit cu, Name name, String fullyQualifiedName) throws CoreException {
String[] args= { BasicElementLabels.getJavaElementName(Signature.getSimpleName(fullyQualifiedName)),
BasicElementLabels.getJavaElementName(Signature.getQualifier(fullyQualifiedName)) };
String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_importtype_description, args);
CompilationUnitChange cuChange= new CompilationUnitChange(label, cu);
ImportRewrite importRewrite= StubUtility.createImportRewrite((CompilationUnit) name.getRoot(), true);
importRewrite.addImport(fullyQualifiedName);
cuChange.setEdit(importRewrite.rewriteImports(null));
return cuChange;
}
示例6: createChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Override
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
final CompilationUnitChange change = new CompilationUnitChange("Remove unnecessary visibility modifiers",
_context.getCompilationUnit());
final AST ast = _context.getAST().getAST();
final ASTRewrite rewriter = ASTRewrite.create(ast);
for (final ASTNode node : _annotationsToRemove) {
rewriter.remove(node, null);
}
addAnnotation(ast, rewriter, "ParametersAreNonnullByDefault", _nodesToAnnotateWithParameterAreNonnullByDefault);
addAnnotation(ast, rewriter, "ReturnValuesAreNonnullByDefault",
_nodesToAnnotateWithReturnValuesAreNonnullByDefault);
change.setEdit(rewriter.rewriteAST());
final boolean addImportForParameters = !_nodesToAnnotateWithParameterAreNonnullByDefault.isEmpty();
final boolean addImportForReturns = !_nodesToAnnotateWithReturnValuesAreNonnullByDefault.isEmpty();
if (addImportForParameters || addImportForReturns) {
final ImportRewrite importRewrite = createImportRewriterWithProjectSettings();
if (addImportForParameters) {
importRewrite.addImport(Jsr305CleanUp.FQN_PARAMETERS_ARE_NONNULL_BY_DEFAULT);
}
if (addImportForReturns) {
importRewrite.addImport(Jsr305CleanUp.FQN_RETURN_VALUES_ARE_NONNULL_BY_DEFAULT);
}
change.addEdit(importRewrite.rewriteImports(progressMonitor));
}
return change;
}
示例7: 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;
}
示例8: run
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
public void run(IProgressMonitor monitor) throws CoreException {
ICompilationUnit icu = clientBundle.getCompilationUnit();
CompilationUnit cu = JavaASTUtils.parseCompilationUnit(icu);
ImportRewrite importRewrite = StubUtility.createImportRewrite(cu, true);
// Find the target type declaration
TypeDeclaration typeDecl = JavaASTUtils.findTypeDeclaration(cu,
clientBundle.getFullyQualifiedName());
if (typeDecl == null) {
throw new CoreException(
StatusUtilities.newErrorStatus("Missing ClientBundle type "
+ clientBundle.getFullyQualifiedName(), GWTPlugin.PLUGIN_ID));
}
// We need to rewrite the AST of the ClientBundle type declaration
ASTRewrite astRewrite = ASTRewrite.create(cu.getAST());
ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(typeDecl);
ListRewrite listRewriter = astRewrite.getListRewrite(typeDecl, property);
// Add the new resource methods
boolean addComments = StubUtility.doAddComments(icu.getJavaProject());
for (ClientBundleResource resource : resources) {
listRewriter.insertLast(resource.createMethodDeclaration(clientBundle,
astRewrite, importRewrite, addComments), null);
}
// Create the edit to add the methods and update the imports
TextEdit rootEdit = new MultiTextEdit();
rootEdit.addChild(astRewrite.rewriteAST());
rootEdit.addChild(importRewrite.rewriteImports(null));
// Apply the change to the compilation unit
CompilationUnitChange cuChange = new CompilationUnitChange(
"Update ClientBundle", icu);
cuChange.setSaveMode(TextFileChange.KEEP_SAVE_STATE);
cuChange.setEdit(rootEdit);
cuChange.perform(new NullProgressMonitor());
}
示例9: createPreChange
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
@Override
public Change createPreChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
CompilationUnitChange change = new CompilationUnitChange(cu.getElementName(), cu);
change.setKeepPreviewEdits(true);
change.setEdit(new MultiTextEdit());
// parse javadocs and update references
for (ImageReference reference : UmletPluginUtils.collectUxfImgRefs(cu)) {
SourceString srcValue = reference.srcAttr.value;
if (UmletPluginUtils.isAbsoluteImageRef(srcValue.getValue())) {
continue;
}
IPackageFragment destinationPackage;
{
Object destination = getArguments().getDestination();
if (!(destination instanceof IPackageFragment)) {
continue;
}
destinationPackage = (IPackageFragment) destination;
}
IPath parentPath = UmletPluginUtils.getCompilationUnitParentPath(cu);
IPath imgPath = parentPath.append(new Path(srcValue.getValue()));
IPath destinationPath = UmletPluginUtils.getPackageFragmentRootRelativePath(cu.getJavaProject(), destinationPackage.getCorrespondingResource());
String newPath = UmletPluginUtils.calculateImageRef(destinationPath, imgPath);
change.addEdit(new ReplaceEdit(srcValue.start, srcValue.length(), newPath));
}
return change;
}
示例10: addAllChangesFor
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
/**
* Apply all changes related to a single ICompilationUnit
* @param icu the compilation unit
* @param vars
* @param unitChange
* @throws CoreException
*/
private void addAllChangesFor(ICompilationUnit icu, Set<ConstraintVariable> vars, CompilationUnitChange unitChange) throws CoreException {
CompilationUnit unit= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(icu, true);
ASTRewrite unitRewriter= ASTRewrite.create(unit.getAST());
MultiTextEdit root= new MultiTextEdit();
unitChange.setEdit(root); // Adam sez don't need this, but then unitChange.addGroupDescription() fails an assertion!
String typeName= updateImports(unit, root);
updateCu(unit, vars, unitChange, unitRewriter, typeName);
root.addChild(unitRewriter.rewriteAST());
}
示例11: 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);
}
示例12: 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
示例13: 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;
}
示例14: 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;
}
示例15: addAllChangesFor
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; //导入方法依赖的package包/类
/**
* Apply all changes related to a single ICompilationUnit
* @param icu the compilation unit
* @param vars
* @param unitChange
* @throws CoreException
*/
private void addAllChangesFor(ICompilationUnit icu, Set<ConstraintVariable> vars, CompilationUnitChange unitChange) throws CoreException {
CompilationUnit unit= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(icu, false);
ASTRewrite unitRewriter= ASTRewrite.create(unit.getAST());
MultiTextEdit root= new MultiTextEdit();
unitChange.setEdit(root); // Adam sez don't need this, but then unitChange.addGroupDescription() fails an assertion!
String typeName= updateImports(unit, root);
updateCu(unit, vars, unitChange, unitRewriter, typeName);
root.addChild(unitRewriter.rewriteAST());
}