/**
   * 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
  /**
   * Creates the package declaration
   *
   * @return the package declaration
   */
  ASTPackageDeclaration createPackageDeclaration() {
    ASTPackageDeclaration packDecl =
        new ASTPackageDeclaration(JavaParserTreeConstants.JJTPACKAGEDECLARATION);
    ASTName packName = new ASTName();
    packName.fromString(m_packageName);
    packDecl.jjtAddChild(packName, 0);

    return packDecl;
  }