use of org.eclipse.ltk.core.refactoring.CompositeChange in project che by eclipse.
the class RefactoringSession method getChangePreview.
public PreviewNode getChangePreview() {
CompositeChange compositeChange;
if (change instanceof CompositeChange) {
compositeChange = (CompositeChange) change;
} else {
//$NON-NLS-1$
compositeChange = new CompositeChange("Dummy Change");
compositeChange.add(change);
}
previewNode = AbstractChangeNode.createNode(null, compositeChange);
return previewNode;
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project che by eclipse.
the class RenameLinkedModeRefactoringSession method doRename.
/**
* Make rename operation.
* @param newName the name which will be applied
* @return result of the rename operation
* @throws CoreException if an error occurs while creating the refactoring instance
* @throws InvocationTargetException if an error occurred while executing the
* operation.
* @throws InterruptedException if the operation has been canceled by the
* user.
*/
public RefactoringResult doRename(String newName) throws CoreException, InvocationTargetException, InterruptedException {
if (fOriginalName.equals(newName)) {
return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
}
RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
if (renameSupport == null)
return DtoConverter.toRefactoringResultDto(RefactoringStatus.createFatalErrorStatus("Can't create rename refactoring"));
RefactoringResult refactoringResult = DtoConverter.toRefactoringResultDto(renameSupport.perform());
PerformChangeOperation operation = renameSupport.getfPerformChangeOperation();
if (operation == null) {
return refactoringResult;
}
CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
Change[] changes = operationChange.getChildren();
List<ChangeInfo> changesInfo = new ArrayList<>();
prepareChangesInfo(changes, changesInfo);
refactoringResult.setChanges(changesInfo);
return refactoringResult;
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project che by eclipse.
the class DeleteChangeCreator method createPackageFragmentRootDeleteChange.
private static Change createPackageFragmentRootDeleteChange(IPackageFragmentRoot root) throws JavaModelException {
IResource resource = root.getResource();
if (resource != null && resource.isLinked()) {
//XXX using this code is a workaround for jcore bug 31998
//jcore cannot handle linked stuff
//normally, we should always create DeletePackageFragmentRootChange
CompositeChange composite = new DynamicValidationStateChange(RefactoringCoreMessages.DeleteRefactoring_delete_package_fragment_root);
ClasspathChange change = ClasspathChange.removeEntryChange(root.getJavaProject(), root.getRawClasspathEntry());
if (change != null) {
composite.add(change);
}
//checked in preconditions
Assert.isTrue(!Checks.isClasspathDelete(root));
composite.add(createDeleteChange(resource));
return composite;
} else {
Assert.isTrue(!root.isExternal());
// TODO remove the query argument
return new DeletePackageFragmentRootChange(root, true, null);
}
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project che by eclipse.
the class JavaMoveProcessor method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
Assert.isTrue(fMovePolicy.getJavaElementDestination() == null || fMovePolicy.getResourceDestination() == null);
Assert.isTrue(fMovePolicy.getJavaElementDestination() != null || fMovePolicy.getResourceDestination() != null);
try {
final DynamicValidationStateChange result = new DynamicValidationStateChange(RefactoringCoreMessages.JavaMoveProcessor_change_name) {
@Override
public ChangeDescriptor getDescriptor() {
return fMovePolicy.getDescriptor();
}
@Override
public Change perform(IProgressMonitor pm2) throws CoreException {
Change change = super.perform(pm2);
Change[] changes = getChildren();
for (int index = 0; index < changes.length; index++) {
if (!(changes[index] instanceof TextEditBasedChange))
return null;
}
return change;
}
};
CreateTargetExecutionLog log = null;
if (fCreateTargetQueries instanceof MonitoringCreateTargetQueries) {
final MonitoringCreateTargetQueries queries = (MonitoringCreateTargetQueries) fCreateTargetQueries;
final ICreateTargetQueries delegate = queries.getDelegate();
if (delegate instanceof LoggedCreateTargetQueries)
log = queries.getCreateTargetExecutionLog();
}
if (log != null) {
final Object[] selected = log.getSelectedElements();
for (int index = 0; index < selected.length; index++) {
result.add(new LoggedCreateTargetChange(selected[index], fCreateTargetQueries));
}
}
Change change = fMovePolicy.createChange(pm);
if (change instanceof CompositeChange) {
CompositeChange subComposite = (CompositeChange) change;
result.merge(subComposite);
} else {
result.add(change);
}
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.CompositeChange 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