KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > classfile > engine > asm > ClassNodeAnalysisEngine


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.asm;
21
22 import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
23 import edu.umd.cs.findbugs.classfile.ClassDescriptor;
24 import edu.umd.cs.findbugs.classfile.IAnalysisCache;
25 import edu.umd.cs.findbugs.classfile.IClassAnalysisEngine;
26 import edu.umd.cs.findbugs.classfile.ICodeBaseEntry;
27 import edu.umd.cs.findbugs.classfile.InvalidClassFileFormatException;
28
29 import org.objectweb.asm.ClassReader;
30 import org.objectweb.asm.tree.ClassNode;
31
32 /**
33  * Analysis engine to produce the ClassNode (ASM tree format)
34  * for a class.
35  *
36  * @author David Hovemeyer
37  */

38 public class ClassNodeAnalysisEngine implements IClassAnalysisEngine {
39
40     /* (non-Javadoc)
41      * @see edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs.classfile.IAnalysisCache, java.lang.Object)
42      */

43     public Object JavaDoc analyze(IAnalysisCache analysisCache, ClassDescriptor descriptor) throws CheckedAnalysisException {
44         ClassReader classReader = analysisCache.getClassAnalysis(ClassReader.class, descriptor);
45         
46         ICodeBaseEntry entry = analysisCache.getClassPath().lookupResource(descriptor.toResourceName());
47
48         // One of the less-than-ideal features of ASM is that
49
// invalid classfile format is indicated by a
50
// random runtime exception rather than something
51
// indicative of the real problem.
52
try {
53             ClassNode cn = new ClassNode();
54             classReader.accept(cn, 0);
55             return cn;
56         } catch (RuntimeException JavaDoc e) {
57             throw new InvalidClassFileFormatException(descriptor, entry, e);
58         }
59     }
60
61     /* (non-Javadoc)
62      * @see edu.umd.cs.findbugs.classfile.IAnalysisEngine#registerWith(edu.umd.cs.findbugs.classfile.IAnalysisCache)
63      */

64     public void registerWith(IAnalysisCache analysisCache) {
65         analysisCache.registerClassAnalysisEngine(ClassNode.class, this);
66     }
67
68     /* (non-Javadoc)
69      * @see edu.umd.cs.findbugs.classfile.IAnalysisEngine#retainAnalysisResults()
70      */

71     public boolean retainAnalysisResults() {
72         // Perhaps we should retain these, like we do with JavaClass objects?
73
return false;
74     }
75 }
76
Popular Tags