QuickReviewEngine.java


Package: org.hammurapi

Results
Date2007/07/27
Codebase2224
Reviews4109
DPMO472
Sigma4.807

Metrics
NameNumberMinAvgMaxTotal
Class complexity130.0030.0030.0030.00
Code length151.0013.0077.00195.00
File length1213.00213.00213.00213.00
Operation complexity151.003.3318.0050.00
Work order119.7119.7119.7119.71

Violations
#LineColumnNameSeverityDescription
1231ER-0233Packages should begin with []
258141ER-0363Line is too long
36890ER-0363Line is too long
47192ER-0363Line is too long
57381ER-0363Line is too long
674107ER-0363Line is too long
777167ER-0363Line is too long
88587ER-0363Line is too long
99181ER-0363Line is too long
1094105ER-0363Line is too long
119587ER-0363Line is too long
1210190ER-0363Line is too long
1310595ER-0363Line is too long
1410687ER-0363Line is too long
1511290ER-0363Line is too long
1612197ER-0363Line is too long
17137130ER-0363Line is too long
1813892ER-0363Line is too long
19139105ER-0363Line is too long
2014080ER-0363Line is too long
2114491ER-0363Line is too long
22151100ER-0363Line is too long
2315281ER-0363Line is too long
2415383ER-0363Line is too long
25157106ER-0363Line is too long
2616089ER-0363Line is too long
2716180ER-0363Line is too long
2816295ER-0363Line is too long
2917092ER-0363Line is too long
3017892ER-0363Line is too long
3118381ER-0363Line is too long
3218581ER-0363Line is too long
33187101ER-0363Line is too long
3419181ER-0363Line is too long
35192100ER-0363Line is too long
3619596ER-0363Line is too long
37471ER-0492Unify logging strategy - define individual logger for class
386441ER-0823Avoid using method parameter names that conflict with class member names
396225ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
406842ER-0303Avoid hardwired string literals
417366ER-0303Avoid hardwired string literals
4277145ER-0303Avoid hardwired string literals
43919ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
441219ER-0111Cyclomatic complexity (18) exceeds 12
4512166ER-0823Avoid using method parameter names that conflict with class member names
461219ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
4713859ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
4815133ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
4915245ER-0303Avoid hardwired string literals
5015345ER-0303Avoid hardwired string literals
5115445ER-0303Avoid hardwired string literals
5215733ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
5315953ER-0303Avoid hardwired string literals
5416053ER-0303Avoid hardwired string literals
5516153ER-0303Avoid hardwired string literals
5616253ER-0303Avoid hardwired string literals
5716353ER-0303Avoid hardwired string literals
5816733ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
5916953ER-0303Avoid hardwired string literals
6017053ER-0303Avoid hardwired string literals
6117153ER-0303Avoid hardwired string literals
6217533ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
6317753ER-0303Avoid hardwired string literals
6417853ER-0303Avoid hardwired string literals
6517953ER-0303Avoid hardwired string literals
6618333ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
6718445ER-0303Avoid hardwired string literals
6818545ER-0303Avoid hardwired string literals
6918753ER-0303Avoid hardwired string literals
7019133ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
7119245ER-0303Avoid hardwired string literals
7219533ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
7319645ER-0303Avoid hardwired string literals
7419745ER-0303Avoid hardwired string literals
7519845ER-0303Avoid hardwired string literals
762049ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
772089ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc

JavaDoc
QuickReviewEngine

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.sql.SQLException;
27import java.util.Collection;
28
29import org.apache.tools.ant.BuildException;
30import org.apache.tools.ant.Project;
31import org.hammurapi.results.AggregatedResults;
32import org.hammurapi.results.ResultsFactory;
33
34import com.pavelvlasov.jsel.CompilationUnit;
35import com.pavelvlasov.review.SourceMarker;
36import com.pavelvlasov.util.DispatchingVisitor;
37import com.pavelvlasov.util.OrderedTarget;
38import com.pavelvlasov.util.VisitorExceptionSink;
39import com.pavelvlasov.util.VisitorStack;
40import com.pavelvlasov.util.VisitorStackSource;
41
42/**
43 * Pool of review threads. Delegates review work to threads.
44 * @author Pavel Vlasov
45 * @version $Revision: 1.3 $
46 */

47public class QuickReviewEngine implements VisitorStackSource {
48 private DispatchingVisitor visitor;
49 private QuickResultsCollector collector;
50 private QuickHammurapiTask task;
51
52 /**
53 * @param task
54 * @param rules
55 * @param poolSize If > 1 then multithreaded processing will be used.
56 * @throws SQLException
57 */

58 public QuickReviewEngine(Collection inspectors, final QuickHammurapiTask task, QuickResultsCollector collector) throws SQLException {
59 super();
60 VisitorExceptionSink esink=new VisitorExceptionSink() {
61
62 public void consume(
63 final DispatchingVisitor dispatcher,
64 final Object visitor,
65 final Method method,
66 final Object visitee,
67 final Exception e) {
68 task.log("WARN: Exception in "+visitee, Project.MSG_WARN);
69 e.printStackTrace();
70
71 AggregatedResults results=ResultsFactory.getThreadResults();
72 if (task.failOnFirstException) {
73 throw new BuildException("Cause: "+e, e);
74 } else if (results==null || e instanceof HammurapiNonConsumableException) {
75 task.setHadExceptions();
76 } else {
77 results.addWarning(new SimpleViolation(visitee instanceof SourceMarker ? (SourceMarker) visitee : null, "Exception "+e, null));
78 }
79
80 if (task.evictBadInspectors) {
81 dispatcher.remove(visitor);
82 }
83 }
84 };
85 visitor = new DispatchingVisitor(inspectors, esink, getListener(task));
86 this.collector=collector;
87 collector.getEngine().init();
88 this.task=task;
89 }
90
91 public void review(CompilationUnit compilationUnit) throws SQLException {
92 if (!task.force) {
93 if (task.forceOnWarnings) {
94 Integer id = collector.getEngine().getResultByNameSizeChecksumNoWarnings(
95 compilationUnit.getPackage().getName(),
96 compilationUnit.getName(),
97 compilationUnit.getSize(),
98 compilationUnit.getCheckSum());
99
100 if (id!=null) {
101 collector.getEngine().setUntouched(id.intValue());
102 return;
103 }
104 } else {
105 Integer id = collector.getEngine().getResultByNameSizeChecksum(
106 compilationUnit.getPackage().getName(),
107 compilationUnit.getName(),
108 compilationUnit.getSize(),
109 compilationUnit.getCheckSum());
110
111 if (id!=null) {
112 collector.getEngine().setUntouched(id.intValue());
113 return;
114 }
115 }
116 }
117
118 compilationUnit.accept(visitor);
119 }
120
121 protected static DispatchingVisitor.Listener getListener(final QuickHammurapiTask task) {
122 if (task.getDebugType()==null) {
123 return null;
124 } else {
125 return new DispatchingVisitor.Listener() {
126 private boolean isEnabled=true;
127 private Class type;
128
129 private void log(String message) {
130 task.log(message, Project.MSG_INFO);
131 }
132
133 boolean isListeningFor(Object o) {
134 if (isEnabled) {
135 if (type==null) {
136 try {
137 type=o.getClass().getClassLoader().loadClass(task.getDebugType());
138 } catch (ClassNotFoundException e) {
139 task.log(e.toString(), Project.MSG_WARN);
140 isEnabled=false;
141 return false;
142 }
143 }
144 return type.isAssignableFrom(o.getClass());
145
146 } else {
147 return false;
148 }
149 }
150
151 public void onInvocationRegistration(Object target, Method method) {
152 log("\tDispatch invocaton registration");
153 log("\t\tTarget type: "+target.getClass());
154 log("\t\tTarget method: "+method);
155 }
156
157 public void onInvocation(Object target, Method method, Object visitable) {
158 if (isListeningFor(visitable)) {
159 log("Dispatch invocation");
160 log("\tTarget type: "+target.getClass());
161 log("\tTarget method: "+method);
162 log("\tVisitable type: "+visitable.getClass());
163 log("\tVisitable: "+visitable);
164 }
165 }
166
167 public void onVisit(Object target) {
168 if (isListeningFor(target)) {
169 log("Dispatch visit");
170 log("\tVisitable type: "+target.getClass());
171 log("\tVisitable: "+target);
172 }
173 }
174
175 public void onLeave(Object target) {
176 if (isListeningFor(target)) {
177 log("Dispatch leave");
178 log("\tVisitable type: "+target.getClass());
179 log("\tVisitable: "+target);
180 }
181 }
182
183 public void onTargetRegistration(Object target) {
184 log("Dispatch type registration");
185 log("\tTarget type: "+target.getClass());
186 if (target instanceof OrderedTarget) {
187 log("\tOrder: "+((OrderedTarget) target).getOrder());
188 }
189 }
190
191 public void noInvocationsWarning(Object target) {
192 log("WARNING: No invocations for type: "+target.getClass());
193 }
194
195 public void onFilterRegistration(Method filter, Method target) {
196 log("\tFilter registration");
197 log("\t\tFilter method: "+filter);
198 log("\t\tTarget method: "+target);
199 }
200 };
201 }
202 }
203
204 public VisitorStack getVisitorStack() {
205 return visitor.getVisitorStack();
206 }
207
208 public DispatchingVisitor getVisitor() {
209 return visitor;
210 }
211
212}
213
214

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