01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2003-2007 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.classfile.engine.bcel;
21:
22: import org.apache.bcel.generic.MethodGen;
23:
24: import edu.umd.cs.findbugs.ba.AssertionMethods;
25: import edu.umd.cs.findbugs.ba.CFG;
26: import edu.umd.cs.findbugs.ba.ClassContext;
27: import edu.umd.cs.findbugs.ba.DepthFirstSearch;
28: import edu.umd.cs.findbugs.ba.JavaClassAndMethod;
29: import edu.umd.cs.findbugs.ba.MethodUnprofitableException;
30: import edu.umd.cs.findbugs.ba.npe.IsNullValueAnalysis;
31: import edu.umd.cs.findbugs.ba.npe.IsNullValueDataflow;
32: import edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow;
33: import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
34: import edu.umd.cs.findbugs.classfile.IAnalysisCache;
35: import edu.umd.cs.findbugs.classfile.MethodDescriptor;
36:
37: /**
38: * Analysis engine to produce IsNullValueDataflow objects
39: * for an analyzed method.
40: *
41: * @author David Hovemeyer
42: */
43: public class IsNullValueDataflowFactory extends
44: AnalysisFactory<IsNullValueDataflow> {
45: /**
46: * Constructor.
47: */
48: public IsNullValueDataflowFactory() {
49: super ("null value analysis", IsNullValueDataflow.class);
50: }
51:
52: /* (non-Javadoc)
53: * @see edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs.classfile.IAnalysisCache, java.lang.Object)
54: */
55: public IsNullValueDataflow analyze(IAnalysisCache analysisCache,
56: MethodDescriptor descriptor)
57: throws CheckedAnalysisException {
58: MethodGen methodGen = getMethodGen(analysisCache, descriptor);
59: if (methodGen == null) {
60: throw new MethodUnprofitableException(descriptor);
61: }
62: CFG cfg = getCFG(analysisCache, descriptor);
63: ValueNumberDataflow vnaDataflow = getValueNumberDataflow(
64: analysisCache, descriptor);
65: DepthFirstSearch dfs = getDepthFirstSearch(analysisCache,
66: descriptor);
67: AssertionMethods assertionMethods = getAssertionMethods(
68: analysisCache, descriptor.getClassDescriptor());
69:
70: IsNullValueAnalysis invAnalysis = new IsNullValueAnalysis(
71: methodGen, cfg, vnaDataflow, dfs, assertionMethods);
72:
73: // Set return value and parameter databases
74:
75: invAnalysis.setClassAndMethod(new JavaClassAndMethod(
76: getJavaClass(analysisCache, descriptor
77: .getClassDescriptor()), getMethod(
78: analysisCache, descriptor)));
79:
80: IsNullValueDataflow invDataflow = new IsNullValueDataflow(cfg,
81: invAnalysis);
82: invDataflow.execute();
83: if (ClassContext.DUMP_DATAFLOW_ANALYSIS) {
84: invDataflow.dumpDataflow(invAnalysis);
85: }
86: return invDataflow;
87:
88: }
89: }
|