KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on 27.02.2004
3  *
4  * To change the template for this generated file go to
5  * Window - Preferences - Java - Code Generation - Code and Comments
6  */

7 package org.hammurapi.inspectors;
8
9 import java.util.LinkedList JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.hammurapi.InspectorBase;
13 import org.hammurapi.HammurapiException;
14
15 import com.pavelvlasov.jsel.Constructor;
16 import com.pavelvlasov.jsel.statements.SuperConstructorCall;
17 import com.pavelvlasov.review.SourceMarker;
18 import com.pavelvlasov.util.AccumulatingVisitorExceptionSink;
19 import com.pavelvlasov.util.DispatchingVisitor;
20
21 /**
22  * @author Johannes
23  *
24  * To change the template for this generated type comment go to
25  * Window - Preferences - Java - Code Generation - Code and Comments
26  */

27 public class ConstructorWithoutSuperRule extends InspectorBase {
28     
29     public static class SuperSnooper {
30         List JavaDoc returns=new LinkedList JavaDoc();
31         
32         public void visit(SuperConstructorCall superCall) {
33             returns.add(superCall);
34         }
35     }
36     
37     public void visit(Constructor construct )throws HammurapiException { {
38         if (construct!=null) {
39             AccumulatingVisitorExceptionSink es=new AccumulatingVisitorExceptionSink();
40             SuperSnooper rs=new SuperSnooper();
41             construct.accept(new DispatchingVisitor(rs, es));
42             
43             if( rs.returns.isEmpty()) {
44                 context.reportViolation((SourceMarker)construct);
45             }
46             if (!es.getExceptions().isEmpty()) {
47             es.dump();
48                 throw new HammurapiException("There have been exceptions (see above)");
49             }
50         }
51     }
52     }
53     
54 }
55
Popular Tags