From 12c4f8e7f9a11fea467a3f0d861beb77b9f5675f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 13 Dec 2012 00:07:36 +0100 Subject: [PATCH] Polishing --- ...nitDestroyAnnotationBeanPostProcessor.java | 6 +- .../springframework/core/MethodParameter.java | 72 +++++++++---------- .../core/MethodParameterTests.java | 5 +- .../support/ReflectivePropertyAccessor.java | 8 +-- .../multiaction/MultiActionController.java | 4 +- 5 files changed, 46 insertions(+), 49 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java index f584458f44..6fef569d8b 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -265,7 +265,7 @@ public class InitDestroyAnnotationBeanPostProcessor } public void checkConfigMembers(RootBeanDefinition beanDefinition) { - synchronized(this.initMethods) { + synchronized (this.initMethods) { for (Iterator it = this.initMethods.iterator(); it.hasNext();) { String methodIdentifier = it.next().getIdentifier(); if (!beanDefinition.isExternallyManagedInitMethod(methodIdentifier)) { @@ -276,7 +276,7 @@ public class InitDestroyAnnotationBeanPostProcessor } } } - synchronized(this.destroyMethods) { + synchronized (this.destroyMethods) { for (Iterator it = this.destroyMethods.iterator(); it.hasNext();) { String methodIdentifier = it.next().getIdentifier(); if (!beanDefinition.isExternallyManagedDestroyMethod(methodIdentifier)) { diff --git a/org.springframework.core/src/main/java/org/springframework/core/MethodParameter.java b/org.springframework.core/src/main/java/org/springframework/core/MethodParameter.java index 9c33cb2578..a9ace68956 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/MethodParameter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/MethodParameter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -269,7 +269,6 @@ public class MethodParameter { * @param annotationType the annotation type to look for * @return the annotation object, or null if not found */ - @SuppressWarnings("unchecked") public T getMethodAnnotation(Class annotationType) { return getAnnotatedElement().getAnnotation(annotationType); } @@ -311,14 +310,14 @@ public class MethodParameter { * Return true if the parameter has at least one annotation, false if it has none. */ public boolean hasParameterAnnotations() { - return getParameterAnnotations().length != 0; + return (getParameterAnnotations().length != 0); } /** * Return true if the parameter has the given annotation type, and false if it doesn't. */ public boolean hasParameterAnnotation(Class annotationType) { - return getParameterAnnotation(annotationType) != null; + return (getParameterAnnotation(annotationType) != null); } /** @@ -417,6 +416,38 @@ public class MethodParameter { return this.typeIndexesPerLevel; } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj != null && obj instanceof MethodParameter) { + MethodParameter other = (MethodParameter) obj; + + if (this.parameterIndex != other.parameterIndex) { + return false; + } + else if (this.getMember().equals(other.getMember())) { + return true; + } + else { + return false; + } + } + return false; + } + + @Override + public int hashCode() { + int result = this.hash; + if (result == 0) { + result = getMember().hashCode(); + result = 31 * result + this.parameterIndex; + this.hash = result; + } + return result; + } + /** * Create a new MethodParameter for the given method or constructor. @@ -439,37 +470,4 @@ public class MethodParameter { } } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj != null && obj instanceof MethodParameter) { - MethodParameter other = (MethodParameter) obj; - - if (this.parameterIndex != other.parameterIndex) { - return false; - } - else if (this.getMember().equals(other.getMember())) { - return true; - } - else { - return false; - } - } - return false; - } - - - @Override - public int hashCode() { - int result = this.hash; - if (result == 0) { - result = getMember().hashCode(); - result = 31 * result + this.parameterIndex; - this.hash = result; - } - return result; - } - } diff --git a/org.springframework.core/src/test/java/org/springframework/core/MethodParameterTests.java b/org.springframework.core/src/test/java/org/springframework/core/MethodParameterTests.java index 2f1ce99bfd..c3c3e7d139 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/MethodParameterTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/MethodParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -34,6 +34,7 @@ public class MethodParameterTests { private MethodParameter intReturnType; + @Before public void setUp() throws NoSuchMethodException { Method method = getClass().getMethod("method", String.class, Long.TYPE); @@ -42,8 +43,6 @@ public class MethodParameterTests { intReturnType = new MethodParameter(method, -1); } - - @Test public void testEquals() throws NoSuchMethodException { assertEquals(stringParameter, stringParameter); diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java index 7566b833a1..22eeb366e2 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java @@ -86,7 +86,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { Field field = findField(name, type, target); if (field != null) { TypeDescriptor typeDescriptor = new TypeDescriptor(field); - this.readerCache.put(cacheKey, new InvokerPair(field,typeDescriptor)); + this.readerCache.put(cacheKey, new InvokerPair(field, typeDescriptor)); this.typeDescriptorCache.put(cacheKey, typeDescriptor); return true; } @@ -264,15 +264,15 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { return TypeDescriptor.valueOf(Integer.TYPE); } CacheKey cacheKey = new CacheKey(type, name); - TypeDescriptor typeDescriptor = this.typeDescriptorCache.get(cacheKey); + TypeDescriptor typeDescriptor = this.typeDescriptorCache.get(cacheKey); if (typeDescriptor == null) { // attempt to populate the cache entry try { if (canRead(context, target, name)) { - typeDescriptor = this.typeDescriptorCache.get(cacheKey); + typeDescriptor = this.typeDescriptorCache.get(cacheKey); } else if (canWrite(context, target, name)) { - typeDescriptor = this.typeDescriptorCache.get(cacheKey); + typeDescriptor = this.typeDescriptorCache.get(cacheKey); } } catch (AccessException ex) { diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/multiaction/MultiActionController.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/multiaction/MultiActionController.java index 178f0fcf89..f88c921c91 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/multiaction/MultiActionController.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/multiaction/MultiActionController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2012 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. @@ -513,7 +513,7 @@ public class MultiActionController extends AbstractController implements LastMod * @throws Exception if the command object could not be instantiated * @see org.springframework.beans.BeanUtils#instantiateClass(Class) */ - protected Object newCommandObject(Class clazz) throws Exception { + protected Object newCommandObject(Class clazz) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Creating new command of class [" + clazz.getName() + "]"); }