01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2006, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.asm;
21:
22: import org.objectweb.asm.tree.ClassNode;
23:
24: import edu.umd.cs.findbugs.BugReporter;
25: import edu.umd.cs.findbugs.Detector2;
26: import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
27: import edu.umd.cs.findbugs.classfile.ClassDescriptor;
28: import edu.umd.cs.findbugs.classfile.Global;
29:
30: /**
31: * Abstract base class to to reduce boilerplate needed for writing
32: * ASM-based Detectors implemented as ClassNode visitors
33: *
34: * @author pugh
35: */
36: abstract public class ClassNodeDetector extends ClassNode implements
37: Detector2 {
38:
39: protected final BugReporter bugReporter;
40:
41: /**
42: * Construct a ClassNodeDetector. The bugReporter
43: * is passed to the constructor and stored in a protected final field.
44: *
45: * @param bugReporter the BugReporter that bug should be reporter to.
46: */
47: public ClassNodeDetector(BugReporter bugReporter) {
48: this .bugReporter = bugReporter;
49: }
50:
51: public String getDetectorClassName() {
52: return this .getClass().getName();
53: }
54:
55: public void visitClass(ClassDescriptor classDescriptor)
56: throws CheckedAnalysisException {
57:
58: FBClassReader cr = Global.getAnalysisCache().getClassAnalysis(
59: FBClassReader.class, classDescriptor);
60: cr.accept(this , 0);
61: }
62:
63: public void finishPass() {
64: // do nothing
65: }
66:
67: }
|