KickJava   Java API By Example, From Geeks To Geeks.

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


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.Instruction;
25 import org.apache.bcel.generic.InstructionHandle;
26 import org.apache.bcel.generic.PUTFIELD;
27 import org.apache.bcel.generic.PUTSTATIC;
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 store to a field.
35  * Variables represent the field and the value stored.
36  *
37  * @author David Hovemeyer
38  * @see PatternElement
39  */

40 public class Store extends FieldAccess {
41     /**
42      * Constructor.
43      *
44      * @param fieldVarName the name of the field variable
45      * @param valueVarName the name of the variable representing the value stored
46      */

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