/** * Inspects the target class. Exceptions will be logged and a maker map returned * to indicate the lack of debug information. */ private Map<Member, String[]> inspectClass(Class<?> clazz) { InputStream is = clazz.getResourceAsStream(ClassUtils.getClassFileName(clazz)); if (is == null) { // We couldn‘t load the class file, which is not fatal as it // simply means this method of discovering parameter names won‘t work. if (logger.isDebugEnabled()) { logger.debug("Cannot find ‘.class‘ file for class [" + clazz + "] - unable to determine constructors/methods parameter names"); } return NO_DEBUG_INFO_MAP; } try { ClassReader classReader = new ClassReader(is); Map<Member, String[]> map = new ConcurrentHashMap<Member, String[]>(32); classReader.accept(new ParameterNameDiscoveringVisitor(clazz, map), 0); return map; } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug("Exception thrown while reading ‘.class‘ file for class [" + clazz + "] - unable to determine constructors/methods parameter names", ex); } } catch (IllegalArgumentException ex) { if (logger.isDebugEnabled()) { logger.debug("ASM ClassReader failed to parse class file [" + clazz + "], probably due to a new Java class file version that isn‘t supported yet " + "- unable to determine constructors/methods parameter names", ex); } } finally { try { is.close(); } catch (IOException ex) { // ignore } } return NO_DEBUG_INFO_MAP; }
本文出自 “程序猿De香蕉” 博客,请务必保留此出处http://qiyubin.blog.51cto.com/3642349/1642064
用ASM吧,获取方法参数名称!参见SPRING源代码LocalVariableTableParameterNameDiscoverer
原文地址:http://qiyubin.blog.51cto.com/3642349/1642064