SimpleReviewEngine.java


Package: org.hammurapi

Results
Date2007/07/27
Codebase1878
Reviews3373
DPMO563
Sigma4.757

Metrics
NameNumberMinAvgMaxTotal
Class complexity127.0027.0027.0027.00
Code length151.0010.9378.00164.00
File length1172.00172.00172.00172.00
Operation complexity151.003.2018.0048.00
Work order123.7123.7123.7123.71

Violations
#LineColumnNameSeverityDescription
1231ER-0233Packages should begin with []
24984ER-0363Line is too long
352136ER-0363Line is too long
45390ER-0363Line is too long
55692ER-0363Line is too long
65881ER-0363Line is too long
759107ER-0363Line is too long
862167ER-0363Line is too long
968121ER-0363Line is too long
1069215ER-0363Line is too long
117487ER-0363Line is too long
128192ER-0363Line is too long
1398122ER-0363Line is too long
149984ER-0363Line is too long
1510097ER-0363Line is too long
1610583ER-0363Line is too long
1711292ER-0363Line is too long
1811898ER-0363Line is too long
1912181ER-0363Line is too long
2012387ER-0363Line is too long
2113184ER-0363Line is too long
2213984ER-0363Line is too long
2314893ER-0363Line is too long
2415392ER-0363Line is too long
2515688ER-0363Line is too long
26461ER-0492Unify logging strategy - define individual logger for class
27499ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
28499ER-1093It is good practice to call in any case super() in a constructor. (see also: UnnecessaryConstructorRule )
295276ER-0823Avoid using method parameter names that conflict with class member names
305225ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
315342ER-0303Avoid hardwired string literals
325866ER-0303Avoid hardwired string literals
3362145ER-0303Avoid hardwired string literals
3469182ER-1163Use StringBuffer for excessive String concatenation
3569180ER-1163Use StringBuffer for excessive String concatenation
3669170ER-1163Use StringBuffer for excessive String concatenation
3769153ER-0303Avoid hardwired string literals
3869171ER-0303Avoid hardwired string literals
3969183ER-0303Avoid hardwired string literals
40779ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
41819ER-0111Cyclomatic complexity (18) exceeds 12
42819ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
439951ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
4411225ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
4511337ER-0303Avoid hardwired string literals
4611437ER-0303Avoid hardwired string literals
4711537ER-0303Avoid hardwired string literals
4811825ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
4912045ER-0303Avoid hardwired string literals
5012145ER-0303Avoid hardwired string literals
5112245ER-0303Avoid hardwired string literals
5212345ER-0303Avoid hardwired string literals
5312445ER-0303Avoid hardwired string literals
5412825ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
5513045ER-0303Avoid hardwired string literals
5613145ER-0303Avoid hardwired string literals
5713245ER-0303Avoid hardwired string literals
5813625ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
5913845ER-0303Avoid hardwired string literals
6013945ER-0303Avoid hardwired string literals
6114045ER-0303Avoid hardwired string literals
6214425ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
6314537ER-0303Avoid hardwired string literals
6414637ER-0303Avoid hardwired string literals
6514845ER-0303Avoid hardwired string literals
6615225ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
6715337ER-0303Avoid hardwired string literals
6815625ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
6915737ER-0303Avoid hardwired string literals
7015837ER-0303Avoid hardwired string literals
7115937ER-0303Avoid hardwired string literals
721649ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
731689ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc

JavaDoc
SimpleReviewEngine

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 */

23package org.hammurapi;
24
25import java.lang.reflect.Method;
26import java.util.Collection;
27
28import org.apache.tools.ant.BuildException;
29import org.apache.tools.ant.Project;
30import org.hammurapi.results.AggregatedResults;
31import org.hammurapi.results.ResultsFactory;
32
33import com.pavelvlasov.jsel.Repository;
34import com.pavelvlasov.review.SourceMarker;
35import com.pavelvlasov.util.DispatchingVisitor;
36import com.pavelvlasov.util.OrderedTarget;
37import com.pavelvlasov.util.VisitorExceptionSink;
38import com.pavelvlasov.util.VisitorStack;
39import com.pavelvlasov.util.VisitorStackSource;
40
41/**
42 * Pool of review threads. Delegates review work to threads.
43 * @author Pavel Vlasov
44 * @version $Revision: 1.8 $
45 */

46public class SimpleReviewEngine implements VisitorStackSource {
47 private DispatchingVisitor visitor;
48
49 public SimpleReviewEngine(Collection inspectors, final HammurapiTask task) {
50 VisitorExceptionSink esink=new VisitorExceptionSink() {
51
52 public void consume(DispatchingVisitor dispatcher, Object visitor, Method method, Object visitee, Exception e) {
53 task.log("WARN: Exception in "+visitee, Project.MSG_WARN);
54 e.printStackTrace();
55
56 AggregatedResults results=ResultsFactory.getThreadResults();
57 if (task.failOnFirstException) {
58 throw new BuildException("Cause: "+e, e);
59 } else if (results==null || e instanceof HammurapiNonConsumableException) {
60 task.setHadExceptions();
61 } else {
62 results.addWarning(new SimpleViolation(visitee instanceof SourceMarker ? (SourceMarker) visitee : null, "Exception "+e, null));
63 }
64
65 if (task.evictBadInspectors) {
66 dispatcher.remove(visitor);
67 if (visitor instanceof Inspector) {
68 String name=((Inspector) visitor).getContext().getDescriptor().getName();
69 results.addWarning(new SimpleViolation(visitee instanceof SourceMarker ? (SourceMarker) visitee : null, "Inspector "+name+" threw "+e+" and has been disabled", null));
70 }
71 }
72 }
73 };
74 visitor = new DispatchingVisitor(inspectors, esink, getListener(task));
75 }
76
77 public void review(Repository repository) {
78 repository.accept(visitor);
79 }
80
81 protected static DispatchingVisitor.Listener getListener(final HammurapiTask task) {
82 if (task.getDebugType()==null) {
83 return null;
84 }
85
86 return new DispatchingVisitor.Listener() {
87 private boolean isEnabled=true;
88 private Class type;
89
90 private void log(String message) {
91 task.log(message, Project.MSG_INFO);
92 }
93
94 boolean isListeningFor(Object o) {
95 if (isEnabled) {
96 if (type==null) {
97 try {
98 type=o.getClass().getClassLoader().loadClass(task.getDebugType());
99 } catch (ClassNotFoundException e) {
100 task.log(e.toString(), Project.MSG_WARN);
101 isEnabled=false;
102 return false;
103 }
104 }
105 return type.isAssignableFrom(o.getClass());
106
107 }
108
109 return false;
110 }
111
112 public void onInvocationRegistration(Object target, Method method) {
113 log("\tDispatch invocaton registration");
114 log("\t\tTarget type: "+target.getClass());
115 log("\t\tTarget method: "+method);
116 }
117
118 public void onInvocation(Object target, Method method, Object visitable) {
119 if (isListeningFor(visitable)) {
120 log("Dispatch invocation");
121 log("\tTarget type: "+target.getClass());
122 log("\tTarget method: "+method);
123 log("\tVisitable type: "+visitable.getClass());
124 log("\tVisitable: "+visitable);
125 }
126 }
127
128 public void onVisit(Object target) {
129 if (isListeningFor(target)) {
130 log("Dispatch visit");
131 log("\tVisitable type: "+target.getClass());
132 log("\tVisitable: "+target);
133 }
134 }
135
136 public void onLeave(Object target) {
137 if (isListeningFor(target)) {
138 log("Dispatch leave");
139 log("\tVisitable type: "+target.getClass());
140 log("\tVisitable: "+target);
141 }
142 }
143
144 public void onTargetRegistration(Object target) {
145 log("Dispatch type registration");
146 log("\tTarget type: "+target.getClass());
147 if (target instanceof OrderedTarget) {
148 log("\tOrder: "+((OrderedTarget) target).getOrder());
149 }
150 }
151
152 public void noInvocationsWarning(Object target) {
153 log("WARNING: No invocations for type: "+target.getClass());
154 }
155
156 public void onFilterRegistration(Method filter, Method target) {
157 log("\tFilter registration");
158 log("\t\tFilter method: "+filter);
159 log("\t\tTarget method: "+target);
160 }
161 };
162 }
163
164 public VisitorStack getVisitorStack() {
165 return visitor.getVisitorStack();
166 }
167
168 public DispatchingVisitor getVisitor() {
169 return visitor;
170 }
171}
172
173

Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.