KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > classfile > engine > ClassInfoAnalysisEngine


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.classfile.engine;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.DataInputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26
27 import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
28 import edu.umd.cs.findbugs.classfile.ClassDescriptor;
29 import edu.umd.cs.findbugs.classfile.ClassNameMismatchException;
30 import edu.umd.cs.findbugs.classfile.FieldDescriptor;
31 import edu.umd.cs.findbugs.classfile.IAnalysisCache;
32 import edu.umd.cs.findbugs.classfile.IClassAnalysisEngine;
33 import edu.umd.cs.findbugs.classfile.IClassConstants;
34 import edu.umd.cs.findbugs.classfile.ICodeBaseEntry;
35 import edu.umd.cs.findbugs.classfile.InvalidClassFileFormatException;
36 import edu.umd.cs.findbugs.classfile.analysis.ClassData;
37 import edu.umd.cs.findbugs.classfile.analysis.ClassInfo;
38
39 /**
40  * Analysis engine to produce the ClassInfo for a loaded class.
41  * We parse just enough information from the classfile to
42  * get the needed information.
43  *
44  * @author David Hovemeyer
45  */

46 public class ClassInfoAnalysisEngine implements IClassAnalysisEngine {
47
48     /* (non-Javadoc)
49      * @see edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs.classfile.IAnalysisCache, java.lang.Object)
50      */

51     public Object JavaDoc analyze(IAnalysisCache analysisCache,
52             ClassDescriptor descriptor) throws CheckedAnalysisException {
53         // Get InputStream reading from class data
54
ClassData classData = analysisCache.getClassAnalysis(ClassData.class, descriptor);
55         DataInputStream JavaDoc classDataIn =
56             new DataInputStream JavaDoc(new ByteArrayInputStream JavaDoc(classData.getData()));
57
58         // Read the class info
59
ClassParser parser = new ClassParser(classDataIn, descriptor, classData.getCodeBaseEntry());
60         ClassInfo classInfo = new ClassInfo();
61         parser.parse(classInfo);
62         
63         if (!classInfo.getClassDescriptor().equals(descriptor)) {
64             throw new ClassNameMismatchException(
65                     descriptor,
66                     classInfo.getClassDescriptor(),
67                     classData.getCodeBaseEntry());
68         }
69         return classInfo;
70     }
71
72     /* (non-Javadoc)
73      * @see edu.umd.cs.findbugs.classfile.IAnalysisEngine#registerWith(edu.umd.cs.findbugs.classfile.IAnalysisCache)
74      */

75     public void registerWith(IAnalysisCache analysisCache) {
76         analysisCache.registerClassAnalysisEngine(ClassInfo.class, this);
77     }
78
79     /* (non-Javadoc)
80      * @see edu.umd.cs.findbugs.classfile.IAnalysisEngine#retainAnalysisResults()
81      */

82     public boolean retainAnalysisResults() {
83         // ClassInfo can be recomputed easily.
84
// TODO: perhaps we should retain it - it's relatively small
85
return false;
86     }
87 }
88
Popular Tags