KickJava   Java API By Example, From Geeks To Geeks.

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


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.Package
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 JavaLangPackageNative extends NativeMethodClass {
34     public JavaLangPackageNative( 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.String getSystemPackage0(java.lang.String)")) {
49       java_lang_Package_getSystemPackage0(method, thisVar, returnVar, params);
50       return;
51
52     } else if (subSignature.equals("java.lang.String[] getSystemPackages0()")){
53       java_lang_Package_getSystemPackages0(method, thisVar, returnVar, params);
54       return;
55
56     } else {
57       defaultMethod(method, thisVar, returnVar, params);
58       return;
59
60     }
61   }
62
63   /************************** java.lang.Package *************************/
64   /**
65    * This is an undocumented private native method, it returns the first
66    * (without caller) method's package.
67    *
68    * It should be formulated as a string constants.
69    * private static
70    * native java.lang.String getSystemPackage0(java.lang.String);
71    */

72   public
73     void java_lang_Package_getSystemPackage0(SootMethod method,
74                          ReferenceVariable thisVar,
75                          ReferenceVariable returnVar,
76                          ReferenceVariable params[]) {
77     helper.assignObjectTo(returnVar, Environment.v().getStringObject());
78   }
79
80   /**
81    * private static native java.lang.String getSystemPackages0()[];
82    */

83   public
84     void java_lang_Package_getSystemPackages0(SootMethod method,
85                           ReferenceVariable thisVar,
86                           ReferenceVariable returnVar,
87                           ReferenceVariable params[]) {
88     helper.assignObjectTo(returnVar, Environment.v().getLeastArrayObject());
89   }
90
91
92 }
93
Popular Tags