use of org.eclipse.ltk.core.refactoring.NullChange in project che by eclipse.
the class MultiStateUndoChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError())
return new NullChange();
if (pm == null)
pm = new NullProgressMonitor();
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
//$NON-NLS-1$
pm.beginTask("", 2);
ITextFileBuffer buffer = null;
try {
manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument document = buffer.getDocument();
ContentStamp currentStamp = ContentStamps.get(fFile, document);
// perform the changes
LinkedList list = new LinkedList();
for (int index = 0; index < fUndos.length; index++) {
UndoEdit edit = fUndos[index];
UndoEdit redo = edit.apply(document, TextEdit.CREATE_UNDO);
list.addFirst(redo);
}
// try to restore the document content stamp
boolean success = ContentStamps.set(document, fContentStampToRestore);
if (needsSaving()) {
buffer.commit(pm, false);
if (!success) {
// We weren't able to restore document stamp.
// Since we save restore the file stamp instead
ContentStamps.set(fFile, fContentStampToRestore);
}
}
return createUndoChange((UndoEdit[]) list.toArray(new UndoEdit[list.size()]), currentStamp);
} catch (BadLocationException e) {
throw Changes.asCoreException(e);
} finally {
if (buffer != null)
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
}
}
use of org.eclipse.ltk.core.refactoring.NullChange in project che by eclipse.
the class RenamePackageChange method createUndoChange.
@Override
protected Change createUndoChange(long stampToRestore) throws CoreException {
IPackageFragment pack = getPackage();
if (pack == null)
return new NullChange();
Map<IResource, Long> stamps = new HashMap<IResource, Long>();
if (!fRenameSubpackages) {
addStamps(stamps, pack.getCompilationUnits());
} else {
IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(pack);
for (int i = 0; i < allPackages.length; i++) {
IPackageFragment currentPackage = allPackages[i];
addStamps(stamps, currentPackage.getCompilationUnits());
}
}
return new RenamePackageChange(createNewPath(), getNewName(), getOldName(), stampToRestore, stamps, fRenameSubpackages);
// Note: This reverse change only works if the renamePackage change did
// not merge the source package into an existing target.
}
use of org.eclipse.ltk.core.refactoring.NullChange in project che by eclipse.
the class ClasspathChange method perform.
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
pm.beginTask(RefactoringCoreMessages.ClasspathChange_progress_message, 1);
try {
if (!JavaConventions.validateClasspath(fProject, fNewClasspath, fOutputLocation).matches(IStatus.ERROR)) {
IClasspathEntry[] oldClasspath = fProject.getRawClasspath();
IPath oldOutputLocation = fProject.getOutputLocation();
fProject.setRawClasspath(fNewClasspath, fOutputLocation, new SubProgressMonitor(pm, 1));
return new ClasspathChange(fProject, oldClasspath, oldOutputLocation);
} else {
return new NullChange();
}
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.NullChange in project che by eclipse.
the class CreatePackageChange method perform.
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
try {
pm.beginTask(RefactoringCoreMessages.CreatePackageChange_Creating_package, 1);
if (fPackageFragment.exists()) {
return new NullChange();
} else {
IPackageFragmentRoot root = (IPackageFragmentRoot) fPackageFragment.getParent();
root.createPackageFragment(fPackageFragment.getElementName(), false, pm);
return new DeleteResourceChange(fPackageFragment.getPath(), true);
}
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.NullChange in project che by eclipse.
the class DeletePackageFragmentRootChange method doDelete.
@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
if (!confirmDeleteIfReferenced())
return new NullChange();
int resourceUpdateFlags = IResource.KEEP_HISTORY;
int jCoreUpdateFlags = IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH | IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;
//$NON-NLS-1$
pm.beginTask("", 2);
IPackageFragmentRoot root = getRoot();
IResource rootResource = root.getResource();
CompositeChange result = new CompositeChange(getName());
ResourceDescription rootDescription = ResourceDescription.fromResource(rootResource);
IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(root);
HashMap<IFile, String> classpathFilesContents = new HashMap<IFile, String>();
for (int i = 0; i < referencingProjects.length; i++) {
IJavaProject javaProject = referencingProjects[i];
//$NON-NLS-1$
IFile classpathFile = javaProject.getProject().getFile(".classpath");
if (classpathFile.exists()) {
classpathFilesContents.put(classpathFile, getFileContents(classpathFile));
}
}
root.delete(resourceUpdateFlags, jCoreUpdateFlags, new SubProgressMonitor(pm, 1));
rootDescription.recordStateFromHistory(rootResource, new SubProgressMonitor(pm, 1));
for (Iterator<Entry<IFile, String>> iterator = classpathFilesContents.entrySet().iterator(); iterator.hasNext(); ) {
Entry<IFile, String> entry = iterator.next();
IFile file = entry.getKey();
String contents = entry.getValue();
//Restore time stamps? This should probably be some sort of UndoTextFileChange.
TextFileChange classpathUndo = new TextFileChange(Messages.format(RefactoringCoreMessages.DeletePackageFragmentRootChange_restore_file, BasicElementLabels.getPathLabel(file.getFullPath(), true)), file);
classpathUndo.setEdit(new ReplaceEdit(0, getFileLength(file), contents));
result.add(classpathUndo);
}
result.add(new UndoDeleteResourceChange(rootDescription));
pm.done();
return result;
}
Aggregations