Esempio n. 1
0
  /**
   * 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;
  }
Esempio n. 2
0
  /**
   * 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);
  }
Esempio n. 3
0
  /**
   * Checks if it is ok to start with the refactoring
   *
   * @return status
   * @throws OperationCanceledException
   */
  public RefactoringStatus checkInitialConditions() throws OperationCanceledException {
    IResource[] sourceResources = fProcessor.getSourceSelection();

    phpFiles = new HashSet<IFile>();
    MoveUtils.getAllPHPFiles(sourceResources, phpFiles);
    return new RefactoringStatus();
  }
Esempio n. 4
0
  /**
   * Adds the text and move changes to the root change This change is the a more global change, it
   * includes both the file(s) move, the update of it's includes and update all the references, all
   * the files that have includes to the moved file.
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @return the root change after the additions
   */
  private Change createReferenceUpdatingMoveChange(IProgressMonitor pm, CompositeChange rootChange)
      throws CoreException, OperationCanceledException {
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.0"), 100); // $NON-NLS-1$

      IResource[] sourceResources = fProcessor.getSourceSelection();

      createTextChanges(new SubProgressMonitor(pm, 80), rootChange, phpFiles, sourceResources);
      pm.worked(80);

      // update configuration file.
      createRunConfigurationChange(sourceResources, rootChange);

      // There is a tricky thing here.
      // The resource move must be happened after text change, and run
      // configuration changes(this is because the share file under the
      // project)
      // but before the other changes, e.g. break point and etc.
      createMoveChange(sourceResources, rootChange);

      // update associated break point.
      createBreakPointChange(sourceResources, rootChange);

      createBuildPathChange(sourceResources, rootChange);

      createRenameLibraryFolderChange(sourceResources, rootChange);

      pm.worked(20);

    } finally {
      pm.done();
    }
    return rootChange;
  }
Esempio n. 5
0
 /**
  * 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);
   }
 }
Esempio n. 6
0
  /**
   * Adds the move changes to the root change This change is the proper move change, nothing else
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @return the root change after the additions
   */
  private Change createSimpleMoveChange(final IProgressMonitor pm, final CompositeChange rootChange)
      throws CoreException, OperationCanceledException {
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.0"), 100); // $NON-NLS-1$

      IResource[] sourceResources = fProcessor.getSourceSelection();
      createMoveChange(sourceResources, rootChange);
      pm.worked(100);

    } finally {
      pm.done();
    }
    return rootChange;
  }
Esempio n. 7
0
  /**
   * Checks whether the given move included is vaild
   *
   * @param destination
   * @return a staus indicating whether the included is valid or not
   */
  public RefactoringStatus verifyDestination(IResource destination) {
    RefactoringStatus status = new RefactoringStatus();

    Assert.isNotNull(destination);
    if (!destination.exists() || destination.isPhantom())
      return RefactoringStatus.createFatalErrorStatus(
          PhpRefactoringCoreMessages.getString("MoveDelegate.2")); // $NON-NLS-1$
    if (!destination.isAccessible())
      return RefactoringStatus.createFatalErrorStatus(
          PhpRefactoringCoreMessages.getString("MoveDelegate.3")); // $NON-NLS-1$
    Assert.isTrue(destination.getType() != IResource.ROOT);

    IResource[] sourceResources = fProcessor.getSourceSelection();
    for (IResource element : sourceResources) {
      if (destination.equals(element.getParent()))
        return RefactoringStatus.createFatalErrorStatus(
            PhpRefactoringCoreMessages.getString("MoveDelegate.4")); // $NON-NLS-1$
      if (destination.equals(element)) {
        return RefactoringStatus.createFatalErrorStatus(
            PhpRefactoringCoreMessages.getString("MoveDelegate.5")); // $NON-NLS-1$
      }
    }
    return status;
  }