001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developer of the Original Code is Andrei Popovici.
017: // The code has been extended by Angela Nicoara.
018: // Portions created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
019: // All Rights Reserved.
020: //
021: // Contributor(s):
022: // $Id: JNIUtil.java,v 1.1.1.1 2003/07/02 15:30:50 apopovic Exp $
023: // =====================================================================
024: //
025: // (history at end)
026: //
027:
028: package ch.ethz.inf.iks.jvmai.jvmdi;
029:
030: // used packages
031: import java.lang.reflect.*;
032:
033: /**
034: * Class JNIUtil provides some useful methods for working with JNI.
035: *
036: * @version $Revision: 1.1.1.1 $
037: * @author Andrei Popovici
038: */
039: public class JNIUtil {
040:
041: /** Return the JNI signature of the method <code>m</code> */
042: public static String jniSignature(Method m) {
043: Class[] params = m.getParameterTypes();
044: StringBuffer result = new StringBuffer();
045: result.append("(");
046: for (int i = 0; i < params.length; i++)
047: result.append(jniSignature(params[i]));
048: result.append(")" + jniSignature(m.getReturnType()));
049: return result.toString();
050:
051: }
052:
053: /** Return the JNI signature of the constructor <code>m</code> */
054: public static String jniSignature(Constructor m) {
055: Class[] params = m.getParameterTypes();
056: StringBuffer result = new StringBuffer();
057: result.append("(");
058: for (int i = 0; i < params.length; i++)
059: result.append(jniSignature(params[i]));
060: result.append(")V");
061: return result.toString();
062: }
063:
064: /** Return the JNI signature of the class <code>c</code> */
065: public static String jniSignature(Class c) {
066: if (c.isPrimitive()) {
067: String result = null;
068: if ((c.toString()).equals("int"))
069: result = "I";
070: if ((c.toString()).equals("byte"))
071: result = "B";
072: if ((c.toString()).equals("short"))
073: result = "S";
074: if ((c.toString()).equals("long"))
075: result = "J";
076: if ((c.toString()).equals("double"))
077: result = "D";
078: if ((c.toString()).equals("float"))
079: result = "F";
080: if ((c.toString()).equals("char"))
081: result = "C";
082: if ((c.toString()).equals("boolean"))
083: result = "Z";
084: if ((c.toString()).equals("void"))
085: result = "V";
086: return result;
087: } else if (c.isArray())
088: return "[" + jniSignature(c.getComponentType());
089: else
090: return "L" + (c.getName()).replace('.', '/') + ";";
091: }
092:
093: }
094:
095: //======================================================================
096: //
097: // $Log: JNIUtil.java,v $
098: // Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
099: // Imported from ETH Zurich
100: //
101: // Revision 1.4 2003/03/04 11:26:41 popovici
102: // Important refactorization step (march):
103: // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
104: // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
105: // structures
106: //
107: // Revision 1.3 2002/03/28 13:48:14 popovici
108: // Mozilla-ified
109: //
110: // Revision 1.2 2002/02/14 16:02:25 popovici
111: // Bug fixes, PROSEVM moved to boot
112: //
113: // Revision 1.1 2002/02/06 11:53:52 popovici
114: // Refactoring from prose classical to jvmai
115: //
116: // Revision 1.1 2001/11/27 12:44:41 popovici
117: // Initial Revision
118: //
119: // Revision 1.1.2.6 2001/11/21 11:56:30 popovici
120: //
121: // -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
122: // replaced with the iks.jvmdi package. References to this old
123: // functionality replaced throughout the code.
124: // -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
125: // part of their functionality moved to the ch.ethz.inf.runes.reflect
126: // abstract classes. New classes and functionality added to the
127: // ch.ethz.inf.runes.reflect package, partially to reflect the
128: // more stable features taken from the iks.runes packages, partially
129: // to reflect the structure of the VM (constant pool, etc). Functionality in
130: // ch.ethz.inf.runes.crosscut and the junit classes adapted to use the
131: // new form of the ch.ethz.inf.runes.reflect package
132: //
133: // Revision 1.1.2.5 2001/02/21 13:23:30 popovici
134: // methods 'executiveFieldSignature', 'executiveClassSignature', and 'executiveMethodSignature' added. They return non-fully qualified names
135: // of signatures. Their place might not be in this class. Where else?!
136: //
137: // Revision 1.1.2.4 2001/01/18 14:24:37 popovici
138: // SignatureTokenizer changed:constructor now accepts either bare signatures or singatures including the method name. The tokenizer and its methods are now public.
139: //
140: // Revision 1.1.2.3 2000/11/21 14:37:08 groos
141: // added method realField(Class c, long fieldID) which returns the corresponding Field object.
142: //
143: // Revision 1.1.2.2 2000/11/13 18:59:16 popovici
144: // severe bug in 'realMethods' fixed. The tokenization used to parse the
145: // singature using normal chars lieke 'L' or 'B' which could have beend
146: // in the name of normal classes. A SignatureTokenizer was added.
147: //
148: // Revision 1.1.2.1 2000/10/24 18:08:30 popovici
149: // Minor documentation fix.
150: //
151: // Revision 1.1 2000/10/16 11:48:24 popovici
152: // InitialRevision
153: //
|