use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo in project che by eclipse.
the class RefactoringSession method prepareRenamePackageChange.
private void prepareRenamePackageChange(List<ChangeInfo> changesInfo, ChangeInfo changeInfo, Change ch) {
changeInfo.setName(ChangeInfo.ChangeName.RENAME_PACKAGE);
RenamePackageChange renameChange = (RenamePackageChange) ch;
IPath oldPackageName = new Path(renameChange.getOldName().replace('.', IPath.SEPARATOR));
IPath newPackageName = new Path(renameChange.getNewName().replace('.', IPath.SEPARATOR));
changeInfo.setOldPath(renameChange.getResourcePath().removeLastSegments(oldPackageName.segmentCount()).append(newPackageName).toString());
changeInfo.setPath(renameChange.getResourcePath().toString());
Set<IResource> compilationUnits = renameChange.getFCompilationUnitStamps().keySet();
for (IResource iResource : compilationUnits) {
ChangeInfo change = DtoFactory.newDto(ChangeInfo.class);
change.setName(ChangeInfo.ChangeName.UPDATE);
IPath fullPathOldPath = iResource.getFullPath();
IPath newPath = renameChange.getResourcePath().append(fullPathOldPath.toFile().getName());
change.setOldPath(fullPathOldPath.toString());
change.setPath(newPath.toString());
changesInfo.add(change);
}
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo in project che by eclipse.
the class RenamePresenterTest method changesShouldBeAppliedWithOkStatus.
@Test
public void changesShouldBeAppliedWithOkStatus() throws Exception {
RefactorInfo refactorInfo = RefactorInfo.of(MoveType.REFACTOR_MENU, RefactoredItemType.COMPILATION_UNIT, new Resource[] { file });
List<ChangeInfo> changes = new ArrayList<>();
when(refactoringStatus.getChanges()).thenReturn(changes);
when(changeCreationResult.isCanShowPreviewPage()).thenReturn(true);
when(refactoringStatus.getSeverity()).thenReturn(0);
renamePresenter.show(refactorInfo);
verify(refactorService).createRenameRefactoring(createRenameRefactoringDto);
verify(renameRefactoringSessionPromise).then(renameRefactoringSessionCaptor.capture());
renameRefactoringSessionCaptor.getValue().apply(session);
renamePresenter.onAcceptButtonClicked();
verify(refactoringSession).setSessionId(SESSION_ID);
verifyPreparingRenameSettingsDto();
verifyPreparingRenameChanges();
verify(changeCreationResultPromise).then(changeCreationResultCaptor.capture());
changeCreationResultCaptor.getValue().apply(changeCreationResult);
verify(refactorService).applyRefactoring(refactoringSession);
verify(refactoringStatusPromise).then(refactoringStatusCaptor.capture());
refactoringStatusCaptor.getValue().apply(refactoringStatus);
verify(refactoringStatus, times(2)).getSeverity();
verify(view).hide();
verify(refactoringUpdater).updateAfterRefactoring(changes);
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo in project che by eclipse.
the class RefactoringSession method prepareChangesInfo.
/**
* Prepare the information about changes which were applied.
*
* @param changes array of the applied changes
* @param changesInfo prepared list of {@link ChangeInfo}
*/
public void prepareChangesInfo(Change[] changes, List<ChangeInfo> changesInfo) {
for (Change ch : changes) {
if (ch instanceof DynamicValidationStateChange) {
prepareChangesInfo(((DynamicValidationStateChange) ch).getChildren(), changesInfo);
} else {
ChangeInfo changeInfo = DtoFactory.newDto(ChangeInfo.class);
String refactoringName = ch.getName();
if (ch instanceof UndoTextFileChange) {
changeInfo.setName(ChangeInfo.ChangeName.UPDATE);
changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
}
if (refactoringName.startsWith("Rename")) {
if (ch instanceof RenameCompilationUnitChange) {
prepareRenameCompilationUnitChange(changeInfo, ch);
} else if (ch instanceof RenamePackageChange) {
prepareRenamePackageChange(changesInfo, changeInfo, ch);
}
}
if (refactoringName.startsWith("Move")) {
prepareMoveChange(changeInfo, ch);
}
changesInfo.add(changeInfo);
}
}
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo 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.che.ide.ext.java.shared.dto.refactoring.ChangeInfo in project che by eclipse.
the class RefactoringUpdater method updateAfterRefactoring.
/**
* Iterates over each refactoring change and according to change type performs specific update operation.
* i.e. for {@code ChangeName#UPDATE} updates only opened editors, for {@code ChangeName#MOVE or ChangeName#RENAME_COMPILATION_UNIT}
* updates only new paths and opened editors, for {@code ChangeName#RENAME_PACKAGE} reloads package structure and restore expansion.
*
* @param changes
* applied changes
*/
public void updateAfterRefactoring(List<ChangeInfo> changes) {
if (changes == null || changes.isEmpty()) {
return;
}
ExternalResourceDelta[] deltas = new ExternalResourceDelta[0];
final List<String> pathChanged = new ArrayList<>();
for (ChangeInfo change : changes) {
final ExternalResourceDelta delta;
final Path newPath = Path.valueOf(change.getPath());
final Path oldPath = !isNullOrEmpty(change.getOldPath()) ? Path.valueOf(change.getOldPath()) : Path.EMPTY;
switch(change.getName()) {
case MOVE:
case RENAME_COMPILATION_UNIT:
delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
registerRemovedFile(change);
break;
case RENAME_PACKAGE:
delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
break;
case UPDATE:
if (!isFileRemoved(change.getPath(), changes)) {
pathChanged.add(change.getPath());
registerRemovedFile(change);
}
default:
continue;
}
final int index = deltas.length;
deltas = Arrays.copyOf(deltas, index + 1);
deltas[index] = delta;
}
//here we need to remove file for file that moved or renamed JDT lib sent it to
for (int i = 0; i < deltas.length; i++) {
if (pathChanged.contains(deltas[i].getToPath().toString())) {
pathChanged.remove(deltas[i].getToPath().toString());
}
if (pathChanged.contains(deltas[i].getFromPath().toString())) {
pathChanged.remove(deltas[i].getFromPath().toString());
}
}
if (deltas.length > 0) {
appContext.getWorkspaceRoot().synchronize(deltas).then(new Operation<ResourceDelta[]>() {
@Override
public void apply(final ResourceDelta[] appliedDeltas) throws OperationException {
for (ResourceDelta delta : appliedDeltas) {
eventBus.fireEvent(new RevealResourceEvent(delta.getToPath()));
}
for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
final String path = editorPartPresenter.getEditorInput().getFile().getLocation().toString();
if (pathChanged.contains(path)) {
eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
}
}
setActiveEditor();
}
});
} else {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
}
setActiveEditor();
}
});
}
}
Aggregations