KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > pointer > nativemethods > JavaLangReflectFieldNative


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Feng Qian
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
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /**
21  * Simulates the native method side effects in class java.lang.reflect.Field
22  *
23  * @author Feng Qian
24  * @author <XXX>
25  */

26
27 package soot.jimple.toolkits.pointer.nativemethods;
28
29 import soot.*;
30 import soot.jimple.toolkits.pointer.representations.*;
31 import soot.jimple.toolkits.pointer.util.*;
32
33 public class JavaLangReflectFieldNative extends NativeMethodClass {
34     public JavaLangReflectFieldNative( NativeHelper helper ) { super(helper); }
35
36   /**
37    * Implements the abstract method simulateMethod.
38    * It distributes the request to the corresponding methods
39    * by signatures.
40    */

41   public void simulateMethod(SootMethod method,
42                  ReferenceVariable thisVar,
43                  ReferenceVariable returnVar,
44                  ReferenceVariable params[]){
45
46     String JavaDoc subSignature = method.getSubSignature();
47
48     if (subSignature.equals("void set(java.lang.Object,java.lang.Object)")){
49       java_lang_reflect_Field_set(method, thisVar, returnVar, params);
50       return;
51
52     } else if (subSignature.equals("java.lang.Object get(java.lang.Object)")){
53       java_lang_reflect_Field_get(method, thisVar, returnVar, params);
54       return;
55
56     } else {
57       defaultMethod(method, thisVar, returnVar, params);
58       return;
59
60     }
61   }
62
63   /*********************** java.lang.reflect.Field *********************/
64   /**
65    * NOTE: make all fields pointing to @param1
66    *
67    * public native void set(java.lang.Object, java.lang.Object)
68    * throws java.lang.IllegalArgumentException,
69    * java.lang.IllegalAccessException;
70    */

71   public
72     void java_lang_reflect_Field_set(SootMethod method,
73                      ReferenceVariable thisVar,
74                      ReferenceVariable returnVar,
75                      ReferenceVariable params[]){
76     /* Warn the user that reflection may not be handle correctly. */
77     throw new NativeMethodNotSupportedException(method);
78   }
79
80   /**
81    * Returns the value of the field represented by this Field, on the
82    * specified object. The value is automatically wrapped in an object
83    * if it has a primitive type.
84    *
85    * NOTE: this really needs precise info of @this (its name).
86    * conservative way, makes return value possibly point
87    * to universal objects.
88    *
89    * public native java.lang.Object get(java.lang.Object)
90    * throws java.lang.IllegalArgumentException,
91    * java.lang.IllegalAccessException;
92    */

93   public
94     void java_lang_reflect_Field_get(SootMethod method,
95                      ReferenceVariable thisVar,
96                      ReferenceVariable returnVar,
97                      ReferenceVariable params[]){
98     throw new NativeMethodNotSupportedException(method);
99   }
100   
101   /**
102    * All other native methods in this class has no side effects.
103    *
104    * public native boolean getBoolean(java.lang.Object)
105    * throws java.lang.IllegalArgumentException,
106    * java.lang.IllegalAccessException;
107    *
108    * public native byte getByte(java.lang.Object)
109    * throws java.lang.IllegalArgumentException,
110    * java.lang.IllegalAccessException;
111    *
112    * public native char getChar(java.lang.Object)
113    * throws java.lang.IllegalArgumentException,
114    * java.lang.IllegalAccessException;
115    *
116    * public native short getShort(java.lang.Object)
117    * throws java.lang.IllegalArgumentException,
118    * java.lang.IllegalAccessException;
119    *
120    * public native int getInt(java.lang.Object)
121    * throws java.lang.IllegalArgumentException,
122    * java.lang.IllegalAccessException;
123    *
124    * public native long getLong(java.lang.Object)
125    * throws java.lang.IllegalArgumentException,
126    * java.lang.IllegalAccessException;
127    *
128    * public native float getFloat(java.lang.Object)
129    * throws java.lang.IllegalArgumentException,
130    * java.lang.IllegalAccessException;
131    *
132    * public native double getDouble(java.lang.Object)
133    * throws java.lang.IllegalArgumentException,
134    * java.lang.IllegalAccessException;
135    *
136    * public native void setBoolean(java.lang.Object, boolean)
137    * throws java.lang.IllegalArgumentException,
138    * java.lang.IllegalAccessException;
139    *
140    * public native void setByte(java.lang.Object, byte)
141    * throws java.lang.IllegalArgumentException,
142    * java.lang.IllegalAccessException;
143    *
144    * public native void setChar(java.lang.Object, char)
145    * throws java.lang.IllegalArgumentException,
146    * java.lang.IllegalAccessException;
147    *
148    * public native void setShort(java.lang.Object, short)
149    * throws java.lang.IllegalArgumentException,
150    * java.lang.IllegalAccessException;
151    *
152    * public native void setInt(java.lang.Object, int)
153    * throws java.lang.IllegalArgumentException,
154    * java.lang.IllegalAccessException;
155    *
156    * public native void setLong(java.lang.Object, long)
157    * throws java.lang.IllegalArgumentException,
158    * java.lang.IllegalAccessException;
159    *
160    * public native void setFloat(java.lang.Object, float)
161    * throws java.lang.IllegalArgumentException,
162    * java.lang.IllegalAccessException;
163    *
164    * public native void setDouble(java.lang.Object, double)
165    * throws java.lang.IllegalArgumentException,
166    * java.lang.IllegalAccessException;
167    *
168    * @see default(...)
169    */

170 }
171
Popular Tags