Example #1
0
  protected Map getExtImpMap(ASTClassOrInterfaceDeclaration coid, Class extImpClass) {
    Map map = new HashMap();
    SimpleNode list = SimpleNodeUtil.findChild(coid, extImpClass);

    if (list == null) {
      // tr.Ace.log("no list");
    } else {
      ASTClassOrInterfaceType[] types =
          (ASTClassOrInterfaceType[])
              SimpleNodeUtil.findChildren(list, ASTClassOrInterfaceType.class);

      for (int ti = 0; ti < types.length; ++ti) {
        ASTClassOrInterfaceType type = types[ti];
        String typeName = SimpleNodeUtil.toString(type);
        map.put(typeName, type);
      }
    }

    return map;
  }
Example #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);
    }
  }
Example #3
0
  protected void compareImpExt(
      ASTClassOrInterfaceDeclaration at,
      ASTClassOrInterfaceDeclaration bt,
      String addMsg,
      String chgMsg,
      String delMsg,
      Class extImpCls,
      Relatorio.TipoDeclaracao tipoElemento) {
    Map aMap = getExtImpMap(at, extImpCls);
    Map bMap = getExtImpMap(bt, extImpCls);

    /*
     * Compara as implementacoes de interface
     */

    // Nesse caso uma mudanca em 2 ou mais declaracoes de heranca iriam
    // contar
    // mais de uma vez, logo eu coloco um return para garantir que só será
    // contada uma vez

    // tr.Ace.log("aMap", aMap);
    // tr.Ace.log("bMap", bMap);

    // I don't like this special case, but it is better than two separate
    // "add" and "remove" messages.

    if (aMap.size() == 1 && bMap.size() == 1) {
      String aName = (String) aMap.keySet().iterator().next();
      String bName = (String) bMap.keySet().iterator().next();

      if (aName.equals(bName)) {
        // tr.Ace.log("no change");
      } else {
        ASTClassOrInterfaceType a = (ASTClassOrInterfaceType) aMap.get(aName);
        ASTClassOrInterfaceType b = (ASTClassOrInterfaceType) bMap.get(bName);

        addChanged(chgMsg, new Object[] {aName, bName}, a, b, tipoElemento);

        return;
      }
    } else {
      List typeNames = new ArrayList();
      typeNames.addAll(aMap.keySet());
      typeNames.addAll(bMap.keySet());

      dubaj.tr.Ace.log("typeNames", typeNames);

      Iterator tit = typeNames.iterator();
      while (tit.hasNext()) {
        String typeName = (String) tit.next();

        ASTClassOrInterfaceType aType = (ASTClassOrInterfaceType) aMap.get(typeName);
        ASTClassOrInterfaceType bType = (ASTClassOrInterfaceType) bMap.get(typeName);

        if (aType == null) {
          addChanged(addMsg, new Object[] {typeName}, at, bType, tipoElemento);

          return;
        } else if (bType == null) {
          addChanged(delMsg, new Object[] {typeName}, aType, bt, tipoElemento);

          return;

        } else {
          // tr.Ace.log("no change");
        }
      }
    }
  }