KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > backport175 > bytecode > SignatureHelper


1 /*******************************************************************************************
2  * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3  * http://backport175.codehaus.org *
4  * --------------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of Apache License Version 2.0 *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  *******************************************************************************************/

8 package com.tc.backport175.bytecode;
9
10 import com.tc.asm.Type;
11
12 import java.lang.reflect.Constructor JavaDoc;
13 import java.lang.reflect.Method JavaDoc;
14 import java.lang.reflect.Field JavaDoc;
15
16 /**
17  * Returns JVM type signature for a members and types.
18  *
19  * @author <a HREF="mailto:jboner@codehaus.org">Jonas Bonér</a>
20  */

21 public class SignatureHelper {
22     /**
23      * Returns JVM type signature for a constructor.
24      *
25      * @param constructor
26      * @return
27      */

28     public static String JavaDoc getConstructorSignature(final Constructor JavaDoc constructor) {
29         //TODO: raise issue in ASM for the Type API to accept Constructor
30
Class JavaDoc[] paramTypes = constructor.getParameterTypes();
31         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
32         buf.append('(');
33         for (int i = 0; i < paramTypes.length; i++) {
34             buf.append(Type.getDescriptor(paramTypes[i]));
35         }
36         buf.append(')');
37         buf.append(Type.VOID_TYPE.getDescriptor());
38         return buf.toString();
39     }
40
41     /**
42      * Returns JVM type signature for a method.
43      *
44      * @param method
45      * @return
46      */

47     public static String JavaDoc getMethodSignature(final Method JavaDoc method) {
48         return Type.getMethodDescriptor(method);
49     }
50
51     /**
52      * Returns JVM type signature for a field.
53      *
54      * @param field
55      * @return
56      */

57     public static String JavaDoc getFieldSignature(final Field JavaDoc field) {
58         return Type.getDescriptor(field.getType());
59     }
60
61     /**
62      * Returns JVM type signature for given class.
63      *
64      * @param klass
65      * @return
66      */

67     public static String JavaDoc getClassSignature(Class JavaDoc klass) {
68         return Type.getDescriptor(klass);
69     }
70
71 }
72
Popular Tags