public void testConverterMetricaParaMudancaClasse() { Metrica metrica = new Metrica(); metrica.setUrlProjetoAtual("teste1.java"); metrica.setMudancasClasse(1); metrica.setMudancasAtributos(2); metrica.setMudancasMetodos(3); metrica.setCodeChurn(4); Relatorio.setMudancaClasse(new SubVersion().converterMetricaParaMudancaClasse(metrica)); assertEquals(Relatorio.getMudancaClasse().getNomClasse(), metrica.getUrlProjetoAtual()); assertEquals( Relatorio.getMudancaClasse().calcularMudancasClasse(), metrica.getMudancasClasse()); assertEquals( Relatorio.getMudancaClasse().calcularMudancasMetodo(), metrica.getMudancasMetodos()); assertEquals( Relatorio.getMudancaClasse().calcularMudancasAtributo(), metrica.getMudancasAtributos()); assertEquals(Relatorio.getMudancaClasse().obterCodeChurn(), metrica.getCodeChurn()); }
protected void compareImplements( ASTClassOrInterfaceDeclaration at, ASTClassOrInterfaceDeclaration bt) { if (compararInterface( at, bt, IMPLEMENTED_TYPE_ADDED, IMPLEMENTED_TYPE_CHANGED, IMPLEMENTED_TYPE_REMOVED, ASTImplementsList.class, Relatorio.TipoDeclaracao.Interface)) { Relatorio.getMudancaClasse().incrementarMudancasClasse(); } }
protected void compareExtends( ASTClassOrInterfaceDeclaration at, ASTClassOrInterfaceDeclaration bt) { if (compararHeranca( at, bt, EXTENDED_TYPE_ADDED, EXTENDED_TYPE_CHANGED, EXTENDED_TYPE_REMOVED, ASTExtendsList.class, Relatorio.TipoDeclaracao.Heranca)) { Relatorio.getMudancaClasse().incrementarMudancasClasse(); } }
public void compare(ASTClassOrInterfaceDeclaration at, ASTClassOrInterfaceDeclaration bt) { // SimpleNodeUtil.dump(at, "a"); // SimpleNodeUtil.dump(bt, "b"); if (at.isInterface() == bt.isInterface()) { dubaj.tr.Ace.log("no change in types"); } else if (bt.isInterface()) { addChanged( TYPE_CHANGED_FROM_CLASS_TO_INTERFACE, null, at, bt, Relatorio.TipoDeclaracao.DeclaracaoClasse); } else { addChanged( TYPE_CHANGED_FROM_INTERFACE_TO_CLASS, null, at, bt, Relatorio.TipoDeclaracao.DeclaracaoClasse); } SimpleNode atParent = SimpleNodeUtil.getParent(at); SimpleNode btParent = SimpleNodeUtil.getParent(bt); if (compararAcessoMetodo(atParent, btParent, Relatorio.TipoDeclaracao.Classe)) { Relatorio.getMudancaClasse().incrementarMudancasClasse(); } if (compararModificadorMetodo( atParent, btParent, VALID_TYPE_MODIFIERS, Relatorio.TipoDeclaracao.Classe)) { Relatorio.getMudancaClasse().incrementarMudancasClasse(); } compareExtends(at, bt); compareImplements(at, bt); compareDeclarations(at, bt); }
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); } }
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); } }