Exemple #1
0
  private void removeBuildPath(IResource resource, IProject project) {

    IScriptProject projrct = DLTKCore.create(project);
    IPath filePath = resource.getFullPath();

    oldBuildEntries = Arrays.asList(projrct.readRawBuildpath());

    newBuildEntries = new ArrayList<IBuildpathEntry>();

    newBuildEntries.addAll(oldBuildEntries);

    for (int i = 0; i < oldBuildEntries.size(); i++) {
      IBuildpathEntry fEntryToChange = oldBuildEntries.get(i);
      IPath entryPath = fEntryToChange.getPath();

      int mattchedPath = entryPath.matchingFirstSegments(filePath);

      if (mattchedPath == filePath.segmentCount()) {
        newBuildEntries.remove(fEntryToChange);
      } else {
        IBuildpathEntry newEntry =
            RefactoringUtility.createNewBuildpathEntry(
                fEntryToChange, fEntryToChange.getPath(), filePath, ""); // $NON-NLS-1$
        newBuildEntries.remove(fEntryToChange);
        newBuildEntries.add(newEntry);
      }
    }

    oldIncludePath = new ArrayList<IBuildpathEntry>();

    newIncludePathEntries = new ArrayList<IBuildpathEntry>();
    List<IncludePath> includePathEntries =
        Arrays.asList(IncludePathManager.getInstance().getIncludePaths(project));

    for (IncludePath entry : includePathEntries) {
      Object includePathEntry = entry.getEntry();
      IResource includeResource = null;
      if (!(includePathEntry instanceof IBuildpathEntry)) {
        includeResource = (IResource) includePathEntry;
        IPath entryPath = includeResource.getFullPath();

        IBuildpathEntry oldEntry =
            RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath);
        oldIncludePath.add((IBuildpathEntry) oldEntry);

        if (filePath.isPrefixOf(entryPath) || entryPath.equals(filePath)) {
        } else {
          IBuildpathEntry newEntry =
              RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath);
          newIncludePathEntries.add(newEntry);
        }
      } else {
        newIncludePathEntries.add((IBuildpathEntry) includePathEntry);
        oldIncludePath.add((IBuildpathEntry) includePathEntry);
      }
    }
  }
Exemple #2
0
  private void createBuildPathChange(IResource[] sourceResources, CompositeChange rootChange)
      throws ModelException {
    IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources);
    for (IResource element : uniqueSourceResources) {
      // only container need handle build/include path.
      if (element instanceof IContainer) {
        IProject project = element.getProject();

        // if moving to another project
        if (RefactoringUtility.getResource(fMainDestinationPath).getProject() != project) {
          removeBuildPath(element, project);
          IPath path = element.getFullPath().removeLastSegments(1);
          RenameBuildAndIcludePathChange biChange =
              new RenameBuildAndIcludePathChange(
                  path,
                  path,
                  element.getName(),
                  "",
                  oldBuildEntries, //$NON-NLS-1$
                  newBuildEntries,
                  oldIncludePath,
                  newIncludePathEntries);

          if (newBuildEntries.size() > 0 || newIncludePathEntries.size() > 0) {
            rootChange.add(biChange);
          }

        } else {
          updateBuildPath(element, project);
          RenameBuildAndIcludePathChange biChange =
              new RenameBuildAndIcludePathChange(
                  element.getFullPath().removeLastSegments(1),
                  fMainDestinationPath,
                  element.getName(),
                  element.getName(),
                  oldBuildEntries,
                  newBuildEntries,
                  oldIncludePath,
                  newIncludePathEntries);
          if (newBuildEntries.size() > 0 || newIncludePathEntries.size() > 0) {
            rootChange.add(biChange);
          }
        }
      }
    }
  }
Exemple #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;
  }