예제 #1
0
  /**
   * Collects all identifiers which are affected by the renaming of this component, grouped by the
   * file, which defines them.
   *
   * @param pm
   * @return
   * @throws CoreException
   * @throws MissingNatureException
   * @throws IOException
   */
  private Map<IFile, Collection<Identifier>> gatherAffectedIdentifiers(IProgressMonitor pm)
      throws CoreException, MissingNatureException, IOException {
    Map<IFile, Collection<Identifier>> files2Identifiers =
        new HashMap<IFile, Collection<Identifier>>();

    // Add Identifier of component definition
    declaringIdentifier = getIdentifierForPath(componentDefinition.getPath(), pm);
    List<Identifier> identifiers = new LinkedList<Identifier>();
    identifiers.add(declaringIdentifier);
    files2Identifiers.put(declaringFile, identifiers);

    // Add Identifiers of referencing elements
    Collection<IASTModelPath> paths = new LinkedList<IASTModelPath>();
    paths.add(componentDefinition.getPath());
    for (IFile file : getAllFiles()) {
      identifiers = getReferencingIdentifiersInFileForTargetPathsUseHoleRange(file, paths, pm);
      identifiers = throwAwayDifferentNames(identifiers, declaringIdentifier.getName());
      if (identifiers.size() > 0) {
        AstAnalyzerFactory factory = new AstAnalyzerFactory(identifiers.get(0));
        List<Identifier> toRename = new LinkedList<Identifier>();
        for (Identifier identifier : identifiers) {
          ComponentSelectionIdentifier selection =
              new ComponentSelectionIdentifier(identifier, factory);
          if (selection.isComponent()) {
            toRename.add(identifier);
          }
        }
        files2Identifiers.put(file, toRename);
      }
    }
    return files2Identifiers;
  }
예제 #2
0
 /**
  * Find the component definition. If couldnt find fatalError is addet to Refactoringstatus.
  *
  * @return false if couldnt find definition, true otherwise.
  * @param ret
  * @throws CoreException
  * @throws MissingNatureException
  */
 private boolean findComponentDefinition(RefactoringStatus ret)
     throws CoreException, MissingNatureException {
   Identifier selectedIdentifier = getSelectedIdentifier();
   ComponentSelectionIdentifier selectionIdentifier =
       new ComponentSelectionIdentifier(selectedIdentifier);
   if (!selectionIdentifier.isComponent()) {
     ret.addFatalError("No Component selected.");
     return false;
   }
   componentDefinition = getProjectUtil().getComponentDefinition(selectedIdentifier.getName());
   if (componentDefinition == null) {
     ret.addFatalError(
         "Did not find an component Definition, for selection: "
             + selectedIdentifier.getName()
             + "!");
     return false;
   } else if (!componentDefinition.getParseFile().isProjectFile()) {
     ret.addFatalError("Component definition is out of project range!");
     return false;
   }
   return true;
 }