KickJava   Java API By Example, From Geeks To Geeks.

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


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.FieldInstruction;
24 import org.apache.bcel.generic.GETFIELD;
25 import org.apache.bcel.generic.GETSTATIC;
26 import org.apache.bcel.generic.Instruction;
27 import org.apache.bcel.generic.InstructionHandle;
28
29 import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
30 import edu.umd.cs.findbugs.ba.vna.ValueNumber;
31 import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
32
33 /**
34  * A PatternElement representing a load from a field.
35  * Variables represent the field and the result of the load.
36  *
37  * @author David Hovemeyer
38  * @see PatternElement
39  */

40 public class Load extends FieldAccess {
41
42     /**
43      * Constructor.
44      *
45      * @param fieldVarName the name of the field variable
46      * @param resultVarName the name of the result variable
47      */

48     public Load(String JavaDoc fieldVarName, String JavaDoc resultVarName) {
49         super(fieldVarName, resultVarName);
50     }
51
52     @Override JavaDoc
53          public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg,
54                              ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException {
55
56         Variable field;
57         Instruction ins = handle.getInstruction();
58         FieldInstruction fieldIns;
59
60         // The instruction must be GETFIELD or GETSTATIC
61
if (ins instanceof GETFIELD) {
62             fieldIns = (GETFIELD) ins;
63             ValueNumber ref = before.getTopValue();
64             field = new FieldVariable(ref, fieldIns.getClassName(cpg), fieldIns.getFieldName(cpg), fieldIns.getSignature(cpg));
65         } else if (ins instanceof GETSTATIC) {
66             fieldIns = (GETSTATIC) ins;
67             field = new FieldVariable(fieldIns.getClassName(cpg), fieldIns.getFieldName(cpg), fieldIns.getSignature(cpg));
68         } else
69             return null;
70
71         Variable result = snarfFieldValue(fieldIns, cpg, after);
72
73         return checkConsistent(field, result, bindingSet);
74     }
75 }
76
77 // vim:ts=4
78
Popular Tags