KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > inf > iks > jvmai > jvmdi > JNIUtil


1 //
2
// This file is part of the prose package.
3
//
4
// The contents of this file are subject to the Mozilla Public License
5
// Version 1.1 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
// http://www.mozilla.org/MPL/
8
//
9
// Software distributed under the License is distributed on an "AS IS" basis,
10
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
// for the specific language governing rights and limitations under the
12
// License.
13
//
14
// The Original Code is prose.
15
//
16
// The Initial Developer of the Original Code is Andrei Popovici. Portions
17
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18
// All Rights Reserved.
19
//
20
// Contributor(s):
21
// $Id: JNIUtil.java,v 1.1.1.1 2003/07/02 15:30:50 apopovic Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.inf.iks.jvmai.jvmdi;
28
29 // used packages
30
import java.util.*;
31 import java.io.*;
32 import java.lang.reflect.*;
33
34
35 /**
36  * Class JNIUtil provides some useful methods for working with JNI.
37  *
38  * @version $Revision: 1.1.1.1 $
39  * @author Andrei Popovici
40  */

41 public
42 class JNIUtil {
43
44     /** Return the JNI signature of the method <code>m</code> */
45     public static String JavaDoc jniSignature(Method m)
46     {
47     Class JavaDoc[] params = m.getParameterTypes();
48     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
49     result.append("(");
50     for (int i = 0; i < params.length; i++)
51         result.append(jniSignature(params[i]));
52     result.append(")" + jniSignature(m.getReturnType()));
53     return result.toString();
54
55     }
56
57     /** Return the JNI signature of the class <code>c</code> */
58     public static String JavaDoc jniSignature(Class JavaDoc c)
59     {
60     if (c.isPrimitive())
61         {
62         String JavaDoc result = null;
63         if ((c.toString()).equals("int")) result = "I";
64         if ((c.toString()).equals("byte")) result = "B";
65         if ((c.toString()).equals("short")) result = "S";
66         if ((c.toString()).equals("long")) result = "J";
67             if ((c.toString()).equals("double")) result = "D";
68         if ((c.toString()).equals("float")) result = "F";
69         if ((c.toString()).equals("char")) result = "C";
70         if ((c.toString()).equals("boolean")) result = "Z";
71         if ((c.toString()).equals("void")) result = "V";
72         return result;
73         }
74     else if (c.isArray())
75         return "[" + jniSignature(c.getComponentType());
76     else
77         return "L" + (c.getName()).replace('.','/') + ";";
78     }
79
80
81
82 }
83
84
85
86
87 //======================================================================
88
//
89
// $Log: JNIUtil.java,v $
90
// Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
91
// Imported from ETH Zurich
92
//
93
// Revision 1.4 2003/03/04 11:26:41 popovici
94
// Important refactorization step (march):
95
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
96
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
97
// structures
98
//
99
// Revision 1.3 2002/03/28 13:48:14 popovici
100
// Mozilla-ified
101
//
102
// Revision 1.2 2002/02/14 16:02:25 popovici
103
// Bug fixes, PROSEVM moved to boot
104
//
105
// Revision 1.1 2002/02/06 11:53:52 popovici
106
// Refactoring from prose classical to jvmai
107
//
108
// Revision 1.1 2001/11/27 12:44:41 popovici
109
// Initial Revision
110
//
111
// Revision 1.1.2.6 2001/11/21 11:56:30 popovici
112
//
113
// -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
114
// replaced with the iks.jvmdi package. References to this old
115
// functionality replaced throughout the code.
116
// -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
117
// part of their functionality moved to the ch.ethz.inf.runes.reflect
118
// abstract classes. New classes and functionality added to the
119
// ch.ethz.inf.runes.reflect package, partially to reflect the
120
// more stable features taken from the iks.runes packages, partially
121
// to reflect the structure of the VM (constant pool, etc). Functionality in
122
// ch.ethz.inf.runes.crosscut and the junit classes adapted to use the
123
// new form of the ch.ethz.inf.runes.reflect package
124
//
125
// Revision 1.1.2.5 2001/02/21 13:23:30 popovici
126
// methods 'executiveFieldSignature', 'executiveClassSignature', and 'executiveMethodSignature' added. They return non-fully qualified names
127
// of signatures. Their place might not be in this class. Where else?!
128
//
129
// Revision 1.1.2.4 2001/01/18 14:24:37 popovici
130
// SignatureTokenizer changed:constructor now accepts either bare signatures or singatures including the method name. The tokenizer and its methods are now public.
131
//
132
// Revision 1.1.2.3 2000/11/21 14:37:08 groos
133
// added method realField(Class c, long fieldID) which returns the corresponding Field object.
134
//
135
// Revision 1.1.2.2 2000/11/13 18:59:16 popovici
136
// severe bug in 'realMethods' fixed. The tokenization used to parse the
137
// singature using normal chars lieke 'L' or 'B' which could have beend
138
// in the name of normal classes. A SignatureTokenizer was added.
139
//
140
// Revision 1.1.2.1 2000/10/24 18:08:30 popovici
141
// Minor documentation fix.
142
//
143
// Revision 1.1 2000/10/16 11:48:24 popovici
144
// InitialRevision
145
//
146
Popular Tags