use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class RenameFieldProcessor method addDelegates.
private RefactoringStatus addDelegates() throws JavaModelException, CoreException {
RefactoringStatus status = new RefactoringStatus();
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(fField.getCompilationUnit());
rewrite.setResolveBindings(true);
// add delegate for the field
if (RefactoringAvailabilityTester.isDelegateCreationAvailable(fField)) {
FieldDeclaration fieldDeclaration = ASTNodeSearchUtil.getFieldDeclarationNode(fField, rewrite.getRoot());
if (fieldDeclaration.fragments().size() > 1) {
status.addWarning(Messages.format(RefactoringCoreMessages.DelegateCreator_cannot_create_field_delegate_more_than_one_fragment, BasicElementLabels.getJavaElementName(fField.getElementName())), JavaStatusContext.create(fField));
} else if (((VariableDeclarationFragment) fieldDeclaration.fragments().get(0)).getInitializer() == null) {
status.addWarning(Messages.format(RefactoringCoreMessages.DelegateCreator_cannot_create_field_delegate_no_initializer, BasicElementLabels.getJavaElementName(fField.getElementName())), JavaStatusContext.create(fField));
} else {
DelegateFieldCreator creator = new DelegateFieldCreator();
creator.setDeclareDeprecated(fDelegateDeprecation);
creator.setDeclaration(fieldDeclaration);
creator.setNewElementName(getNewElementName());
creator.setSourceRewrite(rewrite);
creator.prepareDelegate();
creator.createEdit();
}
}
// there may be getters even if the field is static final
if (getGetter() != null && fRenameGetter)
addMethodDelegate(getGetter(), getNewGetterName(), rewrite);
if (getSetter() != null && fRenameSetter)
addMethodDelegate(getSetter(), getNewSetterName(), rewrite);
final CompilationUnitChange change = rewrite.createChange(true);
if (change != null) {
change.setKeepPreviewEdits(true);
fChangeManager.manage(fField.getCompilationUnit(), change);
}
return status;
}
use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class RenameNonVirtualMethodProcessor method addDeclarationUpdate.
private void addDeclarationUpdate(TextChangeManager manager) throws CoreException {
if (getDelegateUpdating()) {
// create the delegate
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(getDeclaringCU());
rewrite.setResolveBindings(true);
MethodDeclaration methodDeclaration = ASTNodeSearchUtil.getMethodDeclarationNode(getMethod(), rewrite.getRoot());
DelegateMethodCreator creator = new DelegateMethodCreator();
creator.setDeclaration(methodDeclaration);
creator.setDeclareDeprecated(getDeprecateDelegates());
creator.setSourceRewrite(rewrite);
creator.setCopy(true);
creator.setNewElementName(getNewElementName());
creator.prepareDelegate();
creator.createEdit();
CompilationUnitChange cuChange = rewrite.createChange(true);
if (cuChange != null) {
cuChange.setKeepPreviewEdits(true);
manager.manage(getDeclaringCU(), cuChange);
}
}
String editName = RefactoringCoreMessages.RenameMethodRefactoring_update_declaration;
ISourceRange nameRange = getMethod().getNameRange();
ReplaceEdit replaceEdit = new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName());
addTextEdit(manager.get(getDeclaringCU()), editName, replaceEdit);
}
use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class FixCorrectionProposal method createTextChange.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal#createTextChange()
*/
@Override
protected TextChange createTextChange() throws CoreException {
CompilationUnitChange createChange = fFix.createChange(null);
createChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
return createChange;
}
use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class InferTypeArgumentsRefactoring method rewriteDeclarations.
private void rewriteDeclarations(InferTypeArgumentsUpdate update, IProgressMonitor pm) throws CoreException {
HashMap<ICompilationUnit, CuUpdate> updates = update.getUpdates();
Set<Entry<ICompilationUnit, CuUpdate>> entrySet = updates.entrySet();
//$NON-NLS-1$
pm.beginTask("", entrySet.size());
pm.setTaskName(RefactoringCoreMessages.InferTypeArgumentsRefactoring_creatingChanges);
for (Iterator<Entry<ICompilationUnit, CuUpdate>> iter = entrySet.iterator(); iter.hasNext(); ) {
if (pm.isCanceled())
throw new OperationCanceledException();
Entry<ICompilationUnit, CuUpdate> entry = iter.next();
ICompilationUnit cu = entry.getKey();
pm.worked(1);
pm.subTask(BasicElementLabels.getFileName(cu));
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(cu);
rewrite.setResolveBindings(false);
CuUpdate cuUpdate = entry.getValue();
for (Iterator<CollectionElementVariable2> cvIter = cuUpdate.getDeclarations().iterator(); cvIter.hasNext(); ) {
ConstraintVariable2 cv = cvIter.next();
rewriteConstraintVariable(cv, rewrite, fTCModel, fLeaveUnconstrainedRaw, null);
}
for (Iterator<CastVariable2> castsIter = cuUpdate.getCastsToRemove().iterator(); castsIter.hasNext(); ) {
CastVariable2 castCv = castsIter.next();
rewriteCastVariable(castCv, rewrite, fTCModel);
}
CompilationUnitChange change = rewrite.createChange(true);
if (change != null) {
fChangeManager.manage(cu, change);
}
}
}
use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.
the class PromoteTempToFieldRefactoring method createChange.
/*
* @see org.eclipse.jdt.internal.corext.refactoring.base.IRefactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 1);
try {
if (fFieldName.length() == 0) {
fFieldName = getInitialFieldName();
}
ASTRewrite rewrite = ASTRewrite.create(fCompilationUnitNode.getAST());
if (fInitializeIn == INITIALIZE_IN_METHOD && tempHasInitializer())
addLocalDeclarationSplit(rewrite);
else
addLocalDeclarationRemoval(rewrite);
if (fInitializeIn == INITIALIZE_IN_CONSTRUCTOR)
addInitializersToConstructors(rewrite);
addTempRenames(rewrite);
addFieldDeclaration(rewrite);
CompilationUnitChange result = new CompilationUnitChange(RefactoringCoreMessages.PromoteTempToFieldRefactoring_name, fCu);
result.setDescriptor(new RefactoringChangeDescriptor(getRefactoringDescriptor()));
TextEdit resultingEdits = rewrite.rewriteAST();
TextChangeCompatibility.addTextEdit(result, RefactoringCoreMessages.PromoteTempToFieldRefactoring_editName, resultingEdits);
return result;
} finally {
pm.done();
}
}
Aggregations