示例#1
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();
  }
示例#2
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;
  }
示例#3
0
  private Map<IFile, Program> collectReferencingFiles(IFile sourceFile, IProgressMonitor pm) {
    ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(sourceFile);

    Map<IFile, Program> participantFiles = new HashMap<IFile, Program>();

    Collection<Node> references = MoveUtils.getReferencingFiles(sourceModule);
    if (references != null) {
      for (Iterator<Node> it = references.iterator(); it.hasNext(); ) {
        Node node = it.next();
        IFile file = (IFile) node.getFile().getResource();
        try {
          participantFiles.put(file, RefactoringUtility.getProgramForFile(file));
        } catch (Exception e) {
        }
      }
    }

    return participantFiles;
  }