KickJava   Java API By Example, From Geeks To Geeks.

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


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.Method
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 JavaLangReflectMethodNative extends NativeMethodClass {
34     public JavaLangReflectMethodNative( 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("java.lang.Object invoke(java.lang.Object,java.lang.Object[])")){
49       java_lang_reflect_Method_invoke(method, thisVar, returnVar, params);
50       return;
51
52     } else {
53       defaultMethod(method, thisVar, returnVar, params);
54       return;
55
56     }
57   }
58   /****************** java.lang.reflect.Method *********************/
59   /**
60    * nvokes the underlying method represented by this Method object,
61    * on the specified object with the specified parameters.
62    * Individual parameters are automatically unwrapped to match
63    * primitive formal parameters, and both primitive and reference
64    * parameters are subject to widening conversions as necessary. The
65    * value returned by the underlying method is automatically wrapped
66    * in an object if it has a primitive type.
67    *
68    * Method invocation proceeds with the following steps, in order:
69    *
70    * If the underlying method is static, then the specified obj
71    * argument is ignored. It may be null.
72    *
73    * NOTE: @this is an variable pointing to method objects,
74    * @param0 points to receivers
75    *
76    * The possible target of this call is made by
77    * [thisVar] X [param0]
78    *
79    * Also the parameters are not distinguishable.
80    *
81    * public native java.lang.Object invoke(java.lang.Object,
82    * java.lang.Object[])
83    * throws java.lang.IllegalAccessException,
84    * java.lang.IllegalArgumentException,
85    * java.lang.reflect.InvocationTargetException
86    */

87   public
88     void java_lang_reflect_Method_invoke(SootMethod method,
89                      ReferenceVariable thisVar,
90                      ReferenceVariable returnVar,
91                      ReferenceVariable params[]){
92     throw new NativeMethodNotSupportedException(method);
93   }
94 }
95
Popular Tags