From 64f0200675470dc75a517938e65cff83b617073b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 16 Feb 2010 18:21:25 +0000 Subject: [PATCH] polishing --- ...erceptorDrivenBeanDefinitionDecorator.java | 9 ++-- ...lVariableTableParameterNameDiscoverer.java | 47 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/org.springframework.aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java b/org.springframework.aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java index 4db89eb52f..2b36d2ff31 100644 --- a/org.springframework.aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java +++ b/org.springframework.aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java @@ -65,7 +65,7 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement String existingBeanName = definitionHolder.getBeanName(); BeanDefinition existingDefinition = definitionHolder.getBeanDefinition(); - // delegate to subclass for interceptor def + // delegate to subclass for interceptor definition BeanDefinition interceptorDefinition = createInterceptorDefinition(node); // generate name and register the interceptor @@ -75,9 +75,9 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement BeanDefinitionHolder result = definitionHolder; if (!isProxyFactoryBeanDefinition(existingDefinition)) { - // create the proxy definitionHolder + // create the proxy definition RootBeanDefinition proxyDefinition = new RootBeanDefinition(); - // create proxy factory bean definitionHolder + // create proxy factory bean definition proxyDefinition.setBeanClass(ProxyFactoryBean.class); // set up property values @@ -88,8 +88,7 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement mpvs.add("target", existingDefinition); // create the interceptor names list - ManagedList interceptorList = new ManagedList(); - mpvs.add("interceptorNames", interceptorList); + mpvs.add("interceptorNames", new ManagedList()); result = new BeanDefinitionHolder(proxyDefinition, existingBeanName); } diff --git a/org.springframework.core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java b/org.springframework.core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java index 26da60811f..6f0a29e8a7 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java +++ b/org.springframework.core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.asm.ClassReader; import org.springframework.asm.Label; import org.springframework.asm.MethodVisitor; @@ -46,27 +47,29 @@ import org.springframework.util.ClassUtils; * as far as possible. * * @author Adrian Colyer - * @author Juergen Hoeller * @author Costin Leau + * @author Juergen Hoeller * @since 2.0 */ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer { private static Log logger = LogFactory.getLog(LocalVariableTableParameterNameDiscoverer.class); - // the cache uses a nested index (value is a map) to keep the top level cache relatively small in size - private final Map, Map> parameterNamesCache = new ConcurrentHashMap, Map>(); - // marker object for classes that do not have any debug info private static final Map NO_DEBUG_INFO_MAP = Collections.emptyMap(); + // the cache uses a nested index (value is a map) to keep the top level cache relatively small in size + private final Map, Map> parameterNamesCache = + new ConcurrentHashMap, Map>(); + + public String[] getParameterNames(Method method) { Class declaringClass = method.getDeclaringClass(); - Map map = parameterNamesCache.get(declaringClass); + Map map = this.parameterNamesCache.get(declaringClass); if (map == null) { // initialize cache map = inspectClass(declaringClass); - parameterNamesCache.put(declaringClass, map); + this.parameterNamesCache.put(declaringClass, map); } if (map != NO_DEBUG_INFO_MAP) { return map.get(method); @@ -77,11 +80,11 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD @SuppressWarnings("unchecked") public String[] getParameterNames(Constructor ctor) { Class declaringClass = ctor.getDeclaringClass(); - Map map = parameterNamesCache.get(declaringClass); + Map map = this.parameterNamesCache.get(declaringClass); if (map == null) { // initialize cache map = inspectClass(declaringClass); - parameterNamesCache.put(declaringClass, map); + this.parameterNamesCache.put(declaringClass, map); } if (map != NO_DEBUG_INFO_MAP) { return map.get(ctor); @@ -91,10 +94,8 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD } /** - * Inspects the target class. Exceptions will be logged and a maker map returned to indicate the lack of debug information. - * - * @param clazz - * @return + * Inspects the target class. Exceptions will be logged and a maker map returned + * to indicate the lack of debug information. */ private Map inspectClass(Class clazz) { InputStream is = clazz.getResourceAsStream(ClassUtils.getClassFileName(clazz)); @@ -105,40 +106,42 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD 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 map = new ConcurrentHashMap(); classReader.accept(new ParameterNameDiscoveringVisitor(clazz, map), false); return map; - } catch (IOException ex) { + } + 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); } - } finally { + } + finally { try { is.close(); - } catch (IOException ex) { + } + catch (IOException ex) { // ignore } } - return NO_DEBUG_INFO_MAP; } + /** * Helper class that inspects all methods (constructor included) and then * attempts to find the parameter names for that member. */ private static class ParameterNameDiscoveringVisitor extends EmptyVisitor { + private static final String STATIC_CLASS_INIT = ""; + private final Class clazz; private final Map memberMap; - private static final String STATIC_CLASS_INIT = ""; public ParameterNameDiscoveringVisitor(Class clazz, Map memberMap) { this.clazz = clazz; @@ -163,6 +166,7 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD } } + private static class LocalVariableTableVisitor extends EmptyVisitor { private static final String CONSTRUCTOR = ""; @@ -255,4 +259,5 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD return (aType == Type.LONG_TYPE || aType == Type.DOUBLE_TYPE); } } -} \ No newline at end of file + +}