diff options
author | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:06:37 +0200 |
---|---|---|
committer | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:06:37 +0200 |
commit | 72194b7982ddfa8e9864d0a9934905bb76b90f33 (patch) | |
tree | ebed806c358c1a3960c5d6be4c13b26ca41809df /weaver | |
parent | c3289ab86bfb2c97cf34147239b3dde46de92a7c (diff) | |
download | aspectj-72194b7982ddfa8e9864d0a9934905bb76b90f33.tar.gz aspectj-72194b7982ddfa8e9864d0a9934905bb76b90f33.zip |
'for' loop replaceable with enhanced 'for' loop
Reports for loops which iterate over collections or arrays, and can be replaced with an enhanced for loop (i.e. the foreach iteration syntax).
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
Diffstat (limited to 'weaver')
34 files changed, 321 insertions, 404 deletions
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java index 08a261569..f49a1bb33 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -203,8 +203,7 @@ public class AtAjAttributes { boolean containsPointcut = false; boolean containsAnnotationClassReference = false; Constant[] cpool = javaClass.getConstantPool().getConstantPool(); - for (int i = 0; i < cpool.length; i++) { - Constant constant = cpool[i]; + for (Constant constant : cpool) { if (constant != null && constant.getTag() == Constants.CONSTANT_Utf8) { String constantValue = ((ConstantUtf8) constant).getValue(); if (constantValue.length() > 28 && constantValue.charAt(1) == PACKAGE_INITIAL_CHAR) { @@ -233,8 +232,7 @@ public class AtAjAttributes { boolean hasAtPrecedenceAnnotation = false; WeaverVersionInfo wvinfo = null; - for (int i = 0; i < attributes.length; i++) { - Attribute attribute = attributes[i]; + for (Attribute attribute : attributes) { if (acceptAttribute(attribute)) { RuntimeAnnos rvs = (RuntimeAnnos) attribute; // we don't need to look for several attribute occurrences since @@ -345,8 +343,7 @@ public class AtAjAttributes { AjAttributeMethodStruct mstruct = null; boolean processedPointcut = false; Attribute[] mattributes = method.getAttributes(); - for (int j = 0; j < mattributes.length; j++) { - Attribute mattribute = mattributes[j]; + for (Attribute mattribute : mattributes) { if (acceptAttribute(mattribute)) { // TODO speed all this nonsense up rather than looking // through all the annotations every time @@ -368,8 +365,7 @@ public class AtAjAttributes { // code style declare error / warning / implements / parents are field // attributes Field[] fs = javaClass.getFields(); - for (int i = 0; i < fs.length; i++) { - Field field = fs[i]; + for (Field field : fs) { if (field.getName().startsWith(NameMangler.PREFIX)) { continue; // already dealt with by ajc... } @@ -378,8 +374,7 @@ public class AtAjAttributes { AjAttributeFieldStruct fstruct = new AjAttributeFieldStruct(field, null, type, context, msgHandler); Attribute[] fattributes = field.getAttributes(); - for (int j = 0; j < fattributes.length; j++) { - Attribute fattribute = fattributes[j]; + for (Attribute fattribute : fattributes) { if (acceptAttribute(fattribute)) { RuntimeAnnos frvs = (RuntimeAnnos) fattribute; if (handleDeclareErrorOrWarningAnnotation(model, frvs, fstruct) @@ -433,8 +428,7 @@ public class AtAjAttributes { // be too silent. boolean hasAtAspectJAnnotation = false; boolean hasAtAspectJAnnotationMustReturnVoid = false; - for (int i = 0; i < attributes.length; i++) { - Attribute attribute = attributes[i]; + for (Attribute attribute : attributes) { try { if (acceptAttribute(attribute)) { RuntimeAnnos rvs = (RuntimeAnnos) attribute; @@ -762,8 +756,7 @@ public class AtAjAttributes { || Modifier.isProtected(implModifiers) || Modifier.isPublic(implModifiers)); boolean hasNoCtorOrANoArgOne = true; ResolvedMember foundOneOfIncorrectVisibility = null; - for (int i = 0; i < mm.length; i++) { - ResolvedMember resolvedMember = mm[i]; + for (ResolvedMember resolvedMember : mm) { if (resolvedMember.getName().equals("<init>")) { hasNoCtorOrANoArgOne = false; @@ -994,14 +987,13 @@ public class AtAjAttributes { boolean hasAtLeastOneMethod = false; - for (Iterator<ResolvedType> iterator = newInterfaceTypes.iterator(); iterator.hasNext();) { - ResolvedType typeForDelegation = iterator.next(); + for (ResolvedType typeForDelegation : newInterfaceTypes) { // TODO check for overlapping interfaces. Eg. A implements I, I extends J - if they specify interfaces={I,J} we dont // want to do any methods twice ResolvedMember[] methods = typeForDelegation.getMethodsWithoutIterator(true, false, false).toArray( new ResolvedMember[0]); - for (int i = 0; i < methods.length; i++) { - ResolvedMember method = methods[i]; + for (ResolvedMember resolvedMember : methods) { + ResolvedMember method = resolvedMember; if (method.isAbstract()) { hasAtLeastOneMethod = true; if (method.hasBackingGenericMember()) { @@ -1648,14 +1640,14 @@ public class AtAjAttributes { */ public static int extractExtraArgument(String[] argumentSignatures) { int extraArgument = 0; - for (int i = 0; i < argumentSignatures.length; i++) { - if (AjcMemberMaker.TYPEX_JOINPOINT.getSignature().equals(argumentSignatures[i])) { + for (String argumentSignature : argumentSignatures) { + if (AjcMemberMaker.TYPEX_JOINPOINT.getSignature().equals(argumentSignature)) { extraArgument |= Advice.ThisJoinPoint; - } else if (AjcMemberMaker.TYPEX_PROCEEDINGJOINPOINT.getSignature().equals(argumentSignatures[i])) { + } else if (AjcMemberMaker.TYPEX_PROCEEDINGJOINPOINT.getSignature().equals(argumentSignature)) { extraArgument |= Advice.ThisJoinPoint; - } else if (AjcMemberMaker.TYPEX_STATICJOINPOINT.getSignature().equals(argumentSignatures[i])) { + } else if (AjcMemberMaker.TYPEX_STATICJOINPOINT.getSignature().equals(argumentSignature)) { extraArgument |= Advice.ThisJoinPointStaticPart; - } else if (AjcMemberMaker.TYPEX_ENCLOSINGSTATICJOINPOINT.getSignature().equals(argumentSignatures[i])) { + } else if (AjcMemberMaker.TYPEX_ENCLOSINGSTATICJOINPOINT.getSignature().equals(argumentSignature)) { extraArgument |= Advice.ThisEnclosingJoinPointStaticPart; } } @@ -1738,8 +1730,7 @@ public class AtAjAttributes { LocalVariableTable lt = method.getLocalVariableTable(); if (lt != null) { LocalVariable[] lvt = lt.getLocalVariableTable(); - for (int j = 0; j < lvt.length; j++) { - LocalVariable localVariable = lvt[j]; + for (LocalVariable localVariable : lvt) { if (localVariable != null) { // pr348488 if (localVariable.getStartPC() == 0) { if (localVariable.getIndex() >= startAtStackIndex) { @@ -1909,8 +1900,7 @@ public class AtAjAttributes { // register ImplicitBindings as to be ignored since unbound // TODO is it likely to fail in a bad way if f.e. this(jp) etc ? List<String> ignores = new ArrayList<String>(); - for (int i = 0; i < bindings.length; i++) { - FormalBinding formalBinding = bindings[i]; + for (FormalBinding formalBinding : bindings) { if (formalBinding instanceof FormalBinding.ImplicitFormalBinding) { ignores.add(formalBinding.getName()); } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAdvice.java index 0c2cadb1f..7736addcd 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAdvice.java @@ -79,8 +79,8 @@ class BcelAdvice extends Advice { public boolean bindsProceedingJoinPoint() { UnresolvedType[] parameterTypes = signature.getParameterTypes(); - for (int i=0;i<parameterTypes.length;i++) { - if (parameterTypes[i].equals(UnresolvedType.PROCEEDING_JOINPOINT)) { + for (UnresolvedType parameterType : parameterTypes) { + if (parameterType.equals(UnresolvedType.PROCEEDING_JOINPOINT)) { return true; } } @@ -428,11 +428,11 @@ class BcelAdvice extends Advice { ResolvedType runtimeException = world.getCoreType(UnresolvedType.RUNTIME_EXCEPTION); ResolvedType error = world.getCoreType(UnresolvedType.ERROR); - for (int i = 0, len = excs.length; i < len; i++) { - ResolvedType t = world.resolve(excs[i], true); + for (UnresolvedType exc : excs) { + ResolvedType t = world.resolve(exc, true); if (t.isMissing()) { world.getLint().cantFindType - .signal(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE, excs[i].getName()), + .signal(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE, exc.getName()), getSourceLocation()); // IMessage msg = new Message( // WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE,excs[i].getName()), @@ -546,8 +546,7 @@ class BcelAdvice extends Advice { LocalVariableTable lvt = shadow.getEnclosingMethod().getMemberView().getMethod().getLocalVariableTable(); if (lvt != null) { LocalVariable[] lvTable = lvt.getLocalVariableTable(); - for (int i = 0; i < lvTable.length; i++) { - LocalVariable lv = lvTable[i]; + for (LocalVariable lv : lvTable) { if (lv.getStartPC() == 0) { start.addTargeter(new LocalVariableTag(lv.getSignature(), lv.getName(), lv.getIndex(), 0)); } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAnnotation.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAnnotation.java index 275eae512..b11afc77d 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAnnotation.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAnnotation.java @@ -76,8 +76,8 @@ public class BcelAnnotation extends AbstractAnnotationAJ { ArrayElementValue aev = (ArrayElementValue) envp.getValue(); ElementValue[] evs = aev.getElementValuesArray(); Set<String> targets = new HashSet<String>(); - for (int i = 0; i < evs.length; i++) { - EnumElementValue ev = (EnumElementValue) evs[i]; + for (ElementValue elementValue : evs) { + EnumElementValue ev = (EnumElementValue) elementValue; targets.add(ev.getEnumValueString()); } return targets; diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java index 66ccfd0ce..3c4f64aa2 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -187,10 +187,10 @@ class BcelClassWeaver implements IClassWeaver { private void initializeSuperInitializerMap(ResolvedType child) { ResolvedType[] superInterfaces = child.getDeclaredInterfaces(); - for (int i = 0, len = superInterfaces.length; i < len; i++) { - if (ty.getResolvedTypeX().isTopmostImplementor(superInterfaces[i])) { - if (addSuperInitializer(superInterfaces[i])) { - initializeSuperInitializerMap(superInterfaces[i]); + for (ResolvedType superInterface : superInterfaces) { + if (ty.getResolvedTypeX().isTopmostImplementor(superInterface)) { + if (addSuperInitializer(superInterface)) { + initializeSuperInitializerMap(superInterface); } } } @@ -512,8 +512,8 @@ class BcelClassWeaver implements IClassWeaver { // now proceed with late type mungers if (lateTypeMungers != null) { - for (Iterator<ConcreteTypeMunger> i = lateTypeMungers.iterator(); i.hasNext();) { - BcelTypeMunger munger = (BcelTypeMunger) i.next(); + for (ConcreteTypeMunger lateTypeMunger : lateTypeMungers) { + BcelTypeMunger munger = (BcelTypeMunger) lateTypeMunger; if (munger.matches(clazz.getType())) { boolean typeMungerAffectedType = munger.munge(this); if (typeMungerAffectedType) { @@ -723,9 +723,8 @@ class BcelClassWeaver implements IClassWeaver { boolean inSamePackage = packageName.equals(mpkg); ResolvedMember[] methods = typeToCheck.getDeclaredMethods(); - for (int ii = 0; ii < methods.length; ii++) { + for (ResolvedMember methodThatMightBeGettingOverridden : methods) { // the method we are going to check - ResolvedMember methodThatMightBeGettingOverridden = methods[ii]; ResolvedMember isOverriding = isOverriding(typeToCheck, methodThatMightBeGettingOverridden, mname, mrettype, mmods, inSamePackage, methodParamsArray); if (isOverriding != null) { @@ -735,8 +734,7 @@ class BcelClassWeaver implements IClassWeaver { // was: List l = typeToCheck.getInterTypeMungers(); List<ConcreteTypeMunger> l = (typeToCheck.isRawType() ? typeToCheck.getGenericType().getInterTypeMungers() : typeToCheck .getInterTypeMungers()); - for (Iterator<ConcreteTypeMunger> iterator = l.iterator(); iterator.hasNext();) { - ConcreteTypeMunger o = iterator.next(); + for (ConcreteTypeMunger o : l) { // FIXME asc if its not a BcelTypeMunger then its an // EclipseTypeMunger ... do I need to worry about that? if (o instanceof BcelTypeMunger) { @@ -763,9 +761,8 @@ class BcelClassWeaver implements IClassWeaver { checkForOverride(superclass, mname, mparams, mrettype, mmods, mpkg, methodParamsArray,overriddenMethodsCollector); ResolvedType[] interfaces = typeToCheck.getDeclaredInterfaces(); - for (int i = 0; i < interfaces.length; i++) { - ResolvedType anInterface = interfaces[i]; - checkForOverride(anInterface, mname, mparams, mrettype, mmods, mpkg, methodParamsArray,overriddenMethodsCollector); + for (ResolvedType anInterface : interfaces) { + checkForOverride(anInterface, mname, mparams, mrettype, mmods, mpkg, methodParamsArray, overriddenMethodsCollector); } } @@ -793,17 +790,15 @@ class BcelClassWeaver implements IClassWeaver { // Keep a set of all methods from this type - it'll help us to check if bridge methods // have already been created, we don't want to do it twice! Set<String> methodsSet = new HashSet<String>(); - for (int i = 0; i < methods.size(); i++) { - LazyMethodGen aMethod = methods.get(i); + for (LazyMethodGen aMethod : methods) { StringBuilder sb = new StringBuilder(aMethod.getName()); sb.append(aMethod.getSignature()); methodsSet.add(sb.toString()); // e.g. "foo(Ljava/lang/String;)V" } // Now go through all the methods in this type - for (int i = 0; i < methods.size(); i++) { + for (LazyMethodGen bridgeToCandidate : methods) { // This is the local method that we *might* have to bridge to - LazyMethodGen bridgeToCandidate = methods.get(i); if (bridgeToCandidate.isBridgeMethod()) { continue; // Doh! } @@ -833,7 +828,7 @@ class BcelClassWeaver implements IClassWeaver { List<ResolvedMember> overriddenMethodsCollector = new ArrayList<ResolvedMember>(); checkForOverride(theSuperclass, name, psig, rsig, bridgeToCandidate.getAccessFlags(), pkgName, bm, overriddenMethodsCollector); if (overriddenMethodsCollector.size() != 0) { - for (ResolvedMember overriddenMethod: overriddenMethodsCollector) { + for (ResolvedMember overriddenMethod : overriddenMethodsCollector) { String key = new StringBuilder(overriddenMethod.getName()).append(overriddenMethod.getSignatureErased()).toString(); // pr237419 boolean alreadyHaveABridgeMethod = methodsSet.contains(key); if (!alreadyHaveABridgeMethod) { @@ -849,15 +844,15 @@ class BcelClassWeaver implements IClassWeaver { // Check superinterfaces String[] interfaces = clazz.getInterfaceNames(); - for (int j = 0; j < interfaces.length; j++) { + for (String anInterface : interfaces) { if (world.forDEBUG_bridgingCode) { - System.err.println("Bridging:checking superinterface " + interfaces[j]); + System.err.println("Bridging:checking superinterface " + anInterface); } - ResolvedType interfaceType = world.resolve(interfaces[j]); + ResolvedType interfaceType = world.resolve(anInterface); overriddenMethodsCollector.clear(); checkForOverride(interfaceType, name, psig, rsig, bridgeToCandidate.getAccessFlags(), clazz.getPackageName(), bm, overriddenMethodsCollector); - for (ResolvedMember overriddenMethod: overriddenMethodsCollector) { + for (ResolvedMember overriddenMethod : overriddenMethodsCollector) { String key = new StringBuffer().append(overriddenMethod.getName()).append(overriddenMethod.getSignatureErased()).toString(); // pr237419 boolean alreadyHaveABridgeMethod = methodsSet.contains(key); if (!alreadyHaveABridgeMethod) { @@ -1198,14 +1193,13 @@ class BcelClassWeaver implements IClassWeaver { private boolean weaveAtFieldRepeatedly(List<DeclareAnnotation> decaFs, List<ConcreteTypeMunger> itdFields, List<Integer> reportedErrors) { boolean isChanged = false; - for (Iterator<ConcreteTypeMunger> iter = itdFields.iterator(); iter.hasNext();) { - BcelTypeMunger fieldMunger = (BcelTypeMunger) iter.next(); + for (ConcreteTypeMunger itdField : itdFields) { + BcelTypeMunger fieldMunger = (BcelTypeMunger) itdField; ResolvedMember itdIsActually = fieldMunger.getSignature(); Set<DeclareAnnotation> worthRetrying = new LinkedHashSet<DeclareAnnotation>(); boolean modificationOccured = false; - for (Iterator<DeclareAnnotation> iter2 = decaFs.iterator(); iter2.hasNext();) { - DeclareAnnotation decaF = iter2.next(); + for (DeclareAnnotation decaF : decaFs) { if (decaF.matches(itdIsActually, world)) { if (decaF.isRemover()) { LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, fieldMunger); @@ -1242,8 +1236,7 @@ class BcelClassWeaver implements IClassWeaver { while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; List<DeclareAnnotation> forRemoval = new ArrayList<DeclareAnnotation>(); - for (Iterator<DeclareAnnotation> iter2 = worthRetrying.iterator(); iter2.hasNext();) { - DeclareAnnotation decaF = iter2.next(); + for (DeclareAnnotation decaF : worthRetrying) { if (decaF.matches(itdIsActually, world)) { if (decaF.isRemover()) { LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, fieldMunger); @@ -1290,8 +1283,7 @@ class BcelClassWeaver implements IClassWeaver { List<DeclareAnnotation> worthRetrying = new ArrayList<DeclareAnnotation>(); boolean modificationOccured = false; - for (Iterator<DeclareAnnotation> iter2 = decaMCs.iterator(); iter2.hasNext();) { - DeclareAnnotation decaMC = iter2.next(); + for (DeclareAnnotation decaMC : decaMCs) { if (decaMC.matches(unMangledInterMethod, world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForMethodCtorMunger(clazz, methodctorMunger); if (annotationHolder == null @@ -1315,8 +1307,7 @@ class BcelClassWeaver implements IClassWeaver { while (!worthRetrying.isEmpty() && modificationOccured) { modificationOccured = false; List<DeclareAnnotation> forRemoval = new ArrayList<DeclareAnnotation>(); - for (Iterator<DeclareAnnotation> iter2 = worthRetrying.iterator(); iter2.hasNext();) { - DeclareAnnotation decaMC = iter2.next(); + for (DeclareAnnotation decaMC : worthRetrying) { if (decaMC.matches(unMangledInterMethod, world)) { LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, methodctorMunger); if (doesAlreadyHaveAnnotation(annotationHolder, unMangledInterMethod, decaMC, reportedErrors)) { @@ -1453,9 +1444,7 @@ class BcelClassWeaver implements IClassWeaver { modificationOccured = false; // lets have another go with any remaining ones List<DeclareAnnotation> forRemoval = new ArrayList<DeclareAnnotation>(); - for (Iterator<DeclareAnnotation> iter = worthRetrying.iterator(); iter.hasNext();) { - DeclareAnnotation decaF = iter.next(); - + for (DeclareAnnotation decaF : worthRetrying) { if (decaF.matches(field, world)) { if (decaF.isRemover()) { AnnotationAJ annotation = decaF.getAnnotation(); @@ -1471,7 +1460,7 @@ class BcelClassWeaver implements IClassWeaver { } else { // below code is for recursive things unusedDecafs.remove(decaF); - if (doesAlreadyHaveAnnotation(field, decaF, reportedProblems,true)) { + if (doesAlreadyHaveAnnotation(field, decaF, reportedProblems, true)) { continue; } field.addAnnotation(decaF.getAnnotation()); @@ -1806,8 +1795,7 @@ class BcelClassWeaver implements IClassWeaver { // the load instruction // (so we never jump over the monitorexit logic) - for (Iterator<InstructionHandle> iter = rets.iterator(); iter.hasNext();) { - InstructionHandle element = iter.next(); + for (InstructionHandle element : rets) { InstructionList monitorExitBlock = new InstructionList(); monitorExitBlock.append(InstructionFactory.createLoad(enclosingClassType, slotForLockObject)); monitorExitBlock.append(InstructionConstants.MONITOREXIT); @@ -2125,8 +2113,7 @@ class BcelClassWeaver implements IClassWeaver { // load instruction // (so we never jump over the monitorexit logic) - for (Iterator<InstructionHandle> iter = rets.iterator(); iter.hasNext();) { - InstructionHandle element = iter.next(); + for (InstructionHandle element : rets) { // System.err.println("Adding monitor exit block at "+element // ); InstructionList monitorExitBlock = new InstructionList(); @@ -2560,8 +2547,7 @@ class BcelClassWeaver implements IClassWeaver { donorFramePos += 1; } Type[] argTypes = donor.getArgumentTypes(); - for (int i = 0, len = argTypes.length; i < len; i++) { - Type argType = argTypes[i]; + for (Type argType : argTypes) { int argSlot = recipient.allocateLocal(argType); ret.insert(InstructionFactory.createStore(argType, argSlot)); frameEnv.put(donorFramePos, argSlot); @@ -2747,9 +2733,7 @@ class BcelClassWeaver implements IClassWeaver { // now add interface inits if (!isThisCall(superOrThisCall)) { InstructionHandle curr = enclosingShadow.getRange().getStart(); - for (Iterator<IfaceInitList> i = addedSuperInitializersAsList.iterator(); i.hasNext();) { - IfaceInitList l = i.next(); - + for (IfaceInitList l : addedSuperInitializersAsList) { Member ifaceInitSig = AjcMemberMaker.interfaceConstructor(l.onType); BcelShadow initShadow = BcelShadow.makeIfaceInitialization(world, mg, ifaceInitSig); @@ -3041,8 +3025,7 @@ class BcelClassWeaver implements IClassWeaver { */ private ResolvedMember findResolvedMemberNamed(ResolvedType type, String methodName) { ResolvedMember[] allMethods = type.getDeclaredMethods(); - for (int i = 0; i < allMethods.length; i++) { - ResolvedMember member = allMethods[i]; + for (ResolvedMember member : allMethods) { if (member.getName().equals(methodName)) { return member; } @@ -3060,8 +3043,7 @@ class BcelClassWeaver implements IClassWeaver { private ResolvedMember findResolvedMemberNamed(ResolvedType type, String methodName, UnresolvedType[] params) { ResolvedMember[] allMethods = type.getDeclaredMethods(); List<ResolvedMember> candidates = new ArrayList<ResolvedMember>(); - for (int i = 0; i < allMethods.length; i++) { - ResolvedMember candidate = allMethods[i]; + for (ResolvedMember candidate : allMethods) { if (candidate.getName().equals(methodName)) { if (candidate.getArity() == params.length) { candidates.add(candidate); diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java index 9b4c90cbc..7f6c70d72 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelGenericSignatureToTypeXConverter.java @@ -208,9 +208,9 @@ public class BcelGenericSignatureToTypeXConverter { Map<GenericSignature.FormalTypeParameter, ReferenceType> inProgressTypeVariableResolutions) throws GenericSignatureFormatException { GenericSignature.FormalTypeParameter typeVarBounds = null; - for (int i = 0; i < typeParams.length; i++) { - if (typeParams[i].identifier.equals(aTypeVarSig.typeVariableName)) { - typeVarBounds = typeParams[i]; + for (GenericSignature.FormalTypeParameter typeParam : typeParams) { + if (typeParam.identifier.equals(aTypeVarSig.typeVariableName)) { + typeVarBounds = typeParam; break; } } @@ -240,10 +240,10 @@ public class BcelGenericSignatureToTypeXConverter { ReferenceType rt = (ReferenceType) aTypeX; TypeVariable[] typeVars = rt.getTypeVariables(); if (typeVars != null) { - for (int i = 0; i < typeVars.length; i++) { - if (typeVars[i].getUpperBound() instanceof FTPHolder) { - GenericSignature.FormalTypeParameter key = ((FTPHolder) typeVars[i].getUpperBound()).ftpToBeSubstituted; - typeVars[i].setUpperBound(typeVariableResolutions.get(key)); + for (TypeVariable typeVar : typeVars) { + if (typeVar.getUpperBound() instanceof FTPHolder) { + GenericSignature.FormalTypeParameter key = ((FTPHolder) typeVar.getUpperBound()).ftpToBeSubstituted; + typeVar.setUpperBound(typeVariableResolutions.get(key)); } } } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelMethod.java index d1e60e1c7..6da16be27 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelMethod.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelMethod.java @@ -141,8 +141,7 @@ class BcelMethod extends ResolvedMemberImpl { AnnotationAJ[] annos = getAnnotations(); if (annos != null && annos.length != 0) { AnnotationAJ[] axs = getAnnotations(); - for (int i = 0; i < axs.length; i++) { - AnnotationAJ annotationX = axs[i]; + for (AnnotationAJ annotationX : axs) { String typename = annotationX.getTypeName(); if (typename.charAt(0) == PACKAGE_INITIAL_CHAR) { if (typename.equals("org.aspectj.lang.annotation.Pointcut") @@ -164,7 +163,7 @@ class BcelMethod extends ResolvedMemberImpl { while (argsList.size() < requiredCount) { argsList.add("arg" + argsList.size()); } - setParameterNames(argsList.toArray(new String[] {})); + setParameterNames(argsList.toArray(new String[]{})); return; } } @@ -246,8 +245,7 @@ class BcelMethod extends ResolvedMemberImpl { @Override public String getAnnotationDefaultValue() { Attribute[] attrs = method.getAttributes(); - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; + for (Attribute attribute : attrs) { if (attribute.getName().equals("AnnotationDefault")) { AnnotationDefault def = (AnnotationDefault) attribute; return def.getElementValue().stringifyValue(); @@ -261,9 +259,9 @@ class BcelMethod extends ResolvedMemberImpl { Attribute[] as = method.getAttributes(); List<String> names = new ArrayList<String>(); // String[] strs = new String[as.length]; - for (int j = 0; j < as.length; j++) { - if (!onlyIncludeAjOnes || as[j].getName().startsWith(AjAttribute.AttributePrefix)) { - names.add(as[j].getName()); + for (Attribute a : as) { + if (!onlyIncludeAjOnes || a.getName().startsWith(AjAttribute.AttributePrefix)) { + names.add(a.getName()); } } return names.toArray(new String[] {}); @@ -361,9 +359,9 @@ class BcelMethod extends ResolvedMemberImpl { if ((bitflags & HAS_ANNOTATIONS) == 0) { return null; } - for (int i = 0; i < annotations.length; i++) { - if (annotations[i].getTypeName().equals(ofType.getName())) { - return annotations[i]; + for (AnnotationAJ annotation : annotations) { + if (annotation.getTypeName().equals(ofType.getName())) { + return annotation; } } return null; @@ -660,8 +658,8 @@ class BcelMethod extends ResolvedMemberImpl { // synthetic is an attribute String[] synthetics = getAttributeNames(false); if (synthetics != null) { - for (int i = 0; i < synthetics.length; i++) { - if (synthetics[i].equals("Synthetic")) { + for (String synthetic : synthetics) { + if (synthetic.equals("Synthetic")) { bitflags |= IS_SYNTHETIC; break; } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java index 710eb6dc7..b7ce3f842 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java @@ -462,8 +462,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { private void resolveAnnotationDeclares(List<AjAttribute> attributeList) { FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0]; IScope bindingScope = new BindingScope(getResolvedTypeX(), getResolvedTypeX().getSourceContext(), bindings); - for (Iterator<AjAttribute> iter = attributeList.iterator(); iter.hasNext();) { - AjAttribute a = iter.next(); + for (AjAttribute a : attributeList) { if (a instanceof AjAttribute.DeclareAttribute) { Declare decl = (((AjAttribute.DeclareAttribute) a).getDeclare()); if (decl instanceof DeclareErrorOrWarning) { @@ -605,8 +604,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { return false; } else { String lookingForSignature = ofType.getSignature(); - for (int a = 0; a < annos.length; a++) { - AnnotationGen annotation = annos[a]; + for (AnnotationGen annotation : annos) { if (lookingForSignature.equals(annotation.getTypeSignature())) { return true; } @@ -641,8 +639,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { AnnotationAJ ax = annotations[i]; if (ax.getTypeName().equals(UnresolvedType.AT_RETENTION.getName())) { List<NameValuePair> values = ((BcelAnnotation) ax).getBcelAnnotation().getValues(); - for (Iterator<NameValuePair> it = values.iterator(); it.hasNext();) { - NameValuePair element = it.next(); + for (NameValuePair element : values) { EnumElementValue v = (EnumElementValue) element.getValue(); retentionPolicy = v.getEnumValueString(); return retentionPolicy; @@ -659,8 +656,8 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { if (targetKinds == null) { return true; } - for (int i = 0; i < targetKinds.length; i++) { - if (targetKinds[i].equals(AnnotationTargetKind.TYPE)) { + for (AnnotationTargetKind targetKind : targetKinds) { + if (targetKind.equals(AnnotationTargetKind.TYPE)) { return true; } } @@ -677,8 +674,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { List<AnnotationTargetKind> targetKinds = new ArrayList<AnnotationTargetKind>(); if (isAnnotation()) { AnnotationAJ[] annotationsOnThisType = getAnnotations(); - for (int i = 0; i < annotationsOnThisType.length; i++) { - AnnotationAJ a = annotationsOnThisType[i]; + for (AnnotationAJ a : annotationsOnThisType) { if (a.getTypeName().equals(UnresolvedType.AT_TARGET.getName())) { Set<String> targets = a.getTargets(); if (targets != null) { @@ -775,11 +771,11 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { GenericSignature.FormalTypeParameter[] extraFormals = getFormalTypeParametersFromOuterClass(); if (extraFormals.length > 0) { List<FormalTypeParameter> allFormals = new ArrayList<FormalTypeParameter>(); - for (int i = 0; i < formalsForResolution.length; i++) { - allFormals.add(formalsForResolution[i]); + for (FormalTypeParameter formalTypeParameter : formalsForResolution) { + allFormals.add(formalTypeParameter); } - for (int i = 0; i < extraFormals.length; i++) { - allFormals.add(extraFormals[i]); + for (FormalTypeParameter extraFormal : extraFormals) { + allFormals.add(extraFormal); } formalsForResolution = new GenericSignature.FormalTypeParameter[allFormals.size()]; allFormals.toArray(formalsForResolution); diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java index adb7fc921..ca167e2ef 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java @@ -157,8 +157,8 @@ public class BcelShadow extends Shadow { s.mungers = new ArrayList<ShadowMunger>(); } List<ShadowMunger> dest = s.mungers; - for (Iterator<ShadowMunger> i = src.iterator(); i.hasNext();) { - dest.add(i.next()); + for (ShadowMunger shadowMunger : src) { + dest.add(shadowMunger); } } return s; @@ -365,8 +365,7 @@ public class BcelShadow extends Shadow { // something stopped us making it a lazy tjp // can't build tjp lazily, no suitable test... int valid = 0; - for (Iterator<BcelAdvice> iter = badAdvice.iterator(); iter.hasNext();) { - BcelAdvice element = iter.next(); + for (BcelAdvice element : badAdvice) { ISourceLocation sLoc = element.getSourceLocation(); if (sLoc != null && sLoc.getLine() > 0) { valid++; @@ -375,8 +374,7 @@ public class BcelShadow extends Shadow { if (valid != 0) { ISourceLocation[] badLocs = new ISourceLocation[valid]; int i = 0; - for (Iterator<BcelAdvice> iter = badAdvice.iterator(); iter.hasNext();) { - BcelAdvice element = iter.next(); + for (BcelAdvice element : badAdvice) { ISourceLocation sLoc = element.getSourceLocation(); if (sLoc != null) { badLocs[i++] = sLoc; @@ -1047,14 +1045,13 @@ public class BcelShadow extends Shadow { private boolean checkLazyTjp() { // check for around advice - for (Iterator<ShadowMunger> i = mungers.iterator(); i.hasNext();) { - ShadowMunger munger = i.next(); + for (ShadowMunger munger : mungers) { if (munger instanceof Advice) { if (((Advice) munger).getKind() == AdviceKind.Around) { if (munger.getSourceLocation() != null) { // do we know enough to bother reporting? if (world.getLint().canNotImplementLazyTjp.isEnabled()) { - world.getLint().canNotImplementLazyTjp.signal(new String[] { toString() }, getSourceLocation(), - new ISourceLocation[] { munger.getSourceLocation() }); + world.getLint().canNotImplementLazyTjp.signal(new String[]{toString()}, getSourceLocation(), + new ISourceLocation[]{munger.getSourceLocation()}); } } return false; @@ -1454,8 +1451,7 @@ public class BcelShadow extends Shadow { ResolvedType[] rtx = this.getTargetType().resolve(world).getAnnotationTypes(); // what about annotations we havent // gotten yet but we will get in // subclasses? - for (int i = 0; i < rtx.length; i++) { - ResolvedType typeX = rtx[i]; + for (ResolvedType typeX : rtx) { targetAnnotationVars.put(typeX, new TypeAnnotationAccessVar(typeX, (BcelVar) getTargetVar())); } // populate. @@ -1517,8 +1513,7 @@ public class BcelShadow extends Shadow { if (foundMember == null) { // check the ITD'd dooberries List<ConcreteTypeMunger> mungers = relevantType.resolve(world).getInterTypeMungers(); - for (Iterator<ConcreteTypeMunger> iter = mungers.iterator(); iter.hasNext();) { - Object munger = iter.next(); + for (Object munger : mungers) { ConcreteTypeMunger typeMunger = (ConcreteTypeMunger) munger; if (typeMunger.getMunger() instanceof NewMethodTypeMunger || typeMunger.getMunger() instanceof NewConstructorTypeMunger) { @@ -1639,8 +1634,7 @@ public class BcelShadow extends Shadow { private ResolvedMember findMethod(ResolvedType aspectType, ResolvedMember ajcMethod) { ResolvedMember decMethods[] = aspectType.getDeclaredMethods(); - for (int i = 0; i < decMethods.length; i++) { - ResolvedMember member = decMethods[i]; + for (ResolvedMember member : decMethods) { if (member.equals(ajcMethod)) { return member; } @@ -1649,8 +1643,7 @@ public class BcelShadow extends Shadow { } private ResolvedMember findField(ResolvedMember[] members, Member lookingFor) { - for (int i = 0; i < members.length; i++) { - ResolvedMember member = members[i]; + for (ResolvedMember member : members) { if (member.getName().equals(getSignature().getName()) && member.getType().equals(getSignature().getType())) { return member; } @@ -1665,8 +1658,7 @@ public class BcelShadow extends Shadow { withinAnnotationVars = new HashMap<ResolvedType, AnnotationAccessVar>(); ResolvedType[] annotations = getEnclosingType().resolve(world).getAnnotationTypes(); - for (int i = 0; i < annotations.length; i++) { - ResolvedType ann = annotations[i]; + for (ResolvedType ann : annotations) { Kind k = Shadow.StaticInitialization; withinAnnotationVars.put(ann, new AnnotationAccessVar(this, k, ann, getEnclosingType(), null, true)); } @@ -1680,8 +1672,7 @@ public class BcelShadow extends Shadow { // For some shadow we are interested in annotations on the method containing that shadow. ResolvedType[] annotations = getEnclosingMethod().getMemberView().getAnnotationTypes(); - for (int i = 0; i < annotations.length; i++) { - ResolvedType ann = annotations[i]; + for (ResolvedType ann : annotations) { Kind k = (getEnclosingMethod().getMemberView().getKind() == Member.CONSTRUCTOR ? Shadow.ConstructorExecution : Shadow.MethodExecution); withincodeAnnotationVars.put(ann, new AnnotationAccessVar(this, k, ann, getEnclosingType(), @@ -1732,8 +1723,7 @@ public class BcelShadow extends Shadow { if (hasReturnInstructions) { InstructionHandle gotoTarget = advice.getStart(); - for (Iterator<InstructionHandle> i = returns.iterator(); i.hasNext();) { - InstructionHandle ih = i.next(); + for (InstructionHandle ih : returns) { retargetReturnInstruction(munger.hasExtraParameter(), returnValueVar, gotoTarget, ih); } } @@ -2299,8 +2289,7 @@ public class BcelShadow extends Shadow { InstructionList advice = new InstructionList(); // InstructionHandle adviceMethodInvocation; { - for (Iterator<BcelVar> i = argsToCallLocalAdviceMethodWith.iterator(); i.hasNext();) { - BcelVar var = i.next(); + for (BcelVar var : argsToCallLocalAdviceMethodWith) { var.appendLoad(advice, fact); } // ??? we don't actually need to push NULL for the closure if we take care @@ -3255,9 +3244,9 @@ public class BcelShadow extends Shadow { if (targetVar != null && targetVar != thisVar) { ret.put(targetVar.getSlot(), reti++); } - for (int i = 0, len = argVars.length; i < len; i++) { - ret.put(argVars[i].getSlot(), reti); - reti += argVars[i].getType().getSize(); + for (BcelVar argVar : argVars) { + ret.put(argVar.getSlot(), reti); + reti += argVar.getType().getSize(); } if (thisJoinPointVar != null) { ret.put(thisJoinPointVar.getSlot(), reti++); diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java index b92760fe9..1eae17682 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -672,8 +672,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { addMethodDispatch(gen, member, AjcMemberMaker.privilegedAccessMethodForMethod(aspectType, member)); return true; } else if (member.getKind() == Member.CONSTRUCTOR) { - for (Iterator<LazyMethodGen> i = gen.getMethodGens().iterator(); i.hasNext();) { - LazyMethodGen m = i.next(); + for (LazyMethodGen m : gen.getMethodGens()) { if (m.getMemberView() != null && m.getMemberView().getKind() == Member.CONSTRUCTOR) { // m.getMemberView().equals(member)) { m.forcePublic(); @@ -743,8 +742,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { il.append(InstructionConstants.ALOAD_0); pos++; } - for (int i = 0, len = paramTypes.length; i < len; i++) { - Type paramType = paramTypes[i]; + for (Type paramType : paramTypes) { il.append(InstructionFactory.createLoad(paramType, pos)); pos += paramType.getSize(); } @@ -975,8 +973,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { pos++; } Type[] paramTypes = BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes()); - for (int i = 0, len = paramTypes.length; i < len; i++) { - Type paramType = paramTypes[i]; + for (Type paramType : paramTypes) { body.append(InstructionFactory.createLoad(paramType, pos)); pos += paramType.getSize(); } @@ -1111,8 +1108,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { body.append(InstructionFactory.createThis()); pos++; } - for (int i = 0, len = paramTypes.length; i < len; i++) { - Type paramType = paramTypes[i]; + for (Type paramType : paramTypes) { body.append(InstructionFactory.createLoad(paramType, pos)); pos += paramType.getSize(); } @@ -1266,8 +1262,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { // Step1 boolean alreadyDone = false; // Compiler might have done it ResolvedMember[] localMethods = onType.getDeclaredMethods(); - for (int i = 0; i < localMethods.length; i++) { - ResolvedMember member = localMethods[i]; + for (ResolvedMember member : localMethods) { if (member.getName().equals(localMethodName)) { // Check the params if (member.getParameterSignature().equals(localParameterSig)) { @@ -1327,8 +1322,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { body.append(InstructionFactory.createThis()); pos++; } - for (int i = 0, len = paramTypes.length; i < len; i++) { - Type paramType = paramTypes[i]; + for (Type paramType : paramTypes) { body.append(InstructionFactory.createLoad(paramType, pos)); // if (!bridgingSetter.getParameterTypes()[i].getErasureSignature(). // equals @@ -1510,8 +1504,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { pos++; } Type[] paramTypes = BcelWorld.makeBcelTypes(introduced.getParameterTypes()); - for (int i = 0, len = paramTypes.length; i < len; i++) { - Type paramType = paramTypes[i]; + for (Type paramType : paramTypes) { body.append(InstructionFactory.createLoad(paramType, pos)); pos += paramType.getSize(); } @@ -1695,8 +1688,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { annotationsOnRealMember = realMember.getAnnotations(); } if (annotationsOnRealMember != null) { - for (int i = 0; i < annotationsOnRealMember.length; i++) { - AnnotationAJ annotationX = annotationsOnRealMember[i]; + for (AnnotationAJ annotationX : annotationsOnRealMember) { AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation(); AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true); mg.addAnnotation(new BcelAnnotation(ag, weaver.getWorld())); @@ -1706,8 +1698,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { // case where an aspect declares an annotation // on an ITD it declared on itself. List<DeclareAnnotation> allDecams = weaver.getWorld().getDeclareAnnotationOnMethods(); - for (Iterator<DeclareAnnotation> i = allDecams.iterator(); i.hasNext();) { - DeclareAnnotation decaMC = i.next(); + for (DeclareAnnotation decaMC : allDecams) { if (decaMC.matches(explicitConstructor, weaver.getWorld()) && mg.getEnclosingClass().getType() == aspectType) { mg.addAnnotation(decaMC.getAnnotation()); } @@ -1818,8 +1809,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { body.append(InstructionFactory.createThis()); pos++; - for (int i = 0, len = paramTypes.length; i < len; i++) { - Type paramType = paramTypes[i]; + for (Type paramType : paramTypes) { body.append(InstructionFactory.createLoad(paramType, pos)); pos += paramType.getSize(); } @@ -1893,8 +1883,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { FieldGen fg = makeFieldGen(gen, newField); if (annotationsOnRealMember != null) { - for (int i = 0; i < annotationsOnRealMember.length; i++) { - AnnotationAJ annotationX = annotationsOnRealMember[i]; + for (AnnotationAJ annotationX : annotationsOnRealMember) { AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation(); AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true); fg.addAnnotation(ag); @@ -1941,8 +1930,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { weaver.addInitializer(this); FieldGen fg = makeFieldGen(gen,newField); if (annotationsOnRealMember != null) { - for (int i = 0; i < annotationsOnRealMember.length; i++) { - AnnotationAJ annotationX = annotationsOnRealMember[i]; + for (AnnotationAJ annotationX : annotationsOnRealMember) { AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation(); AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true); fg.addAnnotation(ag); diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java index 1b68d27d5..41cbf9a7a 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java @@ -361,8 +361,8 @@ public class BcelWeaver { }); // For each file, add it either as a real .class file or as a resource - for (int i = 0; i < files.length; i++) { - addedClassFiles.add(addClassFile(files[i], inFile, outDir)); + for (File file : files) { + addedClassFiles.add(addClassFile(file, inFile, outDir)); } return addedClassFiles; @@ -501,8 +501,7 @@ public class BcelWeaver { needToReweaveWorld = xcutSet.hasChangedSinceLastReset(); // update mungers - for (Iterator<UnwovenClassFile> i = addedClasses.iterator(); i.hasNext();) { - UnwovenClassFile jc = i.next(); + for (UnwovenClassFile jc : addedClasses) { String name = jc.getClassName(); ResolvedType type = world.resolve(name); // No overweaving guard. If you have one then when overweaving is on the @@ -514,8 +513,7 @@ public class BcelWeaver { } } - for (Iterator<String> i = deletedTypenames.iterator(); i.hasNext();) { - String name = i.next(); + for (String name : deletedTypenames) { if (xcutSet.deleteAspect(UnresolvedType.forName(name))) { needToReweaveWorld = true; } @@ -574,8 +572,7 @@ public class BcelWeaver { private void addCustomMungers() { if (customMungerFactory != null) { - for (Iterator<UnwovenClassFile> i = addedClasses.iterator(); i.hasNext();) { - UnwovenClassFile jc = i.next(); + for (UnwovenClassFile jc : addedClasses) { String name = jc.getClassName(); ResolvedType type = world.resolve(name); if (type.isAspect()) { @@ -822,12 +819,12 @@ public class BcelWeaver { } else if (pc instanceof ConcreteCflowPointcut) { ConcreteCflowPointcut cfp = (ConcreteCflowPointcut) pc; int[] slots = cfp.getUsedFormalSlots(); - for (int i = 0; i < slots.length; i++) { - bindings[slots[i]] = cfp; - if (foundFormals[slots[i]]) { - raiseAmbiguousBindingError(names[slots[i]], userPointcut); + for (int slot : slots) { + bindings[slot] = cfp; + if (foundFormals[slot]) { + raiseAmbiguousBindingError(names[slot], userPointcut); } else { - foundFormals[slots[i]] = true; + foundFormals[slot] = true; } } } @@ -1065,8 +1062,8 @@ public class BcelWeaver { selfMunger.forceMunge(clazz, true); classType.finishedWith(); UnwovenClassFile[] newClasses = getClassFilesFor(clazz); - for (int news = 0; news < newClasses.length; news++) { - requestor.acceptResult(newClasses[news]); + for (UnwovenClassFile newClass : newClasses) { + requestor.acceptResult(newClass); } wovenClassNames.add(classFile.getClassName()); } @@ -1260,8 +1257,8 @@ public class BcelWeaver { List l = world.getCrosscuttingMembersSet().getShadowMungers(); Set<AdviceLocation> alreadyWarnedLocations = new HashSet<AdviceLocation>(); - for (Iterator iter = l.iterator(); iter.hasNext();) { - ShadowMunger element = (ShadowMunger) iter.next(); + for (Object o : l) { + ShadowMunger element = (ShadowMunger) o; // This will stop us incorrectly reporting deow checkers: if (element instanceof BcelAdvice) { BcelAdvice ba = (BcelAdvice) element; @@ -1430,8 +1427,8 @@ public class BcelWeaver { if (newClasses[0].getClassName().equals(classFile.getClassName())) { newClasses[0].setClassNameAsChars(classFile.getClassNameAsChars()); } - for (int i = 0; i < newClasses.length; i++) { - requestor.acceptResult(newClasses[i]); + for (UnwovenClassFile newClass : newClasses) { + requestor.acceptResult(newClass); } } else { requestor.acceptResult(classFile); @@ -1462,8 +1459,7 @@ public class BcelWeaver { UnwovenClassFile[] ret = new UnwovenClassFile[1 + childClasses.size()]; ret[0] = new UnwovenClassFile(clazz.getFileName(), clazz.getClassName(), clazz.getJavaClassBytesIncludingReweavable(world)); int index = 1; - for (Iterator<UnwovenClassFile.ChildClass> iter = childClasses.iterator(); iter.hasNext();) { - UnwovenClassFile.ChildClass element = iter.next(); + for (UnwovenClassFile.ChildClass element : childClasses) { UnwovenClassFile childClass = new UnwovenClassFile(clazz.getFileName() + "$" + element.name, element.bytes); ret[index++] = childClass; } @@ -1509,8 +1505,7 @@ public class BcelWeaver { while ((aParentChangeOccurred || anAnnotationChangeOccurred) && !decpToRepeat.isEmpty()) { anAnnotationChangeOccurred = aParentChangeOccurred = false; List<DeclareParents> decpToRepeatNextTime = new ArrayList<DeclareParents>(); - for (Iterator<DeclareParents> iter = decpToRepeat.iterator(); iter.hasNext();) { - DeclareParents decp = iter.next(); + for (DeclareParents decp : decpToRepeat) { boolean typeChanged = applyDeclareParents(decp, onType); if (typeChanged) { aParentChangeOccurred = true; @@ -1929,8 +1924,7 @@ public class BcelWeaver { writeZipEntry(getEntryName(mainClassName), clazz.getJavaClass(world).getBytes()); List<UnwovenClassFile.ChildClass> childClasses = clazz.getChildClasses(world); if (!childClasses.isEmpty()) { - for (Iterator<UnwovenClassFile.ChildClass> i = childClasses.iterator(); i.hasNext();) { - UnwovenClassFile.ChildClass c = i.next(); + for (UnwovenClassFile.ChildClass c : childClasses) { writeZipEntry(getEntryName(mainClassName + "$" + c.name), c.bytes); } } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWorld.java index 4ade1e125..1ee675655 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWorld.java @@ -885,8 +885,7 @@ public class BcelWorld extends World implements Repository { boolean aParentChangeOccurred = false; boolean anAnnotationChangeOccurred = false; // First pass - apply all decp mungers - for (Iterator<DeclareParents> i = declareParentsList.iterator(); i.hasNext();) { - DeclareParents decp = i.next(); + for (DeclareParents decp : declareParentsList) { boolean typeChanged = applyDeclareParents(decp, onType); if (typeChanged) { aParentChangeOccurred = true; diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/ClassPathManager.java b/weaver/src/main/java/org/aspectj/weaver/bcel/ClassPathManager.java index b7f68ca45..fa45b7df6 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/ClassPathManager.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/ClassPathManager.java @@ -160,13 +160,13 @@ public class ClassPathManager { public String toString() { StringBuffer buf = new StringBuffer(); boolean start = true; - for (Iterator<Entry> i = entries.iterator(); i.hasNext();) { + for (Entry entry : entries) { if (start) { start = false; } else { buf.append(File.pathSeparator); } - buf.append(i.next()); + buf.append(entry); } return buf.toString(); } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java index 57761bbdf..c8185d1c2 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java @@ -331,15 +331,14 @@ public final class LazyClassGen { hasSerialVersionUIDField = hasSerialVersionUIDField(getType()); ResolvedMember[] methods = getType().getDeclaredMethods(); - for (int i = 0; i < methods.length; i++) { - ResolvedMember method = methods[i]; - if (method.getName().equals("<clinit>")) { - if (method.getKind() != Member.STATIC_INITIALIZATION) { - throw new RuntimeException("qui?"); - } - hasClinit = true; - } - } + for (ResolvedMember method : methods) { + if (method.getName().equals("<clinit>")) { + if (method.getKind() != Member.STATIC_INITIALIZATION) { + throw new RuntimeException("qui?"); + } + hasClinit = true; + } + } // Do we need to calculate an SUID and add it? if (!getType().isInterface() && !hasSerialVersionUIDField && world.isAddSerialVerUID()) { @@ -358,9 +357,9 @@ public final class LazyClassGen { } ResolvedMember[] methods = myType.getDeclaredMethods(); - for (int i = 0; i < methods.length; i++) { - addMethodGen(new LazyMethodGen((BcelMethod) methods[i], this)); - } + for (ResolvedMember method : methods) { + addMethodGen(new LazyMethodGen((BcelMethod) method, this)); + } // Method[] methods = myGen.getMethods(); // for (int i = 0; i < methods.length; i++) { @@ -368,21 +367,20 @@ public final class LazyClassGen { // } ResolvedMember[] fields = myType.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - this.fields.add((BcelField) fields[i]); - } + for (ResolvedMember field : fields) { + this.fields.add((BcelField) field); + } } public static boolean hasSerialVersionUIDField(ResolvedType type) { ResolvedMember[] fields = type.getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - ResolvedMember field = fields[i]; - if (field.getName().equals("serialVersionUID") && Modifier.isStatic(field.getModifiers()) - && field.getType().equals(UnresolvedType.LONG)) { - return true; - } - } + for (ResolvedMember field : fields) { + if (field.getName().equals("serialVersionUID") && Modifier.isStatic(field.getModifiers()) + && field.getType().equals(UnresolvedType.LONG)) { + return true; + } + } return false; } @@ -646,19 +644,17 @@ public final class LazyClassGen { if (!needAttribute) { if (myType != null) { ResolvedType[] interfaceRTXs = myType.getDeclaredInterfaces(); - for (int i = 0; i < interfaceRTXs.length; i++) { - ResolvedType typeX = interfaceRTXs[i]; - if (typeX.isGenericType() || typeX.isParameterizedType()) { - needAttribute = true; - } - } + for (ResolvedType typeX : interfaceRTXs) { + if (typeX.isGenericType() || typeX.isParameterizedType()) { + needAttribute = true; + } + } if (extraSuperInterfaces != null) { - for (int i = 0; i < extraSuperInterfaces.length; i++) { - ResolvedType interfaceType = extraSuperInterfaces[i]; - if (interfaceType.isGenericType() || interfaceType.isParameterizedType()) { - needAttribute = true; - } - } + for (ResolvedType interfaceType : extraSuperInterfaces) { + if (interfaceType.isGenericType() || interfaceType.isParameterizedType()) { + needAttribute = true; + } + } } } @@ -685,10 +681,9 @@ public final class LazyClassGen { TypeVariable[] tVars = myType.getTypeVariables(); if (tVars.length > 0) { signature.append("<"); - for (int i = 0; i < tVars.length; i++) { - TypeVariable variable = tVars[i]; - signature.append(variable.getSignatureForAttribute()); - } + for (TypeVariable variable : tVars) { + signature.append(variable.getSignatureForAttribute()); + } signature.append(">"); } } @@ -697,15 +692,15 @@ public final class LazyClassGen { signature.append(supersig); if (myType != null) { ResolvedType[] interfaceRTXs = myType.getDeclaredInterfaces(); - for (int i = 0; i < interfaceRTXs.length; i++) { - String s = interfaceRTXs[i].getSignatureForAttribute(); - signature.append(s); - } + for (ResolvedType interfaceRTX : interfaceRTXs) { + String s = interfaceRTX.getSignatureForAttribute(); + signature.append(s); + } if (extraSuperInterfaces != null) { - for (int i = 0; i < extraSuperInterfaces.length; i++) { - String s = extraSuperInterfaces[i].getSignatureForAttribute(); - signature.append(s); - } + for (ResolvedType extraSuperInterface : extraSuperInterfaces) { + String s = extraSuperInterface.getSignatureForAttribute(); + signature.append(s); + } } } if (sigAttr != null) { @@ -905,10 +900,10 @@ public final class LazyClassGen { myType.printWackyStuff(out); } Field[] fields = myGen.getFields(); - for (int i = 0, len = fields.length; i < len; i++) { - out.print(" "); - out.println(fields[i]); - } + for (Field field : fields) { + out.print(" "); + out.println(field); + } List<LazyMethodGen> methodGens = getMethodGens(); for (Iterator<LazyMethodGen> iter = methodGens.iterator(); iter.hasNext();) { LazyMethodGen gen = iter.next(); @@ -1273,16 +1268,15 @@ public final class LazyClassGen { }); long estimatedSize = 0; - for (Iterator<Map.Entry<BcelShadow, Field>> i = entries.iterator(); i.hasNext();) { - Map.Entry<BcelShadow, Field> entry = i.next(); - if (estimatedSize > Constants.MAX_CODE_SIZE) { - estimatedSize = 0; - list = initInstructionList(); - lists.add(list); - } - estimatedSize += entry.getValue().getSignature().getBytes().length; - initializeTjp(fact, list, entry.getValue(), entry.getKey()); - } + for (Map.Entry<BcelShadow, Field> entry : entries) { + if (estimatedSize > Constants.MAX_CODE_SIZE) { + estimatedSize = 0; + list = initInstructionList(); + lists.add(list); + } + estimatedSize += entry.getValue().getSignature().getBytes().length; + initializeTjp(fact, list, entry.getValue(), entry.getKey()); + } InstructionList listArrayModel[] = new InstructionList[1]; return lists.toArray(listArrayModel); } @@ -1779,11 +1773,11 @@ public final class LazyClassGen { } private boolean hasSyntheticAttribute(List<Attribute> attributes) { - for (int i = 0; i < attributes.size(); i++) { - if ((attributes.get(i)).getName().equals("Synthetic")) { - return true; - } - } + for (Attribute attribute : attributes) { + if (attribute.getName().equals("Synthetic")) { + return true; + } + } return false; } @@ -1839,12 +1833,11 @@ public final class LazyClassGen { if (agens == null) { return false; } - for (int i = 0; i < agens.length; i++) { - AnnotationGen gen = agens[i]; - if (t.equals(UnresolvedType.forSignature(gen.getTypeSignature()))) { - return true; - } - } + for (AnnotationGen gen : agens) { + if (t.equals(UnresolvedType.forSignature(gen.getTypeSignature()))) { + return true; + } + } // annotations added during this weave @@ -1884,14 +1877,14 @@ public final class LazyClassGen { } ResolvedType[] interfaces = aType.getDeclaredInterfaces(); - for (int i = 0; i < interfaces.length; i++) { - if (interfaces[i].isMissing()) { - continue; - } - if (implementsSerializable(interfaces[i])) { - return true; - } - } + for (ResolvedType anInterface : interfaces) { + if (anInterface.isMissing()) { + continue; + } + if (implementsSerializable(anInterface)) { + return true; + } + } ResolvedType superType = aType.getSuperclass(); if (superType != null && !superType.isMissing()) { return implementsSerializable(superType); diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java index 2655a3456..ed9dd2c7a 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java @@ -966,8 +966,8 @@ public final class LazyMethodGen implements Traceable { } MethodGen gen = new MethodGen(flags, getReturnType(), getArgumentTypes(), null, // getArgumentNames(), getName(), getEnclosingClass().getName(), new InstructionList(), getEnclosingClass().getConstantPool()); - for (int i = 0, len = declaredExceptions.length; i < len; i++) { - gen.addException(declaredExceptions[i]); + for (String declaredException : declaredExceptions) { + gen.addException(declaredException); } for (Attribute attr : attributes) { @@ -983,17 +983,17 @@ public final class LazyMethodGen implements Traceable { if (newParameterAnnotations != null) { for (int i = 0; i < newParameterAnnotations.length; i++) { AnnotationAJ[] annos = newParameterAnnotations[i]; - for (int j = 0; j < annos.length; j++) { + for (AnnotationAJ anno : annos) { gen.addParameterAnnotation(i, - new AnnotationGen(((BcelAnnotation) annos[j]).getBcelAnnotation(), gen.getConstantPool(), true)); + new AnnotationGen(((BcelAnnotation) anno).getBcelAnnotation(), gen.getConstantPool(), true)); } } } if (memberView != null && memberView.getAnnotations() != null && memberView.getAnnotations().length != 0) { AnnotationAJ[] ans = memberView.getAnnotations(); - for (int i = 0, len = ans.length; i < len; i++) { - AnnotationGen a = ((BcelAnnotation) ans[i]).getBcelAnnotation(); + for (AnnotationAJ an : ans) { + AnnotationGen a = ((BcelAnnotation) an).getBcelAnnotation(); gen.addAnnotation(new AnnotationGen(a, gen.getConstantPool(), true)); } } @@ -1315,8 +1315,8 @@ public final class LazyMethodGen implements Traceable { int paramSlots = gen.isStatic() ? 0 : 1; Type[] argTypes = gen.getArgumentTypes(); if (argTypes != null) { - for (int i = 0; i < argTypes.length; i++) { - if (argTypes[i].getSize() == 2) { + for (Type argType : argTypes) { + if (argType.getSize() == 2) { paramSlots += 2; } else { paramSlots += 1; diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java b/weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java index 4acf032fc..7279070bc 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java @@ -669,9 +669,9 @@ public class Utility { // We know the value is an array value ArrayElementValue array = (ArrayElementValue) (vals.get(0)).getValue(); ElementValue[] values = array.getElementValuesArray(); - for (int j = 0; j < values.length; j++) { + for (ElementValue elementValue : values) { // We know values in the array are strings - SimpleElementValue value = (SimpleElementValue) values[j]; + SimpleElementValue value = (SimpleElementValue) elementValue; Lint.Kind lintKind = lint.getLintKind(value.getValueString()); if (lintKind != null) { suppressedWarnings.add(lintKind); diff --git a/weaver/src/main/java/org/aspectj/weaver/loadtime/definition/SimpleAOPParser.java b/weaver/src/main/java/org/aspectj/weaver/loadtime/definition/SimpleAOPParser.java index 55166f737..e49988a89 100644 --- a/weaver/src/main/java/org/aspectj/weaver/loadtime/definition/SimpleAOPParser.java +++ b/weaver/src/main/java/org/aspectj/weaver/loadtime/definition/SimpleAOPParser.java @@ -254,8 +254,8 @@ public class SimpleAOPParser { throws Exception { sap.startElement(xml.getName(), xml.getAttributes()); ArrayList childrens = xml.getChildrens(); - for (int i = 0; i < childrens.size(); i++) { - LightXMLParser child = (LightXMLParser) childrens.get(i); + for (Object children : childrens) { + LightXMLParser child = (LightXMLParser) children; traverse(sap, child); } sap.endElement(xml.getName()); diff --git a/weaver/src/main/java/org/aspectj/weaver/ltw/LTWWorld.java b/weaver/src/main/java/org/aspectj/weaver/ltw/LTWWorld.java index de5a4d854..1fc72dd06 100644 --- a/weaver/src/main/java/org/aspectj/weaver/ltw/LTWWorld.java +++ b/weaver/src/main/java/org/aspectj/weaver/ltw/LTWWorld.java @@ -193,9 +193,9 @@ public class LTWWorld extends BcelWorld implements IReflectionWorld { String betterChoices[] = { "java.util.concurrent.ConcurrentHashMap", "edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap", "EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap" }; - for (int i = 0; i < betterChoices.length; i++) { + for (String betterChoice : betterChoices) { try { - return Class.forName(betterChoices[i]); + return Class.forName(betterChoice); } catch (ClassNotFoundException cnfe) { // try the next one } catch (SecurityException se) { diff --git a/weaver/src/main/java/org/aspectj/weaver/model/AsmRelationshipProvider.java b/weaver/src/main/java/org/aspectj/weaver/model/AsmRelationshipProvider.java index 5801397a8..2e8a91291 100644 --- a/weaver/src/main/java/org/aspectj/weaver/model/AsmRelationshipProvider.java +++ b/weaver/src/main/java/org/aspectj/weaver/model/AsmRelationshipProvider.java @@ -604,8 +604,7 @@ public class AsmRelationshipProvider { private static void addPointcuts(AsmManager model, String sourcefilename, ResolvedType aspect, IProgramElement containingAspect, ResolvedMember[] pointcuts) { - for (int i = 0; i < pointcuts.length; i++) { - ResolvedMember pointcut = pointcuts[i]; + for (ResolvedMember pointcut : pointcuts) { if (pointcut instanceof ResolvedPointcutDefinition) { ResolvedPointcutDefinition rpcd = (ResolvedPointcutDefinition) pointcut; Pointcut p = rpcd.getPointcut(); @@ -624,8 +623,7 @@ public class AsmRelationshipProvider { private static final String NO_COMMENT = null; private static void addChildNodes(AsmManager asm, ResolvedType aspect, IProgramElement parent, ResolvedMember[] children) { - for (int i = 0; i < children.length; i++) { - ResolvedMember pcd = children[i]; + for (ResolvedMember pcd : children) { if (pcd instanceof ResolvedPointcutDefinition) { ResolvedPointcutDefinition rpcd = (ResolvedPointcutDefinition) pcd; Pointcut p = rpcd.getPointcut(); @@ -767,8 +765,8 @@ public class AsmRelationshipProvider { pe.setParameterSignatures(Collections.<char[]>emptyList(), Collections.<String>emptyList()); } else { List<char[]> paramSigs = new ArrayList<char[]>(); - for (int i = 0; i < ts.length; i++) { - paramSigs.add(ts[i].getSignature().toCharArray()); + for (UnresolvedType t : ts) { + paramSigs.add(t.getSignature().toCharArray()); } pe.setParameterSignatures(paramSigs, Collections.<String>emptyList()); } @@ -944,8 +942,7 @@ public class AsmRelationshipProvider { */ private static IProgramElement findOrCreateCodeNode(AsmManager asm, IProgramElement enclosingNode, Member shadowSig, Shadow shadow) { - for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext();) { - IProgramElement node = (IProgramElement) it.next(); + for (IProgramElement node : enclosingNode.getChildren()) { int excl = node.getBytecodeName().lastIndexOf('!'); if (((excl != -1 && shadowSig.getName().equals(node.getBytecodeName().substring(0, excl))) || shadowSig.getName() .equals(node.getBytecodeName())) @@ -984,8 +981,7 @@ public class AsmRelationshipProvider { if (typeElement == null) { return null; } - for (Iterator it = typeElement.getChildren().iterator(); it.hasNext();) { - IProgramElement element = (IProgramElement) it.next(); + for (IProgramElement element : typeElement.getChildren()) { if (member.getName().equals(element.getBytecodeName()) && member.getSignature().equals(element.getBytecodeSignature())) { return element; } diff --git a/weaver/src/main/java/org/aspectj/weaver/reflect/Java15AnnotationFinder.java b/weaver/src/main/java/org/aspectj/weaver/reflect/Java15AnnotationFinder.java index 016becf87..842863ae3 100644 --- a/weaver/src/main/java/org/aspectj/weaver/reflect/Java15AnnotationFinder.java +++ b/weaver/src/main/java/org/aspectj/weaver/reflect/Java15AnnotationFinder.java @@ -149,9 +149,9 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder { if (anns == null) anns = new org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[0]; // convert to our Annotation type - for (int i = 0; i < anns.length; i++) { - if (anns[i].getTypeSignature().equals(ofType.getSignature())) { - return new BcelAnnotation(anns[i], world); + for (org.aspectj.apache.bcel.classfile.annotation.AnnotationGen ann : anns) { + if (ann.getTypeSignature().equals(ofType.getSignature())) { + return new BcelAnnotation(ann, world); } } return null; @@ -175,8 +175,7 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder { // onMember.getName()+"' in class '"+jc.getClassName()+"'"); } else { Attribute[] attrs = bcelMethod.getAttributes(); - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; + for (Attribute attribute : attrs) { if (attribute.getName().equals("AnnotationDefault")) { AnnotationDefault def = (AnnotationDefault) attribute; return def.getElementValue().stringifyValue(); diff --git a/weaver/src/main/java/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java b/weaver/src/main/java/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java index 6b65ed31e..f617f49da 100644 --- a/weaver/src/main/java/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java +++ b/weaver/src/main/java/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java @@ -108,8 +108,8 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends ReflectionBasedR public boolean hasAnnotation(UnresolvedType ofType) { ResolvedType[] myAnns = getAnnotationTypes(); ResolvedType toLookFor = ofType.resolve(getWorld()); - for (int i = 0; i < myAnns.length; i++) { - if (myAnns[i] == toLookFor) { + for (ResolvedType myAnn : myAnns) { + if (myAnn == toLookFor) { return true; } } @@ -270,8 +270,8 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends ReflectionBasedR parser = new InternalUseOnlyPointcutParser(classLoaderReference.getClassLoader()); } Set additionalPointcutHandlers = world.getRegisteredPointcutHandlers(); - for (Iterator handlerIterator = additionalPointcutHandlers.iterator(); handlerIterator.hasNext();) { - PointcutDesignatorHandler handler = (PointcutDesignatorHandler) handlerIterator.next(); + for (Object additionalPointcutHandler : additionalPointcutHandlers) { + PointcutDesignatorHandler handler = (PointcutDesignatorHandler) additionalPointcutHandler; parser.registerPointcutDesignatorHandler(handler); } diff --git a/weaver/src/main/java/org/aspectj/weaver/tools/Jdk14Trace.java b/weaver/src/main/java/org/aspectj/weaver/tools/Jdk14Trace.java index 061b0b0a0..4fc7a1087 100644 --- a/weaver/src/main/java/org/aspectj/weaver/tools/Jdk14Trace.java +++ b/weaver/src/main/java/org/aspectj/weaver/tools/Jdk14Trace.java @@ -84,8 +84,7 @@ public class Jdk14Trace extends AbstractTrace { Logger parent = logger.getParent(); if (parent != null) handlers = parent.getHandlers(); } - for (int i = 0; i < handlers.length; i++) { - Handler handler = handlers[i]; + for (Handler handler : handlers) { handler.setLevel(Level.FINER); } } diff --git a/weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java b/weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java index 1c0d6e28d..5bb0fd80d 100644 --- a/weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java +++ b/weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java @@ -570,8 +570,8 @@ public class WeavingAdaptor implements IMessageContext { private void registerAspectLibraries(List aspectPath) { // System.err.println("? WeavingAdaptor.registerAspectLibraries(" + aspectPath + ")"); - for (Iterator i = aspectPath.iterator(); i.hasNext();) { - String libName = (String) i.next(); + for (Object o : aspectPath) { + String libName = (String) o; addAspectLibrary(libName); } diff --git a/weaver/src/main/java/org/aspectj/weaver/tools/cache/DefaultCacheKeyResolver.java b/weaver/src/main/java/org/aspectj/weaver/tools/cache/DefaultCacheKeyResolver.java index 4951923d3..44728d041 100644 --- a/weaver/src/main/java/org/aspectj/weaver/tools/cache/DefaultCacheKeyResolver.java +++ b/weaver/src/main/java/org/aspectj/weaver/tools/cache/DefaultCacheKeyResolver.java @@ -55,15 +55,14 @@ public class DefaultCacheKeyResolver implements CacheKeyResolver { // Add the list of loader urls to the hash list if (cl != null && cl instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) cl).getURLs(); - for (int i = 0; i < urls.length; i++) { - hashableStrings.add(urls[i].toString()); + for (URL url : urls) { + hashableStrings.add(url.toString()); } } hashableStrings.addAll(aspects); Collections.sort(hashableStrings); - for (Iterator<String> it = hashableStrings.iterator(); it.hasNext(); ) { - String url = it.next(); + for (String url : hashableStrings) { hashable.append(url); } String hash = null; diff --git a/weaver/src/test/java/org/aspectj/weaver/GenericSignatureParserTest.java b/weaver/src/test/java/org/aspectj/weaver/GenericSignatureParserTest.java index 433eb2c1f..a328a3464 100644 --- a/weaver/src/test/java/org/aspectj/weaver/GenericSignatureParserTest.java +++ b/weaver/src/test/java/org/aspectj/weaver/GenericSignatureParserTest.java @@ -36,8 +36,8 @@ public class GenericSignatureParserTest extends TestCase { "java.lang.InheritableThreadLocal", "java.lang.ThreadLocal", "java.util.Collection", "java.util.Comparator", "java.util.Enumeration", "java.util.Iterator", "java.util.List", "java.util.ListIterator", "java.util.Map", "java.util.Map$Entry", "java.util.Queue", "java.util.Set", "java.util.SortedMap", "java.util.SortedSet" }; - for (int i = 0; i < testClasses.length; i++) { - JavaClass jc = repository.loadClass(testClasses[i]); + for (String testClass : testClasses) { + JavaClass jc = repository.loadClass(testClass); String sig = jc.getGenericSignature(); parser.parseAsClassSignature(sig); } @@ -49,11 +49,11 @@ public class GenericSignatureParserTest extends TestCase { "java.lang.InheritableThreadLocal", "java.lang.ThreadLocal", "java.util.Collection", "java.util.Comparator", "java.util.Enumeration", "java.util.Iterator", "java.util.List", "java.util.ListIterator", "java.util.Map", "java.util.Map$Entry", "java.util.Queue", "java.util.Set", "java.util.SortedMap", "java.util.SortedSet" }; - for (int i = 0; i < testClasses.length; i++) { - JavaClass jc = repository.loadClass(testClasses[i]); + for (String testClass : testClasses) { + JavaClass jc = repository.loadClass(testClass); Method[] methods = jc.getMethods(); - for (int j = 0; j < methods.length; j++) { - String sig = methods[j].getGenericSignature(); + for (Method method : methods) { + String sig = method.getGenericSignature(); if (sig != null) parser.parseAsMethodSignature(sig); } diff --git a/weaver/src/test/java/org/aspectj/weaver/Member15Test.java b/weaver/src/test/java/org/aspectj/weaver/Member15Test.java index 6cb0ce83f..66980f612 100644 --- a/weaver/src/test/java/org/aspectj/weaver/Member15Test.java +++ b/weaver/src/test/java/org/aspectj/weaver/Member15Test.java @@ -26,12 +26,12 @@ public class Member15Test extends TestCase { ResolvedType javaLangClass = world.resolve(UnresolvedType.forName("java/lang/Class")); ResolvedMember[] methods = javaLangClass.getDeclaredMethods(); ResolvedMember getAnnotations = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("getAnnotations")) { - getAnnotations = methods[i]; - break; - } - } + for (ResolvedMember method : methods) { + if (method.getName().equals("getAnnotations")) { + getAnnotations = method; + break; + } + } if (getAnnotations != null) { // so can run on non-Java 5 // System.out.println("got it"); assertFalse(getAnnotations.canBeParameterized()); @@ -46,9 +46,9 @@ public class Member15Test extends TestCase { if (javaLangClass == null) return; // for < 1.5 ResolvedMember[] methods = javaLangClass.getDeclaredMethods(); ResolvedMember asSubclass = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("asSubclass")) { - asSubclass = methods[i]; + for (ResolvedMember method : methods) { + if (method.getName().equals("asSubclass")) { + asSubclass = method; break; } } @@ -66,9 +66,9 @@ public class Member15Test extends TestCase { if (javaUtilList == null) return; // for < 1.5 ResolvedMember[] methods = javaUtilList.getDeclaredMethods(); ResolvedMember add = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("add")) { - add = methods[i]; + for (ResolvedMember method : methods) { + if (method.getName().equals("add")) { + add = method; break; } } diff --git a/weaver/src/test/java/org/aspectj/weaver/Member15TestCase.java b/weaver/src/test/java/org/aspectj/weaver/Member15TestCase.java index 3b37d5ba8..08569f181 100644 --- a/weaver/src/test/java/org/aspectj/weaver/Member15TestCase.java +++ b/weaver/src/test/java/org/aspectj/weaver/Member15TestCase.java @@ -26,12 +26,12 @@ public class Member15TestCase extends TestCase { ResolvedType javaLangClass = world.resolve(UnresolvedType.forName("java/lang/Class")); ResolvedMember[] methods = javaLangClass.getDeclaredMethods(); ResolvedMember getAnnotations = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("getAnnotations")) { - getAnnotations = methods[i]; - break; - } - } + for (ResolvedMember method : methods) { + if (method.getName().equals("getAnnotations")) { + getAnnotations = method; + break; + } + } if (getAnnotations != null) { // so can run on non-Java 5 // System.out.println("got it"); assertFalse(getAnnotations.canBeParameterized()); @@ -46,9 +46,9 @@ public class Member15TestCase extends TestCase { if (javaLangClass == null) return; // for < 1.5 ResolvedMember[] methods = javaLangClass.getDeclaredMethods(); ResolvedMember asSubclass = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("asSubclass")) { - asSubclass = methods[i]; + for (ResolvedMember method : methods) { + if (method.getName().equals("asSubclass")) { + asSubclass = method; break; } } @@ -66,9 +66,9 @@ public class Member15TestCase extends TestCase { if (javaUtilList == null) return; // for < 1.5 ResolvedMember[] methods = javaUtilList.getDeclaredMethods(); ResolvedMember add = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("add")) { - add = methods[i]; + for (ResolvedMember method : methods) { + if (method.getName().equals("add")) { + add = method; break; } } diff --git a/weaver/src/test/java/org/aspectj/weaver/ParameterizedReferenceTypeTestCase.java b/weaver/src/test/java/org/aspectj/weaver/ParameterizedReferenceTypeTestCase.java index 8e04d8c53..695980e6f 100644 --- a/weaver/src/test/java/org/aspectj/weaver/ParameterizedReferenceTypeTestCase.java +++ b/weaver/src/test/java/org/aspectj/weaver/ParameterizedReferenceTypeTestCase.java @@ -33,10 +33,10 @@ public class ParameterizedReferenceTypeTestCase extends TestCase { public void testDeclaredMethodWithParameter() { ResolvedMember[] methods = listOfString.getDeclaredMethods(); ResolvedMember add = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("add")) { - if (methods[i].getParameterTypes().length == 1) { - add = methods[i]; + for (ResolvedMember resolvedMember : methods) { + if (resolvedMember.getName().equals("add")) { + if (resolvedMember.getParameterTypes().length == 1) { + add = resolvedMember; System.out.println(add); // j8: boolean java.util.List<java.lang.String>.add(java.lang.Object) // break; @@ -47,10 +47,10 @@ public class ParameterizedReferenceTypeTestCase extends TestCase { assertEquals("Ljava/lang/String;",parameterType.getSignature()); ResolvedMember get = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("get")) { - if (methods[i].getParameterTypes().length == 1) { - get = methods[i]; + for (ResolvedMember method : methods) { + if (method.getName().equals("get")) { + if (method.getParameterTypes().length == 1) { + get = method; break; } } @@ -63,9 +63,9 @@ public class ParameterizedReferenceTypeTestCase extends TestCase { public void testDeclaredMethodWithParameterizedReturnType() { ResolvedMember[] methods = listOfString.getDeclaredMethods(); ResolvedMember iterator = null; - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals("iterator")) { - iterator = methods[i]; + for (ResolvedMember method : methods) { + if (method.getName().equals("iterator")) { + iterator = method; break; } } diff --git a/weaver/src/test/java/org/aspectj/weaver/WeaverMessagesTestCase.java b/weaver/src/test/java/org/aspectj/weaver/WeaverMessagesTestCase.java index 7326971d3..eddcd146d 100644 --- a/weaver/src/test/java/org/aspectj/weaver/WeaverMessagesTestCase.java +++ b/weaver/src/test/java/org/aspectj/weaver/WeaverMessagesTestCase.java @@ -27,17 +27,16 @@ public class WeaverMessagesTestCase extends TestCase { Class<?> wmClass = WeaverMessages.class; Field[] fields = wmClass.getDeclaredFields(); List<String> fieldList = new ArrayList<String>(); - for (int i = 0; i < fields.length; i++) { - Field f = fields[i]; + for (Field f : fields) { if (f.getType() == String.class) { try { String key = (String) f.get(null); // String value = WeaverMessages.format(key); - assertFalse("Each key should be unique",fieldList.contains(key)); + assertFalse("Each key should be unique", fieldList.contains(key)); fieldList.add(key); // System.out.println(key + "," + value); - } catch (IllegalAccessException ex) { - } catch(MissingResourceException mrEx) { + } catch (IllegalAccessException ex) { + } catch (MissingResourceException mrEx) { fail("Missing resource: " + mrEx); } } diff --git a/weaver/src/test/java/org/aspectj/weaver/bcel/ClassLoaderRepositoryTest.java b/weaver/src/test/java/org/aspectj/weaver/bcel/ClassLoaderRepositoryTest.java index a65a25c54..42c5189a4 100644 --- a/weaver/src/test/java/org/aspectj/weaver/bcel/ClassLoaderRepositoryTest.java +++ b/weaver/src/test/java/org/aspectj/weaver/bcel/ClassLoaderRepositoryTest.java @@ -100,10 +100,10 @@ public class ClassLoaderRepositoryTest extends TestCase { threads[i] = new TestThread((i%3)*1000); threads[i].start(); } - for (int i=0; i<threads.length; i++) { - threads[i].join(); - if (threads[i].getFailure() != null) { - throw threads[i].getFailure(); + for (TestThread thread : threads) { + thread.join(); + if (thread.getFailure() != null) { + throw thread.getFailure(); } } } diff --git a/weaver/src/test/java/org/aspectj/weaver/bcel/WeaveTestCase.java b/weaver/src/test/java/org/aspectj/weaver/bcel/WeaveTestCase.java index d336b580c..6e69e2c0f 100644 --- a/weaver/src/test/java/org/aspectj/weaver/bcel/WeaveTestCase.java +++ b/weaver/src/test/java/org/aspectj/weaver/bcel/WeaveTestCase.java @@ -277,15 +277,13 @@ public abstract class WeaveTestCase extends TestCase { // ---- protected void weaveTest(String[] inClassNames, String outKind, ShadowMunger patternMunger) throws IOException { - for (int i = 0; i < inClassNames.length; i++) { - String inFileName = inClassNames[i]; + for (String inFileName : inClassNames) { weaveTest(inFileName, outKind + inFileName, patternMunger); } } protected void weaveTest(String[] inClassNames, String outKind, List<ShadowMunger> patternMungers) throws IOException { - for (int i = 0; i < inClassNames.length; i++) { - String inFileName = inClassNames[i]; + for (String inFileName : inClassNames) { weaveTest(inFileName, outKind + inFileName, patternMungers); } } @@ -300,17 +298,18 @@ public abstract class WeaveTestCase extends TestCase { // XXX cut-and-paster from IdWeaveTestCase public void checkShadowSet(List l, String[] ss) { - outer: for (int i = 0, len = ss.length; i < len; i++) { + outer: + for (String s : ss) { // inner: - for (Iterator j = l.iterator(); j.hasNext();) { + for (Iterator j = l.iterator(); j.hasNext(); ) { BcelShadow shadow = (BcelShadow) j.next(); String shadowString = shadow.toString(); - if (shadowString.equals(ss[i])) { + if (shadowString.equals(s)) { j.remove(); continue outer; } } - assertTrue("didn't find " + ss[i] + " in " + l, false); + assertTrue("didn't find " + s + " in " + l, false); } assertTrue("too many things in " + l, l.size() == 0); } diff --git a/weaver/src/test/java/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java b/weaver/src/test/java/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java index fdf8d5424..0433846fb 100644 --- a/weaver/src/test/java/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java +++ b/weaver/src/test/java/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java @@ -355,8 +355,8 @@ public class AnnotationPatternTestCase extends TestCase { } public boolean hasAnnotation(UnresolvedType ofType) { - for (int i = 0; i < annotationTypes.length; i++) { - if (annotationTypes[i].equals(ofType.getName())) { + for (String annotationType : annotationTypes) { + if (annotationType.equals(ofType.getName())) { return true; } } diff --git a/weaver/src/test/java/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java b/weaver/src/test/java/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java index a0465b34a..9aa4c5a80 100644 --- a/weaver/src/test/java/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java +++ b/weaver/src/test/java/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java @@ -257,23 +257,23 @@ public abstract class ReflectionBasedReferenceTypeDelegateTest extends TestCase ResolvedMember[] rms2 = rawReflectType.getDelegate().getDeclaredMethods(); StringBuffer errors = new StringBuffer(); Set one = new HashSet(); - for (int i = 0; i < rms1.length; i++) { - one.add(rms1[i].toString()); + for (ResolvedMember item : rms1) { + one.add(item.toString()); } Set two = new HashSet(); - for (int i = 0; i < rms2.length; i++) { - two.add(rms2[i].toString()); + for (ResolvedMember value : rms2) { + two.add(value.toString()); } - for (int i = 0; i < rms2.length; i++) { - if (!one.contains(rms2[i].toString())) { - errors.append("Couldn't find " + rms2[i].toString() + " in the bcel set\n"); + for (ResolvedMember member : rms2) { + if (!one.contains(member.toString())) { + errors.append("Couldn't find " + member.toString() + " in the bcel set\n"); } } - for (int i = 0; i < rms1.length; i++) { - if (!two.contains(rms1[i].toString())) { - if (!barfIfClinitMissing && rms1[i].getName().equals("<clinit>")) + for (ResolvedMember resolvedMember : rms1) { + if (!two.contains(resolvedMember.toString())) { + if (!barfIfClinitMissing && resolvedMember.getName().equals("<clinit>")) continue; - errors.append("Couldn't find " + rms1[i].toString() + " in the reflection set\n"); + errors.append("Couldn't find " + resolvedMember.toString() + " in the reflection set\n"); } } assertTrue("Errors:" + errors.toString(), errors.length() == 0); diff --git a/weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java b/weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java index e1a140803..f65053f7e 100644 --- a/weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java +++ b/weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java @@ -298,10 +298,9 @@ public class Java15PointcutExpressionTest extends TestCase { } if (expected.size()>0) { // we have excess ones! StringBuffer excessTokens = new StringBuffer(); - for (Iterator iterator = expected.iterator(); iterator.hasNext();) { - String string = (String) iterator.next(); - excessTokens.append(string).append(" "); - } + for (String string : expected) { + excessTokens.append(string).append(" "); + } fail("In pointcut expression "+pe.getPointcutExpression()+" parameter "+parameterNumber+". The annotation type pattern has these unexpected parameter type annotations "+excessTokens.toString()); } @@ -318,10 +317,9 @@ public class Java15PointcutExpressionTest extends TestCase { } if (expected.size()>0) { // we have excess ones! StringBuffer excessTokens = new StringBuffer(); - for (Iterator iterator = expected.iterator(); iterator.hasNext();) { - String string = (String) iterator.next(); - excessTokens.append(string).append(" "); - } + for (String string : expected) { + excessTokens.append(string).append(" "); + } fail("In pointcut expression "+pe.getPointcutExpression()+" parameter "+parameterNumber+". The annotation type pattern has these unexpected parameter annotations "+excessTokens.toString()); } diff --git a/weaver/src/test/java/org/aspectj/weaver/tools/ReadingAttributesTest.java b/weaver/src/test/java/org/aspectj/weaver/tools/ReadingAttributesTest.java index 11f74ebc1..25dc54009 100644 --- a/weaver/src/test/java/org/aspectj/weaver/tools/ReadingAttributesTest.java +++ b/weaver/src/test/java/org/aspectj/weaver/tools/ReadingAttributesTest.java @@ -34,10 +34,10 @@ public class ReadingAttributesTest extends TestCase { JavaClass jc = getClassFrom(new File("n:/temp"), "com.springsource.petclinic.domain.Visit"); assertNotNull(jc); Attribute[] attrs = jc.getAttributes(); - for (int i = 0; i < attrs.length; i++) { - System.out.println(attrs[i].getName()); - if (attrs[i].getName().endsWith("WeaverState")) { - Unknown u = (Unknown) attrs[i]; + for (Attribute attr : attrs) { + System.out.println(attr.getName()); + if (attr.getName().endsWith("WeaverState")) { + Unknown u = (Unknown) attr; VersionedDataInputStream vdis = new VersionedDataInputStream(new ByteArrayInputStream(u.getBytes()), null); // WeaverStateInfo wsi = WeaverStateInfo.read(vdis, null); |