01: /*******************************************************************************************
02: * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
03: * http://backport175.codehaus.org *
04: * --------------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of Apache License Version 2.0 *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: *******************************************************************************************/package com.tc.backport175.bytecode;
08:
09: import com.tc.asm.Type;
10:
11: import java.lang.reflect.Constructor;
12: import java.lang.reflect.Method;
13: import java.lang.reflect.Field;
14:
15: /**
16: * Returns JVM type signature for a members and types.
17: *
18: * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér</a>
19: */
20: public class SignatureHelper {
21: /**
22: * Returns JVM type signature for a constructor.
23: *
24: * @param constructor
25: * @return
26: */
27: public static String getConstructorSignature(
28: final Constructor constructor) {
29: //TODO: raise issue in ASM for the Type API to accept Constructor
30: Class[] paramTypes = constructor.getParameterTypes();
31: StringBuffer buf = new StringBuffer();
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 getMethodSignature(final Method 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 getFieldSignature(final Field 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 getClassSignature(Class klass) {
68: return Type.getDescriptor(klass);
69: }
70:
71: }
|