/** * Final check before the actual refactoring * * @return status * @throws OperationCanceledException */ public RefactoringStatus checkFinalConditions() throws OperationCanceledException { RefactoringStatus status = new RefactoringStatus(); IContainer destination = fProcessor.getDestination(); IProject sourceProject = fProcessor.getSourceSelection()[0].getProject(); IProject destinationProject = destination.getProject(); if (sourceProject != destinationProject) status.merge(MoveUtils.checkMove(phpFiles, sourceProject, destination)); // Checks if one of the resources already exists with the same name in // the destination IPath dest = fProcessor.getDestination().getFullPath(); IResource[] sourceResources = fProcessor.getSourceSelection(); for (IResource element : sourceResources) { String newFilePath = dest.toOSString() + File.separatorChar + element.getName(); IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(newFilePath)); if (resource != null && resource.exists()) { status.merge( RefactoringStatus.createFatalErrorStatus( NLS.bind( PhpRefactoringCoreMessages.getString("MoveDelegate.6"), element.getName(), dest.toOSString()))); // $NON-NLS-1$ } } return status; }
/** * Add move changes for each for the selected resources * * @param sourceResources * @param rootChange */ private void createMoveChange(IResource[] sourceResources, CompositeChange rootChange) { IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources); for (IResource element : uniqueSourceResources) { MoveResourceChange moveResource = new MoveResourceChange(element, fProcessor.getDestination()); rootChange.add(moveResource); } }
/** * Creates the change for the move action. The change can be a simple change (the move itslef) or * a more complex change (including references update and includes in the file itself) depending * on the user selection (update references checkbox) * * @param pm - progress monitor * @param rootChange * @return the root change after the additions * @throws OperationCanceledException */ public Change createChange(IProgressMonitor pm, CompositeChange rootChange) throws CoreException, OperationCanceledException { fMainDestinationPath = fProcessor.getDestination().getFullPath(); fProcessor.getSourceSelection(); if (!fProcessor.getUpdateReferences()) { return createSimpleMoveChange(pm, rootChange); } return createReferenceUpdatingMoveChange(pm, rootChange); }