KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > DetectorToDetector2Adapter


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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;
21
22 import edu.umd.cs.findbugs.ba.ClassContext;
23 import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
24 import edu.umd.cs.findbugs.classfile.ClassDescriptor;
25 import edu.umd.cs.findbugs.classfile.Global;
26 import edu.umd.cs.findbugs.classfile.IAnalysisCache;
27
28 /**
29  * An adapter allowing classes implementing the Detector interface
30  * to support the new Detector2 interface.
31  *
32  * @author David Hovemeyer
33  */

34 public class DetectorToDetector2Adapter implements Detector2 {
35     private Detector detector;
36
37     /**
38      * Constructor.
39      *
40      * @param detector the Detector we want to adapt
41      */

42     public DetectorToDetector2Adapter(Detector detector) {
43         this.detector = detector;
44     }
45
46     /* (non-Javadoc)
47      * @see edu.umd.cs.findbugs.Detector2#finishPass()
48      */

49     public void finishPass() {
50         detector.report();
51     }
52
53     /* (non-Javadoc)
54      * @see edu.umd.cs.findbugs.Detector2#visitClass(edu.umd.cs.findbugs.classfile.ClassDescriptor)
55      */

56     public void visitClass(ClassDescriptor classDescriptor)
57             throws CheckedAnalysisException {
58         
59         // Just get the ClassContext from the analysis cache
60
// and apply the detector to it.
61

62         IAnalysisCache analysisCache = Global.getAnalysisCache();
63         ClassContext classContext = analysisCache.getClassAnalysis(ClassContext.class, classDescriptor);
64         detector.visitClassContext(classContext);
65     }
66
67     /* (non-Javadoc)
68      * @see edu.umd.cs.findbugs.Detector2#getDetectorClassName()
69      */

70     public String JavaDoc getDetectorClassName() {
71         return detector.getClass().getName();
72     }
73 }
74
Popular Tags