KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > bcp > IfNull


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 2003,2004 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.ba.bcp;
21
22 import org.apache.bcel.generic.ConstantPoolGen;
23 import org.apache.bcel.generic.IFNONNULL;
24 import org.apache.bcel.generic.IFNULL;
25 import org.apache.bcel.generic.Instruction;
26 import org.apache.bcel.generic.InstructionHandle;
27
28 import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
29 import edu.umd.cs.findbugs.ba.Edge;
30 import edu.umd.cs.findbugs.ba.EdgeTypes;
31 import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
32
33 public class IfNull extends OneVariableInstruction implements EdgeTypes {
34
35     public IfNull(String JavaDoc varName) {
36         super(varName);
37     }
38
39     @Override JavaDoc
40          public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg,
41                              ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException {
42
43         // Instruction must be IFNULL or IFNONNULL.
44
Instruction ins = handle.getInstruction();
45         if (!(ins instanceof IFNULL || ins instanceof IFNONNULL))
46             return null;
47
48         // Ensure reference used is consistent with previous uses of
49
// same variable.
50
LocalVariable ref = new LocalVariable(before.getTopValue());
51         return addOrCheckDefinition(ref, bindingSet);
52     }
53
54     @Override JavaDoc
55          public boolean acceptBranch(Edge edge, InstructionHandle source) {
56         boolean isIfNull = (source.getInstruction() instanceof IFNULL);
57         return edge.getType() == (isIfNull ? IFCMP_EDGE : FALL_THROUGH_EDGE);
58     }
59 }
60
61 // vim:ts=4
62
Popular Tags