Exemplo n.º 1
0
  public void compare(ASTTypeDeclaration a, ASTTypeDeclaration b) {
    dubaj.tr.Ace.log("a", a);
    dubaj.tr.Ace.log("b", b);

    // should have only one child, the type itself, either an interface or a
    // class declaration

    ASTClassOrInterfaceDeclaration at = TypeDeclarationUtil.getType(a);
    ASTClassOrInterfaceDeclaration bt = TypeDeclarationUtil.getType(b);

    dubaj.tr.Ace.log("at", at);
    dubaj.tr.Ace.log("bt", bt);

    if (at == null && bt == null) {
      dubaj.tr.Ace.log("skipping 'semicolon declarations'");
    } else {
      compare(at, bt);
    }
  }
Exemplo n.º 2
0
  protected void compareDeclarations(
      ASTClassOrInterfaceDeclaration aNode, ASTClassOrInterfaceDeclaration bNode) {
    // now the children, below the modifiers in the AST.

    ASTClassOrInterfaceBodyDeclaration[] aDecls = TypeDeclarationUtil.getDeclarations(aNode);
    ASTClassOrInterfaceBodyDeclaration[] bDecls = TypeDeclarationUtil.getDeclarations(bNode);

    // compare declarations in A against B

    if (aDecls.length == 0) {
      if (bDecls.length == 0) {
        // tr.Ace.log("no change (both of zero length)");
      } else {
        addAllDeclarations(bDecls, aNode, true);
      }
    } else if (bDecls.length == 0) {
      addAllDeclarations(aDecls, bNode, false);
    } else {
      MethodUtil methodUtil = new MethodUtil();
      Map matches = TypeDeclarationUtil.matchDeclarations(aDecls, bDecls, methodUtil);
      Iterator sit = matches.keySet().iterator();
      List aSeen = new ArrayList();
      List bSeen = new ArrayList();

      // TimedEvent dte = new TimedEvent("diffs");

      Collection diffs = get();

      while (sit.hasNext()) {
        Double dScore = (Double) sit.next();
        List atScore = (List) matches.get(dScore);

        Iterator vit = atScore.iterator();
        while (vit.hasNext()) {
          Object[] values = (Object[]) vit.next();

          ASTClassOrInterfaceBodyDeclaration aDecl = (ASTClassOrInterfaceBodyDeclaration) values[0];
          ASTClassOrInterfaceBodyDeclaration bDecl = (ASTClassOrInterfaceBodyDeclaration) values[1];

          aSeen.add(aDecl);
          bSeen.add(bDecl);

          dubaj.tr.Ace.log("aDecl", aDecl);
          dubaj.tr.Ace.log("bDecl", bDecl);

          SimpleNode ad = TypeDeclarationUtil.getDeclaration(aDecl);
          SimpleNode bd = TypeDeclarationUtil.getDeclaration(bDecl);

          // TODO: Adiciona Mudanca do Metodo
          // we know that the classes of aDecl and bDecl are the same
          if (ad instanceof ASTMethodDeclaration) {
            MethodDiff differ = new MethodDiff(diffs);

            boolean achouMudanca = false;

            if (differ.compararAcessoMetodo(aDecl, bDecl, Relatorio.TipoDeclaracao.Metodo)) {
              Relatorio.getMudancaClasse().incrementarMudancasMetodo(new MudancaMetodo());
            }

            if (differ.comparar(
                (ASTMethodDeclaration) ad,
                (ASTMethodDeclaration) bd,
                Relatorio.TipoDeclaracao.Metodo)) {}

          } else if (ad instanceof ASTFieldDeclaration) {
            FieldDiff differ = new FieldDiff(diffs);

            if (differ.compararAcessoMetodo(aDecl, bDecl, Relatorio.TipoDeclaracao.Classe)) {
              Relatorio.getMudancaClasse().incrementarMudancasAtributo();
            }

            differ.compare(
                (ASTFieldDeclaration) ad,
                (ASTFieldDeclaration) bd,
                Relatorio.TipoDeclaracao.Classe);
          } else if (ad instanceof ASTConstructorDeclaration) {
            CtorDiff differ = new CtorDiff(diffs);

            boolean achouMudanca = false;

            if (differ.compararAcessoMetodo(aDecl, bDecl, Relatorio.TipoDeclaracao.Construtor)) {
              achouMudanca = true;
            }

            if (differ.comparar(
                (ASTConstructorDeclaration) ad,
                (ASTConstructorDeclaration) bd,
                Relatorio.TipoDeclaracao.Construtor)) {
              achouMudanca = true;
            }

            if (achouMudanca) {

              String nomeAntigo = CtorUtil.getFullName((ASTConstructorDeclaration) ad);
              String nomeNovo = CtorUtil.getFullName((ASTConstructorDeclaration) bd);
            }

          } else if (ad instanceof ASTClassOrInterfaceDeclaration) {
            // access comparison is done in TypeDiff; confusing.
            compare((ASTClassOrInterfaceDeclaration) ad, (ASTClassOrInterfaceDeclaration) bd);
          } else if (ad == null && bd == null) {
            // a match between semicolons.
            dubaj.tr.Ace.log("matched 'semicolon declarations'");
          } else {
            dubaj.tr.Ace.reverse("WTF? aDecl: " + ad.getClass());
          }
        }
      }

      // dte.close();

      addDeclarations(aDecls, aSeen, bNode, false);
      addDeclarations(bDecls, bSeen, aNode, true);
    }
  }
Exemplo n.º 3
0
  protected void addDeclaration(SimpleNode decl, SimpleNode other, boolean added) {
    dubaj.tr.Ace.log("decl: " + decl);

    if (decl instanceof ASTClassOrInterfaceBodyDeclaration) {
      decl = TypeDeclarationUtil.getDeclaration((ASTClassOrInterfaceBodyDeclaration) decl);
    }

    if (decl instanceof ASTMethodDeclaration) {
      ASTMethodDeclaration method = (ASTMethodDeclaration) decl;
      String fullName = MethodUtil.getFullName(method);
      addDeclaration(
          added,
          METHOD_ADDED,
          METHOD_REMOVED,
          fullName,
          other,
          method,
          Relatorio.TipoDeclaracao.Metodo);
      if (added) {
        Relatorio.getMudancaClasse().incrementarMudancasMetodo(new MudancaMetodoAdicao(method));
      } else {
        Relatorio.getMudancaClasse().incrementarMudancasMetodo(new MudancaMetodoRemocao(method));
      }

    } else if (decl instanceof ASTFieldDeclaration) {
      ASTFieldDeclaration field = (ASTFieldDeclaration) decl;
      String names = FieldUtil.getNames(field);
      addDeclaration(
          added,
          FIELD_ADDED,
          FIELD_REMOVED,
          names,
          other,
          field,
          Relatorio.TipoDeclaracao.Atributo);

      if (added) {
        Relatorio.getMudancaClasse().incrementarMudancasAtributo();
      } else {
        Relatorio.getMudancaClasse().incrementarMudancasAtributo();
      }

    } else if (decl instanceof ASTConstructorDeclaration) {
      ASTConstructorDeclaration ctor = (ASTConstructorDeclaration) decl;
      String fullName = CtorUtil.getFullName(ctor);
      addDeclaration(
          added,
          CONSTRUCTOR_ADDED,
          CONSTRUCTOR_REMOVED,
          fullName,
          other,
          ctor,
          Relatorio.TipoDeclaracao.Construtor);
    } else if (decl instanceof ASTClassOrInterfaceDeclaration) {
      ASTClassOrInterfaceDeclaration coid = (ASTClassOrInterfaceDeclaration) decl;
      String name = ClassUtil.getName(coid).image;
      String addMsg = null;
      String remMsg = null;
      if (coid.isInterface()) {
        addMsg = INNER_INTERFACE_ADDED;
        remMsg = INNER_INTERFACE_REMOVED;
      } else {
        addMsg = INNER_CLASS_ADDED;
        remMsg = INNER_CLASS_REMOVED;
      }
      addDeclaration(
          added, addMsg, remMsg, name, other, coid, Relatorio.TipoDeclaracao.DeclaracaoClasse);
    } else if (decl == null) {
      // nothing.
    } else {
      dubaj.tr.Ace.stack(dubaj.tr.Ace.REVERSE, "WTF? decl: " + decl);
    }
  }