/**
   * Adds the name of the newly created interface to the implements clause of each class selected
   * for the refactoring.
   */
  private void addInterfaceToClasses() {
    for (int i = 0; i < m_summaryList.size(); i++) {
      TypeSummary ts = (TypeSummary) m_summaryList.elementAt(i);
      FileSummary fileSummary = (FileSummary) ts.getParent();
      File file = fileSummary.getFile();
      ASTName interfaceName = new ASTName(0);

      String currentPackageName = ts.getPackageSummary().getName();
      /*
       *  If the interface package differs from the class package, then
       *  specify the interface package name
       */
      if ((m_packageName.length() > 0) && !(currentPackageName.equals(m_packageName))) {
        interfaceName.fromString(m_packageName + "." + m_interfaceName);
      } else {
        interfaceName.fromString(m_interfaceName);
      }
      m_complexTransform.clear();
      // Very Important so we don't re-apply the interface transforms
      m_complexTransform.add(new AddImplementedInterfaceTransform(interfaceName));

      if (!m_packageName.equals(currentPackageName)) {
        m_complexTransform.add(new AddImportTransform(interfaceName));
      }
      m_complexTransform.apply(file, new File(file.getAbsolutePath()));
    }
  }
Exemplo n.º 2
0
 /**
  * Adds the type in a certain file
  *
  * @param summary the file summary
  * @param list the linked list to add to
  */
 private void add(FileSummary summary, LinkedList list) {
   Iterator iter = summary.getTypes();
   if (iter != null) {
     while (iter.hasNext()) {
       TypeSummary typeSummary = (TypeSummary) iter.next();
       if (isIncluded(typeSummary)) {
         list.add(typeSummary.getName());
       }
     }
   }
 }