Skip to content

Commit 85661c6

Browse files
committed
Java 5 code style
1 parent b0790bf commit 85661c6

File tree

49 files changed

+353
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+353
-477
lines changed

org.springframework.aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2008 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.aop.aspectj;
1818

19+
import java.lang.annotation.Annotation;
1920
import java.lang.reflect.Constructor;
2021
import java.lang.reflect.Method;
2122
import java.util.ArrayList;
@@ -30,7 +31,6 @@
3031
import org.aspectj.weaver.tools.PointcutPrimitive;
3132

3233
import org.springframework.core.ParameterNameDiscoverer;
33-
import org.springframework.util.ClassUtils;
3434
import org.springframework.util.StringUtils;
3535

3636
/**
@@ -118,8 +118,6 @@
118118
*/
119119
public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscoverer {
120120

121-
private static final String ANNOTATION_CLASS_NAME = "java.lang.annotation.Annotation";
122-
123121
private static final String THIS_JOIN_POINT = "thisJoinPoint";
124122
private static final String THIS_JOIN_POINT_STATIC_PART = "thisJoinPointStaticPart";
125123

@@ -133,10 +131,8 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
133131
private static final int STEP_REFERENCE_PCUT_BINDING = 7;
134132
private static final int STEP_FINISHED = 8;
135133

136-
private static final Set singleValuedAnnotationPcds = new HashSet();
137-
private static final Set nonReferencePointcutTokens = new HashSet();
138-
139-
private static Class annotationClass;
134+
private static final Set<String> singleValuedAnnotationPcds = new HashSet<String>();
135+
private static final Set<String> nonReferencePointcutTokens = new HashSet<String>();
140136

141137

142138
static {
@@ -157,15 +153,6 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
157153
nonReferencePointcutTokens.add("and");
158154
nonReferencePointcutTokens.add("or");
159155
nonReferencePointcutTokens.add("not");
160-
161-
try {
162-
annotationClass = ClassUtils.forName(ANNOTATION_CLASS_NAME,
163-
AspectJAdviceParameterNameDiscoverer.class.getClassLoader());
164-
}
165-
catch (ClassNotFoundException ex) {
166-
// Running on < JDK 1.5, this is OK...
167-
annotationClass = null;
168-
}
169156
}
170157

171158

@@ -192,8 +179,6 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
192179

193180
private int numberOfRemainingUnboundArguments;
194181

195-
private int algorithmicStep = STEP_JOIN_POINT_BINDING;
196-
197182

198183
/**
199184
* Create a new discoverer that attempts to discover parameter names
@@ -241,7 +226,6 @@ public String[] getParameterNames(Method method) {
241226
this.argumentTypes = method.getParameterTypes();
242227
this.numberOfRemainingUnboundArguments = this.argumentTypes.length;
243228
this.parameterNameBindings = new String[this.numberOfRemainingUnboundArguments];
244-
this.algorithmicStep = STEP_JOIN_POINT_BINDING;
245229

246230
int minimumNumberUnboundArgs = 0;
247231
if (this.returningName != null) {
@@ -256,8 +240,9 @@ public String[] getParameterNames(Method method) {
256240
}
257241

258242
try {
259-
while ((this.numberOfRemainingUnboundArguments > 0) && (this.algorithmicStep < STEP_FINISHED)) {
260-
switch (this.algorithmicStep++) {
243+
int algorithmicStep = STEP_JOIN_POINT_BINDING;
244+
while ((this.numberOfRemainingUnboundArguments > 0) && algorithmicStep < STEP_FINISHED) {
245+
switch (algorithmicStep++) {
261246
case STEP_JOIN_POINT_BINDING:
262247
if (!maybeBindThisJoinPoint()) {
263248
maybeBindThisJoinPointStaticPart();
@@ -282,7 +267,7 @@ public String[] getParameterNames(Method method) {
282267
maybeBindReferencePointcutParameter();
283268
break;
284269
default:
285-
throw new IllegalStateException("Unknown algorithmic step: " + (this.algorithmicStep - 1));
270+
throw new IllegalStateException("Unknown algorithmic step: " + (algorithmicStep - 1));
286271
}
287272
}
288273
}
@@ -429,7 +414,7 @@ private void maybeBindReturningVariable() {
429414
* <p>Some more support from AspectJ in doing this exercise would be nice... :)
430415
*/
431416
private void maybeBindAnnotationsFromPointcutExpression() {
432-
List varNames = new ArrayList();
417+
List<String> varNames = new ArrayList<String>();
433418
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
434419
for (int i = 0; i < tokens.length; i++) {
435420
String toMatch = tokens[i];
@@ -458,7 +443,7 @@ else if (tokens[i].startsWith("@args(") || tokens[i].equals("@args")) {
458443
/**
459444
* Match the given list of extracted variable names to argument slots.
460445
*/
461-
private void bindAnnotationsFromVarNames(List varNames) {
446+
private void bindAnnotationsFromVarNames(List<String> varNames) {
462447
if (!varNames.isEmpty()) {
463448
// we have work to do...
464449
int numAnnotationSlots = countNumberOfUnboundAnnotationArguments();
@@ -470,7 +455,7 @@ private void bindAnnotationsFromVarNames(List varNames) {
470455
else if (numAnnotationSlots == 1) {
471456
if (varNames.size() == 1) {
472457
// it's a match
473-
findAndBind(annotationClass, (String) varNames.get(0));
458+
findAndBind(Annotation.class, varNames.get(0));
474459
}
475460
else {
476461
// multiple candidate vars, but only one slot
@@ -495,8 +480,8 @@ private String maybeExtractVariableName(String candidateToken) {
495480
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
496481
Character.isLowerCase(candidateToken.charAt(0))) {
497482
char[] tokenChars = candidateToken.toCharArray();
498-
for (int i = 0; i < tokenChars.length; i++) {
499-
if (!Character.isJavaIdentifierPart(tokenChars[i])) {
483+
for (char tokenChar : tokenChars) {
484+
if (!Character.isJavaIdentifierPart(tokenChar)) {
500485
return null;
501486
}
502487
}
@@ -511,11 +496,10 @@ private String maybeExtractVariableName(String candidateToken) {
511496
* Given an args pointcut body (could be <code>args</code> or <code>at_args</code>),
512497
* add any candidate variable names to the given list.
513498
*/
514-
private void maybeExtractVariableNamesFromArgs(String argsSpec, List varNames) {
499+
private void maybeExtractVariableNamesFromArgs(String argsSpec, List<String> varNames) {
515500
if (argsSpec == null) {
516501
return;
517502
}
518-
519503
String[] tokens = StringUtils.tokenizeToStringArray(argsSpec, ",");
520504
for (int i = 0; i < tokens.length; i++) {
521505
tokens[i] = StringUtils.trimWhitespace(tokens[i]);
@@ -536,7 +520,7 @@ private void maybeBindThisOrTargetOrArgsFromPointcutExpression() {
536520
+ " unbound args at this(),target(),args() binding stage, with no way to determine between them");
537521
}
538522

539-
List varNames = new ArrayList();
523+
List<String> varNames = new ArrayList<String>();
540524
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
541525
for (int i = 0; i < tokens.length; i++) {
542526
if (tokens[i].equals("this") ||
@@ -553,12 +537,11 @@ private void maybeBindThisOrTargetOrArgsFromPointcutExpression() {
553537
else if (tokens[i].equals("args") || tokens[i].startsWith("args(")) {
554538
PointcutBody body = getPointcutBody(tokens, i);
555539
i += body.numTokensConsumed;
556-
List candidateVarNames = new ArrayList();
540+
List<String> candidateVarNames = new ArrayList<String>();
557541
maybeExtractVariableNamesFromArgs(body.text, candidateVarNames);
558542
// we may have found some var names that were bound in previous primitive args binding step,
559543
// filter them out...
560-
for (Iterator iter = candidateVarNames.iterator(); iter.hasNext();) {
561-
String varName = (String) iter.next();
544+
for (String varName : candidateVarNames) {
562545
if (!alreadyBound(varName)) {
563546
varNames.add(varName);
564547
}
@@ -574,7 +557,7 @@ else if (tokens[i].equals("args") || tokens[i].startsWith("args(")) {
574557
else if (varNames.size() == 1) {
575558
for (int j = 0; j < this.parameterNameBindings.length; j++) {
576559
if (isUnbound(j)) {
577-
bindParameterName(j, (String) varNames.get(0));
560+
bindParameterName(j, varNames.get(0));
578561
break;
579562
}
580563
}
@@ -588,7 +571,7 @@ private void maybeBindReferencePointcutParameter() {
588571
+ " unbound args at reference pointcut binding stage, with no way to determine between them");
589572
}
590573

591-
List varNames = new ArrayList();
574+
List<String> varNames = new ArrayList<String>();
592575
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
593576
for (int i = 0; i < tokens.length; i++) {
594577
String toMatch = tokens[i];
@@ -634,7 +617,7 @@ private void maybeBindReferencePointcutParameter() {
634617
else if (varNames.size() == 1) {
635618
for (int j = 0; j < this.parameterNameBindings.length; j++) {
636619
if (isUnbound(j)) {
637-
bindParameterName(j, (String) varNames.get(0));
620+
bindParameterName(j, varNames.get(0));
638621
break;
639622
}
640623
}
@@ -700,7 +683,7 @@ private void maybeBindPrimitiveArgsFromPointcutExpression() {
700683
}
701684
if (numUnboundPrimitives == 1) {
702685
// Look for arg variable and bind it if we find exactly one...
703-
List varNames = new ArrayList();
686+
List<String> varNames = new ArrayList<String>();
704687
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
705688
for (int i = 0; i < tokens.length; i++) {
706689
if (tokens[i].equals("args") || tokens[i].startsWith("args(")) {
@@ -751,14 +734,9 @@ private boolean isSubtypeOf(Class supertype, int argumentNumber) {
751734
}
752735

753736
private int countNumberOfUnboundAnnotationArguments() {
754-
if (annotationClass == null) {
755-
// We're running on a JDK < 1.5
756-
return 0;
757-
}
758-
759737
int count = 0;
760738
for (int i = 0; i < this.argumentTypes.length; i++) {
761-
if (isUnbound(i) && isSubtypeOf(annotationClass, i)) {
739+
if (isUnbound(i) && isSubtypeOf(Annotation.class, i)) {
762740
count++;
763741
}
764742
}

org.springframework.aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2008 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,15 +19,14 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
2223
import org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator;
2324
import org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator;
2425
import org.springframework.beans.factory.config.BeanDefinition;
2526
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
2627
import org.springframework.beans.factory.support.RootBeanDefinition;
27-
import org.springframework.core.JdkVersion;
2828
import org.springframework.core.Ordered;
2929
import org.springframework.util.Assert;
30-
import org.springframework.util.ClassUtils;
3130

3231
/**
3332
* Utility class for handling registration of AOP auto-proxy creators.
@@ -52,26 +51,18 @@ public abstract class AopConfigUtils {
5251
public static final String AUTO_PROXY_CREATOR_BEAN_NAME =
5352
"org.springframework.aop.config.internalAutoProxyCreator";
5453

55-
/**
56-
* The class name of the <code>AnnotationAwareAspectJAutoProxyCreator</code> class.
57-
* Only available with AspectJ and Java 5.
58-
*/
59-
private static final String ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME =
60-
"org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator";
61-
62-
6354
/**
6455
* Stores the auto proxy creator classes in escalation order.
6556
*/
66-
private static final List APC_PRIORITY_LIST = new ArrayList();
57+
private static final List<Class> APC_PRIORITY_LIST = new ArrayList<Class>();
6758

6859
/**
6960
* Setup the escalation list.
7061
*/
7162
static {
72-
APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class.getName());
73-
APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class.getName());
74-
APC_PRIORITY_LIST.add(ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME);
63+
APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class);
64+
APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class);
65+
APC_PRIORITY_LIST.add(AnnotationAwareAspectJAutoProxyCreator.class);
7566
}
7667

7768

@@ -96,8 +87,7 @@ public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessar
9687
}
9788

9889
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
99-
Class cls = getAspectJAnnotationAutoProxyCreatorClassIfPossible();
100-
return registerOrEscalateApcAsRequired(cls, registry, source);
90+
return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
10191
}
10292

10393
public static void forceAutoProxyCreatorToUseClassProxying(BeanDefinitionRegistry registry) {
@@ -114,7 +104,7 @@ private static BeanDefinition registerOrEscalateApcAsRequired(Class cls, BeanDef
114104
BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
115105
if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
116106
int currentPriority = findPriorityForClass(apcDefinition.getBeanClassName());
117-
int requiredPriority = findPriorityForClass(cls.getName());
107+
int requiredPriority = findPriorityForClass(cls);
118108
if (currentPriority < requiredPriority) {
119109
apcDefinition.setBeanClassName(cls.getName());
120110
}
@@ -123,32 +113,20 @@ private static BeanDefinition registerOrEscalateApcAsRequired(Class cls, BeanDef
123113
}
124114
RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
125115
beanDefinition.setSource(source);
126-
beanDefinition.getPropertyValues().addPropertyValue("order", new Integer(Ordered.HIGHEST_PRECEDENCE));
116+
beanDefinition.getPropertyValues().addPropertyValue("order", Ordered.HIGHEST_PRECEDENCE);
127117
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
128118
registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME, beanDefinition);
129119
return beanDefinition;
130120
}
131121

132-
private static Class getAspectJAnnotationAutoProxyCreatorClassIfPossible() {
133-
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
134-
throw new IllegalStateException(
135-
"AnnotationAwareAspectJAutoProxyCreator is only available on Java 1.5 and higher");
136-
}
137-
try {
138-
return ClassUtils.forName(
139-
ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME, AopConfigUtils.class.getClassLoader());
140-
}
141-
catch (Throwable ex) {
142-
throw new IllegalStateException("Unable to load Java 1.5 dependent class [" +
143-
ASPECTJ_ANNOTATION_AUTO_PROXY_CREATOR_CLASS_NAME + "]", ex);
144-
}
122+
private static int findPriorityForClass(Class clazz) {
123+
return APC_PRIORITY_LIST.indexOf(clazz);
145124
}
146125

147126
private static int findPriorityForClass(String className) {
148-
Assert.notNull(className, "Class name must not be null");
149127
for (int i = 0; i < APC_PRIORITY_LIST.size(); i++) {
150-
String str = (String) APC_PRIORITY_LIST.get(i);
151-
if (className.equals(str)) {
128+
Class clazz = APC_PRIORITY_LIST.get(i);
129+
if (clazz.getName().equals(className)) {
152130
return i;
153131
}
154132
}

0 commit comments

Comments
 (0)