Exemplo n.º 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;
  }
Exemplo n.º 2
0
  @Override
  public RefactoringStatus initializeRefactoring(IProgressMonitor pm) {
    RefactoringStatus ret = new RefactoringStatus();
    ProjectUtil projectUtil = getProjectUtil();
    try {
      if (!isApplicable()) {
        ret.addFatalError("The Refactoring is no Accessable");
      }
      if (!findComponentDefinition(ret)) {
        return ret;
      }
      declaringFile = getIFile4ParseFile(componentDefinition.getParseFile());
      affectedIdentifiers = gatherAffectedIdentifiers(pm);

    } catch (Exception e) {
      ret.addFatalError("Exception during initialization. See project log for more information.");
      projectUtil.log("Exception during initialization.", e);
    }
    return ret;
  }
Exemplo n.º 3
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;
 }