aboutsummaryrefslogtreecommitdiffstats
path: root/loadtime
diff options
context:
space:
mode:
Diffstat (limited to 'loadtime')
-rw-r--r--loadtime/src/main/java/org/aspectj/weaver/loadtime/Aj.java6
-rw-r--r--loadtime/src/main/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java37
-rw-r--r--loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java191
-rw-r--r--loadtime/src/main/java/org/aspectj/weaver/loadtime/Options.java6
-rw-r--r--loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java4
5 files changed, 117 insertions, 127 deletions
diff --git a/loadtime/src/main/java/org/aspectj/weaver/loadtime/Aj.java b/loadtime/src/main/java/org/aspectj/weaver/loadtime/Aj.java
index 652ea0932..abd8ecc87 100644
--- a/loadtime/src/main/java/org/aspectj/weaver/loadtime/Aj.java
+++ b/loadtime/src/main/java/org/aspectj/weaver/loadtime/Aj.java
@@ -199,8 +199,7 @@ public class Aj implements ClassPreProcessor {
System.err.println("Weaver adaptors before queue processing:");
Map<AdaptorKey,ExplicitlyInitializedClassLoaderWeavingAdaptor> m = WeaverContainer.weavingAdaptors;
Set<AdaptorKey> keys = m.keySet();
- for (Iterator<AdaptorKey> iterator = keys.iterator(); iterator.hasNext();) {
- Object object = iterator.next();
+ for (Object object : keys) {
System.err.println(object + " = " + WeaverContainer.weavingAdaptors.get(object));
}
}
@@ -223,8 +222,7 @@ public class Aj implements ClassPreProcessor {
System.err.println("Weaver adaptors after queue processing:");
Map<AdaptorKey,ExplicitlyInitializedClassLoaderWeavingAdaptor> m = WeaverContainer.weavingAdaptors;
Set<AdaptorKey> keys = m.keySet();
- for (Iterator<AdaptorKey> iterator = keys.iterator(); iterator.hasNext();) {
- Object object = iterator.next();
+ for (Object object : keys) {
System.err.println(object + " = " + WeaverContainer.weavingAdaptors.get(object));
}
}
diff --git a/loadtime/src/main/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java b/loadtime/src/main/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
index 21f81720e..173310591 100644
--- a/loadtime/src/main/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
+++ b/loadtime/src/main/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
@@ -219,8 +219,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
*/
List<String> getAspectClassNames(List<Definition> definitions) {
List<String> aspects = new LinkedList<String>();
- for (Iterator<Definition> it = definitions.iterator(); it.hasNext(); ) {
- Definition def = it.next();
+ for (Definition def : definitions) {
List<String> defAspects = def.getAspectClassNames();
if (defAspects != null) {
aspects.addAll(defAspects);
@@ -598,9 +597,9 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
private void registerIncludeExclude(final BcelWeaver weaver, final ClassLoader loader, final List<Definition> definitions) {
String fastMatchInfo = null;
for (Definition definition : definitions) {
- for (Iterator<String> iterator1 = definition.getIncludePatterns().iterator(); iterator1.hasNext();) {
+ for (String value : definition.getIncludePatterns()) {
hasIncludes = true;
- String include = iterator1.next();
+ String include = value;
fastMatchInfo = looksLikeStartsWith(include);
if (fastMatchInfo != null) {
includeStartsWith.add(fastMatchInfo);
@@ -613,9 +612,9 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
includeTypePattern.add(includePattern);
}
}
- for (Iterator<String> iterator1 = definition.getExcludePatterns().iterator(); iterator1.hasNext();) {
+ for (String s : definition.getExcludePatterns()) {
hasExcludes = true;
- String exclude = iterator1.next();
+ String exclude = s;
fastMatchInfo = looksLikeStartsWith(exclude);
if (fastMatchInfo != null) {
excludeStartsWith.add(fastMatchInfo);
@@ -628,8 +627,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
} else if (exclude
.equals("org.codehaus.groovy..* && !org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController*")) {
// TODO need a more sophisticated analysis here, to allow for similar situations
- excludeSpecial.add(new String[] { "org.codehaus.groovy.",
- "org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController" });
+ excludeSpecial.add(new String[]{"org.codehaus.groovy.",
+ "org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController"});
// for the related test:
// } else if (exclude.equals("testdata..* && !testdata.sub.Oran*")) {
// excludeSpecial.add(new String[] { "testdata.", "testdata.sub.Oran" });
@@ -737,8 +736,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
*/
private void registerDump(final BcelWeaver weaver, final ClassLoader loader, final List<Definition> definitions) {
for (Definition definition : definitions) {
- for (Iterator<String> iterator1 = definition.getDumpPatterns().iterator(); iterator1.hasNext();) {
- String dump = iterator1.next();
+ for (String dump : definition.getDumpPatterns()) {
TypePattern pattern = new PatternParser(dump).parseTypePattern();
dumpTypePattern.add(pattern);
}
@@ -828,9 +826,9 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
}
}
boolean fastAccept = false;// defaults to false if no fast include
- for (int i = 0; i < includeStartsWith.size(); i++) {
+ for (String s : includeStartsWith) {
didSomeIncludeMatching = true;
- fastAccept = fastClassName.startsWith(includeStartsWith.get(i));
+ fastAccept = fastClassName.startsWith(s);
if (fastAccept) {
return true;
}
@@ -866,9 +864,9 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
}
}
}
- for (int i = 0; i < includeStartsWith.size(); i++) {
+ for (String s : includeStartsWith) {
didSomeIncludeMatching = true;
- boolean fastaccept = fastClassName.startsWith(includeStartsWith.get(i));
+ boolean fastaccept = fastClassName.startsWith(s);
if (fastaccept) {
return true;
}
@@ -898,14 +896,14 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
// still try to avoid ResolvedType if we have simple patterns
// EXCLUDE: if one match then reject
String fastClassName = aspectClassName.replace('/', '.').replace('.', '$');
- for (int i = 0; i < aspectExcludeStartsWith.size(); i++) {
- if (fastClassName.startsWith(aspectExcludeStartsWith.get(i))) {
+ for (String value : aspectExcludeStartsWith) {
+ if (fastClassName.startsWith(value)) {
return false;
}
}
// INCLUDE: if one match then accept
- for (int i = 0; i < aspectIncludeStartsWith.size(); i++) {
- if (fastClassName.startsWith(aspectIncludeStartsWith.get(i))) {
+ for (String s : aspectIncludeStartsWith) {
+ if (fastClassName.startsWith(s)) {
return true;
}
}
@@ -946,8 +944,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
// TODO AV - optimize for className.startWith only
ResolvedType classInfo = weaver.getWorld().resolve(UnresolvedType.forName(className), true);
// dump
- for (Iterator<TypePattern> iterator = dumpTypePattern.iterator(); iterator.hasNext();) {
- TypePattern typePattern = iterator.next();
+ for (TypePattern typePattern : dumpTypePattern) {
if (typePattern.matchesStatically(classInfo)) {
// dump match
return true;
diff --git a/loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java b/loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
index 15e1e9fd4..6f5b58702 100644
--- a/loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
+++ b/loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
@@ -173,8 +173,7 @@ public class ConcreteAspectCodeGen {
}
if (parent.isParameterizedType()) {
UnresolvedType[] typeParameters = parent.getTypeParameters();
- for (int i = 0; i < typeParameters.length; i++) {
- UnresolvedType typeParameter = typeParameters[i];
+ for (UnresolvedType typeParameter : typeParameters) {
if (typeParameter instanceof ResolvedType && ((ResolvedType) typeParameter).isMissing()) {
reportError("Unablet to resolve type parameter '" + typeParameter.getName() + "' from " + stringify());
return false;
@@ -306,8 +305,7 @@ public class ConcreteAspectCodeGen {
}
ResolvedMember[] rms = type.getDeclaredMethods();
if (rms != null) {
- for (int i = 0; i < rms.length; i++) {
- ResolvedMember member = rms[i];
+ for (ResolvedMember member : rms) {
String key = member.getName() + member.getSignature();
if (member.isAbstract()) {
collector.put(key, member);
@@ -340,8 +338,8 @@ public class ConcreteAspectCodeGen {
if (as == null || as.length == 0) {
return false;
}
- for (int i = 0; i < as.length; i++) {
- if (as[i].getTypeSignature().equals("Lorg/aspectj/lang/annotation/Pointcut;")) {
+ for (AnnotationAJ a : as) {
+ if (a.getTypeSignature().equals("Lorg/aspectj/lang/annotation/Pointcut;")) {
return true;
}
}
@@ -438,8 +436,7 @@ public class ConcreteAspectCodeGen {
cbody.append(InstructionConstants.RETURN);
cg.addMethodGen(init);
- for (Iterator<Definition.Pointcut> it = concreteAspect.pointcuts.iterator(); it.hasNext();) {
- Definition.Pointcut abstractPc = (Definition.Pointcut) it.next();
+ for (Definition.Pointcut abstractPc : concreteAspect.pointcuts) {
// TODO AV - respect visibility instead of opening up as public?
LazyMethodGen mg = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, abstractPc.name, EMPTY_TYPES, EMPTY_STRINGS, cg);
SimpleElementValue svg = new SimpleElementValue(ElementValue.STRING, cg.getConstantPool(), abstractPc.expression);
@@ -646,113 +643,113 @@ public class ConcreteAspectCodeGen {
value = value.substring(equalsIndex+1).trim();
}
boolean keyIsOk = false;
- for (int m=0;m<rms.length;m++) {
+ for (ResolvedMember rm : rms) {
NameValuePair nvp = null;
- if (rms[m].getName().equals(key)) {
+ if (rm.getName().equals(key)) {
// found it!
- keyIsOk=true;
- UnresolvedType rt = rms[m].getReturnType();
+ keyIsOk = true;
+ UnresolvedType rt = rm.getReturnType();
if (rt.isPrimitiveType()) {
switch (rt.getSignature().charAt(0)) {
- case 'J': // long
- try {
- long longValue = Long.parseLong(value);
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.PRIMITIVE_LONG,cp,longValue),cp);
- } catch (NumberFormatException nfe) {
- reportError("unable to interpret annotation value '"+value+"' as a long");
- return null;
- }
- break;
- case 'S': // short
- try {
- short shortValue = Short.parseShort(value);
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.PRIMITIVE_SHORT,cp,shortValue),cp);
- } catch (NumberFormatException nfe) {
- reportError("unable to interpret annotation value '"+value+"' as a short");
- return null;
- }
- break;
- case 'F': // float
- try {
- float floatValue = Float.parseFloat(value);
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.PRIMITIVE_FLOAT,cp,floatValue),cp);
- } catch (NumberFormatException nfe) {
- reportError("unable to interpret annotation value '"+value+"' as a float");
- return null;
- }
- break;
- case 'D': // double
- try {
- double doubleValue = Double.parseDouble(value);
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.PRIMITIVE_DOUBLE,cp,doubleValue),cp);
- } catch (NumberFormatException nfe) {
- reportError("unable to interpret annotation value '"+value+"' as a double");
- return null;
- }
- break;
- case 'I': // integer
- try {
- int intValue = Integer.parseInt(value);
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.PRIMITIVE_INT,cp,intValue),cp);
- } catch (NumberFormatException nfe) {
- reportError("unable to interpret annotation value '"+value+"' as an integer");
- return null;
- }
- break;
- case 'B': // byte
- try {
- byte byteValue = Byte.parseByte(value);
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.PRIMITIVE_BYTE,cp,byteValue),cp);
- } catch (NumberFormatException nfe) {
- reportError("unable to interpret annotation value '"+value+"' as a byte");
- return null;
- }
- break;
- case 'C': // char
- if (value.length()<2) {
- reportError("unable to interpret annotation value '"+value+"' as a char");
- return null;
- }
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.PRIMITIVE_CHAR,cp,value.charAt(1)),cp);
- break;
- case 'Z': // boolean
- try {
- boolean booleanValue = Boolean.parseBoolean(value);
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.PRIMITIVE_BOOLEAN,cp,booleanValue),cp);
- } catch (NumberFormatException nfe) {
- reportError("unable to interpret annotation value '"+value+"' as a boolean");
- return null;
- }
- break;
+ case 'J': // long
+ try {
+ long longValue = Long.parseLong(value);
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.PRIMITIVE_LONG, cp, longValue), cp);
+ } catch (NumberFormatException nfe) {
+ reportError("unable to interpret annotation value '" + value + "' as a long");
+ return null;
+ }
+ break;
+ case 'S': // short
+ try {
+ short shortValue = Short.parseShort(value);
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.PRIMITIVE_SHORT, cp, shortValue), cp);
+ } catch (NumberFormatException nfe) {
+ reportError("unable to interpret annotation value '" + value + "' as a short");
+ return null;
+ }
+ break;
+ case 'F': // float
+ try {
+ float floatValue = Float.parseFloat(value);
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.PRIMITIVE_FLOAT, cp, floatValue), cp);
+ } catch (NumberFormatException nfe) {
+ reportError("unable to interpret annotation value '" + value + "' as a float");
+ return null;
+ }
+ break;
+ case 'D': // double
+ try {
+ double doubleValue = Double.parseDouble(value);
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.PRIMITIVE_DOUBLE, cp, doubleValue), cp);
+ } catch (NumberFormatException nfe) {
+ reportError("unable to interpret annotation value '" + value + "' as a double");
+ return null;
+ }
+ break;
+ case 'I': // integer
+ try {
+ int intValue = Integer.parseInt(value);
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.PRIMITIVE_INT, cp, intValue), cp);
+ } catch (NumberFormatException nfe) {
+ reportError("unable to interpret annotation value '" + value + "' as an integer");
+ return null;
+ }
+ break;
+ case 'B': // byte
+ try {
+ byte byteValue = Byte.parseByte(value);
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.PRIMITIVE_BYTE, cp, byteValue), cp);
+ } catch (NumberFormatException nfe) {
+ reportError("unable to interpret annotation value '" + value + "' as a byte");
+ return null;
+ }
+ break;
+ case 'C': // char
+ if (value.length() < 2) {
+ reportError("unable to interpret annotation value '" + value + "' as a char");
+ return null;
+ }
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.PRIMITIVE_CHAR, cp, value.charAt(1)), cp);
+ break;
+ case 'Z': // boolean
+ try {
+ boolean booleanValue = Boolean.parseBoolean(value);
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.PRIMITIVE_BOOLEAN, cp, booleanValue), cp);
+ } catch (NumberFormatException nfe) {
+ reportError("unable to interpret annotation value '" + value + "' as a boolean");
+ return null;
+ }
+ break;
default:
- reportError("not yet supporting XML setting of annotation values of type "+rt.getName());
+ reportError("not yet supporting XML setting of annotation values of type " + rt.getName());
return null;
}
} else if (UnresolvedType.JL_STRING.equals(rt)) {
- if (value.length()<2) {
- reportError("Invalid string value specified in annotation string: "+annotationString);
+ if (value.length() < 2) {
+ reportError("Invalid string value specified in annotation string: " + annotationString);
return null;
}
- value = value.substring(1,value.length()-1); // trim the quotes off
- nvp = new NameValuePair(key,new SimpleElementValue(ElementValue.STRING,cp,value),cp);
+ value = value.substring(1, value.length() - 1); // trim the quotes off
+ nvp = new NameValuePair(key, new SimpleElementValue(ElementValue.STRING, cp, value), cp);
} else if (UnresolvedType.JL_CLASS.equals(rt)) {
// format of class string:
// Foo.class
// java.lang.Foo.class
- if (value.length()<6) {
- reportError("Not a well formed class value for an annotation '"+value+"'");
+ if (value.length() < 6) {
+ reportError("Not a well formed class value for an annotation '" + value + "'");
return null;
}
- String clazz = value.substring(0,value.length()-6);
- boolean qualified = clazz.indexOf(".")!=-1;
+ String clazz = value.substring(0, value.length() - 6);
+ boolean qualified = clazz.indexOf(".") != -1;
if (!qualified) {
// if not qualified, have to assume java.lang
- clazz = "java.lang."+clazz;
+ clazz = "java.lang." + clazz;
}
- nvp = new NameValuePair(key,new ClassElementValue(new ObjectType(clazz),cp),cp);
+ nvp = new NameValuePair(key, new ClassElementValue(new ObjectType(clazz), cp), cp);
}
}
- if (nvp!=null) {
+ if (nvp != null) {
aaj.addElementNameValuePair(nvp);
}
}
@@ -920,9 +917,9 @@ public class ConcreteAspectCodeGen {
// Generate code to load the parameters
int pos = 1; // first slot after 'this'
- for (int i = 0; i < paramTypes.size(); i++) {
- adviceBody.append(InstructionFactory.createLoad(paramTypes.get(i), pos));
- pos += paramTypes.get(i).getSize();
+ for (Type paramType : paramTypes) {
+ adviceBody.append(InstructionFactory.createLoad(paramType, pos));
+ pos += paramType.getSize();
}
// Generate the delegate call
diff --git a/loadtime/src/main/java/org/aspectj/weaver/loadtime/Options.java b/loadtime/src/main/java/org/aspectj/weaver/loadtime/Options.java
index 4e60c7b86..31b125610 100644
--- a/loadtime/src/main/java/org/aspectj/weaver/loadtime/Options.java
+++ b/loadtime/src/main/java/org/aspectj/weaver/loadtime/Options.java
@@ -60,8 +60,7 @@ public class Options {
Collections.reverse(flags);
// do a first round on the message handler since it will report the options themselves
- for (Iterator<String> iterator = flags.iterator(); iterator.hasNext();) {
- String arg = iterator.next();
+ for (String arg : flags) {
if (arg.startsWith(OPTIONVALUED_messageHandler)) {
if (arg.length() > OPTIONVALUED_messageHandler.length()) {
String handlerClass = arg.substring(OPTIONVALUED_messageHandler.length()).trim();
@@ -77,8 +76,7 @@ public class Options {
}
// configure the other options
- for (Iterator<String> iterator = flags.iterator(); iterator.hasNext();) {
- String arg = iterator.next();
+ for (String arg : flags) {
if (arg.equals(OPTION_15)) {
weaverOption.java5 = true;
} else if (arg.equalsIgnoreCase(OPTION_lazyTjp)) {
diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java
index 1c5a8536c..cd5590914 100644
--- a/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java
+++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java
@@ -94,9 +94,9 @@ public class JRockitAgentTest extends TestCase {
super(clone.getParent());
URL[] urls = clone.getURLs();
- for (int i = 0; i < urls.length; i++) {
+ for (URL value : urls) {
Object pathElement;
- URL url = urls[i];
+ URL url = value;
if (debug)
System.out.println("JRockitClassLoader.JRockitClassLoader() url=" + url.getPath());
File file = new File(encode(url.getFile()));