Exemplo n.º 1
0
 static ICompilationUnit findWorkingCopyForCu(
     ICompilationUnit[] newWorkingCopies, ICompilationUnit cu) {
   ICompilationUnit original = cu == null ? null : cu.getPrimary();
   for (int i = 0; i < newWorkingCopies.length; i++) {
     if (newWorkingCopies[i].getPrimary().equals(original)) return newWorkingCopies[i];
   }
   return null;
 }
  /* (non-Javadoc)
   * @see org.eclipse.team.ui.history.ElementLocalHistoryPageSource#getFile(java.lang.Object)
   */
  public IFile getFile(Object input) {
    // extract CU from input
    ICompilationUnit cu = null;
    if (input instanceof ICompilationUnit) cu = (ICompilationUnit) input;
    else if (input instanceof IMember) cu = ((IMember) input).getCompilationUnit();

    if (cu == null || !cu.exists()) return null;

    // get to original CU
    cu = cu.getPrimary();

    // find underlying file
    IFile file = (IFile) cu.getResource();
    if (file != null && file.exists()) return file;
    return null;
  }
Exemplo n.º 3
0
  // TODO: Currently filters out declarations (MethodDeclarationMatch, FieldDeclarationMatch).
  // Long term solution: only pass reference search results in.
  static RefactoringStatus analyzeRenameChanges2(
      TextChangeManager manager,
      SearchResultGroup[] oldReferences,
      SearchResultGroup[] newReferences,
      String newElementName) {
    RefactoringStatus result = new RefactoringStatus();

    HashMap<ICompilationUnit, SearchMatch[]> cuToNewResults = new HashMap<>(newReferences.length);
    for (int i1 = 0; i1 < newReferences.length; i1++) {
      ICompilationUnit cu = newReferences[i1].getCompilationUnit();
      if (cu != null) cuToNewResults.put(cu.getPrimary(), newReferences[i1].getSearchResults());
    }

    for (int i = 0; i < oldReferences.length; i++) {
      SearchResultGroup oldGroup = oldReferences[i];
      SearchMatch[] oldMatches = oldGroup.getSearchResults();
      ICompilationUnit cu = oldGroup.getCompilationUnit();
      if (cu == null) continue;

      SearchMatch[] newSearchMatches = cuToNewResults.remove(cu);
      if (newSearchMatches == null) {
        for (int j = 0; j < oldMatches.length; j++) {
          SearchMatch oldMatch = oldMatches[j];
          addShadowsError(cu, oldMatch, result);
        }
      } else {
        analyzeChanges(cu, manager.get(cu), oldMatches, newSearchMatches, newElementName, result);
      }
    }

    for (Iterator<Entry<ICompilationUnit, SearchMatch[]>> iter =
            cuToNewResults.entrySet().iterator();
        iter.hasNext(); ) {
      Entry<ICompilationUnit, SearchMatch[]> entry = iter.next();
      ICompilationUnit cu = entry.getKey();
      SearchMatch[] newSearchMatches = entry.getValue();
      for (int i = 0; i < newSearchMatches.length; i++) {
        SearchMatch newMatch = newSearchMatches[i];
        addReferenceShadowedError(cu, newMatch, newElementName, result);
      }
    }
    return result;
  }
 private IFile getFile(ICompilationUnit unit) {
   unit = unit.getPrimary();
   IResource resource = unit.getResource();
   if (resource != null && resource.getType() == IResource.FILE) return (IFile) resource;
   return null;
 }