private String[] getParamName(Method method) throws Exception {
    CtClass cc = pool.get(method.getDeclaringClass().getName());
    CtClass[] params = new CtClass[method.getParameterTypes().length];
    for(int i = 0; i < method.getParameterTypes().length; i++) {
        params[i] = pool.getCtClass(method.getParameterTypes()[i].getName());
    }
    CtMethod cm = cc.getDeclaredMethod(method.getName(), params);
    MethodInfo methodInfo = cm.getMethodInfo();
    CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
    LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
    String[] paramNames = new String[cm.getParameterTypes().length];
    int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
    for(int i = 0; i < attr.tableLength(); i++) {
        if(attr.index(i) >= pos && attr.index(i) < paramNames.length + pos) {
            paramNames[attr.index(i) - pos] = attr.variableName(i);
        }
    }
    return paramNames;
}
但此描述中第 0 个局部变量是指 slot 排号为 0,而不是位置为 0。
所以正确的做法就是遍历本地变量表,根据 slot 值确认是不是方法参数,体现在代码中的 API 就是 attr.index(i) 将会返回 slot。
原文:http://www.cnblogs.com/asfeixue/p/4278471.html