Here you can find the source of getConstructorSignature(final Constructor constructor)
Parameter | Description |
---|---|
constructor | a parameter |
public static String getConstructorSignature(final Constructor constructor)
//package com.java2s; /************************************************************************************** * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. * * http://aspectwerkz.codehaus.org * * ---------------------------------------------------------------------------------- * * The software in this package is published under the terms of the LGPL license * * a copy of which has been included with this distribution in the license.txt file. * **************************************************************************************/ import java.lang.reflect.Constructor; import java.lang.reflect.Method; public class Main { /**/* ww w. j a va 2 s . com*/ * Returns JVM type signature for a constructor. * * @param constructor * @return */ public static String getConstructorSignature(final Constructor constructor) { return getMethodSignature(constructor.getParameterTypes(), Void.TYPE); } /** * Returns JVM type signature for a method. * * @param method * @return */ public static String getMethodSignature(final Method method) { return getMethodSignature(method.getParameterTypes(), method.getReturnType()); } /** * Returns JVM type signature for given list of parameters and return type. * * @param paramTypes * @param retType * @return */ private static String getMethodSignature(Class[] paramTypes, Class retType) { StringBuffer sbuf = new StringBuffer(); sbuf.append('('); for (int i = 0; i < paramTypes.length; i++) { sbuf.append(getClassSignature(paramTypes[i])); } sbuf.append(')'); sbuf.append(getClassSignature(retType)); return sbuf.toString(); } /** * Returns JVM type signature for given class. * * @param cl * @return */ public static String getClassSignature(Class cl) { StringBuffer sbuf = new StringBuffer(); while (cl.isArray()) { sbuf.append('['); cl = cl.getComponentType(); } if (cl.isPrimitive()) { if (cl == Integer.TYPE) { sbuf.append('I'); } else if (cl == Byte.TYPE) { sbuf.append('B'); } else if (cl == Long.TYPE) { sbuf.append('J'); } else if (cl == Float.TYPE) { sbuf.append('F'); } else if (cl == Double.TYPE) { sbuf.append('D'); } else if (cl == Short.TYPE) { sbuf.append('S'); } else if (cl == Character.TYPE) { sbuf.append('C'); } else if (cl == Boolean.TYPE) { sbuf.append('Z'); } else if (cl == Void.TYPE) { sbuf.append('V'); } else { throw new InternalError(); } } else { sbuf.append('L' + cl.getName().replace('.', '/') + ';'); } return sbuf.toString(); } }