KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > PrioritizingInspector


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22  */

23 package org.hammurapi.inspectors;
24
25 import java.util.Collection JavaDoc;
26
27 import org.hammurapi.HammurapiException;
28 import org.hammurapi.InspectorBase;
29 import org.hammurapi.results.DetailedResults;
30 import org.hammurapi.results.ResultsFactory;
31
32 import com.pavelvlasov.jsel.CompilationUnit;
33 import com.pavelvlasov.jsel.JselException;
34 import com.pavelvlasov.jsel.TypeDefinition;
35 import com.pavelvlasov.review.SourceMarker;
36
37
38 /**
39  * ER-117
40  * Copyrights information should be present in each file.
41  * @author Pavel Vlasov
42  * @version $Revision: 1.9 $
43  */

44 public class PrioritizingInspector extends InspectorBase {
45     private int clients;
46     private boolean disabled;
47     
48     public void visit(CompilationUnit cu) {
49         clients=0;
50     }
51     
52     public void visit(TypeDefinition td) throws JselException {
53         if (!disabled) {
54             Collection JavaDoc cc = td.getClients();
55             if (cc==null) {
56                 // Invoked from Quickurappi.
57
disabled=true;
58             } else {
59                 clients+=cc.size();
60             }
61         }
62     }
63     
64     /**
65      * Reviews the compilation unit if it's file violates agaianst the rule.
66      * @param element the compilation unit to be reviewed.
67      * @throws HammurapiException
68      */

69     public void leave(CompilationUnit cu) throws HammurapiException {
70         if (!disabled) {
71             final SourceMarker sm=context.detach(cu);
72             final DetailedResults result = ResultsFactory.getThreadResults();
73             
74             ResultsFactory.getInstance().execute(new ResultsFactory.Task() {
75     
76                 public void execute() throws HammurapiException {
77                     result.addMetric(sm, "Work order", 100.0/((Math.log(clients+1)+1)*result.getViolationLevel()+1));
78                 }
79                 
80             });
81         }
82     }
83 }
84
Popular Tags