KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > detect > ConfusedInheritance


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2005 Dave Brosius <dbrosius@users.sourceforge.net>
4  * Copyright (C) 2005 University of Maryland
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package edu.umd.cs.findbugs.detect;
21
22 import org.apache.bcel.classfile.Field;
23 import org.apache.bcel.classfile.JavaClass;
24
25 import edu.umd.cs.findbugs.BugInstance;
26 import edu.umd.cs.findbugs.BugReporter;
27 import edu.umd.cs.findbugs.Detector;
28 import edu.umd.cs.findbugs.FieldAnnotation;
29 import edu.umd.cs.findbugs.StatelessDetector;
30 import edu.umd.cs.findbugs.ba.ClassContext;
31 import edu.umd.cs.findbugs.visitclass.PreorderVisitor;
32
33 public class ConfusedInheritance extends PreorderVisitor implements Detector {
34     
35     private BugReporter bugReporter;
36     private JavaClass cls;
37     
38     public ConfusedInheritance(BugReporter bugReporter) {
39         this.bugReporter = bugReporter;
40     }
41     
42
43     
44     public void visitClassContext(ClassContext classContext) {
45         cls = classContext.getJavaClass();
46         if (cls.isFinal()) {
47             cls.accept(this);
48         }
49     }
50     
51     @Override JavaDoc
52          public void visitField(Field obj) {
53         if (obj.isProtected()) {
54             bugReporter.reportBug(
55                 new BugInstance( this, "CI_CONFUSED_INHERITANCE", LOW_PRIORITY)
56                     .addClass(cls)
57                     .addField(
58                         new FieldAnnotation(cls.getClassName(), obj.getName(), obj.getSignature(), obj.isStatic())));
59         }
60     }
61     
62     public void report() {
63     }
64 }
65
Popular Tags