use of org.eclipse.ltk.core.refactoring.Change in project che by eclipse.
the class RenameMethodProcessor method createChange.
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
try {
final TextChange[] changes = fChangeManager.getAllChanges();
final List<TextChange> list = new ArrayList<TextChange>(changes.length);
list.addAll(Arrays.asList(changes));
String project = null;
IJavaProject javaProject = fMethod.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
try {
if (!Flags.isPrivate(fMethod.getFlags()))
flags |= RefactoringDescriptor.MULTI_CHANGE;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final IType declaring = fMethod.getDeclaringType();
try {
if (declaring.isAnonymous() || declaring.isLocal())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description = Messages.format(RefactoringCoreMessages.RenameMethodProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fMethod.getElementName()));
final String header = Messages.format(RefactoringCoreMessages.RenameMethodProcessor_descriptor_description, new String[] { JavaElementLabels.getTextLabel(fMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName()) });
final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(flags);
descriptor.setJavaElement(fMethod);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateReferences(fUpdateReferences);
descriptor.setKeepOriginal(fDelegateUpdating);
descriptor.setDeprecateDelegate(fDelegateDeprecation);
return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameMethodProcessor_change_name, list.toArray(new Change[list.size()]));
} finally {
monitor.done();
}
}
use of org.eclipse.ltk.core.refactoring.Change in project che by eclipse.
the class UndoDocumentChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
try {
UndoEdit redo = performEdits();
Change result = new UndoDocumentChange(getName(), fDocument, redo);
return result;
} catch (MalformedTreeException e) {
throw Changes.asCoreException(e);
} catch (BadLocationException e) {
throw Changes.asCoreException(e);
}
}
use of org.eclipse.ltk.core.refactoring.Change in project che by eclipse.
the class MoveResourceChange method perform.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
*/
public final Change perform(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
try {
if (monitor == null)
monitor = new NullProgressMonitor();
monitor.beginTask(getName(), 4);
Change deleteUndo = null;
// delete destination if required
IResource resourceAtDestination = fTarget.findMember(fSource.getName());
if (resourceAtDestination != null && resourceAtDestination.exists()) {
deleteUndo = performDestinationDelete(resourceAtDestination, new SubProgressMonitor(monitor, 1));
} else {
monitor.worked(1);
}
// move resource
long currentStamp = fSource.getModificationStamp();
IPath destinationPath = fTarget.getFullPath().append(fSource.getName());
fSource.move(destinationPath, IResource.KEEP_HISTORY | IResource.SHALLOW, new SubProgressMonitor(monitor, 2));
resourceAtDestination = ResourcesPlugin.getWorkspace().getRoot().findMember(destinationPath);
// restore timestamp at destination
if (fStampToRestore != IResource.NULL_STAMP) {
resourceAtDestination.revertModificationStamp(fStampToRestore);
}
// restore file at source
if (fRestoreSourceChange != null) {
performSourceRestore(new SubProgressMonitor(monitor, 1));
} else {
monitor.worked(1);
}
return new MoveResourceChange(resourceAtDestination, fSource.getParent(), currentStamp, deleteUndo);
} finally {
monitor.done();
}
}
use of org.eclipse.ltk.core.refactoring.Change in project che by eclipse.
the class ProcessorBasedRefactoring method createChange.
/**
* {@inheritDoc}
*/
public Change createChange(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", fParticipants.size() + 3);
pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_create_change);
Change processorChange = getProcessor().createChange(new SubProgressMonitor(pm, 1));
if (pm.isCanceled())
throw new OperationCanceledException();
fTextChangeMap = new HashMap();
addToTextChangeMap(processorChange);
List /*<Change>*/
changes = new ArrayList();
List /*<Change>*/
preChanges = new ArrayList();
Map /*<Change, RefactoringParticipant>*/
participantMap = new HashMap();
for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
final RefactoringParticipant participant = (RefactoringParticipant) iter.next();
try {
//$NON-NLS-1$
final PerformanceStats stats = PerformanceStats.getStats(PERF_CREATE_CHANGES, getName() + ", " + participant.getName());
stats.startRun();
Change preChange = participant.createPreChange(new SubProgressMonitor(pm, 1));
Change change = participant.createChange(new SubProgressMonitor(pm, 1));
stats.endRun();
if (preChange != null) {
if (fPreChangeParticipants == null)
fPreChangeParticipants = new ArrayList();
fPreChangeParticipants.add(participant);
preChanges.add(preChange);
participantMap.put(preChange, participant);
addToTextChangeMap(preChange);
}
if (change != null) {
changes.add(change);
participantMap.put(change, participant);
addToTextChangeMap(change);
}
} catch (CoreException e) {
disableParticipant(participant, e);
throw e;
} catch (OperationCanceledException e) {
throw e;
} catch (RuntimeException e) {
disableParticipant(participant, e);
throw e;
}
if (pm.isCanceled())
throw new OperationCanceledException();
}
fTextChangeMap = null;
Change postChange = getProcessor().postCreateChange((Change[]) changes.toArray(new Change[changes.size()]), new SubProgressMonitor(pm, 1));
ProcessorChange result = new ProcessorChange(getName());
result.addAll((Change[]) preChanges.toArray(new Change[preChanges.size()]));
result.add(processorChange);
result.addAll((Change[]) changes.toArray(new Change[changes.size()]));
result.setParticipantMap(participantMap);
result.setPreChangeParticipants(fPreChangeParticipants);
if (postChange != null)
result.add(postChange);
return result;
}
use of org.eclipse.ltk.core.refactoring.Change in project che by eclipse.
the class RefactoringSession method createChange.
public ChangeCreationResult createChange() throws RefactoringException {
Change change = createChange(new CreateChangeOperation(new CheckConditionsOperation(refactoring, CheckConditionsOperation.FINAL_CONDITIONS), RefactoringStatus.FATAL), true);
// Status has been updated since we have passed true
RefactoringStatus status = conditionCheckingStatus;
// Creating the change has been canceled
if (change == null && status == null) {
internalSetChange(change);
throw new RefactoringException("Creating the change has been canceled");
}
// Set change if we don't have fatal errors.
if (!status.hasFatalError()) {
internalSetChange(change);
}
ChangeCreationResult result = DtoFactory.newDto(ChangeCreationResult.class);
result.setStatus(DtoConverter.toRefactoringStatusDto(status));
result.setCanShowPreviewPage(status.isOK());
return result;
}
Aggregations