KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > reflect > instruction > FieldAccess


1 /*
2  * Copyright(C) 2001 Mika Riekkinen, Joni Suominen
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or(at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package alt.jiapi.reflect.instruction;
20
21 import alt.jiapi.file.ConstantPool;
22 import alt.jiapi.reflect.SignatureUtil;
23
24 /**
25  * This class represents a field access instruction.
26  *
27  * @author Mika Riekkinen
28  * @author Joni Suominen
29  * @version $Revision: 1.9 $ $Date: 2004/04/04 09:59:22 $
30  */

31 public class FieldAccess extends ReferencingInstruction {
32     public static final int READ_INSTRUCTION = 1;
33     public static final int WRITE_INSTRUCTION = 2;
34
35     public FieldAccess(byte[] bytes, ConstantPool cp) {
36         super(bytes, cp);
37     }
38
39     /**
40      * Get the type name of the target field.
41      */

42     public String JavaDoc getTypeName() {
43         String JavaDoc desc = getDescriptor();
44         
45         return SignatureUtil.toSimpleName(desc);
46     }
47
48     /**
49      * Get the name of the target method.
50      */

51     public String JavaDoc getFieldName() {
52         return getName();
53     }
54
55     
56     public String JavaDoc toString() {
57         StringBuffer JavaDoc sb =
58             new StringBuffer JavaDoc(Opcodes.opcodeStrings[0xff & getOpcode()]);
59
60         byte[] bytes = getBytes();
61         for (int i = 1; i < bytes.length; i++) {
62             sb.append(" ");
63             sb.append(0xff & bytes[i]);
64         }
65
66         sb.append(" ; ");
67         sb.append(getClassName());
68         sb.append(".");
69         sb.append(getFieldName());
70
71         return sb.toString();
72     }
73 }
74
75
Popular Tags