diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/JDTCompilerAdapter.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/JDTCompilerAdapter.java index 1e1c0c1c952..a25db9858e4 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/JDTCompilerAdapter.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/JDTCompilerAdapter.java @@ -244,9 +244,8 @@ protected Commandline setupJavacCommand() throws BuildException { */ if (this.attributes.getNowarn()) { // disable all warnings - Object[] entries = this.customDefaultOptions.entrySet().toArray(); - for (int i = 0, max = entries.length; i < max; i++) { - Map.Entry entry = (Map.Entry) entries[i]; + for (Object o : this.customDefaultOptions.entrySet()) { + Map.Entry entry = (Map.Entry) o; if (!(entry.getKey() instanceof String)) continue; if (!(entry.getValue() instanceof String)) @@ -383,10 +382,10 @@ private String[] processCompilerArguments(Class javacClass) { * @param args compiler arguments to process */ private void checkCompilerArgs(String[] args) { - for (int i = 0; i < args.length; i++) { - if (args[i].charAt(0) == '@') { + for (String arg : args) { + if (arg.charAt(0) == '@') { try { - char[] content = Util.getFileCharContent(new File(args[i].substring(1)), null); + char[] content = Util.getFileCharContent(new File(arg.substring(1)), null); int offset = 0; int prefixLength = ADAPTER_PREFIX.length; while ((offset = CharOperation.indexOf(ADAPTER_PREFIX, content, true, offset)) > -1) { @@ -550,8 +549,8 @@ public int compare(Object o1, Object o2) { Arrays.sort(encodedDirs, comparator); } - for (int i = 0; i < this.compileList.length; i++) { - String arg = this.compileList[i].getAbsolutePath(); + for (File file : this.compileList) { + String arg = file.getAbsolutePath(); boolean encoded = false; if (encodedFiles != null) { //check for file level custom encoding diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/CharOperation.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/CharOperation.java index 02df6a076a7..2f08682850d 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/CharOperation.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/CharOperation.java @@ -1984,8 +1984,8 @@ public static final boolean contains(char[] characters, char[] array) { * @since 3.14 */ public static boolean containsEqual(char[][] array, char[] sequence) { - for (int i = 0; i < array.length; i++) { - if (equals(array[i], sequence)) + for (char[] c : array) { + if (equals(c, sequence)) return true; } return false; @@ -3354,8 +3354,8 @@ public static final boolean pathMatch( */ public static final int occurencesOf(char toBeFound, char[] array) { int count = 0; - for (int i = 0; i < array.length; i++) - if (toBeFound == array[i]) + for (char c : array) + if (toBeFound == c) count++; return count; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ClassFile.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ClassFile.java index 5d7b9d38a9b..f35d9636627 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ClassFile.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ClassFile.java @@ -38,7 +38,6 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -225,8 +224,8 @@ private static void createProblemType(TypeDeclaration typeDeclaration, ClassFile if (typeBinding.hasMemberTypes()) { // see bug 180109 ReferenceBinding[] members = typeBinding.memberTypes; - for (int i = 0, l = members.length; i < l; i++) - classFile.recordInnerClasses(members[i]); + for (ReferenceBinding member : members) + classFile.recordInnerClasses(member); } // TODO (olivier) handle cases where a field cannot be generated (name too long) // TODO (olivier) handle too many methods @@ -235,8 +234,7 @@ private static void createProblemType(TypeDeclaration typeDeclaration, ClassFile classFile.recordInnerClasses(typeBinding); } TypeVariableBinding[] typeVariables = typeBinding.typeVariables(); - for (int i = 0, max = typeVariables.length; i < max; i++) { - TypeVariableBinding typeVariableBinding = typeVariables[i]; + for (TypeVariableBinding typeVariableBinding : typeVariables) { if ((typeVariableBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(classFile, typeVariableBinding); } @@ -273,8 +271,7 @@ private static void createProblemType(TypeDeclaration typeDeclaration, ClassFile // We generate a clinit which contains all the problems, since we may not be able to generate problem methods (< 1.8) and problem constructors (all levels). classFile.addProblemClinit(problemsCopy); } - for (int i = 0, length = methodDecls.length; i < length; i++) { - AbstractMethodDeclaration methodDecl = methodDecls[i]; + for (AbstractMethodDeclaration methodDecl : methodDecls) { MethodBinding method = methodDecl.binding; if (method == null) continue; if (abstractMethodsOnly) { @@ -295,8 +292,7 @@ private static void createProblemType(TypeDeclaration typeDeclaration, ClassFile // propagate generation of (problem) member types if (typeDeclaration.memberTypes != null) { - for (int i = 0, max = typeDeclaration.memberTypes.length; i < max; i++) { - TypeDeclaration memberType = typeDeclaration.memberTypes[i]; + for (TypeDeclaration memberType : typeDeclaration.memberTypes) { if (memberType.binding != null) { ClassFile.createProblemType(memberType, classFile, unitResult); } @@ -441,8 +437,8 @@ else if (this.referenceBinding.isAnnotationType()) this.missingTypes = superclass.collectMissingTypes(this.missingTypes); } ReferenceBinding[] superInterfaces = this.referenceBinding.superInterfaces(); - for (int i = 0, max = superInterfaces.length; i < max; i++) { - this.missingTypes = superInterfaces[i].collectMissingTypes(this.missingTypes); + for (ReferenceBinding superInterface : superInterfaces) { + this.missingTypes = superInterface.collectMissingTypes(this.missingTypes); } attributesNumber += generateHierarchyInconsistentAttribute(); } @@ -566,8 +562,7 @@ public void addModuleAttributes(ModuleBinding module, Annotation[] annotations, public void addDefaultAbstractMethods() { // default abstract methods MethodBinding[] defaultAbstractMethods = this.referenceBinding.getDefaultAbstractMethods(); - for (int i = 0, max = defaultAbstractMethods.length; i < max; i++) { - MethodBinding methodBinding = defaultAbstractMethods[i]; + for (MethodBinding methodBinding : defaultAbstractMethods) { generateMethodInfoHeader(methodBinding); int methodAttributeOffset = this.contentsOffset; int attributeNumber = generateMethodInfoAttributes(methodBinding); @@ -795,8 +790,8 @@ public void addFieldInfos() { } if (syntheticFields != null) { - for (int i = 0, max = syntheticFields.length; i < max; i++) { - addFieldInfo(syntheticFields[i]); + for (FieldBinding syntheticField : syntheticFields) { + addFieldInfo(syntheticField); } } } @@ -1080,8 +1075,7 @@ public void addSpecialMethods(TypeDeclaration typeDecl) { generateMissingAbstractMethods(this.referenceBinding.scope.referenceType().missingAbstractMethods, this.referenceBinding.scope.referenceCompilationUnit().compilationResult); MethodBinding[] defaultAbstractMethods = this.referenceBinding.getDefaultAbstractMethods(); - for (int i = 0, max = defaultAbstractMethods.length; i < max; i++) { - MethodBinding methodBinding = defaultAbstractMethods[i]; + for (MethodBinding methodBinding : defaultAbstractMethods) { generateMethodInfoHeader(methodBinding); int methodAttributeOffset = this.contentsOffset; int attributeNumber = generateMethodInfoAttributes(methodBinding); @@ -3753,8 +3747,8 @@ private int addBootStrapLambdaEntry(int localContentsOffset, FunctionalExpressio int markerInterfaceCountIndex = this.constantPool.literalIndex(markerInterfaces.length); this.contents[localContentsOffset++] = (byte)(markerInterfaceCountIndex>>8); this.contents[localContentsOffset++] = (byte)(markerInterfaceCountIndex); - for (int m = 0, maxm = markerInterfaces.length; m < maxm; m++) { - int classTypeIndex = this.constantPool.literalIndexForType(markerInterfaces[m]); + for (TypeBinding markerInterface : markerInterfaces) { + int classTypeIndex = this.constantPool.literalIndexForType(markerInterface); this.contents[localContentsOffset++] = (byte)(classTypeIndex>>8); this.contents[localContentsOffset++] = (byte)(classTypeIndex); } @@ -3763,8 +3757,8 @@ private int addBootStrapLambdaEntry(int localContentsOffset, FunctionalExpressio int bridgeCountIndex = this.constantPool.literalIndex(bridges.length); this.contents[localContentsOffset++] = (byte) (bridgeCountIndex >> 8); this.contents[localContentsOffset++] = (byte) (bridgeCountIndex); - for (int m = 0, maxm = bridges.length; m < maxm; m++) { - char [] bridgeSignature = bridges[m].signature(); + for (MethodBinding bridge : bridges) { + char [] bridgeSignature = bridge.signature(); int bridgeMethodTypeIndex = this.constantPool.literalIndexForMethodType(bridgeSignature); this.contents[localContentsOffset++] = (byte) (bridgeMethodTypeIndex >> 8); this.contents[localContentsOffset++] = (byte) bridgeMethodTypeIndex; @@ -4495,8 +4489,7 @@ private int completeRuntimeTypeAnnotations(int attributesNumber, if (allTypeAnnotationContexts.size() > 0) { AnnotationContext[] allTypeAnnotationContextsArray = new AnnotationContext[allTypeAnnotationContexts.size()]; allTypeAnnotationContexts.toArray(allTypeAnnotationContextsArray); - for (int j = 0, max2 = allTypeAnnotationContextsArray.length; j < max2; j++) { - AnnotationContext annotationContext = allTypeAnnotationContextsArray[j]; + for (AnnotationContext annotationContext : allTypeAnnotationContextsArray) { if ((annotationContext.visibility & AnnotationContext.INVISIBLE) != 0) { invisibleTypeAnnotationsCounter++; } else { @@ -4663,8 +4656,7 @@ public void generateMissingAbstractMethods(MethodDeclaration[] methodDeclaration TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext; int typeDeclarationSourceStart = currentDeclaration.sourceStart(); int typeDeclarationSourceEnd = currentDeclaration.sourceEnd(); - for (int i = 0, max = methodDeclarations.length; i < max; i++) { - MethodDeclaration methodDeclaration = methodDeclarations[i]; + for (MethodDeclaration methodDeclaration : methodDeclarations) { MethodBinding methodBinding = methodDeclaration.binding; String readableName = new String(methodBinding.readableName()); CategorizedProblem[] problems = compilationResult.problems; @@ -4871,9 +4863,9 @@ private int generateRuntimeAnnotationsForParameters(Argument[] arguments) { Argument argument = arguments[i]; Annotation[] annotations = argument.annotations; if (annotations != null) { - for (int j = 0, max2 = annotations.length; j < max2; j++) { + for (Annotation a : annotations) { Annotation annotation; - if ((annotation = annotations[j].getPersistibleAnnotation()) == null) continue; // already packaged into container. + if ((annotation = a.getPersistibleAnnotation()) == null) continue; // already packaged into container. long annotationMask = annotation.resolvedType != null ? annotation.resolvedType.getAnnotationTagBits() & TagBits.AnnotationTargetMASK : 0; if (annotationMask != 0 && (annotationMask & TagBits.AnnotationForParameter) == 0) continue; if (annotation.isRuntimeInvisible()) { @@ -4917,9 +4909,9 @@ private int generateRuntimeAnnotationsForParameters(Argument[] arguments) { if (numberOfInvisibleAnnotations != 0) { Argument argument = arguments[i]; Annotation[] annotations = argument.annotations; - for (int j = 0, max = annotations.length; j < max; j++) { + for (Annotation a : annotations) { Annotation annotation; - if ((annotation = annotations[j].getPersistibleAnnotation()) == null) continue; // already packaged into container. + if ((annotation = a.getPersistibleAnnotation()) == null) continue; // already packaged into container. long annotationMask = annotation.resolvedType != null ? annotation.resolvedType.getAnnotationTagBits() & TagBits.AnnotationTargetMASK : 0; if (annotationMask != 0 && (annotationMask & TagBits.AnnotationForParameter) == 0) continue; if (annotation.isRuntimeInvisible()) { @@ -4978,9 +4970,9 @@ private int generateRuntimeAnnotationsForParameters(Argument[] arguments) { if (numberOfVisibleAnnotations != 0) { Argument argument = arguments[i]; Annotation[] annotations = argument.annotations; - for (int j = 0, max = annotations.length; j < max; j++) { + for (Annotation a : annotations) { Annotation annotation; - if ((annotation = annotations[j].getPersistibleAnnotation()) == null) continue; // already packaged into container. + if ((annotation = a.getPersistibleAnnotation()) == null) continue; // already packaged into container. long annotationMask = annotation.resolvedType != null ? annotation.resolvedType.getAnnotationTagBits() & TagBits.AnnotationTargetMASK : 0; if (annotationMask != 0 && (annotationMask & TagBits.AnnotationForParameter) == 0) continue; if (annotation.isRuntimeVisible()) { @@ -6221,8 +6213,7 @@ private void initializeDefaultLocals(StackMapFrame frame, TypeBinding[] arguments; if ((arguments = methodBinding.parameters) != null) { - for (int i = 0, max = arguments.length; i < max; i++) { - final TypeBinding typeBinding = arguments[i]; + for (final TypeBinding typeBinding : arguments) { frame.putLocal(resolvedPosition, new VerificationTypeInfo(typeBinding)); switch (typeBinding.id) { @@ -6261,8 +6252,7 @@ private void initializeDefaultLocals(StackMapFrame frame, } else { TypeBinding[] arguments; if ((arguments = methodBinding.parameters) != null) { - for (int i = 0, max = arguments.length; i < max; i++) { - final TypeBinding typeBinding = arguments[i]; + for (final TypeBinding typeBinding : arguments) { frame.putLocal(resolvedPosition, new VerificationTypeInfo(typeBinding)); switch (typeBinding.id) { @@ -6565,8 +6555,7 @@ private List filterFakeFrames(Set realJumpTargets, Map result = new ArrayList<>(); - for (Iterator iterator = realJumpTargets.iterator(); iterator.hasNext(); ) { - Integer jumpTarget = iterator.next(); + for (Integer jumpTarget : realJumpTargets) { StackMapFrame frame = frames.get(jumpTarget); if (frame != null) { result.add(frame); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseMessagerImpl.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseMessagerImpl.java index fd51160eba1..6c28ab2c903 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseMessagerImpl.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseMessagerImpl.java @@ -225,8 +225,8 @@ public static AptProblem createProblem(Kind kind, CharSequence msg, Element e, } private static Annotation findAnnotation(Annotation[] elementAnnotations, AnnotationBinding annotationBinding) { - for (int i = 0; i < elementAnnotations.length; i++) { - Annotation annotation = findAnnotation(elementAnnotations[i], annotationBinding); + for (Annotation elementAnnotation : elementAnnotations) { + Annotation annotation = findAnnotation(elementAnnotation, annotationBinding); if (annotation != null) { return annotation; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java index 7117c2c15b6..be99d72313f 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/dispatch/RoundEnvImpl.java @@ -162,8 +162,8 @@ private void addAnnotatedElements(ReferenceBinding anno, ReferenceBinding type, result.add(this._factory.newElement(type)); } } - for (ReferenceBinding element : type.memberTypes()) { - addAnnotatedElements(anno, element, result); + for (ReferenceBinding binding : type.memberTypes()) { + addAnnotatedElements(anno, binding, result); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java index 78d075b4b04..61bf96dfe4f 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/AnnotationMirrorImpl.java @@ -148,11 +148,11 @@ public DeclaredType getAnnotationType() { for (MethodBinding method : annoType.methods()) { // if binding is in ElementValuePair list, then get value from there boolean foundExplicitValue = false; - for (int i = 0; i < pairs.length; ++i) { - MethodBinding explicitBinding = pairs[i].getMethodBinding(); + for (ElementValuePair pair : pairs) { + MethodBinding explicitBinding = pair.getMethodBinding(); if (method == explicitBinding) { ExecutableElement e = new ExecutableElementImpl(this._env, explicitBinding); - AnnotationValue v = new AnnotationMemberValue(this._env, pairs[i].getValue(), explicitBinding); + AnnotationValue v = new AnnotationMemberValue(this._env, pair.getValue(), explicitBinding); valueMap.put(e, v); foundExplicitValue = true; break; @@ -337,9 +337,9 @@ private Object getReflectionValue(Object actualValue, TypeBinding actualType, Cl if(bindings != null) { List mirrors = new ArrayList<>(bindings.length); - for (int i = 0; i < bindings.length; ++i) { - if (bindings[i] instanceof TypeBinding) { - mirrors.add(this._env.getFactory().newTypeMirror((TypeBinding)bindings[i])); + for (Object binding : bindings) { + if (binding instanceof TypeBinding) { + mirrors.add(this._env.getFactory().newTypeMirror((TypeBinding)binding)); } } throw new MirroredTypesException(mirrors); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java index b1d6c0114a9..b597dfb2b37 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/ExecutableElementImpl.java @@ -309,9 +309,9 @@ public boolean overrides(ExecutableElement overridden, TypeElement type) LookupEnvironment lookupEnvironment = this._env.getLookupEnvironment(); if (lookupEnvironment == null) return false; MethodVerifier methodVerifier = lookupEnvironment.methodVerifier(); - for (int i = 0, length = superMethods.length; i < length; i++) { - if (superMethods[i].original() == overriddenBinding) { - return methodVerifier.doesMethodOverride(overriderBinding, superMethods[i]); + for (MethodBinding superMethod : superMethods) { + if (superMethod.original() == overriddenBinding) { + return methodVerifier.doesMethodOverride(overriderBinding, superMethod); } } return false; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java index b42b2d9500a..6be4076b79b 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/Factory.java @@ -162,58 +162,58 @@ private static void appendModifier(Set result, int modifiers, int modi private static void decodeModifiers(Set result, int modifiers, int[] checkBits) { if (checkBits == null) return; - for (int i = 0, max = checkBits.length; i < max; i++) { - switch(checkBits[i]) { + for (int checkBit : checkBits) { + switch(checkBit) { case ClassFileConstants.AccPublic : - appendModifier(result, modifiers, checkBits[i], Modifier.PUBLIC); + appendModifier(result, modifiers, checkBit, Modifier.PUBLIC); break; case ClassFileConstants.AccProtected: - appendModifier(result, modifiers, checkBits[i], Modifier.PROTECTED); + appendModifier(result, modifiers, checkBit, Modifier.PROTECTED); break; case ClassFileConstants.AccPrivate : - appendModifier(result, modifiers, checkBits[i], Modifier.PRIVATE); + appendModifier(result, modifiers, checkBit, Modifier.PRIVATE); break; case ClassFileConstants.AccAbstract : - appendModifier(result, modifiers, checkBits[i], Modifier.ABSTRACT); + appendModifier(result, modifiers, checkBit, Modifier.ABSTRACT); break; case ExtraCompilerModifiers.AccDefaultMethod : try { - appendModifier(result, modifiers, checkBits[i], Modifier.valueOf("DEFAULT")); //$NON-NLS-1$ + appendModifier(result, modifiers, checkBit, Modifier.valueOf("DEFAULT")); //$NON-NLS-1$ } catch(IllegalArgumentException iae) { // Don't have JDK 1.8, just ignore and proceed. } break; case ClassFileConstants.AccStatic : - appendModifier(result, modifiers, checkBits[i], Modifier.STATIC); + appendModifier(result, modifiers, checkBit, Modifier.STATIC); break; case ClassFileConstants.AccFinal : - appendModifier(result, modifiers, checkBits[i], Modifier.FINAL); + appendModifier(result, modifiers, checkBit, Modifier.FINAL); break; case ClassFileConstants.AccSynchronized : - appendModifier(result, modifiers, checkBits[i], Modifier.SYNCHRONIZED); + appendModifier(result, modifiers, checkBit, Modifier.SYNCHRONIZED); break; case ClassFileConstants.AccNative : - appendModifier(result, modifiers, checkBits[i], Modifier.NATIVE); + appendModifier(result, modifiers, checkBit, Modifier.NATIVE); break; case ClassFileConstants.AccStrictfp : - appendModifier(result, modifiers, checkBits[i], Modifier.STRICTFP); + appendModifier(result, modifiers, checkBit, Modifier.STRICTFP); break; case ClassFileConstants.AccTransient : - appendModifier(result, modifiers, checkBits[i], Modifier.TRANSIENT); + appendModifier(result, modifiers, checkBit, Modifier.TRANSIENT); break; case ClassFileConstants.AccVolatile : - appendModifier(result, modifiers, checkBits[i], Modifier.VOLATILE); + appendModifier(result, modifiers, checkBit, Modifier.VOLATILE); break; case ExtraCompilerModifiers.AccNonSealed : try { - appendModifier(result, modifiers, checkBits[i], Modifier.valueOf("NON_SEALED")); //$NON-NLS-1$ + appendModifier(result, modifiers, checkBit, Modifier.valueOf("NON_SEALED")); //$NON-NLS-1$ } catch(IllegalArgumentException iae) { // Don't have JDK 15, just ignore and proceed. } break; case ExtraCompilerModifiers.AccSealed : try { - appendModifier(result, modifiers, checkBits[i], Modifier.valueOf("SEALED")); //$NON-NLS-1$ + appendModifier(result, modifiers, checkBit, Modifier.valueOf("SEALED")); //$NON-NLS-1$ } catch(IllegalArgumentException iae) { // Don't have JDK 15, just ignore and proceed. } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ASTNode.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ASTNode.java index 85bcb0f164f..1e3747d0138 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ASTNode.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ASTNode.java @@ -722,8 +722,7 @@ public static StringBuilder printModifiers(int modifiers, StringBuilder output) public static void resolveStatements(Statement[] statements, BlockScope scope) { LocalVariableBinding [] livePatternVariables = NO_VARIABLES; - for (int i = 0, length = statements.length; i < length; i++) { - final Statement stmt = statements[i]; + for (final Statement stmt : statements) { stmt.resolveWithBindings(livePatternVariables, scope); livePatternVariables = LocalVariableBinding.merge(livePatternVariables, stmt.bindingsWhenComplete()); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java index d05c3029a88..cbe2362fc70 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java @@ -153,8 +153,8 @@ public void bindArguments() { if (this.arguments != null) { // by default arguments in abstract/native methods are considered to be used (no complaint is expected) if (this.binding == null) { - for (int i = 0, length = this.arguments.length; i < length; i++) { - this.arguments[i].bind(this.scope, null, true); + for (Argument argument : this.arguments) { + argument.bind(this.scope, null, true); } return; } @@ -377,9 +377,9 @@ public void generateCode(ClassFile classFile) { // arguments initialization for local variable debug attributes if (this.arguments != null) { - for (int i = 0, max = this.arguments.length; i < max; i++) { + for (Argument argument : this.arguments) { LocalVariableBinding argBinding; - codeStream.addVisibleLocalVariable(argBinding = this.arguments[i].binding); + codeStream.addVisibleLocalVariable(argBinding = argument.binding); argBinding.recordInitializationStartPC(0); } } @@ -572,9 +572,9 @@ public StringBuilder printBody(int indent, StringBuilder output) { output.append(" {"); //$NON-NLS-1$ if (this.statements != null) { - for (int i = 0; i < this.statements.length; i++) { + for (Statement statement : this.statements) { output.append('\n'); - this.statements[i].printStatement(indent, output); + statement.printStatement(indent, output); } } output.append('\n'); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java index 6af8af020cd..5bdba6f7fe5 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java @@ -167,8 +167,7 @@ public void checkCapturedLocalInitializationIfNecessary(ReferenceBinding checked NestedTypeBinding nestedType = (NestedTypeBinding) checkedType; SyntheticArgumentBinding[] syntheticArguments = nestedType.syntheticOuterLocalVariables(); if (syntheticArguments != null) - for (int i = 0, count = syntheticArguments.length; i < count; i++){ - SyntheticArgumentBinding syntheticArgument = syntheticArguments[i]; + for (SyntheticArgumentBinding syntheticArgument : syntheticArguments) { LocalVariableBinding targetLocal; if ((targetLocal = syntheticArgument.actualOuterLocalVariable) == null) continue; if (targetLocal.declaration != null && !flowInfo.isDefinitelyAssigned(targetLocal)){ @@ -403,8 +402,8 @@ public TypeBinding resolveType(BlockScope scope) { } if (this.argumentsHaveErrors) { if (this.arguments != null) { // still attempt to resolve arguments - for (int i = 0, max = this.arguments.length; i < max; i++) { - this.arguments[i].resolveType(scope); + for (Expression argument : this.arguments) { + argument.resolveType(scope); } } return null; @@ -729,16 +728,16 @@ public void setFieldIndex(int i) { public void traverse(ASTVisitor visitor, BlockScope scope) { if (visitor.visit(this, scope)) { if (this.typeArguments != null) { - for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) { - this.typeArguments[i].traverse(visitor, scope); + for (TypeReference typeArgument : this.typeArguments) { + typeArgument.traverse(visitor, scope); } } if (this.type != null) { // enum constant scenario this.type.traverse(visitor, scope); } if (this.arguments != null) { - for (int i = 0, argumentsLength = this.arguments.length; i < argumentsLength; i++) - this.arguments[i].traverse(visitor, scope); + for (Expression argument : this.arguments) + argument.traverse(visitor, scope); } } visitor.endVisit(this, scope); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Annotation.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Annotation.java index 744acd2a8f7..ed8e0370a20 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Annotation.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Annotation.java @@ -213,8 +213,8 @@ public String toString() { .append("search location for ") //$NON-NLS-1$ .append(this.searchedAnnotation) .append("\ncurrent type_path entries : "); //$NON-NLS-1$ - for (int i = 0, maxi = this.typePathEntries.size(); i < maxi; i++) { - int[] typePathEntry = (int[]) this.typePathEntries.get(i); + for (Object entry : this.typePathEntries) { + int[] typePathEntry = (int[]) entry; buffer .append('(') .append(typePathEntry[0]) @@ -357,8 +357,7 @@ private long detectStandardAnnotation(Scope scope, ReferenceBinding annotationTy ArrayInitializer initializer = (ArrayInitializer) expr; final Expression[] expressions = initializer.expressions; if (expressions != null) { - for (int i = 0, length = expressions.length; i < length; i++) { - Expression initExpr = expressions[i]; + for (Expression initExpr : expressions) { if ((initExpr.bits & Binding.VARIABLE) == Binding.FIELD) { FieldBinding field = ((Reference) initExpr).fieldBinding(); if (field != null && field.declaringClass.id == T_JavaLangAnnotationElementType) { @@ -626,8 +625,7 @@ public void checkRepeatableMetaAnnotation(BlockScope scope) { public static void checkContainerAnnotationType(ASTNode culpritNode, BlockScope scope, ReferenceBinding containerAnnotationType, ReferenceBinding repeatableAnnotationType, boolean useSite) { MethodBinding[] annotationMethods = containerAnnotationType.methods(); boolean sawValue = false; - for (int i = 0, length = annotationMethods.length; i < length; ++i) { - MethodBinding method = annotationMethods[i]; + for (MethodBinding method : annotationMethods) { if (CharOperation.equals(method.selector, TypeConstants.VALUE)) { sawValue = true; if (method.returnType.isArrayType() && method.returnType.dimensions() == 1) { @@ -840,18 +838,18 @@ public void recordSuppressWarnings(Scope scope, int startSuppresss, int endSuppr ArrayInitializer initializer = (ArrayInitializer) value; Expression[] inits = initializer.expressions; if (inits != null) { - for (int j = 0, initsLength = inits.length; j < initsLength; j++) { - Constant cst = inits[j].constant; + for (Expression init : inits) { + Constant cst = init.constant; if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) { IrritantSet irritants = CompilerOptions.warningTokenToIrritants(cst.stringValue()); if (irritants != null) { if (suppressWarningIrritants == null) { suppressWarningIrritants = new IrritantSet(irritants); } else if (suppressWarningIrritants.set(irritants) == null) { - scope.problemReporter().unusedWarningToken(inits[j]); + scope.problemReporter().unusedWarningToken(init); } } else { - scope.problemReporter().unhandledWarningToken(inits[j]); + scope.problemReporter().unhandledWarningToken(init); } } } @@ -1366,8 +1364,7 @@ public static void checkForInstancesOfRepeatableWithRepeatingContainerAnnotation TypeBinding elementsType = array.elementsType(); if (! elementsType.isRepeatableAnnotationType()) return; // Can't be a problem, then - for (int i= 0; i < sourceAnnotations.length; ++i) { - Annotation annotation = sourceAnnotations[i]; + for (Annotation annotation : sourceAnnotations) { if (TypeBinding.equalsEquals(elementsType, annotation.resolvedType)) { scope.problemReporter().repeatableAnnotationWithRepeatingContainer(annotation, repeatedAnnotationType); return; // One is enough for this annotation type @@ -1399,8 +1396,7 @@ public static void isTypeUseCompatible(TypeReference reference, Scope scope, Ann return; nextAnnotation: - for (int i = 0, annotationsLength = annotations.length; i < annotationsLength; i++) { - Annotation annotation = annotations[i]; + for (Annotation annotation : annotations) { long metaTagBits = annotation.resolvedType.getAnnotationTagBits(); if ((metaTagBits & TagBits.AnnotationForTypeUse) != 0 && (metaTagBits & TagBits.AnnotationForDeclarationMASK) == 0) { ReferenceBinding currentType = (ReferenceBinding) resolvedType; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java index 3a810d11773..01b231f4c85 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java @@ -43,9 +43,9 @@ public class ArrayAllocationExpression extends Expression { @Override public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { - for (int i = 0, max = this.dimensions.length; i < max; i++) { + for (Expression dimension : this.dimensions) { Expression dim; - if ((dim = this.dimensions[i]) != null) { + if ((dim = dimension) != null) { flowInfo = dim.analyseCode(currentScope, flowContext, flowInfo); dim.checkNPEbyUnboxing(currentScope, flowContext, flowInfo); } @@ -72,9 +72,9 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolea } int explicitDimCount = 0; - for (int i = 0, max = this.dimensions.length; i < max; i++) { + for (Expression dimension : this.dimensions) { Expression dimExpression; - if ((dimExpression = this.dimensions[i]) == null) break; // implicit dim, no further explict after this point + if ((dimExpression = dimension) == null) break; // implicit dim, no further explict after this point dimExpression.generateCode(currentScope, codeStream, true); explicitDimCount++; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java index abc8aa4a15d..5daf55cea1b 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java @@ -51,14 +51,14 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl CompilerOptions compilerOptions = currentScope.compilerOptions(); boolean analyseResources = compilerOptions.analyseResourceLeaks; boolean evalNullTypeAnnotations = currentScope.environment().usesNullTypeAnnotations(); - for (int i = 0, max = this.expressions.length; i < max; i++) { - flowInfo = this.expressions[i].analyseCode(currentScope, flowContext, flowInfo).unconditionalInits(); + for (Expression expression : this.expressions) { + flowInfo = expression.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits(); - if (analyseResources && FakedTrackingVariable.isAnyCloseable(this.expressions[i].resolvedType)) { - flowInfo = FakedTrackingVariable.markPassedToOutside(currentScope, this.expressions[i], flowInfo, flowContext, false); + if (analyseResources && FakedTrackingVariable.isAnyCloseable(expression.resolvedType)) { + flowInfo = FakedTrackingVariable.markPassedToOutside(currentScope, expression, flowInfo, flowContext, false); } if (evalNullTypeAnnotations) { - checkAgainstNullTypeAnnotation(currentScope, this.binding.elementsType(), this.expressions[i], flowContext, flowInfo); + checkAgainstNullTypeAnnotation(currentScope, this.binding.elementsType(), expression, flowContext, flowInfo); } } } @@ -184,8 +184,7 @@ public TypeBinding resolveTypeExpecting(BlockScope scope, TypeBinding expectedTy if (this.expressions == null) return this.binding; TypeBinding elementType = this.binding.elementsType(); - for (int i = 0, length = this.expressions.length; i < length; i++) { - Expression expression = this.expressions[i]; + for (Expression expression : this.expressions) { expression.setExpressionContext(ASSIGNMENT_CONTEXT); expression.setExpectedType(elementType); TypeBinding expressionType = expression instanceof ArrayInitializer diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java index 4ff6b693bb2..94d390a9dd2 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java @@ -171,10 +171,9 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { } } if (this.annotationsOnDimensions != null) { - for (int i = 0, max = this.annotationsOnDimensions.length; i < max; i++) { - Annotation[] annotations2 = this.annotationsOnDimensions[i]; - for (int j = 0, max2 = annotations2 == null ? 0 : annotations2.length; j < max2; j++) { - Annotation annotation = annotations2[j]; + for (Annotation[] annotationsOnDimension : this.annotationsOnDimensions) { + for (int j = 0, max2 = annotationsOnDimension == null ? 0 : annotationsOnDimension.length; j < max2; j++) { + Annotation annotation = annotationsOnDimension[j]; annotation.traverse(visitor, scope); } } @@ -195,10 +194,9 @@ public void traverse(ASTVisitor visitor, ClassScope scope) { } } if (this.annotationsOnDimensions != null) { - for (int i = 0, max = this.annotationsOnDimensions.length; i < max; i++) { - Annotation[] annotations2 = this.annotationsOnDimensions[i]; - for (int j = 0, max2 = annotations2 == null ? 0 : annotations2.length; j < max2; j++) { - Annotation annotation = annotations2[j]; + for (Annotation[] annotationsOnDimension : this.annotationsOnDimensions) { + for (int j = 0, max2 = annotationsOnDimension == null ? 0 : annotationsOnDimension.length; j < max2; j++) { + Annotation annotation = annotationsOnDimension[j]; annotation.traverse(visitor, scope); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java index 9535c415a12..4a7cae4e7ad 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java @@ -167,11 +167,9 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { } } if (this.annotationsOnDimensions != null) { - for (int i = 0, max = this.annotationsOnDimensions.length; i < max; i++) { - Annotation[] annotations2 = this.annotationsOnDimensions[i]; - if (annotations2 != null) { - for (int j = 0, max2 = annotations2.length; j < max2; j++) { - Annotation annotation = annotations2[j]; + for (Annotation[] annotationsOnDimension : this.annotationsOnDimensions) { + if (annotationsOnDimension != null) { + for (Annotation annotation : annotationsOnDimension) { annotation.traverse(visitor, scope); } } @@ -191,11 +189,9 @@ public void traverse(ASTVisitor visitor, ClassScope scope) { } } if (this.annotationsOnDimensions != null) { - for (int i = 0, max = this.annotationsOnDimensions.length; i < max; i++) { - Annotation[] annotations2 = this.annotationsOnDimensions[i]; - if (annotations2 != null) { - for (int j = 0, max2 = annotations2.length; j < max2; j++) { - Annotation annotation = annotations2[j]; + for (Annotation[] annotationsOnDimension : this.annotationsOnDimensions) { + if (annotationsOnDimension != null) { + for (Annotation annotation : annotationsOnDimension) { annotation.traverse(visitor, scope); } } @@ -295,8 +291,7 @@ public boolean hasNullTypeAnnotation(AnnotationPosition position) { if (this.resolvedType != null && !this.resolvedType.hasNullTypeAnnotations()) return false; // shortcut if (this.annotationsOnDimensions != null) { - for (int i = 0; i < this.annotationsOnDimensions.length; i++) { - Annotation[] innerAnnotations = this.annotationsOnDimensions[i]; + for (Annotation[] innerAnnotations : this.annotationsOnDimensions) { if (containsNullAnnotation(innerAnnotations)) return true; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java index 6c830cb3ce0..ee98c8b7423 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java @@ -200,8 +200,7 @@ public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo f // find and enable assertion support TypeDeclaration typeDeclaration = outerMostClass.scope.referenceType(); AbstractMethodDeclaration[] methods = typeDeclaration.methods; - for (int i = 0, max = methods.length; i < max; i++) { - AbstractMethodDeclaration method = methods[i]; + for (AbstractMethodDeclaration method : methods) { if (method.isClinit()) { ((Clinit) method).setAssertionSupport(this.assertionSyntheticFieldBinding, currentScope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_5); break; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Block.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Block.java index 3e3db4a8bb0..00ef6de2f0d 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Block.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Block.java @@ -44,8 +44,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl int complaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; CompilerOptions compilerOptions = currentScope.compilerOptions(); boolean enableSyntacticNullAnalysisForFields = compilerOptions.enableSyntacticNullAnalysisForFields; - for (int i = 0, max = this.statements.length; i < max; i++) { - Statement stat = this.statements[i]; + for (Statement stat : this.statements) { if ((complaintLevel = stat.complainIfUnreachable(flowInfo, this.scope, complaintLevel, true)) < Statement.COMPLAINED_UNREACHABLE) { flowInfo = stat.analyseCode(this.scope, flowContext, flowInfo); } @@ -101,8 +100,8 @@ public boolean isEmptyBlock() { public StringBuilder printBody(int indent, StringBuilder output) { if (this.statements == null) return output; - for (int i = 0; i < this.statements.length; i++) { - this.statements[i].printStatement(indent + 1, output); + for (Statement statement : this.statements) { + statement.printStatement(indent + 1, output); output.append('\n'); } return output; @@ -145,8 +144,8 @@ public void resolveUsing(BlockScope givenScope) { public void traverse(ASTVisitor visitor, BlockScope blockScope) { if (visitor.visit(this, blockScope)) { if (this.statements != null) { - for (int i = 0, length = this.statements.length; i < length; i++) - this.statements[i].traverse(visitor, this.scope); + for (Statement statement : this.statements) + statement.traverse(visitor, this.scope); } } visitor.endVisit(this, blockScope); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java index b5673d938b1..dbed4fb4f54 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java @@ -141,8 +141,8 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { } int pc = codeStream.position; if (this.targetLabels != null) { - for (int i = 0, l = this.targetLabels.length; i < l; ++i) { - this.targetLabels[i].place(); + for (BranchLabel label : this.targetLabels) { + label.place(); } } if (this.targetLabel != null) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Clinit.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Clinit.java index ff59204efe0..b95100a14ab 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Clinit.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Clinit.java @@ -74,8 +74,7 @@ public void analyseCode( // check missing blank final field initializations flowInfo = flowInfo.mergedWith(staticInitializerFlowContext.initsOnReturn); FieldBinding[] fields = this.scope.enclosingSourceType().fields(); - for (int i = 0, count = fields.length; i < count; i++) { - FieldBinding field = fields[i]; + for (FieldBinding field : fields) { if (field.isStatic()) { if (!flowInfo.isDefinitelyAssigned(field)) { if (field.isFinal()) { @@ -256,8 +255,7 @@ private void generateCode( } } } else if (fieldDeclarations != null) { - for (int i = 0, max = fieldDeclarations.length; i < max; i++) { - FieldDeclaration fieldDecl = fieldDeclarations[i]; + for (FieldDeclaration fieldDecl : fieldDeclarations) { if (fieldDecl.isStatic()) { if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { fieldDecl.generateCode(staticInitializerScope, codeStream); @@ -273,8 +271,7 @@ private void generateCode( codeStream.anewarray(declaringType.binding); if (enumCount > 0) { if (fieldDeclarations != null) { - for (int i = 0, max = fieldDeclarations.length; i < max; i++) { - FieldDeclaration fieldDecl = fieldDeclarations[i]; + for (FieldDeclaration fieldDecl : fieldDeclarations) { // $VALUES[i] = if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { codeStream.dup(); @@ -314,8 +311,7 @@ private void generateCode( } } else { if (fieldDeclarations != null) { - for (int i = 0, max = fieldDeclarations.length; i < max; i++) { - FieldDeclaration fieldDecl = fieldDeclarations[i]; + for (FieldDeclaration fieldDecl : fieldDeclarations) { switch (fieldDecl.getKind()) { case AbstractVariableDeclaration.INITIALIZER : if (!fieldDecl.isStatic()) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java index ba617d368cf..66459d6e9b7 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java @@ -133,8 +133,8 @@ public void analyseCode() { return; try { if (this.types != null) { - for (int i = 0, count = this.types.length; i < count; i++) { - this.types[i].analyseCode(this.scope); + for (TypeDeclaration t : this.types) { + t.analyseCode(this.scope); } } if (this.moduleDeclaration != null) { @@ -154,8 +154,8 @@ public void analyseCode() { */ public void cleanUp() { if (this.types != null) { - for (int i = 0, max = this.types.length; i < max; i++) { - cleanUp(this.types[i]); + for (TypeDeclaration t : this.types) { + cleanUp(t); } for (LocalTypeBinding localType : this.localTypes.values()) { // null out the type's scope backpointers @@ -172,9 +172,8 @@ public void cleanUp() { this.compilationResult.recoveryScannerData = null; // recovery is already done ClassFile[] classFiles = this.compilationResult.getClassFiles(); - for (int i = 0, max = classFiles.length; i < max; i++) { + for (ClassFile classFile : classFiles) { // clear the classFile back pointer to the bindings - ClassFile classFile = classFiles[i]; // null out the classfile backpointer to a type binding classFile.referenceBinding = null; classFile.innerClassesBindings = null; @@ -191,8 +190,8 @@ public void cleanUp() { private void cleanUp(TypeDeclaration type) { if (type.memberTypes != null) { - for (int i = 0, max = type.memberTypes.length; i < max; i++){ - cleanUp(type.memberTypes[i]); + for (TypeDeclaration memberType : type.memberTypes) { + cleanUp(memberType); } } if (type.binding != null && type.binding.isAnnotationType()) @@ -205,8 +204,7 @@ private void cleanUp(TypeDeclaration type) { public void checkUnusedImports(){ if (this.scope.imports != null){ - for (int i = 0, max = this.scope.imports.length; i < max; i++){ - ImportBinding importBinding = this.scope.imports[i]; + for (ImportBinding importBinding : this.scope.imports) { ImportReference importReference = importBinding.reference; if (importReference != null && ((importReference.bits & ASTNode.Used) == 0)){ this.scope.problemReporter().unusedImport(importReference); @@ -235,8 +233,8 @@ public void createPackageInfoType() { * e.g. if we're looking for X.A.B then a type name would be {X, A, B} */ public TypeDeclaration declarationOfType(char[][] typeName) { - for (int i = 0; i < this.types.length; i++) { - TypeDeclaration typeDecl = this.types[i].declarationOfType(typeName); + for (TypeDeclaration t : this.types) { + TypeDeclaration typeDecl = t.declarationOfType(typeName); if (typeDecl != null) { return typeDecl; } @@ -410,8 +408,8 @@ public void generateCode() { } try { if (this.types != null) { - for (int i = 0, count = this.types.length; i < count; i++) - this.types[i].generateCode(this.scope); + for (TypeDeclaration t : this.types) + t.generateCode(this.scope); } if (this.moduleDeclaration != null) { this.moduleDeclaration.generateCode(); @@ -494,9 +492,8 @@ public StringBuilder print(int indent, StringBuilder output) { this.currentPackage.print(0, output, false).append(";\n"); //$NON-NLS-1$ } if (this.imports != null) - for (int i = 0; i < this.imports.length; i++) { + for (ImportReference currentImport : this.imports) { printIndent(indent, output).append("import "); //$NON-NLS-1$ - ImportReference currentImport = this.imports[i]; if (currentImport.isStatic()) { output.append("static "); //$NON-NLS-1$ } @@ -505,8 +502,8 @@ public StringBuilder print(int indent, StringBuilder output) { if (this.moduleDeclaration != null) { this.moduleDeclaration.print(indent, output).append("\n"); //$NON-NLS-1$ } else if (this.types != null) { - for (int i = 0; i < this.types.length; i++) { - this.types[i].print(indent, output).append("\n"); //$NON-NLS-1$ + for (TypeDeclaration t : this.types) { + t.print(indent, output).append("\n"); //$NON-NLS-1$ } } return output; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java index 9fdb32469ad..5e75b4d53ca 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java @@ -115,8 +115,7 @@ public void analyseCode(ClassScope classScope, InitializationFlowContext initial // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780 if (this.typeParameters != null && !this.scope.referenceCompilationUnit().compilationResult.hasSyntaxError) { - for (int i = 0, length = this.typeParameters.length; i < length; ++i) { - TypeParameter typeParameter = this.typeParameters[i]; + for (TypeParameter typeParameter : this.typeParameters) { if ((typeParameter.binding.modifiers & ExtraCompilerModifiers.AccLocallyUsed) == 0) { this.scope.problemReporter().unusedTypeParameter(typeParameter); } @@ -158,9 +157,8 @@ public void analyseCode(ClassScope classScope, InitializationFlowContext initial // set since they are supposed to be set inside other local constructor if (this.constructorCall.accessMode == ExplicitConstructorCall.This) { FieldBinding[] fields = this.binding.declaringClass.fields(); - for (int i = 0, count = fields.length; i < count; i++) { - FieldBinding field; - if (!(field = fields[i]).isStatic()) { + for (FieldBinding field : fields) { + if (!field.isStatic()) { flowInfo.markAsDefinitelyAssigned(field); } } @@ -176,8 +174,7 @@ public void analyseCode(ClassScope classScope, InitializationFlowContext initial CompilerOptions compilerOptions = this.scope.compilerOptions(); boolean enableSyntacticNullAnalysisForFields = compilerOptions.enableSyntacticNullAnalysisForFields; int complaintLevel = (nonStaticFieldInfoReachMode & FlowInfo.UNREACHABLE) == 0 ? Statement.NOT_COMPLAINED : Statement.COMPLAINED_FAKE_REACHABLE; - for (int i = 0, count = this.statements.length; i < count; i++) { - Statement stat = this.statements[i]; + for (Statement stat : this.statements) { if ((complaintLevel = stat.complainIfUnreachable(flowInfo, this.scope, complaintLevel, true)) < Statement.COMPLAINED_UNREACHABLE) { flowInfo = stat.analyseCode(this.scope, constructorContext, flowInfo); } @@ -217,8 +214,7 @@ public void analyseCode(ClassScope classScope, InitializationFlowContext initial } } protected void doFieldReachAnalysis(FlowInfo flowInfo, FieldBinding[] fields) { - for (int i = 0, count = fields.length; i < count; i++) { - FieldBinding field = fields[i]; + for (FieldBinding field : fields) { if (!field.isStatic() && !flowInfo.isDefinitelyAssigned(field)) { if (field.isFinal()) { this.scope.problemReporter().uninitializedBlankFinalField( @@ -254,18 +250,18 @@ boolean isValueProvidedUsingAnnotation(FieldDeclaration fieldDecl) { MemberValuePair[] memberValuePairs = annotation.memberValuePairs(); if (memberValuePairs == Annotation.NoValuePairs) return true; - for (int j = 0; j < memberValuePairs.length; j++) { + for (MemberValuePair memberValuePair : memberValuePairs) { // if "optional=false" is specified, don't rely on initialization by the injector: - if (CharOperation.equals(memberValuePairs[j].name, TypeConstants.OPTIONAL)) - return memberValuePairs[j].value instanceof FalseLiteral; + if (CharOperation.equals(memberValuePair.name, TypeConstants.OPTIONAL)) + return memberValuePair.value instanceof FalseLiteral; } } else if (annotation.resolvedType.id == TypeIds.T_OrgSpringframeworkBeansFactoryAnnotationAutowired) { MemberValuePair[] memberValuePairs = annotation.memberValuePairs(); if (memberValuePairs == Annotation.NoValuePairs) return true; - for (int j = 0; j < memberValuePairs.length; j++) { - if (CharOperation.equals(memberValuePairs[j].name, TypeConstants.REQUIRED)) - return memberValuePairs[j].value instanceof TrueLiteral; + for (MemberValuePair memberValuePair : memberValuePairs) { + if (CharOperation.equals(memberValuePair.name, TypeConstants.REQUIRED)) + return memberValuePair.value instanceof TrueLiteral; } } } @@ -352,9 +348,8 @@ public void generateSyntheticFieldInitializationsIfNecessary(MethodScope methodS SyntheticArgumentBinding[] syntheticArgs = nestedType.syntheticEnclosingInstances(); if (syntheticArgs != null) { - for (int i = 0, max = syntheticArgs.length; i < max; i++) { - SyntheticArgumentBinding syntheticArg; - if ((syntheticArg = syntheticArgs[i]).matchingField != null) { + for (SyntheticArgumentBinding syntheticArg : syntheticArgs) { + if (syntheticArg.matchingField != null) { codeStream.aload_0(); codeStream.load(syntheticArg); codeStream.fieldAccess(Opcodes.OPC_putfield, syntheticArg.matchingField, null /* default declaringClass */); @@ -363,9 +358,8 @@ public void generateSyntheticFieldInitializationsIfNecessary(MethodScope methodS } syntheticArgs = nestedType.syntheticOuterLocalVariables(); if (syntheticArgs != null) { - for (int i = 0, max = syntheticArgs.length; i < max; i++) { - SyntheticArgumentBinding syntheticArg; - if ((syntheticArg = syntheticArgs[i]).matchingField != null) { + for (SyntheticArgumentBinding syntheticArg : syntheticArgs) { + if (syntheticArg.matchingField != null) { codeStream.aload_0(); codeStream.load(syntheticArg); codeStream.fieldAccess(Opcodes.OPC_putfield, syntheticArg.matchingField, null /* default declaringClass */); @@ -404,10 +398,10 @@ private void internalGenerateCode(ClassScope classScope, ClassFile classFile) { } if (this.arguments != null) { - for (int i = 0, max = this.arguments.length; i < max; i++) { + for (Argument argument : this.arguments) { // arguments initialization for local variable debug attributes LocalVariableBinding argBinding; - codeStream.addVisibleLocalVariable(argBinding = this.arguments[i].binding); + codeStream.addVisibleLocalVariable(argBinding = argument.binding); argBinding.recordInitializationStartPC(0); switch(argBinding.type.id) { case TypeIds.T_long : @@ -445,9 +439,9 @@ private void internalGenerateCode(ClassScope classScope, ClassFile classFile) { } // generate user field initialization if (declaringType.fields != null) { - for (int i = 0, max = declaringType.fields.length; i < max; i++) { + for (FieldDeclaration field : declaringType.fields) { FieldDeclaration fieldDecl; - if (!(fieldDecl = declaringType.fields[i]).isStatic()) { + if (!(fieldDecl = field).isStatic()) { fieldDecl.generateCode(initializerScope, codeStream); } } @@ -455,8 +449,8 @@ private void internalGenerateCode(ClassScope classScope, ClassFile classFile) { } // generate statements if (this.statements != null) { - for (int i = 0, max = this.statements.length; i < max; i++) { - this.statements[i].generateCode(this.scope, codeStream); + for (Statement statement : this.statements) { + statement.generateCode(this.scope, codeStream); } } // if a problem got reported during code gen, then trigger problem method creation @@ -527,8 +521,7 @@ public void getAllAnnotationContexts(int targetType, List allAnnotationContexts) TypeReference fakeReturnType = new SingleTypeReference(this.selector, 0); fakeReturnType.resolvedType = this.binding.declaringClass; AnnotationCollector collector = new AnnotationCollector(fakeReturnType, targetType, allAnnotationContexts); - for (int i = 0, max = this.annotations.length; i < max; i++) { - Annotation annotation = this.annotations[i]; + for (Annotation annotation : this.annotations) { annotation.traverse(collector, (BlockScope) null); } } @@ -604,9 +597,9 @@ public StringBuilder printBody(int indent, StringBuilder output) { this.constructorCall.printStatement(indent, output); } if (this.statements != null) { - for (int i = 0; i < this.statements.length; i++) { + for (Statement statement : this.statements) { output.append('\n'); - this.statements[i].printStatement(indent, output); + statement.printStatement(indent, output); } } output.append('\n'); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ContainerAnnotation.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ContainerAnnotation.java index b865829a8aa..f0b038cf677 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ContainerAnnotation.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ContainerAnnotation.java @@ -79,8 +79,7 @@ public TypeBinding resolveType(BlockScope scope) { MethodBinding[] methods = containerAnnotationType.methods(); MemberValuePair pair = memberValuePairs()[0]; - for (int i = 0, length = methods.length; i < length; i++) { - MethodBinding method = methods[i]; + for (MethodBinding method : methods) { if (CharOperation.equals(method.selector, TypeConstants.VALUE)) { pair.binding = method; pair.resolveTypeExpecting(scope, method.returnType); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java index 9f8168aaefa..8c748c1d1ee 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java @@ -321,13 +321,13 @@ public void resolve(BlockScope scope) { this.qualification.resolveType(scope); } if (this.typeArguments != null) { - for (int i = 0, max = this.typeArguments.length; i < max; i++) { - this.typeArguments[i].resolveType(scope, true /* check bounds*/); + for (TypeReference typeArgument : this.typeArguments) { + typeArgument.resolveType(scope, true /* check bounds*/); } } if (this.arguments != null) { - for (int i = 0, max = this.arguments.length; i < max; i++) { - this.arguments[i].resolveType(scope); + for (Expression argument : this.arguments) { + argument.resolveType(scope); } } return; @@ -383,8 +383,8 @@ public void resolve(BlockScope scope) { } if (argHasError) { if (this.arguments != null) { // still attempt to resolve arguments - for (int i = 0, max = this.arguments.length; i < max; i++) { - this.arguments[i].resolveType(scope); + for (Expression argument : this.arguments) { + argument.resolveType(scope); } } return; @@ -514,13 +514,13 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { this.qualification.traverse(visitor, scope); } if (this.typeArguments != null) { - for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) { - this.typeArguments[i].traverse(visitor, scope); + for (TypeReference typeArgument : this.typeArguments) { + typeArgument.traverse(visitor, scope); } } if (this.arguments != null) { - for (int i = 0, argumentLength = this.arguments.length; i < argumentLength; i++) - this.arguments[i].traverse(visitor, scope); + for (Expression argument : this.arguments) + argument.traverse(visitor, scope); } } visitor.endVisit(this, scope); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Expression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Expression.java index 64d75d8255b..87419ccedc4 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Expression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Expression.java @@ -323,8 +323,8 @@ public final boolean checkCastTypesCompatibility(Scope scope, TypeBinding castTy if (castType.isIntersectionType18()) { ReferenceBinding [] intersectingTypes = castType.getIntersectingTypes(); - for (int i = 0, length = intersectingTypes.length; i < length; i++) { - if (!checkCastTypesCompatibility(scope, intersectingTypes[i], expressionType, expression, useAutoBoxing)) + for (ReferenceBinding intersectingType : intersectingTypes) { + if (!checkCastTypesCompatibility(scope, intersectingType, expressionType, expression, useAutoBoxing)) return false; } return true; @@ -418,8 +418,8 @@ public final boolean checkCastTypesCompatibility(Scope scope, TypeBinding castTy return checkCastTypesCompatibility(scope, castType, bound, expression, useAutoBoxing); case Binding.INTERSECTION_TYPE18: ReferenceBinding [] intersectingTypes = expressionType.getIntersectingTypes(); - for (int i = 0, length = intersectingTypes.length; i < length; i++) { - if (checkCastTypesCompatibility(scope, castType, intersectingTypes[i], expression, useAutoBoxing)) + for (ReferenceBinding intersectingType : intersectingTypes) { + if (checkCastTypesCompatibility(scope, castType, intersectingType, expression, useAutoBoxing)) return true; } return false; @@ -481,11 +481,11 @@ public final boolean checkCastTypesCompatibility(Scope scope, TypeBinding castTy MethodBinding[] castTypeMethods = getAllOriginalInheritedMethods((ReferenceBinding) castType); MethodBinding[] expressionTypeMethods = getAllOriginalInheritedMethods((ReferenceBinding) expressionType); int exprMethodsLength = expressionTypeMethods.length; - for (int i = 0, castMethodsLength = castTypeMethods.length; i < castMethodsLength; i++) { + for (MethodBinding castTypeMethod : castTypeMethods) { for (int j = 0; j < exprMethodsLength; j++) { - if ((TypeBinding.notEquals(castTypeMethods[i].returnType, expressionTypeMethods[j].returnType)) - && (CharOperation.equals(castTypeMethods[i].selector, expressionTypeMethods[j].selector)) - && castTypeMethods[i].areParametersEqual(expressionTypeMethods[j])) { + if ((TypeBinding.notEquals(castTypeMethod.returnType, expressionTypeMethods[j].returnType)) + && (CharOperation.equals(castTypeMethod.selector, expressionTypeMethods[j].selector)) + && castTypeMethod.areParametersEqual(expressionTypeMethods[j])) { return false; } @@ -952,12 +952,12 @@ private MethodBinding[] getAllOriginalInheritedMethods(ReferenceBinding binding) private void getAllInheritedMethods0(ReferenceBinding binding, ArrayList collector) { if (!binding.isInterface()) return; MethodBinding[] methodBindings = binding.methods(); - for (int i = 0, max = methodBindings.length; i < max; i++) { - collector.add(methodBindings[i]); + for (MethodBinding methodBinding : methodBindings) { + collector.add(methodBinding); } ReferenceBinding[] superInterfaces = binding.superInterfaces(); - for (int i = 0, max = superInterfaces.length; i < max; i++) { - getAllInheritedMethods0(superInterfaces[i], collector); + for (ReferenceBinding superInterface : superInterfaces) { + getAllInheritedMethods0(superInterface, collector); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java index 5b3250f245b..871fdd8afad 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java @@ -19,7 +19,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.function.Consumer; @@ -1445,10 +1444,8 @@ public boolean reportRecordedErrors(Scope scope, int mergedStatus, boolean atDea } boolean hasReported = false; if (this.recordedLocations != null) { - Iterator> locations = this.recordedLocations.entrySet().iterator(); int reportFlags = 0; - while (locations.hasNext()) { - Entry entry = locations.next(); + for (Entry entry : this.recordedLocations.entrySet()) { reportFlags |= reportError(scope.problemReporter(), entry.getKey(), entry.getValue().intValue()); hasReported = true; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java index 092816d3830..eff6702c2df 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java @@ -167,8 +167,7 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { } public void getAllAnnotationContexts(int targetType, List allAnnotationContexts) { AnnotationCollector collector = new AnnotationCollector(this.type, targetType, allAnnotationContexts); - for (int i = 0, max = this.annotations.length; i < max; i++) { - Annotation annotation = this.annotations[i]; + for (Annotation annotation : this.annotations) { annotation.traverse(collector, (BlockScope) null); } } @@ -273,8 +272,8 @@ public void resolve(MethodScope initializationScope) { resolveAnnotations(initializationScope, this.annotations, this.binding); // Check if this declaration should now have the type annotations bit set if (this.annotations != null) { - for (int i = 0, max = this.annotations.length; i < max; i++) { - TypeBinding resolvedAnnotationType = this.annotations[i].resolvedType; + for (Annotation annotation : this.annotations) { + TypeBinding resolvedAnnotationType = annotation.resolvedType; if (resolvedAnnotationType != null && (resolvedAnnotationType.getAnnotationTagBits() & TagBits.AnnotationForTypeUse) != 0) { this.bits |= ASTNode.HasTypeAnnotations; break; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ForStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ForStatement.java index ce97603d3ac..29bff97e8f7 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ForStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ForStatement.java @@ -81,8 +81,8 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl // process the initializations if (this.initializations != null) { - for (int i = 0, count = this.initializations.length; i < count; i++) { - flowInfo = this.initializations[i].analyseCode(this.scope, flowContext, flowInfo); + for (Statement initialization : this.initializations) { + flowInfo = initialization.analyseCode(this.scope, flowContext, flowInfo); } } this.preCondInitStateIndex = @@ -187,8 +187,8 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl FlowInfo incrementInfo = actionInfo; this.preIncrementsInitStateIndex = currentScope.methodScope().recordInitializationStates(incrementInfo); - for (int i = 0, count = this.increments.length; i < count; i++) { - incrementInfo = this.increments[i]. + for (Statement increment : this.increments) { + incrementInfo = increment. analyseCode(this.scope, incrementContext, incrementInfo); } incrementContext.complainOnDeferredFinalChecks(this.scope, @@ -236,8 +236,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl // Variables initialized only for the purpose of the for loop can be removed for further flow info // https://bugs.eclipse.org/bugs/show_bug.cgi?id=359495 if (this.initializations != null) { - for (int i = 0; i < this.initializations.length; i++) { - Statement init = this.initializations[i]; + for (Statement init : this.initializations) { if (init instanceof LocalDeclaration) { LocalVariableBinding binding = ((LocalDeclaration) init).binding; mergedInfo.resetAssignmentInfo(binding); @@ -266,8 +265,8 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { // generate the initializations if (this.initializations != null) { - for (int i = 0, max = this.initializations.length; i < max; i++) { - this.initializations[i].generateCode(this.scope, codeStream); + for (Statement initialization : this.initializations) { + initialization.generateCode(this.scope, codeStream); } } Constant cst = this.condition == null ? null : this.condition.optimizedBooleanConstant(); @@ -339,8 +338,8 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { this.continueLabel.place(); // generate the increments for next iteration if (this.increments != null) { - for (int i = 0, max = this.increments.length; i < max; i++) { - this.increments[i].generateCode(this.scope, codeStream); + for (Statement increment : this.increments) { + increment.generateCode(this.scope, codeStream); } } // May loose some local variable initializations : affecting the local variable attributes @@ -427,8 +426,8 @@ public void resolve(BlockScope upperScope) { // use the scope that will hold the init declarations this.scope = (this.bits & ASTNode.NeededScope) != 0 ? new BlockScope(upperScope) : upperScope; if (this.initializations != null) - for (int i = 0, length = this.initializations.length; i < length; i++) - this.initializations[i].resolve(this.scope); + for (Statement initialization : this.initializations) + initialization.resolve(this.scope); if (this.condition != null) { if ((this.bits & ASTNode.NeededScope) != 0) { // We have created a new scope for for-inits and the condition has to be resolved in that scope. @@ -442,8 +441,8 @@ public void resolve(BlockScope upperScope) { patternVariablesInTrueScope = this.condition.bindingsWhenTrue(); } if (this.increments != null) - for (int i = 0, length = this.increments.length; i < length; i++) { - this.increments[i].resolveWithBindings(patternVariablesInTrueScope, this.scope); + for (Statement increment : this.increments) { + increment.resolveWithBindings(patternVariablesInTrueScope, this.scope); } if (this.action != null) { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java index e61eb266f36..6dd455c6e13 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/FunctionalExpression.java @@ -205,8 +205,8 @@ public TypeBinding resolveType(BlockScope blockScope, boolean skipKosherCheck) { if (skipKosherCheck || kosherDescriptor(blockScope, sam, true)) { if (this.expectedType instanceof IntersectionTypeBinding18) { ReferenceBinding[] intersectingTypes = ((IntersectionTypeBinding18)this.expectedType).intersectingTypes; - for (int t = 0, max = intersectingTypes.length; t < max; t++) { - if (intersectingTypes[t].findSuperTypeOriginatingFrom(TypeIds.T_JavaIoSerializable, false /*Serializable is not a class*/) != null) { + for (ReferenceBinding intersectingType : intersectingTypes) { + if (intersectingType.findSuperTypeOriginatingFrom(TypeIds.T_JavaIoSerializable, false /*Serializable is not a class*/) != null) { this.isSerializable = true; break; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java index 40dc3e7f22b..9cb8ab99bcf 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java @@ -38,8 +38,8 @@ public IntersectionCastTypeReference(TypeReference[] typeReferences) { this.sourceStart = typeReferences[0].sourceStart; int length = typeReferences.length; this.sourceEnd = typeReferences[length - 1].sourceEnd; - for (int i = 0, max = typeReferences.length; i < max; i++) { - if ((typeReferences[i].bits & ASTNode.HasTypeAnnotations) != 0) { + for (TypeReference reference : typeReferences) { + if ((reference.bits & ASTNode.HasTypeAnnotations) != 0) { this.bits |= ASTNode.HasTypeAnnotations; break; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Javadoc.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Javadoc.java index 8b16c46bb81..c9350927fad 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Javadoc.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Javadoc.java @@ -127,9 +127,9 @@ public ASTNode getNodeStartingAt(int start) { // if binding is valid then look at arguments if (allocationExpr.binding != null && allocationExpr.binding.isValidBinding()) { if (allocationExpr.arguments != null) { - for (int j=0, l=allocationExpr.arguments.length; j\n"); //$NON-NLS-1$ + paramTypeParameter.print(indent, output).append(">\n"); //$NON-NLS-1$ } } if (this.returnStatement != null) { @@ -196,15 +196,15 @@ public StringBuilder print(int indent, StringBuilder output) { this.returnStatement.print(indent, output).append('\n'); } if (this.exceptionReferences != null) { - for (int i = 0, length = this.exceptionReferences.length; i < length; i++) { + for (TypeReference reference : this.exceptionReferences) { printIndent(indent + 1, output).append(" * @throws "); //$NON-NLS-1$ - this.exceptionReferences[i].print(indent, output).append('\n'); + reference.print(indent, output).append('\n'); } } if (this.seeReferences != null) { - for (int i = 0, length = this.seeReferences.length; i < length; i++) { + for (Expression reference : this.seeReferences) { printIndent(indent + 1, output).append(" * @see "); //$NON-NLS-1$ - this.seeReferences[i].print(indent, output).append('\n'); + reference.print(indent, output).append('\n'); } } printIndent(indent, output).append(" */\n"); //$NON-NLS-1$ @@ -843,8 +843,7 @@ private void resolveTypeParameterTags(Scope scope, boolean reportMissing) { } // Look for undocumented arguments if (reportMissing) { - for (int i = 0; i < recordParameters.length; i++) { - RecordComponent component = recordParameters[i]; + for (RecordComponent component : recordParameters) { boolean found = false; for (int j = 0; j < paramReferencesLength && !found; j++) { JavadocSingleNameReference param = this.paramReferences[j]; @@ -863,8 +862,7 @@ private void resolveTypeParameterTags(Scope scope, boolean reportMissing) { JavadocSingleNameReference param = this.paramReferences[i]; String paramName = new String(param.getName()[0]); boolean found = false; - for (int j = 0; j < recordParameters.length; j++) { - RecordComponent component = recordParameters[j]; + for (RecordComponent component : recordParameters) { if (paramName.equals(new String(component.name))) { found = true; } @@ -1219,26 +1217,26 @@ private boolean verifyModuleReference(Expression reference, Expression typeRefer public void traverse(ASTVisitor visitor, BlockScope scope) { if (visitor.visit(this, scope)) { if (this.paramReferences != null) { - for (int i = 0, length = this.paramReferences.length; i < length; i++) { - this.paramReferences[i].traverse(visitor, scope); + for (JavadocSingleNameReference paramReference : this.paramReferences) { + paramReference.traverse(visitor, scope); } } if (this.paramTypeParameters != null) { - for (int i = 0, length = this.paramTypeParameters.length; i < length; i++) { - this.paramTypeParameters[i].traverse(visitor, scope); + for (JavadocSingleTypeReference paramTypeParameter : this.paramTypeParameters) { + paramTypeParameter.traverse(visitor, scope); } } if (this.returnStatement != null) { this.returnStatement.traverse(visitor, scope); } if (this.exceptionReferences != null) { - for (int i = 0, length = this.exceptionReferences.length; i < length; i++) { - this.exceptionReferences[i].traverse(visitor, scope); + for (TypeReference exceptionReference : this.exceptionReferences) { + exceptionReference.traverse(visitor, scope); } } if (this.seeReferences != null) { - for (int i = 0, length = this.seeReferences.length; i < length; i++) { - this.seeReferences[i].traverse(visitor, scope); + for (Expression seeReference : this.seeReferences) { + seeReference.traverse(visitor, scope); } } } @@ -1247,26 +1245,26 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { public void traverse(ASTVisitor visitor, ClassScope scope) { if (visitor.visit(this, scope)) { if (this.paramReferences != null) { - for (int i = 0, length = this.paramReferences.length; i < length; i++) { - this.paramReferences[i].traverse(visitor, scope); + for (JavadocSingleNameReference paramReference : this.paramReferences) { + paramReference.traverse(visitor, scope); } } if (this.paramTypeParameters != null) { - for (int i = 0, length = this.paramTypeParameters.length; i < length; i++) { - this.paramTypeParameters[i].traverse(visitor, scope); + for (JavadocSingleTypeReference paramTypeParameter : this.paramTypeParameters) { + paramTypeParameter.traverse(visitor, scope); } } if (this.returnStatement != null) { this.returnStatement.traverse(visitor, scope); } if (this.exceptionReferences != null) { - for (int i = 0, length = this.exceptionReferences.length; i < length; i++) { - this.exceptionReferences[i].traverse(visitor, scope); + for (TypeReference exceptionReference : this.exceptionReferences) { + exceptionReference.traverse(visitor, scope); } } if (this.seeReferences != null) { - for (int i = 0, length = this.seeReferences.length; i < length; i++) { - this.seeReferences[i].traverse(visitor, scope); + for (Expression seeReference : this.seeReferences) { + seeReference.traverse(visitor, scope); } } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/JavadocAllocationExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/JavadocAllocationExpression.java index d0c1c6d56a3..ea542cc5c0d 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/JavadocAllocationExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/JavadocAllocationExpression.java @@ -168,16 +168,16 @@ public TypeBinding resolveType(ClassScope scope) { public void traverse(ASTVisitor visitor, BlockScope scope) { if (visitor.visit(this, scope)) { if (this.typeArguments != null) { - for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) { - this.typeArguments[i].traverse(visitor, scope); + for (TypeReference typeArgument : this.typeArguments) { + typeArgument.traverse(visitor, scope); } } if (this.type != null) { // enum constant scenario this.type.traverse(visitor, scope); } if (this.arguments != null) { - for (int i = 0, argumentsLength = this.arguments.length; i < argumentsLength; i++) - this.arguments[i].traverse(visitor, scope); + for (Expression argument : this.arguments) + argument.traverse(visitor, scope); } } visitor.endVisit(this, scope); @@ -186,16 +186,16 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { public void traverse(ASTVisitor visitor, ClassScope scope) { if (visitor.visit(this, scope)) { if (this.typeArguments != null) { - for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) { - this.typeArguments[i].traverse(visitor, scope); + for (TypeReference typeArgument : this.typeArguments) { + typeArgument.traverse(visitor, scope); } } if (this.type != null) { // enum constant scenario this.type.traverse(visitor, scope); } if (this.arguments != null) { - for (int i = 0, argumentsLength = this.arguments.length; i < argumentsLength; i++) - this.arguments[i].traverse(visitor, scope); + for (Expression argument : this.arguments) + argument.traverse(visitor, scope); } } visitor.endVisit(this, scope); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java index 778cdda0ed1..52b1df80124 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java @@ -600,8 +600,8 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, fi AbstractMethodDeclaration.analyseArguments(currentScope.environment(), lambdaInfo, flowContext, this.arguments, methodWithParameterDeclaration); if (this.arguments != null) { - for (int i = 0, count = this.arguments.length; i < count; i++) { - this.bits |= (this.arguments[i].bits & ASTNode.HasTypeAnnotations); + for (Argument argument : this.arguments) { + this.bits |= (argument.bits & ASTNode.HasTypeAnnotations); } } @@ -656,8 +656,7 @@ private void mergeParameterNullAnnotations(BlockScope currentScope) { if (ourTagBits == 0L) { if (descTagBits != 0L && !ourParameters[i].isBaseType()) { AnnotationBinding [] annotations = descParameters[i].getTypeAnnotations(); - for (int j = 0, length = annotations.length; j < length; j++) { - AnnotationBinding annotation = annotations[j]; + for (AnnotationBinding annotation : annotations) { if (annotation != null && annotation.getAnnotationType().hasNullBit(TypeIds.BitNonNullAnnotation|TypeIds.BitNullableAnnotation)) { ourParameters[i] = env.createAnnotatedType(ourParameters[i], new AnnotationBinding [] { annotation }); } @@ -728,8 +727,8 @@ public boolean visit(ReturnStatement returnStatement, BlockScope skope) { } else { Expression [] returnExpressions = this.resultExpressions; if (returnExpressions != NO_EXPRESSIONS) { - for (int i = 0, length = returnExpressions.length; i < length; i++) { - if (!returnExpressions[i].isPertinentToApplicability(targetType, method)) + for (Expression returnExpression : returnExpressions) { + if (!returnExpression.isPertinentToApplicability(targetType, method)) return false; } } else { @@ -950,10 +949,10 @@ CompatibilityResult internalIsCompatibleWith(TypeBinding targetType, Scope skope return CompatibilityResult.INCOMPATIBLE; Expression [] returnExpressions = copy.resultExpressions; - for (int i = 0, length = returnExpressions.length; i < length; i++) { + for (Expression returnExpression : returnExpressions) { if (sam.returnType.isProperType(true) // inference variables can reach here during nested inference - && this.enclosingScope.parameterCompatibilityLevel(returnExpressions[i].resolvedType, sam.returnType) == Scope.NOT_COMPATIBLE) { - if (!returnExpressions[i].isConstantValueOfTypeAssignableToType(returnExpressions[i].resolvedType, sam.returnType)) + && this.enclosingScope.parameterCompatibilityLevel(returnExpression.resolvedType, sam.returnType) == Scope.NOT_COMPATIBLE) { + if (!returnExpression.isConstantValueOfTypeAssignableToType(returnExpression.resolvedType, sam.returnType)) if (sam.returnType.id != TypeIds.T_void || this.body instanceof Block) return CompatibilityResult.INCOMPATIBLE; } @@ -1314,18 +1313,18 @@ public void generateCode(ClassFile classFile) { // initialize local positions this.scope.computeLocalVariablePositions(this.outerLocalVariablesSlotSize + (this.binding.isStatic() ? 0 : 1), codeStream); if (this.outerLocalVariables != null) { - for (int i = 0, max = this.outerLocalVariables.length; i < max; i++) { + for (SyntheticArgumentBinding outerLocalVariable : this.outerLocalVariables) { LocalVariableBinding argBinding; - codeStream.addVisibleLocalVariable(argBinding = this.outerLocalVariables[i]); + codeStream.addVisibleLocalVariable(argBinding = outerLocalVariable); codeStream.record(argBinding); argBinding.recordInitializationStartPC(0); } } // arguments initialization for local variable debug attributes if (this.arguments != null) { - for (int i = 0, max = this.arguments.length; i < max; i++) { + for (Argument argument : this.arguments) { LocalVariableBinding argBinding; - codeStream.addVisibleLocalVariable(argBinding = this.arguments[i].binding); + codeStream.addVisibleLocalVariable(argBinding = argument.binding); argBinding.recordInitializationStartPC(0); } } @@ -1465,8 +1464,7 @@ public TypeBinding[] getMarkerInterfaces() { IntersectionTypeBinding18 intersectionType = (IntersectionTypeBinding18)this.expectedType; TypeBinding[] intersectionTypes = intersectionType.intersectingTypes; TypeBinding samType = intersectionType.getSAMType(this.enclosingScope); - for (int i = 0,max = intersectionTypes.length; i < max; i++) { - TypeBinding typeBinding = intersectionTypes[i]; + for (TypeBinding typeBinding : intersectionTypes) { if (!typeBinding.isInterface() // only interfaces || TypeBinding.equalsEquals(samType, typeBinding) // except for the samType itself || typeBinding.id == TypeIds.T_JavaIoSerializable) // but Serializable is captured as a bitflag diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java index b1693b8428b..7511228540b 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java @@ -144,11 +144,10 @@ public boolean visit(SingleNameReference reference, BlockScope scop) { ArrayInitializer initializer = (ArrayInitializer) this.value; final Expression[] expressions = initializer.expressions; if (expressions != null) { - for (int i =0, max = expressions.length; i < max; i++) { - Expression expression = expressions[i]; + for (Expression expression : expressions) { if (expression.resolvedType == null) continue; // fault-tolerance if (expression.constant == Constant.NotAConstant) { - scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, expressions[i], false); + scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, expression, false); } } } @@ -165,8 +164,7 @@ public boolean visit(SingleNameReference reference, BlockScope scop) { ArrayInitializer initializer = (ArrayInitializer) this.value; final Expression[] expressions = initializer.expressions; if (expressions != null) { - for (int i =0, max = expressions.length; i < max; i++) { - Expression currentExpression = expressions[i]; + for (Expression currentExpression : expressions) { if (!(currentExpression instanceof ClassLiteralAccess)) { scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass, this.name, currentExpression); } @@ -184,8 +182,7 @@ public boolean visit(SingleNameReference reference, BlockScope scop) { ArrayInitializer initializer = (ArrayInitializer) this.value; final Expression[] expressions = initializer.expressions; if (expressions != null) { - for (int i =0, max = expressions.length; i < max; i++) { - Expression currentExpression = expressions[i]; + for (Expression currentExpression : expressions) { if (currentExpression instanceof NullLiteral) { scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression, true); } else if (currentExpression instanceof NameReference) { @@ -225,8 +222,7 @@ public boolean visit(SingleNameReference reference, BlockScope scop) { ArrayInitializer initializer = (ArrayInitializer) this.value; final Expression[] expressions = initializer.expressions; if (expressions != null) { - for (int i =0, max = expressions.length; i < max; i++) { - Expression currentExpression = expressions[i]; + for (Expression currentExpression : expressions) { if (currentExpression instanceof NullLiteral || !(currentExpression instanceof Annotation)) { scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass, this.name, currentExpression, leafType); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java index 145a3826550..08e16380597 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java @@ -167,8 +167,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl } } else if (this.arguments != null && this.arguments.length > 0 && FakedTrackingVariable.isAnyCloseable(this.arguments[0].resolvedType)) { // Helper.closeMethod(closeable, ..) - for (int i=0; i= s; - // if ( z0 != (((short) 5) >= ((short) 5))) - // System.out.println(155); - - { s += "\t\t"+decode.type(result)+"0"+" = "+decode.type(left); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$ - s += " "+decode.operator(operator)+" "+decode.type(right)+";\n"; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$ - String begin = result == T_JavaLangString ? "\t\tif (! " : "\t\tif ( "; //$NON-NLS-2$ //$NON-NLS-1$ - String test = result == T_JavaLangString ? ".equals(" : " != ("; //$NON-NLS-2$ //$NON-NLS-1$ - s += begin +decode.type(result)+"0"+test //$NON-NLS-1$ - +decode.constant(left)+" " //$NON-NLS-1$ - +decode.operator(operator)+" " //$NON-NLS-1$ - +decode.constant(right)+"))\n"; //$NON-NLS-1$ - s += "\t\t\tSystem.out.println("+ (++error) +");\n"; //$NON-NLS-1$ //$NON-NLS-2$ + for (int operator : operators) { + for (int left = 0; left < 16; left++) { + for (int right = 0; right < 16; right++) { + int result = (OperatorSignatures[operator][(left << 4) + right]) & 0x0000F; + if (result != T_undefined) + + // 1/ First regular computation then 2/ comparaison + // with a compile time constant (generated by the compiler) + // z0 = s >= s; + // if ( z0 != (((short) 5) >= ((short) 5))) + // System.out.println(155); + + { + s += "\t\t" + decode.type(result) + "0" + " = " + decode.type(left); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$ + s += " " + decode.operator(operator) + " " + decode.type(right) + ";\n"; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$ + String begin = result == T_JavaLangString ? "\t\tif (! " : "\t\tif ( "; //$NON-NLS-2$ //$NON-NLS-1$ + String test = result == T_JavaLangString ? ".equals(" : " != ("; //$NON-NLS-2$ //$NON-NLS-1$ + s += begin + decode.type(result) + "0" + test //$NON-NLS-1$ + + decode.constant(left) + " " //$NON-NLS-1$ + + decode.operator(operator) + " " //$NON-NLS-1$ + + decode.constant(right) + "))\n"; //$NON-NLS-1$ + s += "\t\t\tSystem.out.println(" + (++error) + ");\n"; //$NON-NLS-1$ //$NON-NLS-2$ } } } + } return s += "\n\t\tSystem.out.println(\"binary tables test : done\");}"; //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/PackageVisibilityStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/PackageVisibilityStatement.java index 96adb6e559f..991b3139fd6 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/PackageVisibilityStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/PackageVisibilityStatement.java @@ -45,8 +45,7 @@ public boolean resolve(Scope scope) { boolean errorsExist = resolvePackageReference(scope) == null; if (this.isQualified()) { HashtableOfObject modules = new HashtableOfObject(this.targets.length); - for (int i = 0; i < this.targets.length; i++) { - ModuleReference ref = this.targets[i]; + for (ModuleReference ref : this.targets) { // targets will be resolved later (during ModuleDeclaration.resolveModuleDirectives()) if (modules.containsKey(ref.moduleName)) { scope.problemReporter().duplicateModuleReference(IProblem.DuplicateModuleRef, ref); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java index 55772cfbc3c..71a4a9d1be5 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java @@ -112,11 +112,10 @@ public boolean hasNullTypeAnnotation(AnnotationPosition position) { if (this.resolvedType != null && !this.resolvedType.hasNullTypeAnnotations()) return false; // shortcut if (this.typeArguments != null) { - for (int i = 0; i < this.typeArguments.length; i++) { - TypeReference[] arguments = this.typeArguments[i]; + for (TypeReference[] arguments : this.typeArguments) { if (arguments != null) { - for (int j = 0; j < arguments.length; j++) { - if (arguments[j].hasNullTypeAnnotation(position)) + for (TypeReference argument : arguments) { + if (argument.hasNullTypeAnnotation(position)) return true; } } @@ -483,18 +482,17 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { } Annotation [][] annotationsOnDimensions = getAnnotationsOnDimensions(true); if (annotationsOnDimensions != null) { - for (int i = 0, max = annotationsOnDimensions.length; i < max; i++) { - Annotation[] annotations2 = annotationsOnDimensions[i]; - for (int j = 0, max2 = annotations2 == null ? 0 : annotations2.length; j < max2; j++) { - Annotation annotation = annotations2[j]; + for (Annotation[] annotationsOnDimension : annotationsOnDimensions) { + for (int j = 0, max2 = annotationsOnDimension == null ? 0 : annotationsOnDimension.length; j < max2; j++) { + Annotation annotation = annotationsOnDimension[j]; annotation.traverse(visitor, scope); } } } - for (int i = 0, max = this.typeArguments.length; i < max; i++) { - if (this.typeArguments[i] != null) { - for (int j = 0, max2 = this.typeArguments[i].length; j < max2; j++) { - this.typeArguments[i][j].traverse(visitor, scope); + for (TypeReference[] typeArgument : this.typeArguments) { + if (typeArgument != null) { + for (TypeReference typeReference : typeArgument) { + typeReference.traverse(visitor, scope); } } } @@ -515,18 +513,17 @@ public void traverse(ASTVisitor visitor, ClassScope scope) { } Annotation [][] annotationsOnDimensions = getAnnotationsOnDimensions(true); if (annotationsOnDimensions != null) { - for (int i = 0, max = annotationsOnDimensions.length; i < max; i++) { - Annotation[] annotations2 = annotationsOnDimensions[i]; - for (int j = 0, max2 = annotations2 == null ? 0 : annotations2.length; j < max2; j++) { - Annotation annotation = annotations2[j]; + for (Annotation[] annotationsOnDimension : annotationsOnDimensions) { + for (int j = 0, max2 = annotationsOnDimension == null ? 0 : annotationsOnDimension.length; j < max2; j++) { + Annotation annotation = annotationsOnDimension[j]; annotation.traverse(visitor, scope); } } } - for (int i = 0, max = this.typeArguments.length; i < max; i++) { - if (this.typeArguments[i] != null) { - for (int j = 0, max2 = this.typeArguments[i].length; j < max2; j++) { - this.typeArguments[i][j].traverse(visitor, scope); + for (TypeReference[] typeArgument : this.typeArguments) { + if (typeArgument != null) { + for (TypeReference argument : typeArgument) { + argument.traverse(visitor, scope); } } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java index dc9ae7c2f7c..685ab9f07b0 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java @@ -45,8 +45,8 @@ public ParameterizedSingleTypeReference(char[] name, TypeReference[] typeArgumen super(name, dim, pos); this.originalSourceEnd = this.sourceEnd; this.typeArguments = typeArguments; - for (int i = 0, max = typeArguments.length; i < max; i++) { - if ((typeArguments[i].bits & ASTNode.HasTypeAnnotations) != 0) { + for (TypeReference typeArgument : typeArguments) { + if ((typeArgument.bits & ASTNode.HasTypeAnnotations) != 0) { this.bits |= ASTNode.HasTypeAnnotations; break; } @@ -138,8 +138,8 @@ public boolean hasNullTypeAnnotation(AnnotationPosition position) { if (this.resolvedType != null && !this.resolvedType.hasNullTypeAnnotations()) return false; // shortcut if (this.typeArguments != null) { - for (int i = 0; i < this.typeArguments.length; i++) { - if (this.typeArguments[i].hasNullTypeAnnotation(position)) + for (TypeReference typeArgument : this.typeArguments) { + if (typeArgument.hasNullTypeAnnotation(position)) return true; } } @@ -417,18 +417,16 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { } Annotation [][] annotationsOnDimensions = getAnnotationsOnDimensions(true); if (annotationsOnDimensions != null) { - for (int i = 0, max = annotationsOnDimensions.length; i < max; i++) { - Annotation[] annotations2 = annotationsOnDimensions[i]; - if (annotations2 != null) { - for (int j = 0, max2 = annotations2.length; j < max2; j++) { - Annotation annotation = annotations2[j]; + for (Annotation[] annotationsOnDimension : annotationsOnDimensions) { + if (annotationsOnDimension != null) { + for (Annotation annotation : annotationsOnDimension) { annotation.traverse(visitor, scope); } } } } - for (int i = 0, max = this.typeArguments.length; i < max; i++) { - this.typeArguments[i].traverse(visitor, scope); + for (TypeReference typeArgument : this.typeArguments) { + typeArgument.traverse(visitor, scope); } } visitor.endVisit(this, scope); @@ -445,16 +443,14 @@ public void traverse(ASTVisitor visitor, ClassScope scope) { } Annotation [][] annotationsOnDimensions = getAnnotationsOnDimensions(true); if (annotationsOnDimensions != null) { - for (int i = 0, max = annotationsOnDimensions.length; i < max; i++) { - Annotation[] annotations2 = annotationsOnDimensions[i]; - for (int j = 0, max2 = annotations2.length; j < max2; j++) { - Annotation annotation = annotations2[j]; + for (Annotation[] annotationsOnDimension : annotationsOnDimensions) { + for (Annotation annotation : annotationsOnDimension) { annotation.traverse(visitor, scope); } } } - for (int i = 0, max = this.typeArguments.length; i < max; i++) { - this.typeArguments[i].traverse(visitor, scope); + for (TypeReference typeArgument : this.typeArguments) { + typeArgument.traverse(visitor, scope); } } visitor.endVisit(this, scope); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ProvidesStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ProvidesStatement.java index 6cf87c94510..ef1d80783f2 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ProvidesStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ProvidesStatement.java @@ -47,14 +47,14 @@ public boolean resolve(BlockScope scope) { } ReferenceBinding intf = (ReferenceBinding) this.serviceInterface.resolvedType; Set impls = new HashSet<>(); - for (int i = 0; i < this.implementations.length; i++) { - ReferenceBinding impl = (ReferenceBinding) this.implementations[i].resolveType(scope); + for (TypeReference implementation : this.implementations) { + ReferenceBinding impl = (ReferenceBinding) implementation.resolveType(scope); if (impl == null || !impl.isValidBinding() || !impl.canBeSeenBy(scope)) { hasErrors = true; continue; } if (!impls.add(impl)) { - scope.problemReporter().duplicateTypeReference(IProblem.DuplicateServices, this.implementations[i]); + scope.problemReporter().duplicateTypeReference(IProblem.DuplicateServices, implementation); continue; } int problemId = ProblemReasons.NoError; @@ -76,7 +76,7 @@ public boolean resolve(BlockScope scope) { implType = provider.returnType; if (implType instanceof ReferenceBinding && !implType.canBeSeenBy(scope)) { ReferenceBinding referenceBinding = (ReferenceBinding) implType; - scope.problemReporter().invalidType(this.implementations[i], new ProblemReferenceBinding( + scope.problemReporter().invalidType(implementation, new ProblemReferenceBinding( referenceBinding.compoundName, referenceBinding, ProblemReasons.NotVisible)); hasErrors = true; } @@ -93,12 +93,12 @@ public boolean resolve(BlockScope scope) { } } if (implType.findSuperTypeOriginatingFrom(intf) == null) { - scope.problemReporter().typeMismatchError(implType, intf, this.implementations[i], null); + scope.problemReporter().typeMismatchError(implType, intf, implementation, null); hasErrors = true; } } if (problemId != ProblemReasons.NoError) { - scope.problemReporter().invalidServiceRef(problemId, this.implementations[i]); + scope.problemReporter().invalidServiceRef(problemId, implementation); hasErrors = true; } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java index 3b1fce6f6a6..e4487c88453 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java @@ -418,8 +418,8 @@ private TypeBinding resolveTypeForQualifiedAllocationExpression(BlockScope scope } if (this.argumentsHaveErrors) { if (this.arguments != null) { // still attempt to resolve arguments - for (int i = 0, max = this.arguments.length; i < max; i++) { - this.arguments[i].resolveType(scope); + for (Expression argument : this.arguments) { + argument.resolveType(scope); } } return null; @@ -676,8 +676,8 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { if (this.enclosingInstance != null) this.enclosingInstance.traverse(visitor, scope); if (this.typeArguments != null) { - for (int i = 0, typeArgumentsLength = this.typeArguments.length; i < typeArgumentsLength; i++) { - this.typeArguments[i].traverse(visitor, scope); + for (TypeReference typeArgument : this.typeArguments) { + typeArgument.traverse(visitor, scope); } } if (this.type != null) // case of enum constant diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java index f6db1827fa5..776f7d68919 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java @@ -82,8 +82,8 @@ protected void rejectAnnotationsOnPackageQualifiers(Scope scope, PackageBinding Annotation[] qualifierAnnot = this.annotations[j]; if (qualifierAnnot != null && qualifierAnnot.length > 0) { if (j == 0) { - for (int k = 0; k < qualifierAnnot.length; k++) { - scope.problemReporter().typeAnnotationAtQualifiedName(qualifierAnnot[k]); + for (Annotation annotation : qualifierAnnot) { + scope.problemReporter().typeAnnotationAtQualifiedName(annotation); } } else { scope.problemReporter().misplacedTypeAnnotations(qualifierAnnot[0], @@ -189,8 +189,8 @@ protected TypeBinding getTypeBinding(Scope scope) { void recordResolution(LookupEnvironment env, TypeBinding typeFound) { if (typeFound != null && typeFound.isValidBinding()) { synchronized (env.root) { - for (int i = 0; i < env.root.resolutionListeners.length; i++) { - env.root.resolutionListeners[i].recordResolution(this, typeFound); + for (IQualifiedTypeResolutionListener resolutionListener : env.root.resolutionListeners) { + resolutionListener.recordResolution(this, typeFound); } } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/RecordComponent.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/RecordComponent.java index eab24c571a0..dde93ffb9a2 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/RecordComponent.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/RecordComponent.java @@ -81,8 +81,7 @@ public int getKind() { public void getAllAnnotationContexts(int targetType, List allAnnotationContexts) { AnnotationCollector collector = new AnnotationCollector(this, targetType, allAnnotationContexts); - for (int i = 0, max = this.annotations.length; i < max; i++) { - Annotation annotation = this.annotations[i]; + for (Annotation annotation : this.annotations) { annotation.traverse(collector, (BlockScope) null); } } @@ -96,8 +95,8 @@ public void resolve(BlockScope scope) { resolveAnnotations(scope, this.annotations, this.binding); // Check if this declaration should now have the type annotations bit set if (this.annotations != null) { - for (int i = 0, max = this.annotations.length; i < max; i++) { - TypeBinding resolvedAnnotationType = this.annotations[i].resolvedType; + for (Annotation annotation : this.annotations) { + TypeBinding resolvedAnnotationType = annotation.resolvedType; if (resolvedAnnotationType != null && (resolvedAnnotationType.getAnnotationTagBits() & TagBits.AnnotationForTypeUse) != 0) { this.bits |= ASTNode.HasTypeAnnotations; // also update the accessor's return type: diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java index 41c1a5f57a0..e514a5f3594 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java @@ -848,15 +848,15 @@ enclosing instance of this (8.1.3)", we will actually implement this check in co // OK, we have a compile time declaration, see if it passes muster. TypeBinding [] methodExceptions = this.binding.thrownExceptions; TypeBinding [] kosherExceptions = this.descriptor.thrownExceptions; - next: for (int i = 0, iMax = methodExceptions.length; i < iMax; i++) { - if (methodExceptions[i].isUncheckedException(false)) { + next: for (TypeBinding methodException : methodExceptions) { + if (methodException.isUncheckedException(false)) { continue next; } - for (int j = 0, jMax = kosherExceptions.length; j < jMax; j++) { - if (methodExceptions[i].isCompatibleWith(kosherExceptions[j], scope)) + for (TypeBinding kosherException : kosherExceptions) { + if (methodException.isCompatibleWith(kosherException, scope)) continue next; } - scope.problemReporter().unhandledException(methodExceptions[i], this); + scope.problemReporter().unhandledException(methodException, this); } checkNullAnnotations(scope); this.freeParameters = null; // not used after method lookup @@ -1224,8 +1224,8 @@ there exists at least one potentially applicable method for the method reference – The method reference expression has some other form and at least one potentially applicable method is not static. */ - for (int i = 0, length = this.potentialMethods.length; i < length; i++) { - if (this.potentialMethods[i].isStatic() || this.potentialMethods[i].isConstructor()) { + for (MethodBinding potentialMethod : this.potentialMethods) { + if (potentialMethod.isStatic() || potentialMethod.isConstructor()) { if (!this.haveReceiver) // form ReferenceType ::[TypeArguments] Identifier return true; } else { @@ -1249,8 +1249,8 @@ there exists at least one potentially applicable method for the method reference OR there is no potentially compatible compile time declaration ... */ } - for (int i = 0, length = this.potentialMethods.length; i < length; i++) { - if (!this.potentialMethods[i].isStatic() && !this.potentialMethods[i].isConstructor()) { + for (MethodBinding potentialMethod : this.potentialMethods) { + if (!potentialMethod.isStatic() && !potentialMethod.isConstructor()) { return true; } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Statement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Statement.java index 3fd377e2a83..8a766540c14 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Statement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Statement.java @@ -434,8 +434,8 @@ public void generateArguments(MethodBinding binding, Expression[] arguments, Blo codeStream.newArray(codeGenVarArgsType); // create a mono-dimensional array } } else if (arguments != null) { // standard generation for method arguments - for (int i = 0, max = arguments.length; i < max; i++) - arguments[i].generateCode(currentScope, codeStream, true); + for (Expression argument : arguments) + argument.generateCode(currentScope, codeStream, true); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/StringTemplate.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/StringTemplate.java index 53ad0728c37..22a70c2be43 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/StringTemplate.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/StringTemplate.java @@ -109,8 +109,8 @@ public StringBuilder printExpression(int indent, StringBuilder output) { output.append("\"\"\n"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { char[] source = this.fragments[i].source(); - for (int j = 0; j < source.length; j++) { - Util.appendEscapedChar(output, source[j], true); + for (char c : source) { + Util.appendEscapedChar(output, c, true); } if (i + 1 < length) { output.append("\\{"); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java index 5fc921bfcca..5d6d93dd11e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java @@ -676,8 +676,7 @@ public String toString() { // generate the switch block statements int caseIndex = 0; if (this.statements != null) { - for (int i = 0, maxCases = this.statements.length; i < maxCases; i++) { - Statement statement = this.statements[i]; + for (Statement statement : this.statements) { if ((caseIndex < this.caseCount) && (statement == this.cases[caseIndex])) { // statements[i] is a case this.scope.enclosingCase = this.cases[caseIndex]; // record entering in a switch case block if (this.preSwitchInitStateIndex != -1) { @@ -845,8 +844,7 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { int caseIndex = 0; int typeSwitchIndex = 0; if (this.statements != null) { - for (int i = 0, maxCases = this.statements.length; i < maxCases; i++) { - Statement statement = this.statements[i]; + for (Statement statement : this.statements) { CaseStatement caseStatement = null; if ((caseIndex < constantCount) && (statement == this.cases[caseIndex])) { // statements[i] is a case this.scope.enclosingCase = this.cases[caseIndex]; // record entering in a switch case block @@ -1047,12 +1045,12 @@ public StringBuilder printStatement(int indent, StringBuilder output) { printIndent(indent, output).append("switch ("); //$NON-NLS-1$ this.expression.printExpression(0, output).append(") {"); //$NON-NLS-1$ if (this.statements != null) { - for (int i = 0; i < this.statements.length; i++) { + for (Statement statement : this.statements) { output.append('\n'); - if (this.statements[i] instanceof CaseStatement) { - this.statements[i].printStatement(indent, output); + if (statement instanceof CaseStatement) { + statement.printStatement(indent, output); } else { - this.statements[i].printStatement(indent+2, output); + statement.printStatement(indent+2, output); } } } @@ -1062,8 +1060,7 @@ public StringBuilder printStatement(int indent, StringBuilder output) { private int getNConstants() { int n = 0; - for (int i = 0, l = this.statements.length; i < l; ++i) { - final Statement statement = this.statements[i]; + for (final Statement statement : this.statements) { if (statement instanceof CaseStatement) { Expression[] exprs = ((CaseStatement) statement).peeledLabelExpressions(); int count = 0; @@ -1376,8 +1373,8 @@ private boolean checkAndFlagDefaultSealed(BlockScope skope, CompilerOptions comp } if (ref.isRecord()) { boolean isRecordPattern = false; - for (int i = 0; i < this.caseLabelElements.size(); ++i) { - if (this.caseLabelElements.get(i) instanceof RecordPattern) { + for (Pattern element : this.caseLabelElements) { + if (element instanceof RecordPattern) { isRecordPattern = true; break; } @@ -1427,8 +1424,8 @@ private boolean checkAndFlagDefaultRecord(BlockScope skope, CompilerOptions comp } // non-zero components RNode head = new RNode(ref); - for (int i = 0; i < this.caseLabelElements.size(); ++i) { - head.addPattern(this.caseLabelElements.get(i)); + for (Pattern element : this.caseLabelElements) { + head.addPattern(element); } CoverageCheckerVisitor ccv = new CoverageCheckerVisitor(); head.traverse(ccv); @@ -1632,8 +1629,8 @@ public void branchChainTo(BranchLabel label) { public boolean doesNotCompleteNormally() { if (this.statements == null || this.statements.length == 0) return false; - for (int i = 0, length = this.statements.length; i < length; i++) { - if (this.statements[i].breaksOut(null)) + for (Statement statement : this.statements) { + if (statement.breaksOut(null)) return false; } return this.statements[this.statements.length - 1].doesNotCompleteNormally(); @@ -1643,8 +1640,8 @@ public boolean doesNotCompleteNormally() { public boolean completesByContinue() { if (this.statements == null || this.statements.length == 0) return false; - for (int i = 0, length = this.statements.length; i < length; i++) { - if (this.statements[i].completesByContinue()) + for (Statement statement : this.statements) { + if (statement.completesByContinue()) return true; } return false; @@ -1659,8 +1656,8 @@ public boolean canCompleteNormally() { return true; // last statement as well as last switch label after blocks if exists. if (this.totalPattern == null && this.defaultCase == null) return true; - for (int i = 0, length = this.statements.length; i < length; i++) { - if (this.statements[i].breaksOut(null)) + for (Statement statement : this.statements) { + if (statement.breaksOut(null)) return true; } } else { @@ -1692,8 +1689,8 @@ public boolean canCompleteNormally() { public boolean continueCompletes() { if (this.statements == null || this.statements.length == 0) return false; - for (int i = 0, length = this.statements.length; i < length; i++) { - if (this.statements[i].continueCompletes()) + for (Statement statement : this.statements) { + if (statement.continueCompletes()) return true; } return false; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TryStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TryStatement.java index 3ae6aca6bc2..e58ec2eb945 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TryStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TryStatement.java @@ -178,8 +178,8 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl MethodBinding closeMethod = findCloseMethod(resource, resolvedType); if (closeMethod != null && closeMethod.isValidBinding() && closeMethod.returnType.id == TypeIds.T_void) { ReferenceBinding[] thrownExceptions = closeMethod.thrownExceptions; - for (int j = 0, length = thrownExceptions.length; j < length; j++) { - handlingContext.checkExceptionHandlers(thrownExceptions[j], this.resources[i], tryInfo, currentScope, true); + for (ReferenceBinding thrownException : thrownExceptions) { + handlingContext.checkExceptionHandlers(thrownException, this.resources[i], tryInfo, currentScope, true); } } } @@ -306,8 +306,8 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl MethodBinding closeMethod = findCloseMethod(resource, resolvedType); if (closeMethod != null && closeMethod.isValidBinding() && closeMethod.returnType.id == TypeIds.T_void) { ReferenceBinding[] thrownExceptions = closeMethod.thrownExceptions; - for (int j = 0, length = thrownExceptions.length; j < length; j++) { - handlingContext.checkExceptionHandlers(thrownExceptions[j], this.resources[i], tryInfo, currentScope, true); + for (ReferenceBinding thrownException : thrownExceptions) { + handlingContext.checkExceptionHandlers(thrownException, this.resources[i], tryInfo, currentScope, true); } } } @@ -1267,8 +1267,8 @@ public void resolve(BlockScope upperScope) { public void traverse(ASTVisitor visitor, BlockScope blockScope) { if (visitor.visit(this, blockScope)) { Statement[] statements = this.resources; - for (int i = 0, max = statements.length; i < max; i++) { - statements[i].traverse(visitor, this.scope); + for (Statement statement : statements) { + statement.traverse(visitor, this.scope); } this.tryBlock.traverse(visitor, this.scope); if (this.catchArguments != null) { @@ -1360,8 +1360,8 @@ public boolean doesNotCompleteNormally() { return (this.finallyBlock != null) ? this.finallyBlock.doesNotCompleteNormally() : false; } if (this.catchBlocks != null) { - for (int i = 0; i < this.catchBlocks.length; i++) { - if (!this.catchBlocks[i].doesNotCompleteNormally()) { + for (Block catchBlock : this.catchBlocks) { + if (!catchBlock.doesNotCompleteNormally()) { return (this.finallyBlock != null) ? this.finallyBlock.doesNotCompleteNormally() : false; } } @@ -1375,8 +1375,8 @@ public boolean completesByContinue() { !this.finallyBlock.doesNotCompleteNormally() || this.finallyBlock.completesByContinue(); } if (this.catchBlocks != null) { - for (int i = 0; i < this.catchBlocks.length; i++) { - if (this.catchBlocks[i].completesByContinue()) { + for (Block catchBlock : this.catchBlocks) { + if (catchBlock.completesByContinue()) { return (this.finallyBlock == null) ? true : !this.finallyBlock.doesNotCompleteNormally() || this.finallyBlock.completesByContinue(); } @@ -1390,8 +1390,8 @@ public boolean canCompleteNormally() { return (this.finallyBlock != null) ? this.finallyBlock.canCompleteNormally() : true; } if (this.catchBlocks != null) { - for (int i = 0; i < this.catchBlocks.length; i++) { - if (this.catchBlocks[i].canCompleteNormally()) { + for (Block catchBlock : this.catchBlocks) { + if (catchBlock.canCompleteNormally()) { return (this.finallyBlock != null) ? this.finallyBlock.canCompleteNormally() : true; } } @@ -1405,8 +1405,8 @@ public boolean continueCompletes() { this.finallyBlock.canCompleteNormally() || this.finallyBlock.continueCompletes(); } if (this.catchBlocks != null) { - for (int i = 0; i < this.catchBlocks.length; i++) { - if (this.catchBlocks[i].continueCompletes()) { + for (Block catchBlock : this.catchBlocks) { + if (catchBlock.continueCompletes()) { return (this.finallyBlock == null) ? true : this.finallyBlock.canCompleteNormally() || this.finallyBlock.continueCompletes(); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java index 255f683d7ce..417c389a75a 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java @@ -365,8 +365,8 @@ public ConstructorDeclaration createDefaultConstructorForRecord(boolean needExpl // constructor.modifiers |= ClassFileConstants.AccPublic; // JLS 14 8.10.5 constructor.arguments = getArgumentsFromComponents(this.recordComponents); - for (int i = 0, max = constructor.arguments.length; i < max; i++) { - if ((constructor.arguments[i].bits & ASTNode.HasTypeAnnotations) != 0) { + for (Argument argument : constructor.arguments) { + if ((argument.bits & ASTNode.HasTypeAnnotations) != 0) { constructor.bits |= ASTNode.HasTypeAnnotations; break; } @@ -574,9 +574,9 @@ public MethodBinding createDefaultConstructorWithBinding(MethodBinding inherited */ public FieldDeclaration declarationOf(FieldBinding fieldBinding) { if (fieldBinding != null && this.fields != null) { - for (int i = 0, max = this.fields.length; i < max; i++) { + for (FieldDeclaration field : this.fields) { FieldDeclaration fieldDecl; - if ((fieldDecl = this.fields[i]).binding == fieldBinding) + if ((fieldDecl = field).binding == fieldBinding) return fieldDecl; } } @@ -588,9 +588,9 @@ public FieldDeclaration declarationOf(FieldBinding fieldBinding) { */ public TypeDeclaration declarationOf(MemberTypeBinding memberTypeBinding) { if (memberTypeBinding != null && this.memberTypes != null) { - for (int i = 0, max = this.memberTypes.length; i < max; i++) { + for (TypeDeclaration memberType : this.memberTypes) { TypeDeclaration memberTypeDecl; - if (TypeBinding.equalsEquals((memberTypeDecl = this.memberTypes[i]).binding, memberTypeBinding)) + if (TypeBinding.equalsEquals((memberTypeDecl = memberType).binding, memberTypeBinding)) return memberTypeDecl; } } @@ -602,10 +602,10 @@ public TypeDeclaration declarationOf(MemberTypeBinding memberTypeBinding) { */ public AbstractMethodDeclaration declarationOf(MethodBinding methodBinding) { if (methodBinding != null && this.methods != null) { - for (int i = 0, max = this.methods.length; i < max; i++) { + for (AbstractMethodDeclaration method : this.methods) { AbstractMethodDeclaration methodDecl; - if ((methodDecl = this.methods[i]).binding == methodBinding) + if ((methodDecl = method).binding == methodBinding) return methodDecl; } } @@ -617,9 +617,8 @@ public AbstractMethodDeclaration declarationOf(MethodBinding methodBinding) { */ public RecordComponent declarationOf(RecordComponentBinding recordComponentBinding) { if (recordComponentBinding != null && this.recordComponents != null) { - for (int i = 0, max = this.recordComponents.length; i < max; i++) { - RecordComponent recordComponent; - if ((recordComponent = this.recordComponents[i]).binding == recordComponentBinding) + for (RecordComponent recordComponent : this.recordComponents) { + if (recordComponent.binding == recordComponentBinding) return recordComponent; } } @@ -643,8 +642,8 @@ public TypeDeclaration declarationOfType(char[][] typeName) { } char[][] subTypeName = new char[typeNameLength - 1][]; System.arraycopy(typeName, 1, subTypeName, 0, typeNameLength - 1); - for (int i = 0; i < this.memberTypes.length; i++) { - TypeDeclaration typeDecl = this.memberTypes[i].declarationOfType(subTypeName); + for (TypeDeclaration memberType : this.memberTypes) { + TypeDeclaration typeDecl = memberType.declarationOfType(subTypeName); if (typeDecl != null) { return typeDecl; } @@ -735,8 +734,7 @@ public void generateCode(ClassFile enclosingClassFile) { ocf.recordNestMember(this.binding); } TypeVariableBinding[] typeVariables = this.binding.typeVariables(); - for (int i = 0, max = typeVariables.length; i < max; i++) { - TypeVariableBinding typeVariableBinding = typeVariables[i]; + for (TypeVariableBinding typeVariableBinding : typeVariables) { if ((typeVariableBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(classFile, typeVariableBinding); } @@ -746,8 +744,7 @@ public void generateCode(ClassFile enclosingClassFile) { classFile.addFieldInfos(); if (this.memberTypes != null) { - for (int i = 0, max = this.memberTypes.length; i < max; i++) { - TypeDeclaration memberType = this.memberTypes[i]; + for (TypeDeclaration memberType : this.memberTypes) { classFile.recordInnerClasses(memberType.binding); memberType.generateCode(this.scope, classFile); } @@ -755,8 +752,8 @@ public void generateCode(ClassFile enclosingClassFile) { // generate all methods classFile.setForMethodInfos(); if (this.methods != null) { - for (int i = 0, max = this.methods.length; i < max; i++) { - this.methods[i].generateCode(this.scope, classFile); + for (AbstractMethodDeclaration method : this.methods) { + method.generateCode(this.scope, classFile); } } // generate all synthetic and abstract methods @@ -851,8 +848,7 @@ private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780 if (this.typeParameters != null && !this.scope.referenceCompilationUnit().compilationResult.hasSyntaxError) { - for (int i = 0, length = this.typeParameters.length; i < length; ++i) { - TypeParameter typeParameter = this.typeParameters[i]; + for (TypeParameter typeParameter : this.typeParameters) { if ((typeParameter.binding.modifiers & ExtraCompilerModifiers.AccLocallyUsed) == 0) { this.scope.problemReporter().unusedTypeParameter(typeParameter); } @@ -872,8 +868,7 @@ private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) { FlowInfo nonStaticFieldInfo = flowInfo.unconditionalFieldLessCopy(); FlowInfo staticFieldInfo = flowInfo.unconditionalFieldLessCopy(); if (this.fields != null) { - for (int i = 0, count = this.fields.length; i < count; i++) { - FieldDeclaration field = this.fields[i]; + for (FieldDeclaration field : this.fields) { if (field.isStatic()) { if ((staticFieldInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) field.bits &= ~ASTNode.IsReachable; @@ -913,11 +908,11 @@ private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) { } } if (this.memberTypes != null) { - for (int i = 0, count = this.memberTypes.length; i < count; i++) { + for (TypeDeclaration memberType : this.memberTypes) { if (flowContext != null){ // local type - this.memberTypes[i].analyseCode(this.scope, flowContext, nonStaticFieldInfo.copy().setReachMode(flowInfo.reachMode())); // reset reach mode in case initializers did abrupt completely + memberType.analyseCode(this.scope, flowContext, nonStaticFieldInfo.copy().setReachMode(flowInfo.reachMode())); // reset reach mode in case initializers did abrupt completely } else { - this.memberTypes[i].analyseCode(this.scope); + memberType.analyseCode(this.scope); } } } @@ -941,8 +936,7 @@ private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) { UnconditionalFlowInfo outerInfo = flowInfo.unconditionalFieldLessCopy(); FlowInfo constructorInfo = nonStaticFieldInfo.unconditionalInits().discardNonFieldInitializations().addInitializationsFrom(outerInfo); SimpleSetOfCharArray jUnitMethodSourceValues = getJUnitMethodSourceValues(); - for (int i = 0, count = this.methods.length; i < count; i++) { - AbstractMethodDeclaration method = this.methods[i]; + for (AbstractMethodDeclaration method : this.methods) { if (method.ignoreFurtherInvestigation) continue; if (method.isInitializationMethod()) { @@ -1186,26 +1180,26 @@ public StringBuilder print(int indent, StringBuilder output) { public StringBuilder printBody(int indent, StringBuilder output) { output.append(" {"); //$NON-NLS-1$ if (this.memberTypes != null) { - for (int i = 0; i < this.memberTypes.length; i++) { - if (this.memberTypes[i] != null) { + for (TypeDeclaration memberType : this.memberTypes) { + if (memberType != null) { output.append('\n'); - this.memberTypes[i].print(indent + 1, output); + memberType.print(indent + 1, output); } } } if (this.fields != null) { - for (int fieldI = 0; fieldI < this.fields.length; fieldI++) { - if (this.fields[fieldI] != null) { + for (FieldDeclaration field : this.fields) { + if (field != null) { output.append('\n'); - this.fields[fieldI].print(indent + 1, output); + field.print(indent + 1, output); } } } if (this.methods != null) { - for (int i = 0; i < this.methods.length; i++) { - if (this.methods[i] != null) { + for (AbstractMethodDeclaration method : this.methods) { + if (method != null) { output.append('\n'); - this.methods[i].print(indent + 1, output); + method.print(indent + 1, output); } } } @@ -1404,8 +1398,8 @@ public void resolve() { FieldDeclaration[] enumConstantsWithoutBody = null; if (this.memberTypes != null) { - for (int i = 0, count = this.memberTypes.length; i < count; i++) { - this.memberTypes[i].resolve(this.scope); + for (TypeDeclaration memberType : this.memberTypes) { + memberType.resolve(this.scope); } } if (this.recordComponents != null) { @@ -1488,18 +1482,16 @@ public void resolve() { // check enum abstract methods if (this.binding.isAbstract()) { if (!hasEnumConstants) { - for (int i = 0, count = this.methods.length; i < count; i++) { - final AbstractMethodDeclaration methodDeclaration = this.methods[i]; + for (final AbstractMethodDeclaration methodDeclaration : this.methods) { if (methodDeclaration.isAbstract() && methodDeclaration.binding != null) this.scope.problemReporter().enumAbstractMethodMustBeImplemented(methodDeclaration); } } else if (enumConstantsWithoutBody != null) { - for (int i = 0, count = this.methods.length; i < count; i++) { - final AbstractMethodDeclaration methodDeclaration = this.methods[i]; + for (final AbstractMethodDeclaration methodDeclaration : this.methods) { if (methodDeclaration.isAbstract() && methodDeclaration.binding != null) { - for (int f = 0, l = enumConstantsWithoutBody.length; f < l; f++) - if (enumConstantsWithoutBody[f] != null) - this.scope.problemReporter().enumConstantMustImplementAbstractMethod(methodDeclaration, enumConstantsWithoutBody[f]); + for (FieldDeclaration decl : enumConstantsWithoutBody) + if (decl != null) + this.scope.problemReporter().enumConstantMustImplementAbstractMethod(methodDeclaration, decl); } } } @@ -1513,8 +1505,8 @@ public void resolve() { this.scope.problemReporter().tooManyMethods(this); } if (this.methods != null) { - for (int i = 0, count = this.methods.length; i < count; i++) { - this.methods[i].resolve(this.scope); + for (AbstractMethodDeclaration method : this.methods) { + method.resolve(this.scope); } } // Resolve javadoc diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java index 09b37f5201c..2fd8cbeb2ce 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java @@ -60,8 +60,8 @@ public void checkBounds(Scope scope) { this.type.checkBounds(scope); } if (this.bounds != null) { - for (int i = 0, length = this.bounds.length; i < length; i++) { - this.bounds[i].checkBounds(scope); + for (TypeReference bound : this.bounds) { + bound.checkBounds(scope); } } } @@ -192,9 +192,9 @@ public StringBuilder printStatement(int indent, StringBuilder output) { this.type.print(0, output); } if (this.bounds != null){ - for (int i = 0; i < this.bounds.length; i++) { + for (TypeReference bound : this.bounds) { output.append(" & "); //$NON-NLS-1$ - this.bounds[i].print(0, output); + bound.print(0, output); } } return output; @@ -260,8 +260,7 @@ public void updateWithAnnotations(ClassScope scope) { } } if (this.bounds != null) { - for (int i = 0; i < this.bounds.length; i++) { - TypeReference bound = this.bounds[i]; + for (TypeReference bound : this.bounds) { TypeBinding prevType = bound.resolvedType; bound.updateWithAnnotations(scope, Binding.DefaultLocationTypeBound); if (bound.resolvedType instanceof ReferenceBinding && prevType != bound.resolvedType) { //$IDENTITY-COMPARISON$ diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeReference.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeReference.java index 2daaab99676..7463236210f 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeReference.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeReference.java @@ -447,11 +447,10 @@ public void getAllAnnotationContexts(int targetType, int info, List getSecondaryTypes(String qualifiedPackageName) File[] listFiles = dir.isDirectory() ? dir.listFiles() : null; if (listFiles == null) return packageEntry; - for (int i = 0, l = listFiles.length; i < l; ++i) { - File f = listFiles[i]; + for (File f : listFiles) { if (f.isDirectory()) continue; String s = f.getAbsolutePath(); if (s == null) continue; @@ -234,8 +233,7 @@ private Hashtable getSecondaryTypes(String qualifiedPackageName) CompilationUnitDeclaration unit = parser.parse(cu, compilationResult); org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = unit != null ? unit.types : null; if (types == null) continue; - for (int j = 0, k = types.length; j < k; j++) { - TypeDeclaration type = types[j]; + for (TypeDeclaration type : types) { char[] name = type.isSecondary() ? type.name : null; // add only secondary types if (name != null) packageEntry.put(new String(name), s); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileFinder.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileFinder.java index 247c0c49c82..188b7a7b6b1 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileFinder.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileFinder.java @@ -38,8 +38,8 @@ private static void find0(File f, String pattern, List collector) { if (f.isDirectory()) { String[] files = f.list(); if (files == null) return; - for (int i = 0, max = files.length; i < max; i++) { - File current = new File(f, files[i]); + for (String file : files) { + File current = new File(f, file); if (current.isDirectory()) { find0(current, pattern, collector); } else { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java index 009c0ad67f6..bba7137a271 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java @@ -24,7 +24,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -149,8 +148,7 @@ public static class ClasspathNormalizer { public static ArrayList normalize(ArrayList classpaths) { ArrayList normalizedClasspath = new ArrayList<>(); HashSet cache = new HashSet<>(); - for (Iterator iterator = classpaths.iterator(); iterator.hasNext(); ) { - FileSystem.Classpath classpath = iterator.next(); + for (Classpath classpath : classpaths) { if (!cache.contains(classpath)) { normalizedClasspath.add(classpath); cache.add(classpath); @@ -416,17 +414,17 @@ private void initializeKnownFileNames(String[] initialFileNames) { } /** TESTS ONLY */ public void scanForModules(Parser parser) { - for (int i = 0, max = this.classpaths.length; i < max; i++) { - File file = new File(this.classpaths[i].getPath()); - IModule iModule = ModuleFinder.scanForModule(this.classpaths[i], file, parser, false, null); + for (Classpath classpath : this.classpaths) { + File file = new File(classpath.getPath()); + IModule iModule = ModuleFinder.scanForModule(classpath, file, parser, false, null); if (iModule != null) - this.moduleLocations.put(String.valueOf(iModule.name()), this.classpaths[i]); + this.moduleLocations.put(String.valueOf(iModule.name()), classpath); } } @Override public void cleanup() { - for (int i = 0, max = this.classpaths.length; i < max; i++) - this.classpaths[i].reset(); + for (Classpath classpath : this.classpaths) + classpath.reset(); } private static String convertPathSeparators(String path) { return File.separatorChar == '/' @@ -437,8 +435,7 @@ private static String convertPathSeparators(String path) { private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly, /*NonNull*/char[] moduleName) { NameEnvironmentAnswer answer = internalFindClass(qualifiedTypeName, typeName, asBinaryOnly, moduleName); if (this.annotationsFromClasspath && answer != null && answer.getBinaryType() instanceof ClassFileReader) { - for (int i = 0, length = this.classpaths.length; i < length; i++) { - Classpath classpathEntry = this.classpaths[i]; + for (Classpath classpathEntry : this.classpaths) { if (classpathEntry.hasAnnotationFileFor(qualifiedTypeName)) { // in case of 'this.annotationsFromClasspath' we indeed search for .eea entries inside the main zipFile of the entry: ZipFile zip = classpathEntry instanceof ClasspathJar ? ((ClasspathJar) classpathEntry).zipFile : null; @@ -490,10 +487,10 @@ private NameEnvironmentAnswer internalFindClass(String qualifiedTypeName, char[] String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar); NameEnvironmentAnswer suggestedAnswer = null; if (qualifiedPackageName == qp2) { - for (int i = 0, length = this.classpaths.length; i < length; i++) { - if (!strategy.matches(this.classpaths[i], Classpath::hasModule)) + for (Classpath classpath : this.classpaths) { + if (!strategy.matches(classpath, Classpath::hasModule)) continue; - NameEnvironmentAnswer answer = this.classpaths[i].findClass(typeName, qualifiedPackageName, null, qualifiedBinaryFileName, asBinaryOnly); + NameEnvironmentAnswer answer = classpath.findClass(typeName, qualifiedPackageName, null, qualifiedBinaryFileName, asBinaryOnly); if (answer != null) { if (answer.moduleName() != null && !this.moduleLocations.containsKey(String.valueOf(answer.moduleName()))) continue; // type belongs to an unobservable module @@ -507,8 +504,7 @@ private NameEnvironmentAnswer internalFindClass(String qualifiedTypeName, char[] } } else { String qb2 = qualifiedBinaryFileName.replace('/', File.separatorChar); - for (int i = 0, length = this.classpaths.length; i < length; i++) { - Classpath p = this.classpaths[i]; + for (Classpath p : this.classpaths) { if (!strategy.matches(p, Classpath::hasModule)) continue; NameEnvironmentAnswer answer = !(p instanceof ClasspathDirectory) @@ -545,8 +541,8 @@ public char[][][] findTypeNames(char[][] packageName) { String qualifiedPackageName = new String(CharOperation.concatWith(packageName, '/')); String qualifiedPackageName2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar); if (qualifiedPackageName == qualifiedPackageName2) { - for (int i = 0, length = this.classpaths.length; i < length; i++) { - char[][][] answers = this.classpaths[i].findTypeNames(qualifiedPackageName, null); + for (Classpath classpath : this.classpaths) { + char[][][] answers = classpath.findTypeNames(qualifiedPackageName, null); if (answers != null) { // concat with previous answers if (result == null) { @@ -560,8 +556,7 @@ public char[][][] findTypeNames(char[][] packageName) { } } } else { - for (int i = 0, length = this.classpaths.length; i < length; i++) { - Classpath p = this.classpaths[i]; + for (Classpath p : this.classpaths) { char[][][] answers = !(p instanceof ClasspathDirectory) ? p.findTypeNames(qualifiedPackageName, null) : p.findTypeNames(qualifiedPackageName2, null); if (answers != null) { @@ -676,8 +671,7 @@ public boolean hasCompilationUnit(char[][] qualifiedPackageName, char[] moduleNa } return false; default: - for (int i = 0; i < this.classpaths.length; i++) { - Classpath location = this.classpaths[i]; + for (Classpath location : this.classpaths) { if (strategy.matches(location, Classpath::hasModule)) if (location.hasCompilationUnit(qPackageName, moduleNameString)) return true; @@ -717,9 +711,9 @@ public IModule getModuleFromEnvironment(char[] name) { @Override public char[][] getAllAutomaticModules() { Set set = new HashSet<>(); - for (int i = 0, l = this.classpaths.length; i < l; i++) { - if (this.classpaths[i].isAutomaticModule()) { - set.add(this.classpaths[i].getModule().name()); + for (Classpath classpath : this.classpaths) { + if (classpath.isAutomaticModule()) { + set.add(classpath.getModule().name()); } } return set.toArray(new char[set.size()][]); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java index 0c0fc64457a..ebc3398578b 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -61,7 +61,6 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -199,8 +198,7 @@ public static class Logger { try { Class c = IProblem.class; Field[] fields = c.getFields(); - for (int i = 0, max = fields.length; i < max; i++) { - Field field = fields[i]; + for (Field field : fields) { if (field.getType().equals(Integer.TYPE)) { Integer value = (Integer) field.get(null); int key2 = value.intValue() & IProblem.IgnoreCategoriesMask; @@ -758,8 +756,7 @@ public int compare(Map.Entry o1, Map.Entry o2) { } }); HashMap parameters = new HashMap<>(); - for (int i = 0, max = entries.length; i < max; i++) { - Map.Entry entry = entries[i]; + for (Entry entry : entries) { String key = entry.getKey(); parameters.put(Logger.KEY, key); parameters.put(Logger.VALUE, entry.getValue()); @@ -1581,10 +1578,8 @@ protected void addNewEntry(ArrayList paths, String current if (rulesSpecsSize != 0) { AccessRule[] accessRules = new AccessRule[currentRuleSpecs.size()]; boolean rulesOK = true; - Iterator i = currentRuleSpecs.iterator(); int j = 0; - while (i.hasNext()) { - String ruleSpec = i.next(); + for (String ruleSpec : currentRuleSpecs) { char key = ruleSpec.charAt(0); String pattern = ruleSpec.substring(1); if (pattern.length() > 0) { @@ -3080,8 +3075,7 @@ public void configure(String[] argv) { getAllEncodings(specifiedEncodings))); } if (this.pendingErrors != null) { - for (Iterator iterator = this.pendingErrors.iterator(); iterator.hasNext(); ) { - String message = iterator.next(); + for (String message : this.pendingErrors) { this.logger.logPendingError(message); } this.pendingErrors = null; @@ -3262,8 +3256,7 @@ private void initializeWarnings(String propertiesFile) { e.printStackTrace(); throw new IllegalArgumentException(this.bind("configure.ioexceptionwarningspropertiesfile", propertiesFile)); //$NON-NLS-1$ } - for(Iterator iterator = properties.entrySet().iterator(); iterator.hasNext(); ) { - Map.Entry entry = (Map.Entry) iterator.next(); + for (Map.Entry entry : properties.entrySet()) { final String key = entry.getKey().toString(); if (key.startsWith("org.eclipse.jdt.core.compiler.")) { //$NON-NLS-1$ this.options.put(key, entry.getValue().toString()); @@ -3294,8 +3287,7 @@ protected void enableAll(int severity) { break; } Map.Entry[] entries = this.options.entrySet().toArray(new Map.Entry[this.options.size()]); - for (int i = 0, max = entries.length; i < max; i++) { - Map.Entry entry = entries[i]; + for (Entry entry : entries) { if (entry.getValue().equals(CompilerOptions.IGNORE)) { this.options.put(entry.getKey(), newValue); } @@ -3571,8 +3563,8 @@ protected ArrayList handleModuleSourcepath(String arg) { } String[] paths = new String[modulePaths.size()]; modulePaths.toArray(paths); - for (int i = 0; i < paths.length; i++) { - File dir = new File(paths[i]); + for (String path : paths) { + File dir = new File(path); if (dir.isDirectory()) { // 1. Create FileSystem.Classpath for each module // 2. Iterator each module in case of directory for source files and add to this.fileNames @@ -3734,10 +3726,10 @@ protected ArrayList handleEndorseddirs(ArrayList e for (int i = 0, max = endorsedDirsJars.length; i < max; i++) { File[] current = endorsedDirsJars[i]; if (current != null) { - for (int j = 0, max2 = current.length; j < max2; j++) { + for (File file : current) { FileSystem.Classpath classpath = FileSystem.getClasspath( - current[j].getAbsolutePath(), + file.getAbsolutePath(), null, null, this.options, this.releaseVersion); if (classpath != null) { result.add(classpath); @@ -3795,10 +3787,10 @@ protected ArrayList handleExtdirs(ArrayList extdir for (int i = 0, max = extdirsJars.length; i < max; i++) { File[] current = extdirsJars[i]; if (current != null) { - for (int j = 0, max2 = current.length; j < max2; j++) { + for (File file : current) { FileSystem.Classpath classpath = FileSystem.getClasspath( - current[j].getAbsolutePath(), + file.getAbsolutePath(), null, null, this.options, this.releaseVersion); if (classpath != null) { result.add(classpath); @@ -4601,8 +4593,7 @@ protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean if (customDefaultOptions != null) { this.didSpecifySource = customDefaultOptions.get(CompilerOptions.OPTION_Source) != null; this.didSpecifyTarget = customDefaultOptions.get(CompilerOptions.OPTION_TargetPlatform) != null; - for (Iterator> iter = customDefaultOptions.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = iter.next(); + for (Entry entry : customDefaultOptions.entrySet()) { this.options.put(entry.getKey(), entry.getValue()); } } else { @@ -4667,9 +4658,7 @@ public void outputClassFiles(CompilationResult unitResult) { generateClasspathStructure = true; } // else leave currentDestinationPath null if (currentDestinationPath != null) { - for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) { - // retrieve the key and the corresponding classfile - ClassFile classFile = classFiles[i]; + for (ClassFile classFile : classFiles) { char[] filename = classFile.fileName(); int length = filename.length; char[] relativeName = new char[length + 6]; @@ -5294,8 +5283,7 @@ public final static boolean shouldIgnoreOptionalProblems(char[][] folderNames, c if (folderNames == null || fileName == null) { return false; } - for (int i = 0, max = folderNames.length; i < max; i++) { - char[] folderName = folderNames[i]; + for (char[] folderName : folderNames) { if (isParentOf(folderName, fileName)) { return true; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/AnnotationInfo.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/AnnotationInfo.java index 88b9bb436e8..9b692bb1f24 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/AnnotationInfo.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/AnnotationInfo.java @@ -90,8 +90,7 @@ private void sanitizePairs(ElementValuePairInfo[] oldPairs) { if (oldPairs != null) { ElementValuePairInfo[] newPairs = new ElementValuePairInfo[oldPairs.length]; int count = 0; - for (int i = 0; i < oldPairs.length; i++) { - ElementValuePairInfo evpInfo = oldPairs[i]; + for (ElementValuePairInfo evpInfo : oldPairs) { if (evpInfo != null) newPairs[count++] = evpInfo; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java index 1d82a807f33..1f128dda281 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java @@ -1423,13 +1423,13 @@ private void initialize() throws ClassFormatException { this.methods[i].initialize(); } if (this.innerInfos != null) { - for (int i = 0, max = this.innerInfos.length; i < max; i++) { - this.innerInfos[i].initialize(); + for (InnerClassInfo info : this.innerInfos) { + info.initialize(); } } if (this.annotations != null) { - for (int i = 0, max = this.annotations.length; i < max; i++) { - this.annotations[i].initialize(); + for (AnnotationInfo annotation : this.annotations) { + annotation.initialize(); } } this.getEnclosingMethod(); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfoWithAnnotation.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfoWithAnnotation.java index b17de909431..20a00fc6240 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfoWithAnnotation.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfoWithAnnotation.java @@ -33,15 +33,15 @@ public org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation[] getAnnotations( @Override protected void initialize() { if (this.annotations != null) - for (int i = 0, max = this.annotations.length; i < max; i++) - this.annotations[i].initialize(); + for (AnnotationInfo annotation : this.annotations) + annotation.initialize(); super.initialize(); } @Override protected void reset() { if (this.annotations != null) - for (int i = 0, max = this.annotations.length; i < max; i++) - this.annotations[i].reset(); + for (AnnotationInfo annotation : this.annotations) + annotation.reset(); super.reset(); } @Override @@ -49,8 +49,8 @@ public String toString() { StringBuilder buffer = new StringBuilder(getClass().getName()); if (this.annotations != null) { buffer.append('\n'); - for (int i = 0; i < this.annotations.length; i++) { - buffer.append(this.annotations[i]); + for (AnnotationInfo annotation : this.annotations) { + buffer.append(annotation); buffer.append('\n'); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfoWithTypeAnnotation.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfoWithTypeAnnotation.java index 028f7dcb051..66d553a0a5b 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfoWithTypeAnnotation.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfoWithTypeAnnotation.java @@ -27,15 +27,15 @@ public IBinaryTypeAnnotation[] getTypeAnnotations() { } @Override protected void initialize() { - for (int i = 0, max = this.typeAnnotations.length; i < max; i++) - this.typeAnnotations[i].initialize(); + for (TypeAnnotationInfo typeAnnotation : this.typeAnnotations) + typeAnnotation.initialize(); super.initialize(); } @Override protected void reset() { if (this.typeAnnotations != null) - for (int i = 0, max = this.typeAnnotations.length; i < max; i++) - this.typeAnnotations[i].reset(); + for (TypeAnnotationInfo typeAnnotation : this.typeAnnotations) + typeAnnotation.reset(); super.reset(); } @Override @@ -44,8 +44,8 @@ public String toString() { if (this.typeAnnotations != null) { buffer.append('\n'); buffer.append("type annotations:"); //$NON-NLS-1$ - for (int i = 0; i < this.typeAnnotations.length; i++) { - buffer.append(this.typeAnnotations[i]); + for (TypeAnnotationInfo typeAnnotation : this.typeAnnotations) { + buffer.append(typeAnnotation); buffer.append('\n'); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithAnnotation.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithAnnotation.java index da246037bdc..5de0b05db57 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithAnnotation.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithAnnotation.java @@ -39,15 +39,15 @@ public org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation[] getAnnotations( @Override protected void initialize() { if (this.annotations != null) - for (int i = 0, max = this.annotations.length; i < max; i++) - this.annotations[i].initialize(); + for (AnnotationInfo annotation : this.annotations) + annotation.initialize(); super.initialize(); } @Override protected void reset() { if (this.annotations != null) - for (int i = 0, max = this.annotations.length; i < max; i++) - this.annotations[i].reset(); + for (AnnotationInfo annotation : this.annotations) + annotation.reset(); super.reset(); } @Override @@ -55,8 +55,8 @@ public String toString() { StringBuilder buffer = new StringBuilder(getClass().getName()); if (this.annotations != null) { buffer.append('\n'); - for (int i = 0; i < this.annotations.length; i++) { - buffer.append(this.annotations[i]); + for (AnnotationInfo annotation : this.annotations) { + buffer.append(annotation); buffer.append('\n'); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithTypeAnnotation.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithTypeAnnotation.java index a713557d0f1..ef4e7d6f9be 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithTypeAnnotation.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithTypeAnnotation.java @@ -29,15 +29,15 @@ public IBinaryTypeAnnotation[] getTypeAnnotations() { } @Override protected void initialize() { - for (int i = 0, max = this.typeAnnotations.length; i < max; i++) - this.typeAnnotations[i].initialize(); + for (TypeAnnotationInfo typeAnnotation : this.typeAnnotations) + typeAnnotation.initialize(); super.initialize(); } @Override protected void reset() { if (this.typeAnnotations != null) - for (int i = 0, max = this.typeAnnotations.length; i < max; i++) - this.typeAnnotations[i].reset(); + for (TypeAnnotationInfo typeAnnotation : this.typeAnnotations) + typeAnnotation.reset(); super.reset(); } @Override @@ -46,8 +46,8 @@ public String toString() { if (this.typeAnnotations != null) { buffer.append('\n'); buffer.append("type annotations:"); //$NON-NLS-1$ - for (int i = 0; i < this.typeAnnotations.length; i++) { - buffer.append(this.typeAnnotations[i]); + for (TypeAnnotationInfo typeAnnotation : this.typeAnnotations) { + buffer.append(typeAnnotation); buffer.append('\n'); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java index e6341e26ac9..71b028bbb28 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java @@ -208,8 +208,8 @@ static AnnotationInfo[][] decodeParamAnnotations(int offset, boolean runtimeVisi allParamAnnotations = new AnnotationInfo[numberOfParameters][]; AnnotationInfo[] annos = decodeAnnotations(readOffset, runtimeVisible, numberOfAnnotations, methodInfo); allParamAnnotations[i] = annos; - for (int aIndex = 0; aIndex < annos.length; aIndex++) - readOffset += annos[aIndex].readOffset; + for (AnnotationInfo info : annos) + readOffset += info.readOffset; } } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java index 7eb09702c62..c81b7077c91 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java @@ -261,8 +261,8 @@ void setAnnotations(AnnotationInfo[] annotationInfos, long tagBits, boolean full this.annotations = annotationInfos; this.tagBits = tagBits; if (fullyInitialize) { - for (int i = 0, max = annotationInfos.length; i < max; i++) { - annotationInfos[i].initialize(); + for (AnnotationInfo info : annotationInfos) { + info.initialize(); } } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/TypeAnnotationInfo.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/TypeAnnotationInfo.java index ba20fb02621..c1c10873734 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/TypeAnnotationInfo.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/TypeAnnotationInfo.java @@ -180,8 +180,8 @@ public int hashCode() { result = prime * result + this.info; result = prime * result + this.info2; if (this.typePath != null) { - for (int i = 0, max = this.typePath.length; i < max; i++) { - result = prime * result + this.typePath[i]; + for (int p : this.typePath) { + result = prime * result + p; } } return result; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.java index 5a2082e771c..d85e4247500 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.java @@ -210,8 +210,7 @@ public void place() { // Currently lacking wide support. // end of new code if ((this.codeStream.generateAttributes & (ClassFileConstants.ATTR_VARS | ClassFileConstants.ATTR_STACK_MAP_TABLE | ClassFileConstants.ATTR_STACK_MAP)) != 0) { LocalVariableBinding locals[] = this.codeStream.locals; - for (int i = 0, max = locals.length; i < max; i++) { - LocalVariableBinding local = locals[i]; + for (LocalVariableBinding local : locals) { if ((local != null) && (local.initializationCount > 0)) { if (local.initializationPCs[((local.initializationCount - 1) << 1) + 1] == oldPosition) { // we want to prevent interval of size 0 to have a negative size. diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java index a8dd65189fd..c3b54a91eb0 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java @@ -2804,8 +2804,7 @@ public void generateSyntheticBodyForDeserializeLambda(SyntheticMethodBinding met // Compute a map of hashcodes to a list of synthetic methods whose names share a hashcode Map hashcodesTosynthetics = new LinkedHashMap(); - for (int i=0,max=syntheticMethodBindings.length;i Java 1.4 features here? @@ -2868,8 +2867,8 @@ public void generateSyntheticBodyForDeserializeLambda(SyntheticMethodBinding met // Loop through all lambdas that share the same hashcode // TODO: isn't doing this for just one of these enough because they all share // the same name? - for (int j=0,max=synthetics.size();j= ClassFileConstants.JDK1_4; - for (int i = 0, max = syntheticArgumentTypes.length; i < max; i++) { - ReferenceBinding syntheticArgType = syntheticArgumentTypes[i]; + for (ReferenceBinding syntheticArgType : syntheticArgumentTypes) { if (hasExtraEnclosingInstance && TypeBinding.equalsEquals(syntheticArgType, targetEnclosingType)) { hasExtraEnclosingInstance = false; enclosingInstance.generateCode(currentScope, this, true); @@ -3449,8 +3445,8 @@ public void generateSyntheticOuterArgumentValues(BlockScope currentScope, Refere // generate the synthetic outer arguments then SyntheticArgumentBinding syntheticArguments[]; if ((syntheticArguments = targetType.syntheticOuterLocalVariables()) != null) { - for (int i = 0, max = syntheticArguments.length; i < max; i++) { - LocalVariableBinding targetVariable = syntheticArguments[i].actualOuterLocalVariable; + for (SyntheticArgumentBinding syntheticArgument : syntheticArguments) { + LocalVariableBinding targetVariable = syntheticArgument.actualOuterLocalVariable; VariableBinding[] emulationPath = currentScope.getEmulationPath(targetVariable); generateOuterAccess(emulationPath, invocationSite, targetVariable, currentScope); } @@ -3798,9 +3794,9 @@ public static TypeBinding getConstantPoolDeclaringClass(Scope currentScope, Meth } if (actualReceiverType.isIntersectionType18()) { TypeBinding[] intersectingTypes = ((IntersectionTypeBinding18)actualReceiverType).getIntersectingTypes(); - for(int i = 0; i < intersectingTypes.length; i++) { - if (intersectingTypes[i].findSuperTypeOriginatingFrom(constantPoolDeclaringClass) != null) { - constantPoolDeclaringClass = intersectingTypes[i].erasure(); + for (TypeBinding intersectingType : intersectingTypes) { + if (intersectingType.findSuperTypeOriginatingFrom(constantPoolDeclaringClass) != null) { + constantPoolDeclaringClass = intersectingType.erasure(); break; } } @@ -4619,8 +4615,8 @@ public void initializeMaxLocals(MethodBinding methodBinding) { } TypeBinding[] parameterTypes; if ((parameterTypes = methodBinding.parameters) != null) { - for (int i = 0, max = parameterTypes.length; i < max; i++) { - switch (parameterTypes[i].id) { + for (TypeBinding parameterType : parameterTypes) { + switch (parameterType.id) { case TypeIds.T_long : case TypeIds.T_double : this.maxLocals += 2; @@ -4796,8 +4792,8 @@ public void invoke(byte opcode, MethodBinding methodBinding, TypeBinding declari // outer local variables SyntheticArgumentBinding[] syntheticArguments = nestedType.syntheticOuterLocalVariables(); if (syntheticArguments != null) { - for (int i = 0, max = syntheticArguments.length; i < max; i++) { - switch (syntheticArguments[i].id) { + for (SyntheticArgumentBinding syntheticArgument : syntheticArguments) { + switch (syntheticArgument.id) { case TypeIds.T_double : case TypeIds.T_long : receiverAndArgsSize += 2; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java index 47ad31a8087..f9775de4cb0 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java @@ -427,8 +427,7 @@ public int literalIndex(char[] utf8Constant) { } this.currentOffset += 2; length = 0; - for (int i = 0; i < utf8Constant.length; i++) { - char current = utf8Constant[i]; + for (char current : utf8Constant) { if ((current >= 0x0001) && (current <= 0x007F)) { // we only need one byte: ASCII table writeU1(current); @@ -1064,8 +1063,7 @@ public int literalIndexForLdc(char[] stringCharArray) { } this.currentOffset += 2; length = 0; - for (int i = 0; i < stringCharArray.length; i++) { - char current = stringCharArray[i]; + for (char current : stringCharArray) { if ((current >= 0x0001) && (current <= 0x007F)) { // we only need one byte: ASCII table length++; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/MultiCatchExceptionLabel.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/MultiCatchExceptionLabel.java index 9ab7b3b2632..be1bde25e15 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/MultiCatchExceptionLabel.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/MultiCatchExceptionLabel.java @@ -39,27 +39,27 @@ public void initialize(UnionTypeReference typeReference, Annotation [] annotatio } @Override public void place() { - for (int i = 0, max = this.exceptionLabels.length; i < max; i++) { - this.exceptionLabels[i].place(); + for (ExceptionLabel exceptionLabel : this.exceptionLabels) { + exceptionLabel.place(); } } @Override public void placeEnd() { - for (int i = 0, max = this.exceptionLabels.length; i < max; i++) { - this.exceptionLabels[i].placeEnd(); + for (ExceptionLabel exceptionLabel : this.exceptionLabels) { + exceptionLabel.placeEnd(); } } @Override public void placeStart() { - for (int i = 0, max = this.exceptionLabels.length; i < max; i++) { - this.exceptionLabels[i].placeStart(); + for (ExceptionLabel exceptionLabel : this.exceptionLabels) { + exceptionLabel.placeStart(); } } @Override public int getCount() { int temp = 0; - for (int i = 0, max = this.exceptionLabels.length; i < max; i++) { - temp += this.exceptionLabels[i].getCount(); + for (ExceptionLabel exceptionLabel : this.exceptionLabels) { + temp += exceptionLabel.getCount(); } return temp; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java index ed29f9929ad..52629b02ef6 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java @@ -17,7 +17,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import org.eclipse.jdt.core.compiler.CharOperation; @@ -296,16 +295,10 @@ public ExceptionMarker[] getExceptionMarkers() { int size = exceptionMarkerSet.size(); ExceptionMarker[] markers = new ExceptionMarker[size]; int n = 0; - for (Iterator iterator = exceptionMarkerSet.iterator(); iterator.hasNext();) { - markers[n++] = (ExceptionMarker) iterator.next(); + for (Object marker : exceptionMarkerSet) { + markers[n++] = (ExceptionMarker) marker; } Arrays.sort(markers); -// System.out.print('['); -// for (int n = 0; n < size; n++) { -// if (n != 0) System.out.print(','); -// System.out.print(positions[n]); -// } -// System.out.println(']'); return markers; } @@ -314,16 +307,10 @@ public int[] getFramePositions() { int size = set.size(); int[] positions = new int[size]; int n = 0; - for (Iterator iterator = set.iterator(); iterator.hasNext();) { - positions[n++] = ((Integer) iterator.next()).intValue(); + for (Object pos : set) { + positions[n++] = ((Integer) pos).intValue(); } Arrays.sort(positions); -// System.out.print('['); -// for (int n = 0; n < size; n++) { -// if (n != 0) System.out.print(','); -// System.out.print(positions[n]); -// } -// System.out.println(']'); return positions; } @@ -511,8 +498,7 @@ public void resetForCodeGenUnusedLocals() { } public void resetSecretLocals() { - for (int i = 0, max = this.locals.length; i < max; i++) { - LocalVariableBinding localVariableBinding = this.locals[i]; + for (LocalVariableBinding localVariableBinding : this.locals) { if (localVariableBinding != null && localVariableBinding.isSecret()) { // all other locals are reinitialized inside the computation of their resolved positions localVariableBinding.resetInitializations(); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java index 6d76210f84a..4fbbb376d58 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java @@ -74,8 +74,7 @@ public AccessRule[] getAccessRules() { * @return the first access restriction that applies if any, null else */ public AccessRestriction getViolatedRestriction(char[] targetTypeFilePath) { - for (int i = 0, length = this.accessRules.length; i < length; i++) { - AccessRule accessRule = this.accessRules[i]; + for (AccessRule accessRule : this.accessRules) { if (CharOperation.pathMatch(accessRule.pattern, targetTypeFilePath, true/*case sensitive*/, '/')) { switch (accessRule.getProblemId()) { @@ -105,8 +104,8 @@ private int hashCode(AccessRule[] rules) { if (rules == null) return 0; int result = 1; - for (int i = 0, length = rules.length; i < length; i++) { - result = prime * result + (rules[i] == null ? 0 : rules[i].hashCode()); + for (AccessRule rule : rules) { + result = prime * result + (rule == null ? 0 : rule.hashCode()); } return result; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/env/IUpdatableModule.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/env/IUpdatableModule.java index 7b926468562..1c39e246d19 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/env/IUpdatableModule.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/env/IUpdatableModule.java @@ -73,8 +73,8 @@ public boolean equals(Object other) { public int hashCode() { int hash = CharOperation.hashCode(this.name); if (this.targets != null) { - for (int i = 0; i < this.targets.length; i++) { - hash += 17 * CharOperation.hashCode(this.targets[i]); + for (char[] target : this.targets) { + hash += 17 * CharOperation.hashCode(target); } } return hash; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java index 841a96fe6dc..3d1ee67ccb8 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java @@ -155,11 +155,11 @@ public void complainIfUnusedExceptionHandlers(AbstractMethodDeclaration method) docCommentReferences[i] = method.javadoc.exceptionReferences[i].resolvedType; } } - nextHandledException: for (int i = 0, count = this.handledExceptions.length; i < count; i++) { - int index = this.indexes.get(this.handledExceptions[i]); + nextHandledException: for (ReferenceBinding handledException : this.handledExceptions) { + int index = this.indexes.get(handledException); if ((this.isReached[index / ExceptionHandlingFlowContext.BitCacheSize] & 1 << (index % ExceptionHandlingFlowContext.BitCacheSize)) == 0) { for (int j = 0; j < docCommentReferencesLength; j++) { - if (TypeBinding.equalsEquals(docCommentReferences[j], this.handledExceptions[i])) { + if (TypeBinding.equalsEquals(docCommentReferences[j], handledException)) { continue nextHandledException; } } @@ -198,8 +198,7 @@ private ASTNode getExceptionType(int index) { ASTNode node = this.catchArguments[catchBlock].type; if (node instanceof UnionTypeReference) { TypeReference[] typeRefs = ((UnionTypeReference)node).typeReferences; - for (int i = 0, len = typeRefs.length; i < len; i++) { - TypeReference typeRef = typeRefs[i]; + for (TypeReference typeRef : typeRefs) { if (TypeBinding.equalsEquals(typeRef.resolvedType, this.handledExceptions[index])) return typeRef; } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/FlowContext.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/FlowContext.java index 623bd978c48..bffbac02a54 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/FlowContext.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/FlowContext.java @@ -288,44 +288,41 @@ public void checkExceptionHandlers(TypeBinding raisedException, ASTNode location ReferenceBinding[] caughtExceptions; if ((caughtExceptions = exceptionContext.handledExceptions) != Binding.NO_EXCEPTIONS) { boolean definitelyCaught = false; - for (int caughtIndex = 0, caughtCount = caughtExceptions.length; - caughtIndex < caughtCount; - caughtIndex++) { - ReferenceBinding caughtException = caughtExceptions[caughtIndex]; - FlowInfo exceptionFlow = flowInfo; - int state = caughtException == null - ? Scope.EQUAL_OR_MORE_SPECIFIC /* any exception */ - : Scope.compareTypes(raisedException, caughtException); - if (abruptlyExitedLoops != null && caughtException != null && state != Scope.NOT_RELATED) { - for (int i = 0, abruptlyExitedLoopsCount = abruptlyExitedLoops.size(); i < abruptlyExitedLoopsCount; i++) { - LoopingFlowContext loop = (LoopingFlowContext) abruptlyExitedLoops.get(i); - loop.recordCatchContextOfEscapingException(exceptionContext, caughtException, flowInfo); - } - exceptionFlow = FlowInfo.DEAD_END; // don't use flow info on first round, flow info will be evaluated during loopback simulation - } - switch (state) { - case Scope.EQUAL_OR_MORE_SPECIFIC : - exceptionContext.recordHandlingException( - caughtException, - exceptionFlow.unconditionalInits(), - raisedException, - raisedException, // precise exception that will be caught - location, - definitelyCaught); - // was it already definitely caught ? - definitelyCaught = true; - break; - case Scope.MORE_GENERIC : - exceptionContext.recordHandlingException( - caughtException, - exceptionFlow.unconditionalInits(), - raisedException, - caughtException, - location, - false); - // was not caught already per construction + for (ReferenceBinding caughtException : caughtExceptions) { + FlowInfo exceptionFlow = flowInfo; + int state = caughtException == null + ? Scope.EQUAL_OR_MORE_SPECIFIC /* any exception */ + : Scope.compareTypes(raisedException, caughtException); + if (abruptlyExitedLoops != null && caughtException != null && state != Scope.NOT_RELATED) { + for (Object abruptlyExitedLoop : abruptlyExitedLoops) { + LoopingFlowContext loop = (LoopingFlowContext) abruptlyExitedLoop; + loop.recordCatchContextOfEscapingException(exceptionContext, caughtException, flowInfo); } + exceptionFlow = FlowInfo.DEAD_END; // don't use flow info on first round, flow info will be evaluated during loopback simulation } + switch (state) { + case Scope.EQUAL_OR_MORE_SPECIFIC : + exceptionContext.recordHandlingException( + caughtException, + exceptionFlow.unconditionalInits(), + raisedException, + raisedException, // precise exception that will be caught + location, + definitelyCaught); + // was it already definitely caught ? + definitelyCaught = true; + break; + case Scope.MORE_GENERIC : + exceptionContext.recordHandlingException( + caughtException, + exceptionFlow.unconditionalInits(), + raisedException, + caughtException, + location, + false); + // was not caught already per construction + } +} if (definitelyCaught) return; } @@ -426,8 +423,8 @@ public void checkExceptionHandlers(TypeBinding[] raisedExceptions, ASTNode locat ? Scope.EQUAL_OR_MORE_SPECIFIC /* any exception */ : Scope.compareTypes(raisedException, caughtException); if (abruptlyExitedLoops != null && caughtException != null && state != Scope.NOT_RELATED) { - for (int i = 0, abruptlyExitedLoopsCount = abruptlyExitedLoops.size(); i < abruptlyExitedLoopsCount; i++) { - LoopingFlowContext loop = (LoopingFlowContext) abruptlyExitedLoops.get(i); + for (Object abruptlyExitedLoop : abruptlyExitedLoops) { + LoopingFlowContext loop = (LoopingFlowContext) abruptlyExitedLoop; loop.recordCatchContextOfEscapingException(exceptionContext, caughtException, flowInfo); } exceptionFlow = FlowInfo.DEAD_END; // don't use flow info on first round, flow info will be evaluated during loopback simulation diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java index 7e657781e60..d7445a7a627 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java @@ -774,8 +774,8 @@ void removeFinalAssignmentIfAny(Reference reference) { */ public void simulateThrowAfterLoopBack(FlowInfo flowInfo) { if (this.escapingExceptionCatchSites != null) { - for (int i = 0, exceptionCount = this.escapingExceptionCatchSites.size(); i < exceptionCount; i++) { - ((EscapingExceptionCatchSite) this.escapingExceptionCatchSites.get(i)).simulateThrowAfterLoopBack(flowInfo); + for (Object site : this.escapingExceptionCatchSites) { + ((EscapingExceptionCatchSite) site).simulateThrowAfterLoopBack(flowInfo); } this.escapingExceptionCatchSites = null; // don't care for it anymore. } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java index 0626c8aa724..333378d416d 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/AnnotatableTypeSystem.java @@ -81,8 +81,7 @@ public ArrayBinding getArrayType(TypeBinding leafType, int dimensions, Annotatio } ArrayBinding nakedType = null; TypeBinding[] derivedTypes = getDerivedTypes(leafType); - for (int i = 0, length = derivedTypes.length; i < length; i++) { - TypeBinding derivedType = derivedTypes[i]; + for (TypeBinding derivedType : derivedTypes) { if (derivedType == null) break; if (!derivedType.isArrayType() || derivedType.dimensions() != dimensions || derivedType.leafComponentType() != leafType) //$IDENTITY-COMPARISON$ continue; @@ -152,8 +151,7 @@ public RawTypeBinding getRawType(ReferenceBinding genericType, ReferenceBinding RawTypeBinding nakedType = null; TypeBinding[] derivedTypes = getDerivedTypes(genericType); - for (int i = 0, length = derivedTypes.length; i < length; i++) { - TypeBinding derivedType = derivedTypes[i]; + for (TypeBinding derivedType : derivedTypes) { if (derivedType == null) break; if (!derivedType.isRawType() || derivedType.actualType() != genericType || derivedType.enclosingType() != enclosingType) //$IDENTITY-COMPARISON$ @@ -192,8 +190,7 @@ public WildcardBinding getWildcard(ReferenceBinding genericType, int rank, TypeB WildcardBinding nakedType = null; boolean useDerivedTypesOfBound = bound instanceof TypeVariableBinding || (bound instanceof ParameterizedTypeBinding && !(bound instanceof RawTypeBinding)) ; TypeBinding[] derivedTypes = getDerivedTypes(useDerivedTypesOfBound ? bound : genericType); - for (int i = 0, length = derivedTypes.length; i < length; i++) { - TypeBinding derivedType = derivedTypes[i]; + for (TypeBinding derivedType : derivedTypes) { if (derivedType == null) break; if (!derivedType.isWildcard() || derivedType.actualType() != genericType || derivedType.rank() != rank) //$IDENTITY-COMPARISON$ @@ -303,8 +300,7 @@ private TypeBinding getAnnotatedType(TypeBinding type, TypeBinding enclosingType } TypeBinding nakedType = null; TypeBinding[] derivedTypes = getDerivedTypes(type); - for (int i = 0, length = derivedTypes.length; i < length; i++) { - TypeBinding derivedType = derivedTypes[i]; + for (TypeBinding derivedType : derivedTypes) { if (derivedType == null) break; if (derivedType.enclosingType() != enclosingType || !Util.effectivelyEqual(derivedType.typeArguments(), type.typeArguments())) //$IDENTITY-COMPARISON$ diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java index 15c33a4878c..c2fe228003b 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java @@ -446,8 +446,7 @@ public void setTypeAnnotations(AnnotationBinding[] annotations, boolean evalNull this.nullTagBitsPerDimension = new long[this.dimensions + 1]; int dimension = 0; - for (int i = 0, length = annotations.length; i < length; i++) { - AnnotationBinding annotation = annotations[i]; + for (AnnotationBinding annotation : annotations) { if (annotation != null) { if (annotation.type.hasNullBit(TypeIds.BitNullableAnnotation)) { nullTagBits |= TagBits.AnnotationNullable; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryModuleBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryModuleBinding.java index 7baec60f902..a282b6f083d 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryModuleBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryModuleBinding.java @@ -120,11 +120,11 @@ void cachePartsFrom(IBinaryModule module) { this.requiresTransitive = new ModuleBinding[requiresReferences.length]; int count = 0; int transitiveCount = 0; - for (int i = 0; i < requiresReferences.length; i++) { - ModuleBinding requiredModule = this.environment.getModule(requiresReferences[i].name()); + for (IModuleReference ref : requiresReferences) { + ModuleBinding requiredModule = this.environment.getModule(ref.name()); if (requiredModule != null) { this.requires[count++] = requiredModule; - if (requiresReferences[i].isTransitive()) + if (ref.isTransitive()) this.requiresTransitive[transitiveCount++] = requiredModule; } // TODO(SHMOD): handle null case @@ -187,8 +187,7 @@ public PlainPackageBinding[] getOpens() { private void resolvePackages() { this.exportedPackages = new PlainPackageBinding[this.unresolvedExports.length]; int count = 0; - for (int i = 0; i < this.unresolvedExports.length; i++) { - IPackageExport export = this.unresolvedExports[i]; + for (IPackageExport export : this.unresolvedExports) { // when resolving "exports" in a binary module we simply assume the package must exist, // since this has been checked already when compiling that module. PlainPackageBinding declaredPackage = getOrCreateDeclaredPackage(CharOperation.splitOn('.', export.name())); @@ -201,8 +200,7 @@ private void resolvePackages() { this.openedPackages = new PlainPackageBinding[this.unresolvedOpens.length]; count = 0; - for (int i = 0; i < this.unresolvedOpens.length; i++) { - IPackageExport opens = this.unresolvedOpens[i]; + for (IPackageExport opens : this.unresolvedOpens) { PlainPackageBinding declaredPackage = getOrCreateDeclaredPackage(CharOperation.splitOn('.', opens.name())); this.openedPackages[count++] = declaredPackage; recordOpensRestrictions(declaredPackage, opens.targets()); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java index 68325ce6772..87806b36676 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java @@ -366,9 +366,9 @@ public FieldBinding[] availableFields() { } FieldBinding[] availableFields = new FieldBinding[this.fields.length]; int count = 0; - for (int i = 0; i < this.fields.length; i++) { + for (FieldBinding field : this.fields) { try { - availableFields[count] = resolveTypeFor(this.fields[i]); + availableFields[count] = resolveTypeFor(field); count++; } catch (AbortCompilation a){ // silent abort @@ -392,12 +392,12 @@ private TypeVariableBinding[] addMethodTypeVariables(TypeVariableBinding[] metho TypeVariableBinding[] combinedTypeVars = new TypeVariableBinding[total]; System.arraycopy(this.typeVariables, 0, combinedTypeVars, 0, this.typeVariables.length); int size = this.typeVariables.length; - loop: for (int i = 0, len = methodTypeVars.length; i < len; i++) { + loop: for (TypeVariableBinding methodTypeVar : methodTypeVars) { for (int j = this.typeVariables.length -1 ; j >= 0; j--) { - if (CharOperation.equals(methodTypeVars[i].sourceName, this.typeVariables[j].sourceName)) + if (CharOperation.equals(methodTypeVar.sourceName, this.typeVariables[j].sourceName)) continue loop; } - combinedTypeVars[size++] = methodTypeVars[i]; + combinedTypeVars[size++] = methodTypeVar; } if (size != total) { System.arraycopy(combinedTypeVars, 0, combinedTypeVars = new TypeVariableBinding[size], 0, size); @@ -427,9 +427,9 @@ public MethodBinding[] availableMethods() { } MethodBinding[] availableMethods = new MethodBinding[this.methods.length]; int count = 0; - for (int i = 0; i < this.methods.length; i++) { + for (MethodBinding method : this.methods) { try { - availableMethods[count] = resolveTypesFor(this.methods[i]); + availableMethods[count] = resolveTypesFor(method); count++; } catch (AbortCompilation a){ // silent abort @@ -615,14 +615,12 @@ void cachePartsFrom(IBinaryType binaryType, boolean needFieldsAndMethods) { IBinaryMethod[] iMethods = createMethods(binaryType.getMethods(), binaryType, sourceLevel, missingTypeNames); boolean isViewedAsDeprecated = isViewedAsDeprecated(); if (isViewedAsDeprecated) { - for (int i = 0, max = this.fields.length; i < max; i++) { - FieldBinding field = this.fields[i]; + for (FieldBinding field : this.fields) { if (!field.isDeprecated()) { field.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; } } - for (int i = 0, max = this.methods.length; i < max; i++) { - MethodBinding method = this.methods[i]; + for (MethodBinding method : this.methods) { if (!method.isDeprecated()) { method.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; } @@ -1154,8 +1152,8 @@ private MethodBinding createMethod(IBinaryMethod method, IBinaryType binaryType, result.tagBits |= method.getTagBits(); result.typeVariables = typeVars; // fixup the declaring element of all type variables - for (int i = 0, length = typeVars.length; i < length; i++) - this.environment.typeSystem.fixTypeVariableDeclaringElement(typeVars[i], result); + for (TypeVariableBinding typeVar : typeVars) + this.environment.typeSystem.fixTypeVariableDeclaringElement(typeVar, result); return result; } @@ -1398,8 +1396,7 @@ private MethodBinding findMethod(char[] methodDescriptor, char[][][] missingType int parameterLength = parameters.length; MethodBinding[] methods2 = this.enclosingType.getMethods(selector, parameterLength); // find matching method using parameters - loop: for (int i = 0, max = methods2.length; i < max; i++) { - MethodBinding currentMethod = methods2[i]; + loop: for (MethodBinding currentMethod : methods2) { TypeBinding[] parameters2 = currentMethod.parameters; int currentMethodParameterLength = parameters2.length; if (parameterLength == currentMethodParameterLength) { @@ -2054,8 +2051,8 @@ private void scanFieldForNullAnnotation(IBinaryField field, VariableBinding fiel ? externalAnnotationWalker.getAnnotationsAtCursor(fieldBinding.type.id, false) : field.getAnnotations(); if (annotations != null) { - for (int i = 0; i < annotations.length; i++) { - char[] annotationTypeName = annotations[i].getTypeName(); + for (IBinaryAnnotation annotation : annotations) { + char[] annotationTypeName = annotation.getTypeName(); if (annotationTypeName[0] != Util.C_RESOLVED) continue; int typeBit = this.environment.getAnalysisAnnotationBit(signature2qualifiedTypeName(annotationTypeName)); @@ -2112,13 +2109,13 @@ private void scanMethodForNullAnnotation(IBinaryMethod method, MethodBinding met : method.getAnnotations(); if (annotations != null) { int methodDefaultNullness = NO_NULL_DEFAULT; - for (int i = 0; i < annotations.length; i++) { - char[] annotationTypeName = annotations[i].getTypeName(); + for (IBinaryAnnotation annotation : annotations) { + char[] annotationTypeName = annotation.getTypeName(); if (annotationTypeName[0] != Util.C_RESOLVED) continue; int typeBit = this.environment.getAnalysisAnnotationBit(signature2qualifiedTypeName(annotationTypeName)); if (typeBit == TypeIds.BitNonNullByDefaultAnnotation) { - methodDefaultNullness |= getNonNullByDefaultValue(annotations[i], this.environment); + methodDefaultNullness |= getNonNullByDefaultValue(annotation, this.environment); } else if (typeBit == TypeIds.BitNonNullAnnotation) { methodBinding.tagBits |= TagBits.AnnotationNonNull; if (this.environment.usesNullTypeAnnotations()) { @@ -2154,8 +2151,8 @@ private void scanMethodForNullAnnotation(IBinaryMethod method, MethodBinding met ? parameterWalker.getAnnotationsAtCursor(parameters[j].id, false) : method.getParameterAnnotations(j+startIndex, this.fileName); if (paramAnnotations != null) { - for (int i = 0; i < paramAnnotations.length; i++) { - char[] annotationTypeName = paramAnnotations[i].getTypeName(); + for (IBinaryAnnotation paramAnnotation : paramAnnotations) { + char[] annotationTypeName = paramAnnotation.getTypeName(); if (annotationTypeName[0] != Util.C_RESOLVED) continue; int typeBit = this.environment.getAnalysisAnnotationBit(signature2qualifiedTypeName(annotationTypeName)); @@ -2299,8 +2296,8 @@ static int getNonNullByDefaultValue(IBinaryAnnotation annotation, LookupEnvironm } else if (elementValuePairs.length > 0) { // evaluate the contained EnumConstantSignatures: int nullness = 0; - for (int i = 0; i < elementValuePairs.length; i++) - nullness |= Annotation.nullLocationBitsFromAnnotationValue(elementValuePairs[i].getValue()); + for (IBinaryElementValuePair elementValuePair : elementValuePairs) + nullness |= Annotation.nullLocationBitsFromAnnotationValue(elementValuePair.getValue()); return nullness; } else { // empty argument: cancel all defaults from enclosing scopes @@ -2310,8 +2307,8 @@ static int getNonNullByDefaultValue(IBinaryAnnotation annotation, LookupEnvironm protected long scanForOwningAnnotation(IBinaryAnnotation[] annotations) { if (annotations != null) { - for (int i = 0; i < annotations.length; i++) { - char[] annotationTypeName = annotations[i].getTypeName(); + for (IBinaryAnnotation annotation : annotations) { + char[] annotationTypeName = annotation.getTypeName(); if (annotationTypeName[0] != Util.C_RESOLVED) continue; int typeBit = this.environment.getAnalysisAnnotationBit(signature2qualifiedTypeName(annotationTypeName)); @@ -2675,8 +2672,8 @@ public String toString() { if (this.fields != null) { if (this.fields != Binding.NO_FIELDS) { buffer.append("\n/* fields */"); //$NON-NLS-1$ - for (int i = 0, length = this.fields.length; i < length; i++) - buffer.append((this.fields[i] != null) ? "\n" + this.fields[i].toString() : "\nNULL FIELD"); //$NON-NLS-1$ //$NON-NLS-2$ + for (FieldBinding field : this.fields) + buffer.append((field != null) ? "\n" + field.toString() : "\nNULL FIELD"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { buffer.append("NULL FIELDS"); //$NON-NLS-1$ @@ -2685,8 +2682,8 @@ public String toString() { if (this.methods != null) { if (this.methods != Binding.NO_METHODS) { buffer.append("\n/* methods */"); //$NON-NLS-1$ - for (int i = 0, length = this.methods.length; i < length; i++) - buffer.append((this.methods[i] != null) ? "\n" + this.methods[i].toString() : "\nNULL METHOD"); //$NON-NLS-1$ //$NON-NLS-2$ + for (MethodBinding method : this.methods) + buffer.append((method != null) ? "\n" + method.toString() : "\nNULL METHOD"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { buffer.append("NULL METHODS"); //$NON-NLS-1$ @@ -2695,8 +2692,8 @@ public String toString() { if (this.memberTypes != null) { if (this.memberTypes != Binding.NO_MEMBER_TYPES) { buffer.append("\n/* members */"); //$NON-NLS-1$ - for (int i = 0, length = this.memberTypes.length; i < length; i++) - buffer.append((this.memberTypes[i] != null) ? "\n" + this.memberTypes[i].toString() : "\nNULL TYPE"); //$NON-NLS-1$ //$NON-NLS-2$ + for (ReferenceBinding memberType : this.memberTypes) + buffer.append((memberType != null) ? "\n" + memberType.toString() : "\nNULL TYPE"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { buffer.append("NULL MEMBER TYPES"); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java index c56fd80392b..aa7becf4a42 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java @@ -991,9 +991,9 @@ public final boolean isDuplicateLocalVariable(char[] name) { public int maxShiftedOffset() { int max = -1; if (this.shiftScopes != null){ - for (int i = 0, length = this.shiftScopes.length; i < length; i++){ - if (this.shiftScopes[i] != null) { - int subMaxOffset = this.shiftScopes[i].maxOffset; + for (BlockScope shiftScope : this.shiftScopes) { + if (shiftScope != null) { + int subMaxOffset = shiftScope.maxOffset; if (subMaxOffset > max) max = subMaxOffset; } } @@ -1049,8 +1049,7 @@ public void propagateInnerEmulation(ReferenceBinding targetType, boolean isEnclo SyntheticArgumentBinding[] syntheticArguments; if ((syntheticArguments = targetType.syntheticOuterLocalVariables()) != null) { - for (int i = 0, max = syntheticArguments.length; i < max; i++) { - SyntheticArgumentBinding syntheticArg = syntheticArguments[i]; + for (SyntheticArgumentBinding syntheticArg : syntheticArguments) { // need to filter out the one that could match a supplied enclosing instance if (!(isEnclosingInstanceSupplied && (TypeBinding.equalsEquals(syntheticArg.type, targetType.enclosingType())))) { @@ -1400,8 +1399,8 @@ public void checkAppropriateMethodAgainstSupers(char[] selector, MethodBinding c if (checkAppropriate(compileTimeMethod, otherMethod, site)) { ReferenceBinding[] superInterfaces = enclosingType.superInterfaces(); if (superInterfaces != null) { - for (int i = 0; i < superInterfaces.length; i++) { - otherMethod = getMethod(superInterfaces[i], selector, parameters, site); + for (ReferenceBinding superInterface : superInterfaces) { + otherMethod = getMethod(superInterface, selector, parameters, site); if (!checkAppropriate(compileTimeMethod, otherMethod, site)) break; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java index e3bf84f2380..ae472581238 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BoundSet.java @@ -100,11 +100,9 @@ private boolean addBound1(TypeBound bound) { // pre: this.superBounds != null public TypeBinding[] lowerBounds(boolean onlyProper, InferenceVariable variable) { TypeBinding[] boundTypes = new TypeBinding[this.superBounds.size()]; - Iterator it = this.superBounds.iterator(); long nullHints = variable.nullHints; int i = 0; - while(it.hasNext()) { - TypeBound current = it.next(); + for (TypeBound current : this.superBounds) { TypeBinding boundType = current.right; if (!onlyProper || boundType.isProperType(true)) { boundTypes[i++] = boundType; @@ -285,19 +283,16 @@ TypeBinding combineAndUseNullHints(TypeBinding type, long nullHints, LookupEnvir // TODO(optimization): may want to collect all nullHints in the ThreeSets, which, however, // needs a reference TypeBound->ThreeSets to propagate the bits as they are added. if (this.sameBounds != null) { - Iterator it = this.sameBounds.iterator(); - while(it.hasNext()) - nullHints |= it.next().nullHints; + for (TypeBound bound : this.sameBounds) + nullHints |= bound.nullHints; } if (this.superBounds != null) { - Iterator it = this.superBounds.iterator(); - while(it.hasNext()) - nullHints |= it.next().nullHints; + for (TypeBound bound : this.superBounds) + nullHints |= bound.nullHints; } if (this.subBounds != null) { - Iterator it = this.subBounds.iterator(); - while(it.hasNext()) - nullHints |= it.next().nullHints; + for (TypeBound bound : this.subBounds) + nullHints |= bound.nullHints; } if (nullHints == TagBits.AnnotationNullMASK) // on contradiction remove null type annotations return type.withoutToplevelNullAnnotation(); @@ -383,9 +378,7 @@ public TypeBound[] flatten() { public BoundSet copy() { BoundSet copy = new BoundSet(); if (!this.boundsPerVariable.isEmpty()) { - Iterator> setsIterator = this.boundsPerVariable.entrySet().iterator(); - while (setsIterator.hasNext()) { - Entry entry = setsIterator.next(); + for (Entry entry : this.boundsPerVariable.entrySet()) { copy.boundsPerVariable.put(entry.getKey(), entry.getValue().copy()); } } @@ -457,9 +450,9 @@ else if (boundNullBits != 0) // combine bits from both sources, even if this cre private boolean addBounds(TypeBound[] newBounds, LookupEnvironment environment) { boolean hasProperBound = false; - for (int i = 0; i < newBounds.length; i++) { - addBound(newBounds[i], environment); - hasProperBound |= newBounds[i].isBound(); + for (TypeBound newBound : newBounds) { + addBound(newBound, environment); + hasProperBound |= newBound.isBound(); } return hasProperBound; } @@ -491,8 +484,8 @@ public TypeBinding getInstantiation(InferenceVariable inferenceVariable, LookupE public int numUninstantiatedVariables(InferenceVariable[] variables) { int num = 0; - for (int i = 0; i < variables.length; i++) { - if (!isInstantiated(variables[i])) + for (InferenceVariable variable : variables) { + if (!isInstantiated(variable)) num++; } return num; @@ -544,57 +537,55 @@ boolean incorporate(InferenceContext18 context, TypeBound [] first, TypeBound [] boolean analyzeNull = context.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled; ConstraintTypeFormula [] mostRecentFormulas = new ConstraintTypeFormula[4]; // poor man's cache to toss out duplicates, in pathological cases there are a good quarter million of them. // check each pair, in each way. - for (int i = 0, iLength = first.length; i < iLength; i++) { - TypeBound boundI = first[i]; - for (int j = 0, jLength = next.length; j < jLength; j++) { - TypeBound boundJ = next[j]; - if (boundI == boundJ) + for (TypeBound bound1 : first) { + for (TypeBound bound2 : next) { + if (bound1 == bound2) continue; int iteration = 1; do { ConstraintTypeFormula newConstraint = null; boolean deriveTypeArgumentConstraints = false; if (iteration == 2) { - TypeBound boundX = boundI; - boundI = boundJ; - boundJ = boundX; + TypeBound boundX = bound1; + bound1 = bound2; + bound2 = boundX; } - switch (boundI.relation) { + switch (bound1.relation) { case ReductionResult.SAME: - switch (boundJ.relation) { + switch (bound2.relation) { case ReductionResult.SAME: - newConstraint = combineSameSame(boundI, boundJ, first, next); + newConstraint = combineSameSame(bound1, bound2, first, next); break; case ReductionResult.SUBTYPE: case ReductionResult.SUPERTYPE: - newConstraint = combineSameSubSuper(boundI, boundJ, first, next); + newConstraint = combineSameSubSuper(bound1, bound2, first, next); break; } break; case ReductionResult.SUBTYPE: - switch (boundJ.relation) { + switch (bound2.relation) { case ReductionResult.SAME: - newConstraint = combineSameSubSuper(boundJ, boundI, first, next); + newConstraint = combineSameSubSuper(bound2, bound1, first, next); break; case ReductionResult.SUPERTYPE: - newConstraint = combineSuperAndSub(boundJ, boundI); + newConstraint = combineSuperAndSub(bound2, bound1); break; case ReductionResult.SUBTYPE: - newConstraint = combineEqualSupers(boundI, boundJ); - deriveTypeArgumentConstraints = TypeBinding.equalsEquals(boundI.left, boundJ.left); + newConstraint = combineEqualSupers(bound1, bound2); + deriveTypeArgumentConstraints = TypeBinding.equalsEquals(bound1.left, bound2.left); break; } break; case ReductionResult.SUPERTYPE: - switch (boundJ.relation) { + switch (bound2.relation) { case ReductionResult.SAME: - newConstraint = combineSameSubSuper(boundJ, boundI, first, next); + newConstraint = combineSameSubSuper(bound2, bound1, first, next); break; case ReductionResult.SUBTYPE: - newConstraint = combineSuperAndSub(boundI, boundJ); + newConstraint = combineSuperAndSub(bound1, bound2); break; case ReductionResult.SUPERTYPE: - newConstraint = combineEqualSupers(boundI, boundJ); + newConstraint = combineEqualSupers(bound1, bound2); break; } } @@ -621,37 +612,31 @@ boolean incorporate(InferenceContext18 context, TypeBound [] first, TypeBound [] // record all null tagBits as hints for the final inference solution. long nullHints = (newConstraint.left.tagBits | newConstraint.right.tagBits) & TagBits.AnnotationNullMASK; if (nullHints != 0) { - if (TypeBinding.equalsEquals(boundI.left, boundJ.left) - || (boundI.relation == ReductionResult.SAME && TypeBinding.equalsEquals(boundI.right, boundJ.left)) - || (boundJ.relation == ReductionResult.SAME && TypeBinding.equalsEquals(boundI.left, boundJ.right))) { - boundI.nullHints |= nullHints; - boundJ.nullHints |= nullHints; + if (TypeBinding.equalsEquals(bound1.left, bound2.left) + || (bound1.relation == ReductionResult.SAME && TypeBinding.equalsEquals(bound1.right, bound2.left)) + || (bound2.relation == ReductionResult.SAME && TypeBinding.equalsEquals(bound1.left, bound2.right))) { + bound1.nullHints |= nullHints; + bound2.nullHints |= nullHints; } } } } - ConstraintFormula[] typeArgumentConstraints = deriveTypeArgumentConstraints ? deriveTypeArgumentConstraints(boundI, boundJ) : null; + ConstraintFormula[] typeArgumentConstraints = deriveTypeArgumentConstraints ? deriveTypeArgumentConstraints(bound1, bound2) : null; if (typeArgumentConstraints != null) { - for (int k = 0, length = typeArgumentConstraints.length; k < length; k++) { - if (!reduceOneConstraint(context, typeArgumentConstraints[k])) + for (ConstraintFormula typeArgumentConstraint : typeArgumentConstraints) { + if (!reduceOneConstraint(context, typeArgumentConstraint)) return false; } } if (iteration == 2) { - TypeBound boundX = boundI; - boundI = boundJ; - boundJ = boundX; + TypeBound boundX = bound1; + bound1 = bound2; + bound2 = boundX; } } while (first != next && ++iteration <= 2); } } - /* TODO: are we sure this will always terminate? Cf. e.g. (Discussion in 18.3): - * - * "The assertion that incorporation reaches a fixed point oversimplifies the matter slightly. ..." - */ - Iterator> captIter = this.captures.entrySet().iterator(); - while (captIter.hasNext()) { - Entry capt = captIter.next(); + for (Entry capt : this.captures.entrySet()) { ParameterizedTypeBinding gAlpha = capt.getKey(); ParameterizedTypeBinding gA = capt.getValue(); ReferenceBinding g = (ReferenceBinding) gA.original(); @@ -1004,10 +989,9 @@ public boolean reduceOneConstraint(InferenceContext18 context, ConstraintFormula if (result instanceof ConstraintFormula) { if (!reduceOneConstraint(context, (ConstraintFormula) result)) return false; - } else if (result instanceof ConstraintFormula[]) { - ConstraintFormula[] resultArray = (ConstraintFormula[]) result; - for (int i = 0; i < resultArray.length; i++) - if (!reduceOneConstraint(context, resultArray[i])) + } else if (result instanceof ConstraintFormula[] resultArray) { + for (ConstraintFormula formula : resultArray) + if (!reduceOneConstraint(context, formula)) return false; } else { addBound((TypeBound)result, context.environment); @@ -1025,10 +1009,8 @@ public boolean dependsOnResolutionOf(InferenceVariable alpha, InferenceVariable beta = beta.prototype(); if (TypeBinding.equalsEquals(alpha, beta)) return true; // An inference variable α depends on the resolution of itself. - Iterator> captureIter = this.captures.entrySet().iterator(); boolean betaIsInCaptureLhs = false; - while (captureIter.hasNext()) { // TODO: optimization: consider separate index structure (by IV) - Entry entry = captureIter.next(); + for (Entry entry : this.captures.entrySet()) { // TODO: optimization: consider separate index structure (by IV) ParameterizedTypeBinding g = entry.getKey(); for (int i = 0; i < g.arguments.length; i++) { if (TypeBinding.equalsEquals(g.arguments[i], alpha)) { @@ -1096,11 +1078,9 @@ private void addConnected(Set component, InferenceVariable se // helper for 18.4 public boolean hasCaptureBound(Set variableSet) { - Iterator captureIter = this.captures.keySet().iterator(); - while (captureIter.hasNext()) { - ParameterizedTypeBinding g = captureIter.next(); - for (int i = 0; i < g.arguments.length; i++) - if (variableSet.contains(g.arguments[i])) + for (ParameterizedTypeBinding g : this.captures.keySet()) { + for (TypeBinding argument : g.arguments) + if (variableSet.contains(argument)) return true; } return false; @@ -1109,8 +1089,8 @@ public boolean hasCaptureBound(Set variableSet) { // helper for 18.4 public boolean hasOnlyTrivialExceptionBounds(InferenceVariable variable, TypeBinding[] upperBounds) { if (upperBounds != null) { - for (int i = 0; i < upperBounds.length; i++) { - switch (upperBounds[i].id) { + for (TypeBinding upperBound : upperBounds) { + switch (upperBound.id) { case TypeIds.T_JavaLangException: case TypeIds.T_JavaLangThrowable: case TypeIds.T_JavaLangObject: @@ -1154,15 +1134,13 @@ TypeBinding[] lowerBounds(InferenceVariable variable, boolean onlyProper) { public String toString() { StringBuilder buf = new StringBuilder("Type Bounds:\n"); //$NON-NLS-1$ TypeBound[] flattened = flatten(); - for (int i = 0; i < flattened.length; i++) { - buf.append('\t').append(flattened[i].toString()).append('\n'); + for (TypeBound bound : flattened) { + buf.append('\t').append(bound.toString()).append('\n'); } buf.append("Capture Bounds:\n"); //$NON-NLS-1$ - Iterator> captIter = this.captures.entrySet().iterator(); - while (captIter.hasNext()) { - Entry capt = captIter.next(); - String lhs = String.valueOf(((TypeBinding)capt.getKey()).shortReadableName()); - String rhs = String.valueOf(((TypeBinding)capt.getValue()).shortReadableName()); + for (Entry entry : this.captures.entrySet()) { + String lhs = String.valueOf(((TypeBinding)entry.getKey()).shortReadableName()); + String rhs = String.valueOf(((TypeBinding)entry.getValue()).shortReadableName()); buf.append('\t').append(lhs).append(" = capt(").append(rhs).append(")\n"); //$NON-NLS-1$ //$NON-NLS-2$ } return buf.toString(); @@ -1183,17 +1161,13 @@ public boolean condition18_5_2_bullet_3_3_1(InferenceVariable alpha, TypeBinding if (ts == null) return false; if (ts.sameBounds != null) { - Iterator bounds = ts.sameBounds.iterator(); - while (bounds.hasNext()) { - TypeBound bound = bounds.next(); + for (TypeBound bound : ts.sameBounds) { if (InferenceContext18.parameterizedWithWildcard(bound.right) != null) return true; } } if (ts.superBounds != null) { - Iterator bounds = ts.superBounds.iterator(); - while (bounds.hasNext()) { - TypeBound bound = bounds.next(); + for (TypeBound bound : ts.superBounds) { if (InferenceContext18.parameterizedWithWildcard(bound.right) != null) return true; } @@ -1275,8 +1249,8 @@ protected TypeBinding[] superTypesWithCommonGenericType(TypeBinding s, TypeBindi return result; ReferenceBinding[] superInterfaces = s.superInterfaces(); if (superInterfaces != null) { - for (int i = 0; i < superInterfaces.length; i++) { - result = superTypesWithCommonGenericType(superInterfaces[i], t); + for (ReferenceBinding superInterface : superInterfaces) { + result = superTypesWithCommonGenericType(superInterface, t); if (result != null) return result; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java index 485f1d61105..9dea4749782 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java @@ -290,8 +290,8 @@ public void initializeBounds(Scope scope, ParameterizedTypeBinding capturedParam public ReferenceBinding upwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { if (enterRecursiveProjectionFunction()) { try { - for (int i = 0; i < mentionedTypeVariables.length; ++i) { - if (TypeBinding.equalsEquals(this, mentionedTypeVariables[i])) { + for (TypeBinding mentionedTypeVariable : mentionedTypeVariables) { + if (TypeBinding.equalsEquals(this, mentionedTypeVariable)) { TypeBinding upperBoundForProjection = this.upperBoundForProjection(); if (upperBoundForProjection == null) upperBoundForProjection = scope.getJavaLangObject(); @@ -541,8 +541,8 @@ public TypeBinding uncapture(Scope scope) { public ReferenceBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeVariables) { ReferenceBinding result = null; if (enterRecursiveProjectionFunction()) { - for (int i = 0; i < mentionedTypeVariables.length; ++i) { - if (TypeBinding.equalsEquals(this, mentionedTypeVariables[i])) { + for (TypeBinding mentionedTypeVariable : mentionedTypeVariables) { + if (TypeBinding.equalsEquals(this, mentionedTypeVariable)) { if (this.lowerBound != null) { result = (ReferenceBinding) this.lowerBound.downwardsProjection(scope, mentionedTypeVariables); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java index f1631f99c19..568c74ed3d2 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java @@ -46,8 +46,7 @@ public boolean setUpperBounds(TypeBinding[] upperBounds, ReferenceBinding javaLa int numReferenceInterfaces = 0; if (!isConsistentIntersection(upperBounds)) return false; - for (int i = 0; i < upperBounds.length; i++) { - TypeBinding aBound = upperBounds[i]; + for (TypeBinding aBound : upperBounds) { if (aBound instanceof ReferenceBinding) { if (this.superclass == null && aBound.isClass()) this.superclass = (ReferenceBinding) aBound; @@ -59,8 +58,7 @@ else if (aBound.isInterface()) } this.superInterfaces = new ReferenceBinding[numReferenceInterfaces]; int idx = 0; - for (int i = 0; i < upperBounds.length; i++) { - TypeBinding aBound = upperBounds[i]; + for (TypeBinding aBound : upperBounds) { if (aBound.isInterface()) this.superInterfaces[idx++] = (ReferenceBinding) aBound; } @@ -117,8 +115,7 @@ public boolean isEquivalentTo(TypeBinding otherType) { if (otherType == null) return false; if (this.upperBounds != null) { // from CaptureBinding: - for (int i = 0; i < this.upperBounds.length; i++) { - TypeBinding aBound = this.upperBounds[i]; + for (TypeBinding aBound : this.upperBounds) { // capture of ? extends X[] if (aBound != null && aBound.isArrayType()) { if (!aBound.isCompatibleWith(otherType)) @@ -182,8 +179,8 @@ public boolean isCompatibleWith(TypeBinding otherType, Scope captureScope) { @Override public TypeBinding findSuperTypeOriginatingFrom(TypeBinding otherType) { if (this.upperBounds != null && this.upperBounds.length > 1) { - for (int i = 0; i < this.upperBounds.length; i++) { - TypeBinding candidate = this.upperBounds[i].findSuperTypeOriginatingFrom(otherType); + for (TypeBinding upperBound : this.upperBounds) { + TypeBinding candidate = upperBound.findSuperTypeOriginatingFrom(otherType); if (candidate != null) return candidate; // TODO: maybe we should double check about multiple candidates here, @@ -286,8 +283,8 @@ public boolean isProperType(boolean admitCapture18) { if (this.lowerBound != null && !this.lowerBound.isProperType(admitCapture18)) return false; if (this.upperBounds != null) { - for (int i = 0; i < this.upperBounds.length; i++) { - if (!this.upperBounds[i].isProperType(admitCapture18)) + for (TypeBinding upperBound : this.upperBounds) { + if (!upperBound.isProperType(admitCapture18)) return false; } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java index 884e8308905..ccb9a4aefca 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java @@ -35,7 +35,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -83,8 +82,8 @@ void buildAnonymousTypeBinding(SourceTypeBinding enclosingType, ReferenceBinding if ((inheritedBits & TypeIds.BitWrapperCloseable) != 0) { AbstractMethodDeclaration[] methods = this.referenceContext.methods; if (methods != null) { - for (int i=0; i outputVariables(InferenceContext18 context) { } public boolean applySubstitution(BoundSet solutionSet, InferenceVariable[] variables) { - for (int i=0; i:"); //$NON-NLS-1$ break; } - if (constraintCollected[k] != null) { - buffer.append(constraintCollected[k].shortReadableName()); + if (binding != null) { + buffer.append(binding.shortReadableName()); } } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java index da2e73e59a2..5adcf8395d5 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java @@ -372,8 +372,8 @@ else if (!capturesOnly || typeArguments[i] instanceof CaptureBinding) public void addThrowsContraints(TypeBinding[] parameters, InferenceVariable[] variables, ReferenceBinding[] thrownExceptions) { for (int i = 0; i < parameters.length; i++) { TypeBinding parameter = parameters[i]; - for (int j = 0; j < thrownExceptions.length; j++) { - if (TypeBinding.equalsEquals(parameter, thrownExceptions[j])) { + for (ReferenceBinding thrownException : thrownExceptions) { + if (TypeBinding.equalsEquals(parameter, thrownException)) { this.currentBounds.inThrows.add(variables[i].prototype()); break; } @@ -909,8 +909,8 @@ private Boolean moreSpecificMain(TypeBinding si, TypeBinding ti, Expression expr return null; // bullet 4 // each element of the intersection is a superinterface of I, or a parameterization of a superinterface of I. } - for (int i = 0; i < elements.length; i++) - if (siSubI(elements[i], funcI)) + for (TypeBinding binding : elements) + if (siSubI(binding, funcI)) return null; // bullet 5 // some element of the intersection is a subinterface of I, or a parameterization of a subinterface of I. } @@ -943,8 +943,8 @@ private boolean checkExpression(Expression expri, TypeBinding[] u, TypeBinding r && !(r1.isCompatibleWith(r2) || r2.isCompatibleWith(r1))) { // "these rules are applied recursively to R1 and R2, for each result expression in expi." // (what does "applied .. to R1 and R2" mean? Why mention R1/R2 and not U/V?) - for (int i = 0; i < results.length; i++) { - if (!checkExpression(results[i], u, r1, v, r2)) + for (Expression result : results) { + if (!checkExpression(result, u, r1, v, r2)) return false; } return true; @@ -1004,8 +1004,8 @@ private boolean siSuperI(TypeBinding si, TypeBinding funcI) { return true; TypeBinding[] superIfcs = funcI.superInterfaces(); if (superIfcs == null) return false; - for (int i = 0; i < superIfcs.length; i++) { - if (siSuperI(si, superIfcs[i].original())) + for (TypeBinding superIfc : superIfcs) { + if (siSuperI(si, superIfc.original())) return true; } return false; @@ -1016,8 +1016,8 @@ private boolean siSubI(TypeBinding si, TypeBinding funcI) { return true; TypeBinding[] superIfcs = si.superInterfaces(); if (superIfcs == null) return false; - for (int i = 0; i < superIfcs.length; i++) { - if (siSubI(superIfcs[i], funcI)) + for (TypeBinding superIfc : superIfcs) { + if (siSubI(superIfc, funcI)) return true; } return false; @@ -1104,8 +1104,8 @@ private boolean reduce() throws InferenceFailureException { */ public boolean isResolved(BoundSet boundSet) { if (this.inferenceVariables != null) { - for (int i = 0; i < this.inferenceVariables.length; i++) { - if (!boundSet.isInstantiated(this.inferenceVariables[i])) + for (InferenceVariable inferenceVariable : this.inferenceVariables) { + if (!boundSet.isInstantiated(inferenceVariable)) return false; } } @@ -1124,8 +1124,7 @@ public boolean isResolved(BoundSet boundSet) { if (this.outerContext != null && this.outerContext.stepCompleted < TYPE_INFERRED) outerVariables = this.outerContext.inferenceVariables; for (int i = 0; i < typeParameters.length; i++) { - for (int j = 0; j < this.inferenceVariables.length; j++) { - InferenceVariable variable = this.inferenceVariables[j]; + for (InferenceVariable variable : this.inferenceVariables) { if (isSameSite(variable.site, site) && TypeBinding.equalsEquals(variable.typeParameter, typeParameters[i])) { TypeBinding outerVar = null; if (outerVariables != null && (outerVar = boundSet.getEquivalentOuterVariable(variable, outerVariables)) != null) @@ -1343,8 +1342,8 @@ private boolean setUpperBounds(CaptureBinding18 typeVariable, TypeBinding[] subs if (glbs == null) return false; if (typeVariable.lowerBound != null) { - for (int i = 0; i < glbs.length; i++) { - if (!typeVariable.lowerBound.isCompatibleWith(glbs[i])) + for (TypeBinding glb : glbs) { + if (!typeVariable.lowerBound.isCompatibleWith(glb)) return false; // not well-formed } } @@ -1409,8 +1408,7 @@ private Set getSmallestVariableSet(BoundSet bounds, Inference private void addDependencies(BoundSet boundSet, Set variableSet, InferenceVariable currentVariable) { if (boundSet.isInstantiated(currentVariable)) return; // not added if (!variableSet.add(currentVariable)) return; // already present - for (int j = 0; j < this.inferenceVariables.length; j++) { - InferenceVariable nextVariable = this.inferenceVariables[j]; + for (InferenceVariable nextVariable : this.inferenceVariables) { if (TypeBinding.equalsEquals(nextVariable, currentVariable)) continue; if (boundSet.dependsOnResolutionOf(currentVariable, nextVariable)) addDependencies(boundSet, variableSet, nextVariable); @@ -1628,9 +1626,8 @@ private boolean canInfluenceAnyOf(InferenceVariable in, Set a Set allOutputVariables(Set constraints) { Set result = new LinkedHashSet<>(); - Iterator it = constraints.iterator(); - while (it.hasNext()) { - result.addAll(it.next().outputVariables(this)); + for (ConstraintFormula constraint : constraints) { + result.addAll(constraint.outputVariables(this)); } return result; } @@ -1790,10 +1787,10 @@ public String toString() { buf.append('\n'); if (this.inferenceVariables != null) { buf.append("Inference Variables:\n"); //$NON-NLS-1$ - for (int i = 0; i < this.inferenceVariables.length; i++) { - buf.append('\t').append(this.inferenceVariables[i].sourceName).append("\t:\t"); //$NON-NLS-1$ - if (this.currentBounds != null && this.currentBounds.isInstantiated(this.inferenceVariables[i])) - buf.append(this.currentBounds.getInstantiation(this.inferenceVariables[i], this.environment).readableName()); + for (InferenceVariable inferenceVariable : this.inferenceVariables) { + buf.append('\t').append(inferenceVariable.sourceName).append("\t:\t"); //$NON-NLS-1$ + if (this.currentBounds != null && this.currentBounds.isInstantiated(inferenceVariable)) + buf.append(this.currentBounds.getInstantiation(inferenceVariable, this.environment).readableName()); else buf.append("NOT INSTANTIATED"); //$NON-NLS-1$ buf.append('\n'); @@ -1801,9 +1798,9 @@ public String toString() { } if (this.initialConstraints != null) { buf.append("Initial Constraints:\n"); //$NON-NLS-1$ - for (int i = 0; i < this.initialConstraints.length; i++) - if (this.initialConstraints[i] != null) - buf.append('\t').append(this.initialConstraints[i].toString()).append('\n'); + for (ConstraintFormula initialConstraint : this.initialConstraints) + if (initialConstraint != null) + buf.append('\t').append(initialConstraint.toString()).append('\n'); } if (this.currentBounds != null) buf.append(this.currentBounds.toString()); @@ -1820,8 +1817,8 @@ public static ParameterizedTypeBinding parameterizedWithWildcard(TypeBinding typ ParameterizedTypeBinding parameterizedType = (ParameterizedTypeBinding) type; TypeBinding[] arguments = parameterizedType.arguments; if (arguments != null) { - for (int i = 0; i < arguments.length; i++) - if (arguments[i].isWildcard()) + for (TypeBinding argument : arguments) + if (argument.isWildcard()) return parameterizedType; } return null; @@ -1897,8 +1894,7 @@ public void forwardResults(BoundSet result, Invocation invocation, Parameterized updateInnerDiamonds(pmb, arguments); for (int i = 0, length = arguments == null ? 0 : arguments.length; i < length; i++) { Expression [] expressions = arguments[i].getPolyExpressions(); - for (int j = 0, jLength = expressions.length; j < jLength; j++) { - Expression expression = expressions[j]; + for (Expression expression : expressions) { if (!(expression instanceof Invocation)) continue; Invocation polyInvocation = (Invocation) expression; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java index 03a01809cd5..c6cb99b9ffb 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceSubstitution.java @@ -92,8 +92,8 @@ public TypeBinding substitute(Substitution substitution, TypeBinding originalTyp } private boolean isInSites(InvocationSite otherSite) { - for (int i = 0; i < this.sites.length; i++) - if (InferenceContext18.isSameSite(this.sites[i], otherSite)) + for (InvocationSite site : this.sites) + if (InferenceContext18.isSameSite(site, otherSite)) return true; return false; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java index a684ba71db1..b917863ad02 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/IntersectionTypeBinding18.java @@ -231,8 +231,8 @@ public boolean isSubtypeOf(TypeBinding other, boolean simulatingBugJDK8026527) { return false; } } - for (int i = 0; i < this.intersectingTypes.length; i++) { - if (this.intersectingTypes[i].isSubtypeOf(other, false)) + for (ReferenceBinding intersectingType : this.intersectingTypes) { + if (intersectingType.isSubtypeOf(other, false)) return true; } return false; @@ -327,8 +327,7 @@ public String toString() { } public TypeBinding getSAMType(Scope scope) { - for (int i = 0, max = this.intersectingTypes.length; i < max; i++) { - TypeBinding typeBinding = this.intersectingTypes[i]; + for (ReferenceBinding typeBinding : this.intersectingTypes) { MethodBinding methodBinding = typeBinding.getSingleAbstractMethod(scope, true); // Why doesn't getSingleAbstractMethod do as the javadoc says, and return null // when it is not a SAM type @@ -341,8 +340,8 @@ public TypeBinding getSAMType(Scope scope) { @Override void collectInferenceVariables(Set variables) { - for (int i = 0; i < this.intersectingTypes.length; i++) - this.intersectingTypes[i].collectInferenceVariables(variables); + for (ReferenceBinding intersectingType : this.intersectingTypes) + intersectingType.collectInferenceVariables(variables); } @Override @@ -367,8 +366,8 @@ public ReferenceBinding downwardsProjection(Scope scope, TypeBinding[] mentioned public boolean mentionsAny(TypeBinding[] parameters, int idx) { if (super.mentionsAny(parameters, idx)) return true; - for (int i = 0; i < this.intersectingTypes.length; i++) { - if (this.intersectingTypes[i].mentionsAny(parameters, -1)) + for (ReferenceBinding intersectingType : this.intersectingTypes) { + if (intersectingType.mentionsAny(parameters, -1)) return true; } return false; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java index 0864240351e..9e84835db00 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java @@ -317,8 +317,7 @@ public String toString() { public void updateInnerEmulationDependents() { if (!isPrototype()) throw new IllegalStateException(); if (this.dependents != null) { - for (int i = 0; i < this.dependents.length; i++) { - InnerEmulationDependency dependency = this.dependents[i]; + for (InnerEmulationDependency dependency : this.dependents) { // System.out.println("Updating " + new String(this.readableName()) + " --> " + new String(dependency.scope.enclosingType().readableName())); dependency.scope.propagateInnerEmulation(this, dependency.wasEnclosingInstanceSupplied); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java index 69ced386cf8..d8b4f992c7c 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java @@ -50,6 +50,7 @@ import java.util.function.Function; import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.ClassFilePool; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; @@ -1407,22 +1408,22 @@ public TypeBinding createAnnotatedType(TypeBinding type, AnnotationBinding[] new long tagBitsSeen = 0; AnnotationBinding[] filtered = new AnnotationBinding[newbies.length]; int count = 0; - for (int i = 0; i < newbies.length; i++) { - if (newbies[i] == null) { + for (AnnotationBinding newbie : newbies) { + if (newbie == null) { filtered[count++] = null; // reset tagBitsSeen for next array dimension tagBitsSeen = 0; continue; } long tagBits = 0; - if (newbies[i].type.hasNullBit(TypeIds.BitNonNullAnnotation)) { + if (newbie.type.hasNullBit(TypeIds.BitNonNullAnnotation)) { tagBits = TagBits.AnnotationNonNull; - } else if (newbies[i].type.hasNullBit(TypeIds.BitNullableAnnotation)) { + } else if (newbie.type.hasNullBit(TypeIds.BitNullableAnnotation)) { tagBits = TagBits.AnnotationNullable; } if ((tagBitsSeen & tagBits) == 0) { tagBitsSeen |= tagBits; - filtered[count++] = newbies[i]; + filtered[count++] = newbie; } } if (count < newbies.length) @@ -1907,8 +1908,8 @@ ReferenceBinding getTypeFromConstantPoolName(char[] signature, int start, int en char[][] compoundName = CharOperation.splitOn('/', signature, start, end); boolean wasMissingType = false; if (missingTypeNames != null) { - for (int i = 0, max = missingTypeNames.length; i < max; i++) { - if (CharOperation.equals(compoundName, missingTypeNames[i])) { + for (char[][] missingTypeName : missingTypeNames) { + if (CharOperation.equals(compoundName, missingTypeName)) { wasMissingType = true; break; } @@ -2057,8 +2058,8 @@ boolean qualifiedNameMatchesSignature(char[][] name, char[] signature) { int s = 1; // skip 'L' for (int i = 0; i < name.length; i++) { char[] n = name[i]; - for (int j = 0; j < n.length; j++) - if (n[j] != signature[s++]) + for (char c : n) + if (c != signature[s++]) return false; if (signature[s] == ';' && i == name.length-1) return true; @@ -2250,8 +2251,8 @@ observe any parameterization of super class and/or super interfaces in order to } public void releaseClassFiles(org.eclipse.jdt.internal.compiler.ClassFile[] classFiles) { - for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) - this.classFilePool.release(classFiles[i]); + for (ClassFile classFile : classFiles) + this.classFilePool.release(classFile); } public void reset() { @@ -2335,8 +2336,7 @@ public AnnotationBinding[] filterNullTypeAnnotations(AnnotationBinding[] typeAnn return typeAnnotations; AnnotationBinding[] filtered = new AnnotationBinding[typeAnnotations.length]; int count = 0; - for (int i = 0; i < typeAnnotations.length; i++) { - AnnotationBinding typeAnnotation = typeAnnotations[i]; + for (AnnotationBinding typeAnnotation : typeAnnotations) { if (typeAnnotation == null) { count++; // sentinel in annotation sequence for array dimensions } else { @@ -2355,8 +2355,7 @@ public AnnotationBinding[] filterNullTypeAnnotations(AnnotationBinding[] typeAnn public boolean containsNullTypeAnnotation(IBinaryAnnotation[] typeAnnotations) { if (typeAnnotations.length == 0) return false; - for (int i = 0; i < typeAnnotations.length; i++) { - IBinaryAnnotation typeAnnotation = typeAnnotations[i]; + for (IBinaryAnnotation typeAnnotation : typeAnnotations) { char[] typeName = typeAnnotation.getTypeName(); // typeName must be "Lfoo/X;" if (typeName == null || typeName.length < 3 || typeName[0] != 'L') continue; @@ -2369,8 +2368,7 @@ public boolean containsNullTypeAnnotation(IBinaryAnnotation[] typeAnnotations) { public boolean containsNullTypeAnnotation(AnnotationBinding[] typeAnnotations) { if (typeAnnotations.length == 0) return false; - for (int i = 0; i < typeAnnotations.length; i++) { - AnnotationBinding typeAnnotation = typeAnnotations[i]; + for (AnnotationBinding typeAnnotation : typeAnnotations) { if (typeAnnotation.type.hasNullBit(TypeIds.BitNonNullAnnotation|TypeIds.BitNullableAnnotation)) return true; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java index 2d1fc93366b..b7795cfa4f8 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java @@ -416,18 +416,17 @@ public final boolean canBeSeenBy(TypeBinding receiverType, InvocationSite invoca public List collectMissingTypes(List missingTypes) { if ((this.tagBits & TagBits.HasMissingType) != 0) { missingTypes = this.returnType.collectMissingTypes(missingTypes); - for (int i = 0, max = this.parameters.length; i < max; i++) { - missingTypes = this.parameters[i].collectMissingTypes(missingTypes); + for (TypeBinding parameter : this.parameters) { + missingTypes = parameter.collectMissingTypes(missingTypes); } - for (int i = 0, max = this.thrownExceptions.length; i < max; i++) { - missingTypes = this.thrownExceptions[i].collectMissingTypes(missingTypes); + for (ReferenceBinding thrownException : this.thrownExceptions) { + missingTypes = thrownException.collectMissingTypes(missingTypes); } - for (int i = 0, max = this.typeVariables.length; i < max; i++) { - TypeVariableBinding variable = this.typeVariables[i]; + for (TypeVariableBinding variable : this.typeVariables) { missingTypes = variable.superclass().collectMissingTypes(missingTypes); ReferenceBinding[] interfaces = variable.superInterfaces(); - for (int j = 0, length = interfaces.length; j < length; j++) { - missingTypes = interfaces[j].collectMissingTypes(missingTypes); + for (ReferenceBinding binding : interfaces) { + missingTypes = binding.collectMissingTypes(missingTypes); } } } @@ -604,9 +603,9 @@ public MethodBinding findOriginalInheritedMethod(MethodBinding inheritedMethod) if (TypeBinding.notEquals(inheritedOriginal.declaringClass, superType)) { // must find inherited method with the same substituted variables MethodBinding[] superMethods = ((ReferenceBinding) superType).getMethods(inheritedOriginal.selector, inheritedOriginal.parameters.length); - for (int m = 0, l = superMethods.length; m < l; m++) - if (superMethods[m].original() == inheritedOriginal) - return superMethods[m]; + for (MethodBinding superMethod : superMethods) + if (superMethod.original() == inheritedOriginal) + return superMethod; } return inheritedOriginal; } @@ -624,14 +623,14 @@ public char[] genericSignature() { StringBuilder sig = new StringBuilder(10); if (this.typeVariables != Binding.NO_TYPE_VARIABLES) { sig.append('<'); - for (int i = 0, length = this.typeVariables.length; i < length; i++) { - sig.append(this.typeVariables[i].genericSignature()); + for (TypeVariableBinding typeVariable : this.typeVariables) { + sig.append(typeVariable.genericSignature()); } sig.append('>'); } sig.append('('); - for (int i = 0, length = this.parameters.length; i < length; i++) { - sig.append(this.parameters[i].genericTypeSignature()); + for (TypeBinding parameter : this.parameters) { + sig.append(parameter.genericTypeSignature()); } sig.append(')'); if (this.returnType != null) @@ -1111,8 +1110,7 @@ public final char[] computeSignature(ClassFile classFile) { // take into account the synthetic argument type signatures as well ReferenceBinding[] syntheticArgumentTypes = this.declaringClass.syntheticEnclosingInstanceTypes(); if (syntheticArgumentTypes != null) { - for (int i = 0, count = syntheticArgumentTypes.length; i < count; i++) { - ReferenceBinding syntheticArgumentType = syntheticArgumentTypes[i]; + for (ReferenceBinding syntheticArgumentType : syntheticArgumentTypes) { if ((syntheticArgumentType.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { this.tagBits |= TagBits.ContainsNestedTypeReferences; if (classFile != null) @@ -1128,8 +1126,7 @@ public final char[] computeSignature(ClassFile classFile) { } if (targetParameters != Binding.NO_PARAMETERS) { - for (int i = 0, max = targetParameters.length; i < max; i++) { - TypeBinding targetParameter = targetParameters[i]; + for (TypeBinding targetParameter : targetParameters) { TypeBinding leafTargetParameterType = targetParameter.leafComponentType(); if ((leafTargetParameterType.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { this.tagBits |= TagBits.ContainsNestedTypeReferences; @@ -1193,8 +1190,7 @@ public char[] signature(ClassFile classFile) { // take into account the synthetic argument type signatures as well ReferenceBinding[] syntheticArgumentTypes = this.declaringClass.syntheticEnclosingInstanceTypes(); if (syntheticArgumentTypes != null) { - for (int i = 0, count = syntheticArgumentTypes.length; i < count; i++) { - ReferenceBinding syntheticArgumentType = syntheticArgumentTypes[i]; + for (ReferenceBinding syntheticArgumentType : syntheticArgumentTypes) { if ((syntheticArgumentType.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(classFile, syntheticArgumentType); } @@ -1206,8 +1202,7 @@ public char[] signature(ClassFile classFile) { } if (targetParameters != Binding.NO_PARAMETERS) { - for (int i = 0, max = targetParameters.length; i < max; i++) { - TypeBinding targetParameter = targetParameters[i]; + for (TypeBinding targetParameter : targetParameters) { TypeBinding leafTargetParameterType = targetParameter.leafComponentType(); if ((leafTargetParameterType.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(classFile, leafTargetParameterType); @@ -1348,8 +1343,8 @@ static int getNonNullByDefaultValue(AnnotationBinding annotation) { } else if (elementValuePairs.length > 0) { // evaluate the contained EnumConstantSignatures: int nullness = 0; - for (int i = 0; i < elementValuePairs.length; i++) - nullness |= Annotation.nullLocationBitsFromAnnotationValue(elementValuePairs[i].getValue()); + for (ElementValuePair elementValuePair : elementValuePairs) + nullness |= Annotation.nullLocationBitsFromAnnotationValue(elementValuePair.getValue()); return nullness; } else { // empty argument: cancel all defaults from enclosing scopes diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java index 0db497f065a..8da1abff8d3 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java @@ -358,8 +358,8 @@ public void computeLocalVariablePositions(int initOffset, CodeStream codeStream) // sneak in extra argument before other local variables if (this.extraSyntheticArguments != null) { - for (int iarg = 0, maxArguments = this.extraSyntheticArguments.length; iarg < maxArguments; iarg++){ - SyntheticArgumentBinding argument = this.extraSyntheticArguments[iarg]; + for (SyntheticArgumentBinding extraSyntheticArgument : this.extraSyntheticArguments) { + SyntheticArgumentBinding argument = extraSyntheticArgument; argument.resolvedPosition = this.offset; if ((TypeBinding.equalsEquals(argument.type, TypeBinding.LONG)) || (TypeBinding.equalsEquals(argument.type, TypeBinding.DOUBLE))){ this.offset += 2; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java index eaa8bc84604..2404a4e6cbc 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java @@ -308,8 +308,8 @@ void checkForRedundantSuperinterfaces(ReferenceBinding superclass, ReferenceBind } redundantInterfaces.add(implementedInterface); TypeReference[] refs = this.type.scope.referenceContext.superInterfaces; - for (int r = 0, rl = refs.length; r < rl; r++) { - if (TypeBinding.equalsEquals(refs[r].resolvedType, toCheck)) { + for (TypeReference ref : refs) { + if (TypeBinding.equalsEquals(ref.resolvedType, toCheck)) { problemReporter().redundantSuperInterface(this.type, refs[j], implementedInterface, toCheck); break; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=320911 } @@ -324,8 +324,7 @@ void checkForRedundantSuperinterfaces(ReferenceBinding superclass, ReferenceBind ReferenceBinding superType = superclass; while (superType != null && superType.isValidBinding()) { if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) { - for (int i = 0, l = itsInterfaces.length; i < l; i++) { - ReferenceBinding inheritedInterface = itsInterfaces[i]; + for (ReferenceBinding inheritedInterface : itsInterfaces) { if (!inheritedInterfaces.includes(inheritedInterface) && inheritedInterface.isValidBinding()) { if (interfacesToCheck.includes(inheritedInterface)) { if (redundantInterfaces == null) { @@ -335,9 +334,9 @@ void checkForRedundantSuperinterfaces(ReferenceBinding superclass, ReferenceBind } redundantInterfaces.add(inheritedInterface); TypeReference[] refs = this.type.scope.referenceContext.superInterfaces; - for (int r = 0, rl = refs.length; r < rl; r++) { - if (TypeBinding.equalsEquals(refs[r].resolvedType, inheritedInterface)) { - problemReporter().redundantSuperInterface(this.type, refs[r], inheritedInterface, superType); + for (TypeReference ref : refs) { + if (TypeBinding.equalsEquals(ref.resolvedType, inheritedInterface)) { + problemReporter().redundantSuperInterface(this.type, ref, inheritedInterface, superType); break; } } @@ -371,9 +370,9 @@ void checkForRedundantSuperinterfaces(ReferenceBinding superclass, ReferenceBind } redundantInterfaces.add(inheritedInterface); TypeReference[] refs = this.type.scope.referenceContext.superInterfaces; - for (int r = 0, rl = refs.length; r < rl; r++) { - if (TypeBinding.equalsEquals(refs[r].resolvedType, inheritedInterface)) { - problemReporter().redundantSuperInterface(this.type, refs[r], inheritedInterface, superType); + for (TypeReference ref : refs) { + if (TypeBinding.equalsEquals(ref.resolvedType, inheritedInterface)) { + problemReporter().redundantSuperInterface(this.type, ref, inheritedInterface, superType); break; } } @@ -552,8 +551,7 @@ void computeInheritedMethods(ReferenceBinding superclass, ReferenceBinding[] sup continue nextMethod; MethodBinding[] existingMethods = (MethodBinding[]) this.inheritedMethods.get(inheritedMethod.selector); if (existingMethods != null) { - existing : for (int i = 0, length = existingMethods.length; i < length; i++) { - MethodBinding existingMethod = existingMethods[i]; + existing : for (MethodBinding existingMethod : existingMethods) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358, skip inherited method only if any overriding version // in a subclass is guaranteed to have the same erasure as an existing method. if (TypeBinding.notEquals(existingMethod.declaringClass, inheritedMethod.declaringClass) && areMethodsCompatible(existingMethod, inheritedMethod) && !canOverridingMethodDifferInErasure(existingMethod, inheritedMethod)) { @@ -586,8 +584,8 @@ void computeInheritedMethods(ReferenceBinding superclass, ReferenceBinding[] sup } else { MethodBinding[] nonVisible = (MethodBinding[]) nonVisibleDefaultMethods.get(inheritedMethod.selector); if (nonVisible != null && inheritedMethod.isAbstract()) - for (int i = 0, l = nonVisible.length; i < l; i++) - if (areMethodsCompatible(nonVisible[i], inheritedMethod)) + for (MethodBinding binding : nonVisible) + if (areMethodsCompatible(binding, inheritedMethod)) continue nextMethod; if (nonVisible == null) { nonVisible = new MethodBinding[] {inheritedMethod}; @@ -934,8 +932,8 @@ static boolean hasGenericParameter(MethodBinding method) { // may be only the return type that is generic, need to check parameters TypeBinding[] params = method.parameters; - for (int i = 0, l = params.length; i < l; i++) { - TypeBinding param = params[i].leafComponentType(); + for (TypeBinding binding : params) { + TypeBinding param = binding.leafComponentType(); if (param instanceof ReferenceBinding) { int modifiers = ((ReferenceBinding) param).modifiers; if ((modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java index ebe99eeec67..6d378d27f32 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java @@ -89,8 +89,7 @@ void checkConcreteInheritedMethod(MethodBinding concreteMethod, MethodBinding[] boolean hasReturnNonNullDefault = analyseNullAnnotations && concreteMethod.hasNonNullDefaultForReturnType(srcMethod); ParameterNonNullDefaultProvider hasParameterNonNullDefault = analyseNullAnnotations ? concreteMethod.hasNonNullDefaultForParameter(srcMethod): ParameterNonNullDefaultProvider.FALSE_PROVIDER; - for (int i = 0, l = abstractMethods.length; i < l; i++) { - MethodBinding abstractMethod = abstractMethods[i]; + for (MethodBinding abstractMethod : abstractMethods) { if (concreteMethod.isVarargs() != abstractMethod.isVarargs()) problemReporter().varargsConflict(concreteMethod, abstractMethod, this.type); @@ -209,8 +208,8 @@ void checkForNameClash(MethodBinding currentMethod, MethodBinding inheritedMetho superType = superType.superclass(); // now start with its superclass while (superType != null && superType.isValidBinding()) { MethodBinding[] methods = superType.getMethods(currentMethod.selector); - for (int m = 0, n = methods.length; m < n; m++) { - MethodBinding substitute = computeSubstituteMethod(methods[m], currentMethod); + for (MethodBinding method : methods) { + MethodBinding substitute = computeSubstituteMethod(method, currentMethod); if (substitute != null && !isSubstituteParameterSubsignature(currentMethod, substitute) && detectNameClash(currentMethod, substitute, true)) return; } @@ -237,8 +236,8 @@ void checkForNameClash(MethodBinding currentMethod, MethodBinding inheritedMetho superType = interfacesToVisit[i]; if (superType.isValidBinding()) { MethodBinding[] methods = superType.getMethods(currentMethod.selector); - for (int m = 0, n = methods.length; m < n; m++){ - MethodBinding substitute = computeSubstituteMethod(methods[m], currentMethod); + for (MethodBinding method : methods) { + MethodBinding substitute = computeSubstituteMethod(method, currentMethod); if (substitute != null && !isSubstituteParameterSubsignature(currentMethod, substitute) && detectNameClash(currentMethod, substitute, true)) return; } @@ -446,8 +445,7 @@ void reportRawReferences() { for (int s = methodArray.length; --s >= 0;) { if (methodArray[s] == null) continue; MethodBinding[] current = (MethodBinding[]) methodArray[s]; - for (int i = 0, length = current.length; i < length; i++) { - MethodBinding currentMethod = current[i]; + for (MethodBinding currentMethod : current) { if ((currentMethod.modifiers & (ExtraCompilerModifiers.AccImplementing | ExtraCompilerModifiers.AccOverriding)) == 0) { AbstractMethodDeclaration methodDecl = currentMethod.sourceMethod(); if (methodDecl == null) return; @@ -574,8 +572,7 @@ void checkMethods() { boolean[] isInherited = new boolean[inheritedLength]; Arrays.fill(isInherited, true); if (current != null) { - for (int i = 0, length1 = current.length; i < length1; i++) { - MethodBinding currentMethod = current[i]; + for (MethodBinding currentMethod : current) { MethodBinding[] nonMatchingInherited = null; for (int j = 0; j < inheritedLength; j++) { MethodBinding inheritedMethod = computeSubstituteMethod(inherited[j], currentMethod); @@ -847,8 +844,7 @@ boolean detectNameClash(MethodBinding current, MethodBinding inherited, boolean // clash to report to begin with (the common case), no penalty needs to be paid. MethodBinding[] currentNamesakes = (MethodBinding[]) this.currentMethods.get(inherited.selector); if (currentNamesakes.length > 1) { // we know it ought to at least one and that current is NOT the override - for (int i = 0, length = currentNamesakes.length; i < length; i++) { - MethodBinding currentMethod = currentNamesakes[i]; + for (MethodBinding currentMethod : currentNamesakes) { if (currentMethod != current && doesMethodOverride(currentMethod, inherited)) { methodToCheck = currentMethod; break; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java index 9d75380d81e..c2565c9448f 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java @@ -387,8 +387,8 @@ protected void recordExportRestrictions(PlainPackageBinding exportedPackage, cha targetModuleSet = new SimpleSetOfCharArray(targetModules.length); this.exportRestrictions.put(exportedPackage, targetModuleSet); } - for (int i = 0; i < targetModules.length; i++) { - targetModuleSet.add(targetModules[i]); + for (char[] targetModule : targetModules) { + targetModuleSet.add(targetModule); } } } @@ -405,8 +405,8 @@ protected void recordOpensRestrictions(PlainPackageBinding openedPackage, char[] targetModuleSet = new SimpleSetOfCharArray(targetModules.length); this.openRestrictions.put(openedPackage, targetModuleSet); } - for (int i = 0; i < targetModules.length; i++) { - targetModuleSet.add(targetModules[i]); + for (char[] targetModule : targetModules) { + targetModuleSet.add(targetModule); } } } @@ -516,8 +516,7 @@ public boolean isPackageExportedTo(PackageBinding pkg, ModuleBinding client) { return pkg.enclosingModule == this; // no transitive export } PackageBinding[] initializedExports = getExports(); - for (int i = 0; i < initializedExports.length; i++) { - PackageBinding export = initializedExports[i]; + for (PackageBinding export : initializedExports) { if (export.subsumes(resolved)) { if (this.exportRestrictions != null) { SimpleSetOfCharArray restrictions = this.exportRestrictions.get(export); @@ -732,25 +731,24 @@ public String toString() { buffer.append("module " + new String(readableName())); //$NON-NLS-1$ if (this.requires.length > 0) { buffer.append("\n/* requires */\n"); //$NON-NLS-1$ - for (int i = 0; i < this.requires.length; i++) { + for (ModuleBinding require : this.requires) { buffer.append("\n\t"); //$NON-NLS-1$ if (this.requiresTransitive != null) { for (ModuleBinding reqTrans : this.requiresTransitive) { - if (reqTrans == this.requires[i]) { + if (reqTrans == require) { buffer.append("transitive "); //$NON-NLS-1$ break; } } } - buffer.append(this.requires[i].moduleName); + buffer.append(require.moduleName); } } else { buffer.append("\nNo Requires"); //$NON-NLS-1$ } if (this.exportedPackages != null && this.exportedPackages.length > 0) { buffer.append("\n/* exports */\n"); //$NON-NLS-1$ - for (int i = 0; i < this.exportedPackages.length; i++) { - PackageBinding export = this.exportedPackages[i]; + for (PlainPackageBinding export : this.exportedPackages) { buffer.append("\n\t"); //$NON-NLS-1$ if (export == null) { buffer.append(""); //$NON-NLS-1$ @@ -775,8 +773,7 @@ public String toString() { } if (this.openedPackages != null && this.openedPackages.length > 0) { buffer.append("\n/* exports */\n"); //$NON-NLS-1$ - for (int i = 0; i < this.openedPackages.length; i++) { - PackageBinding opens = this.openedPackages[i]; + for (PlainPackageBinding opens : this.openedPackages) { buffer.append("\n\t"); //$NON-NLS-1$ if (opens == null) { buffer.append(""); //$NON-NLS-1$ @@ -801,23 +798,23 @@ public String toString() { } if (this.uses != null && this.uses.length > 0) { buffer.append("\n/* uses /*\n"); //$NON-NLS-1$ - for (int i = 0; i < this.uses.length; i++) { + for (TypeBinding binding : this.uses) { buffer.append("\n\t"); //$NON-NLS-1$ - buffer.append(this.uses[i].debugName()); + buffer.append(binding.debugName()); } } else { buffer.append("\nNo Uses"); //$NON-NLS-1$ } if (this.services != null && this.services.length > 0) { buffer.append("\n/* Services */\n"); //$NON-NLS-1$ - for (int i = 0; i < this.services.length; i++) { + for (TypeBinding binding : this.services) { buffer.append("\n\t"); //$NON-NLS-1$ buffer.append("provides "); //$NON-NLS-1$ - buffer.append(this.services[i].debugName()); + buffer.append(binding.debugName()); buffer.append(" with "); //$NON-NLS-1$ - if (this.implementations != null && this.implementations.containsKey(this.services[i])) { + if (this.implementations != null && this.implementations.containsKey(binding)) { String sep = ""; //$NON-NLS-1$ - for (TypeBinding impl : this.implementations.get(this.services[i])) { + for (TypeBinding impl : this.implementations.get(binding)) { buffer.append(sep).append(impl.debugName()); sep = ", "; //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java index 49da48a4a01..6f4940b978d 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java @@ -733,8 +733,8 @@ private ParameterizedGenericMethodBinding inferFromExpectedType(Scope scope, Inf if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution } } - for (int j = 0, max = originalVariable.superInterfaces.length; j < max; j++) { - TypeBinding substitutedBound = Scope.substitute(this, originalVariable.superInterfaces[j]); + for (ReferenceBinding superInterface : originalVariable.superInterfaces) { + TypeBinding substitutedBound = Scope.substitute(this, superInterface); argument.collectSubstitutes(scope, substitutedBound, inferenceContext, TypeConstants.CONSTRAINT_SUPER); if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution // JLS 15.12.2.8 claims reverse inference shouldn't occur, however it improves inference diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java index 865aa31790a..7ecbcad0d3b 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java @@ -88,10 +88,10 @@ public ParameterizedTypeBinding(ReferenceBinding type, TypeBinding[] arguments, if (type instanceof UnresolvedReferenceBinding) ((UnresolvedReferenceBinding) type).addWrapper(this, environment); if (arguments != null) { - for (int i = 0, l = arguments.length; i < l; i++) { - if (arguments[i] instanceof UnresolvedReferenceBinding) - ((UnresolvedReferenceBinding) arguments[i]).addWrapper(this, environment); - if (arguments[i].hasNullTypeAnnotations()) + for (TypeBinding argument : arguments) { + if (argument instanceof UnresolvedReferenceBinding) + ((UnresolvedReferenceBinding) argument).addWrapper(this, environment); + if (argument.hasNullTypeAnnotations()) this.tagBits |= TagBits.HasNullTypeAnnotation; } } @@ -243,8 +243,8 @@ public List collectMissingTypes(List missingTypes) { } missingTypes = genericType().collectMissingTypes(missingTypes); if (this.arguments != null) { - for (int i = 0, max = this.arguments.length; i < max; i++) { - missingTypes = this.arguments[i].collectMissingTypes(missingTypes); + for (TypeBinding argument : this.arguments) { + missingTypes = argument.collectMissingTypes(missingTypes); } } } @@ -394,9 +394,8 @@ public char[] computeUniqueKey(boolean isLeaf) { ReferenceBinding captureSourceType = null; if (this.arguments != null) { sig.append('<'); - for (int i = 0, length = this.arguments.length; i < length; i++) { - TypeBinding typeBinding = this.arguments[i]; - sig.append(typeBinding.computeUniqueKey(false/*not a leaf*/)); + for (TypeBinding typeBinding : this.arguments) { + sig.append(typeBinding.computeUniqueKey(false/*not a leaf*/)); if (typeBinding instanceof CaptureBinding) captureSourceType = ((CaptureBinding) typeBinding).sourceType; } @@ -675,8 +674,8 @@ public char[] genericTypeSignature() { } if (this.arguments != null) { sig.append('<'); - for (int i = 0, length = this.arguments.length; i < length; i++) { - sig.append(this.arguments[i].genericTypeSignature()); + for (TypeBinding argument : this.arguments) { + sig.append(argument.genericTypeSignature()); } sig.append('>'); } @@ -963,8 +962,7 @@ void initialize(ReferenceBinding someType, TypeBinding[] someArguments) { } if (someArguments != null) { this.arguments = someArguments; - for (int i = 0, length = someArguments.length; i < length; i++) { - TypeBinding someArgument = someArguments[i]; + for (TypeBinding someArgument : someArguments) { switch (someArgument.kind()) { case Binding.WILDCARD_TYPE : this.tagBits |= TagBits.HasDirectWildcard; @@ -1067,8 +1065,8 @@ public boolean isHierarchyConnected() { @Override public boolean isProperType(boolean admitCapture18) { if (this.arguments != null) { - for (int i = 0; i < this.arguments.length; i++) - if (!this.arguments[i].isProperType(admitCapture18)) + for (TypeBinding argument : this.arguments) + if (!argument.isProperType(admitCapture18)) return false; } return super.isProperType(admitCapture18); @@ -1647,8 +1645,8 @@ public String toString() { if (this.fields != null) { if (this.fields != Binding.NO_FIELDS) { buffer.append("\n/* fields */"); //$NON-NLS-1$ - for (int i = 0, length = this.fields.length; i < length; i++) - buffer.append('\n').append((this.fields[i] != null) ? this.fields[i].toString() : "NULL FIELD"); //$NON-NLS-1$ + for (FieldBinding field : this.fields) + buffer.append('\n').append((field != null) ? field.toString() : "NULL FIELD"); //$NON-NLS-1$ } } else { buffer.append("NULL FIELDS"); //$NON-NLS-1$ @@ -1657,8 +1655,8 @@ public String toString() { if (this.methods != null) { if (this.methods != Binding.NO_METHODS) { buffer.append("\n/* methods */"); //$NON-NLS-1$ - for (int i = 0, length = this.methods.length; i < length; i++) - buffer.append('\n').append((this.methods[i] != null) ? this.methods[i].toString() : "NULL METHOD"); //$NON-NLS-1$ + for (MethodBinding method : this.methods) + buffer.append('\n').append((method != null) ? method.toString() : "NULL METHOD"); //$NON-NLS-1$ } } else { buffer.append("NULL METHODS"); //$NON-NLS-1$ @@ -1767,8 +1765,7 @@ public MethodBinding getSingleAbstractMethod(final Scope scope, boolean replaceW } ReferenceBinding substitutedDeclaringType = (ReferenceBinding) declaringType.findSuperTypeOriginatingFrom(theAbstractMethod.declaringClass); MethodBinding [] choices = substitutedDeclaringType.getMethods(theAbstractMethod.selector); - for (int i = 0, length = choices.length; i < length; i++) { - MethodBinding method = choices[i]; + for (MethodBinding method : choices) { if (!method.isAbstract() || method.redeclaresPublicObjectMethod(scope)) continue; // (re)skip statics, defaults, public object methods ... if (method.problemId() == ProblemReasons.ContradictoryNullAnnotations) method = ((ProblemMethodBinding) method).closestMatch; @@ -1806,13 +1803,13 @@ public TypeBinding[] getNonWildcardParameters(Scope scope) { // Ui allBounds[idx++] = wildcard.bound; if (otherUBounds != null) - for (int j = 0; j < otherUBounds.length; j++) - allBounds[idx++] = otherUBounds[j]; + for (TypeBinding otherUBound : otherUBounds) + allBounds[idx++] = otherUBound; // Bi if (typeParameters[i].firstBound != null) allBounds[idx++] = typeParameters[i].firstBound; - for (int j = 0; j < otherBBounds.length; j++) - allBounds[idx++] = otherBBounds[j]; + for (TypeBinding otherBBound : otherBBounds) + allBounds[idx++] = otherBBound; TypeBinding[] glb = Scope.greaterLowerBound(allBounds, null, this.environment); if (glb == null || glb.length == 0) { return null; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ProblemReferenceBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ProblemReferenceBinding.java index 0e1710f57d7..f7f390d0ff3 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ProblemReferenceBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ProblemReferenceBinding.java @@ -92,8 +92,7 @@ public static String problemReasonString(int problemReason) { simpleName = simpleName.substring(lastDot+1); } Field[] fields = reasons.getFields(); - for (int i = 0, length = fields.length; i < length; i++) { - Field field = fields[i]; + for (Field field : fields) { if (!field.getType().equals(int.class)) continue; if (field.getInt(reasons) == problemReason) { return simpleName + '.' + field.getName(); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java index 06a5611612d..97a04883ceb 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java @@ -274,8 +274,7 @@ public MethodBinding getSingleAbstractMethod(Scope scope, boolean replaceWildcar ReferenceBinding declaringType = (ReferenceBinding) scope.environment().convertToRawType(genericType, true); declaringType = (ReferenceBinding) declaringType.findSuperTypeOriginatingFrom(theAbstractMethod.declaringClass); MethodBinding [] choices = declaringType.getMethods(theAbstractMethod.selector); - for (int i = 0, length = choices.length; i < length; i++) { - MethodBinding method = choices[i]; + for (MethodBinding method : choices) { if (!method.isAbstract() || method.redeclaresPublicObjectMethod(scope)) continue; // (re)skip statics, defaults, public object methods ... this.singleAbstractMethod[index] = method; break; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java index e784402d1d9..0cf8e912f9a 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java @@ -478,8 +478,8 @@ public char[] computeGenericTypeSignature(TypeVariableBinding[] typeVariables) { sig.append(';'); } else { sig.append('<'); - for (int i = 0, length = typeVariables.length; i < length; i++) { - sig.append(typeVariables[i].genericTypeSignature()); + for (TypeVariableBinding typeVariable : typeVariables) { + sig.append(typeVariable.genericTypeSignature()); } sig.append(">;"); //$NON-NLS-1$ } @@ -984,8 +984,8 @@ public void computeId(LookupEnvironment environment) { environment.getUnannotatedType(this); } -/**{@code - * p.X -> Lp/X; +/**{@code + * p.X -> Lp/X; * } */ @Override @@ -1026,16 +1026,16 @@ public boolean detectAnnotationCycle() { this.tagBits |= TagBits.BeginAnnotationCheck; MethodBinding[] currentMethods = methods(); boolean inCycle = false; // check each method before failing - for (int i = 0, l = currentMethods.length; i < l; i++) { - TypeBinding returnType = currentMethods[i].returnType.leafComponentType().erasure(); + for (MethodBinding currentMethod : currentMethods) { + TypeBinding returnType = currentMethod.returnType.leafComponentType().erasure(); if (TypeBinding.equalsEquals(this, returnType)) { if (this instanceof SourceTypeBinding) { - MethodDeclaration decl = (MethodDeclaration) currentMethods[i].sourceMethod(); + MethodDeclaration decl = (MethodDeclaration) currentMethod.sourceMethod(); ((SourceTypeBinding) this).scope.problemReporter().annotationCircularity(this, this, decl != null ? decl.returnType : null); } } else if (returnType.isAnnotationType() && ((ReferenceBinding) returnType).detectAnnotationCycle()) { if (this instanceof SourceTypeBinding) { - MethodDeclaration decl = (MethodDeclaration) currentMethods[i].sourceMethod(); + MethodDeclaration decl = (MethodDeclaration) currentMethod.sourceMethod(); ((SourceTypeBinding) this).scope.problemReporter().annotationCircularity(this, returnType, decl != null ? decl.returnType : null); } inCycle = true; @@ -1058,8 +1058,8 @@ public final ReferenceBinding enclosingTypeAt(int relativeDepth) { public int enumConstantCount() { int count = 0; FieldBinding[] fields = fields(); - for (int i = 0, length = fields.length; i < length; i++) { - if ((fields[i].modifiers & ClassFileConstants.AccEnum) != 0) count++; + for (FieldBinding field : fields) { + if ((field.modifiers & ClassFileConstants.AccEnum) != 0) count++; } return count; } @@ -1601,8 +1601,8 @@ protected boolean isSubTypeOfRTL(TypeBinding other) { if (other instanceof ReferenceBinding) { TypeBinding[] intersecting = ((ReferenceBinding) other).getIntersectingTypes(); if (intersecting != null) { - for (int i = 0; i < intersecting.length; i++) { - if (!isSubtypeOf(intersecting[i], false)) + for (TypeBinding binding : intersecting) { + if (!isSubtypeOf(binding, false)) return false; } return true; @@ -2272,9 +2272,9 @@ public void detectWrapperResource() { int contractsLength = 0; ReferenceBinding [] superInterfaces = superInterfaces(); - for (int i = 0, length = superInterfaces.length; i < length; i++) { + for (ReferenceBinding superInterface : superInterfaces) { // filterDefaultMethods=false => keep default methods needed to filter out any abstract methods they may override: - MethodBinding [] superInterfaceContracts = superInterfaces[i].getInterfaceAbstractContracts(scope, replaceWildcards, false); + MethodBinding [] superInterfaceContracts = superInterface.getInterfaceAbstractContracts(scope, replaceWildcards, false); final int superInterfaceContractsLength = superInterfaceContracts == null ? 0 : superInterfaceContracts.length; if (superInterfaceContractsLength == 0) continue; if (contractsLength < contractsCount + superInterfaceContractsLength) { @@ -2371,8 +2371,7 @@ public MethodBinding getSingleAbstractMethod(Scope scope, boolean replaceWildcar return this.singleAbstractMethod[index] = samProblemBinding; int contractParameterLength = 0; char [] contractSelector = null; - for (int i = 0, length = methods.length; i < length; i++) { - MethodBinding method = methods[i]; + for (MethodBinding method : methods) { if (method == null) continue; if (contractSelector == null) { contractSelector = method.selector; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java index c80d958b895..efcc7800166 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java @@ -135,8 +135,8 @@ private static class NullDefaultRange { } boolean contains(Annotation annotation) { - for (Annotation annotation2 : this.annotations) { - if (annotation2 == annotation) + for (Annotation a : this.annotations) { + if (a == annotation) return true; } return false; @@ -480,9 +480,9 @@ public static TypeBinding[] greaterLowerBound(TypeBinding[] types, /*@Nullable*/ static T[] filterValidTypes(T[] allTypes, Function ctor) { T[] valid = ctor.apply(allTypes.length); int count = 0; - for (int i = 0; i < allTypes.length; i++) { - if (allTypes[i].isValidBinding()) - valid[count++] = allTypes[i]; + for (T type : allTypes) { + if (type.isValidBinding()) + valid[count++] = type; } if (count == allTypes.length) return allTypes; @@ -1262,8 +1262,8 @@ protected MethodBinding findDefaultAbstractMethod( if (compatibleMethod != null) { if (compatibleMethod.isValidBinding()) { if (concreteMatches != null) { - for (int j = 0, length = concreteMatches.length; j < length; j++) { - if (methodVerifier.areMethodsCompatible(concreteMatches[j], compatibleMethod)) + for (MethodBinding concreteMatch : concreteMatches) { + if (methodVerifier.areMethodsCompatible(concreteMatch, compatibleMethod)) continue; // can skip this method since concreteMatch overrides it } } @@ -1730,8 +1730,7 @@ public MethodBinding findMethod0(ReferenceBinding receiverType, char[] selector, if (currentMethods.length == currentLength) { found.addAll(currentMethods); } else { - for (int i = 0, max = currentMethods.length; i < max; i++) { - MethodBinding currentMethod = currentMethods[i]; + for (MethodBinding currentMethod : currentMethods) { if (currentMethod != null) found.add(currentMethod); } @@ -1987,8 +1986,7 @@ protected void findMethodInSuperInterfaces(ReferenceBinding receiverType, char[] MethodBinding[] currentMethods = currentType.getMethods(selector); if (currentMethods.length > 0) { int foundSize = found.size; - next : for (int c = 0, l = currentMethods.length; c < l; c++) { - MethodBinding current = currentMethods[c]; + next : for (MethodBinding current : currentMethods) { if (!current.canBeSeenBy(receiverType, invocationSite, this)) continue next; if (foundSize > 0) { @@ -2232,8 +2230,7 @@ public Binding getBinding(char[] name, int mask, InvocationSite invocationSite, ImportBinding[] imports = unitScope.imports; if (imports != null) { // check single static imports - for (int i = 0, length = imports.length; i < length; i++) { - ImportBinding importBinding = imports[i]; + for (ImportBinding importBinding : imports) { if (importBinding.isStatic() && !importBinding.onDemand) { if (CharOperation.equals(importBinding.getSimpleName(), name)) { if (unitScope.resolveSingleImport(importBinding, Binding.TYPE | Binding.FIELD | Binding.METHOD) != null && importBinding.resolvedImport instanceof FieldBinding) { @@ -2260,8 +2257,7 @@ public Binding getBinding(char[] name, int mask, InvocationSite invocationSite, // check on demand imports boolean foundInImport = false; ReferenceBinding sourceCodeReceiver = null; - for (int i = 0, length = imports.length; i < length; i++) { - ImportBinding importBinding = imports[i]; + for (ImportBinding importBinding : imports) { if (importBinding.isStatic() && importBinding.onDemand) { Binding resolvedImport = importBinding.resolvedImport; if (resolvedImport instanceof ReferenceBinding) { @@ -2351,8 +2347,7 @@ private MethodBinding getExactMethod(TypeBinding receiverType, TypeBinding type, for (int i = 0, typesLength = typePlusSupertypes.length; i < typesLength; i++) { MethodBinding[] methods = i == 0 ? type.getMethods(selector) : new MethodBinding [] { getExactMethod(receiverType, typePlusSupertypes[i], selector, invocationSite, candidate) }; - for (int j = 0, length = methods.length; j < length; j++) { - MethodBinding currentMethod = methods[j]; + for (MethodBinding currentMethod : methods) { if (currentMethod == null || candidate == currentMethod) continue; if (i == 0 && (!currentMethod.canBeSeenBy(receiverType, invocationSite, this) || currentMethod.isSynthetic() || currentMethod.isBridge())) @@ -2432,8 +2427,7 @@ public MethodBinding getExactConstructor(TypeBinding receiverType, InvocationSit unitScope.recordTypeReference(receiverType); MethodBinding[] methods = receiverType.getMethods(TypeConstants.INIT); final TypeBinding[] genericTypeArguments = invocationSite.genericTypeArguments(); - for (int i = 0, length = methods.length; i < length; i++) { - MethodBinding constructor = methods[i]; + for (MethodBinding constructor : methods) { if (!constructor.canBeSeenBy(invocationSite, this)) continue; if (constructor.isVarargs()) @@ -2494,8 +2488,8 @@ public MethodBinding getConstructor0(ReferenceBinding receiverType, TypeBinding[ MethodBinding[] compatible = new MethodBinding[methods.length]; int compatibleIndex = 0; MethodBinding problemMethod = null; - for (int i = 0, length = methods.length; i < length; i++) { - MethodBinding compatibleMethod = computeCompatibleMethod(methods[i], argumentTypes, invocationSite); + for (MethodBinding method : methods) { + MethodBinding compatibleMethod = computeCompatibleMethod(method, argumentTypes, invocationSite); if (compatibleMethod != null) { if (compatibleMethod.isValidBinding()) compatible[compatibleIndex++] = compatibleMethod; @@ -2749,8 +2743,7 @@ public MethodBinding getImplicitMethod(char[] selector, TypeBinding[] argumentTy if (imports != null) { ObjectVector visible = null; boolean skipOnDemand = false; // set to true when matched static import of method name so stop looking for on demand methods - for (int i = 0, length = imports.length; i < length; i++) { - ImportBinding importBinding = imports[i]; + for (ImportBinding importBinding : imports) { if (importBinding.isStatic()) { Binding resolvedImport = importBinding.resolvedImport; MethodBinding possible = null; @@ -3545,8 +3538,7 @@ final Binding getTypeOrPackage(char[] name, int mask, boolean needResolve) { if ((mask & Binding.TYPE) != 0) { ImportBinding[] imports = unitScope.imports; if (imports != null && typeOrPackageCache == null) { // walk single type imports since faultInImports() has not run yet - nextImport : for (int i = 0, length = imports.length; i < length; i++) { - ImportBinding importBinding = imports[i]; + nextImport : for (ImportBinding importBinding : imports) { if (!importBinding.onDemand) { if (CharOperation.equals(importBinding.getSimpleName(), name)) { Binding resolvedImport = unitScope.resolveSingleImport(importBinding, Binding.TYPE); @@ -3583,8 +3575,7 @@ final Binding getTypeOrPackage(char[] name, int mask, boolean needResolve) { if (imports != null) { boolean foundInImport = false; ReferenceBinding type = null; - for (int i = 0, length = imports.length; i < length; i++) { - ImportBinding someImport = imports[i]; + for (ImportBinding someImport : imports) { if (someImport.onDemand) { Binding resolvedImport = someImport.resolvedImport; ReferenceBinding temp = null; @@ -3748,8 +3739,7 @@ public boolean hasErasedCandidatesCollisions(TypeBinding one, TypeBinding two, M invocations.clear(); TypeBinding[] mecs = minimalErasedCandidates(new TypeBinding[] {one, two}, invocations); if (mecs != null) { - nextCandidate: for (int k = 0, max = mecs.length; k < max; k++) { - TypeBinding mec = mecs[k]; + nextCandidate: for (TypeBinding mec : mecs) { if (mec == null) continue nextCandidate; Object value = invocations.get(mec); if (value instanceof TypeBinding[]) { @@ -4006,8 +3996,7 @@ private boolean isOverriddenMethodGeneric(MethodBinding method) { ReferenceBinding currentType = method.declaringClass.superclass(); while (currentType != null) { MethodBinding[] currentMethods = currentType.getMethods(method.selector); - for (int i = 0, l = currentMethods.length; i < l; i++) { - MethodBinding currentMethod = currentMethods[i]; + for (MethodBinding currentMethod : currentMethods) { if (currentMethod != null && currentMethod.original().typeVariables != Binding.NO_TYPE_VARIABLES) if (verifier.doesMethodOverride(method, currentMethod)) return true; @@ -4082,8 +4071,8 @@ private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocation // infer proper parameterized type from invocations TypeBinding[] bestArguments = new TypeBinding[argLength]; - for (int i = 0, length = invocations.length; i < length; i++) { - TypeBinding invocation = invocations[i].leafComponentType(); + for (TypeBinding binding : invocations) { + TypeBinding invocation = binding.leafComponentType(); switch (invocation.kind()) { case Binding.GENERIC_TYPE : TypeVariableBinding[] invocationVariables = invocation.typeVariables(); @@ -4416,8 +4405,7 @@ protected TypeBinding[] minimalErasedCandidates(TypeBinding[] types, Map allInvo // inject super interfaces prior to superclass ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); if (itsInterfaces != null) { // can be null during code assist operations that use LookupEnvironment.completeTypeBindings(parsedUnit, buildFieldsAndMethods) - for (int j = 0, count = itsInterfaces.length; j < count; j++) { - TypeBinding itsInterface = itsInterfaces[j]; + for (ReferenceBinding itsInterface : itsInterfaces) { TypeBinding superType = dim == 0 ? itsInterface : (TypeBinding)environment().createArrayType(itsInterface, dim); // recreate array if needed if (!typesToVisit.contains(superType)) { typesToVisit.add(superType); @@ -4445,8 +4433,8 @@ protected TypeBinding[] minimalErasedCandidates(TypeBinding[] types, Map allInvo int superLength = typesToVisit.size(); TypeBinding[] erasedSuperTypes = new TypeBinding[superLength]; int rank = 0; - for (Iterator iter = typesToVisit.iterator(); iter.hasNext();) { - TypeBinding type = (TypeBinding)iter.next(); + for (Object typeToVisit : typesToVisit) { + TypeBinding type = (TypeBinding)typeToVisit; leafType = type.leafComponentType(); erasedSuperTypes[rank++] = (leafType.isTypeVariable() || leafType.isWildcard() /*&& !leafType.isCapture()*/) ? type : type.erasure(); } @@ -4881,9 +4869,9 @@ public void acceptPotentiallyCompatibleMethods(MethodBinding[] methods) {/* igno } else { // must find inherited method with the same substituted variables MethodBinding[] superMethods = ((ReferenceBinding) superType).getMethods(original.selector, argumentTypes.length); - for (int m = 0, l = superMethods.length; m < l; m++) { - if (superMethods[m].original() == original) { - original = superMethods[m]; + for (MethodBinding superMethod : superMethods) { + if (superMethod.original() == original) { + original = superMethod; break; } } @@ -4894,9 +4882,9 @@ public void acceptPotentiallyCompatibleMethods(MethodBinding[] methods) {/* igno } else { // must find inherited method with the same substituted variables MethodBinding[] superMethods = ((ReferenceBinding) superType).getMethods(original2.selector, argumentTypes.length); - for (int m = 0, l = superMethods.length; m < l; m++) { - if (superMethods[m].original() == original2) { - original2 = superMethods[m]; + for (MethodBinding superMethod : superMethods) { + if (superMethod.original() == original2) { + original2 = superMethod; break; } } @@ -5298,8 +5286,7 @@ public MethodBinding getStaticFactory (ParameterizedTypeBinding allocationType, MethodBinding[] methods = typeToSearch.getMethods(TypeConstants.INIT, argumentTypes.length); MethodBinding [] staticFactories = new MethodBinding[methods.length]; int sfi = 0; - for (int i = 0, length = methods.length; i < length; i++) { - MethodBinding method = methods[i]; + for (MethodBinding method : methods) { if (!method.canBeSeenBy(allocationSite, this)) continue; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java index e929ad67aec..8a95de66160 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java @@ -1103,8 +1103,8 @@ private void checkAnnotationsInType() { this.tagBits |= (enclosingType.tagBits & TagBits.AnnotationTerminallyDeprecated); } - for (int i = 0, length = this.memberTypes.length; i < length; i++) - ((SourceTypeBinding) this.memberTypes[i]).checkAnnotationsInType(); + for (ReferenceBinding memberType : this.memberTypes) + ((SourceTypeBinding) memberType).checkAnnotationsInType(); } void faultInTypesForFieldsAndMethods() { @@ -1206,8 +1206,8 @@ else if (this.isInterface()) } } } - for (int i = 0, length = this.memberTypes.length; i < length; i++) - ((SourceTypeBinding) this.memberTypes[i]).checkPermitsInType(); + for (ReferenceBinding memberType : this.memberTypes) + ((SourceTypeBinding) memberType).checkPermitsInType(); if (this.scope.referenceContext.permittedTypes == null) { // Ignore implicitly permitted case @@ -1518,8 +1518,8 @@ private void internalFaultInTypeForFieldsAndMethods() { fields(); methods(); - for (int i = 0, length = this.memberTypes.length; i < length; i++) - ((SourceTypeBinding) this.memberTypes[i]).internalFaultInTypeForFieldsAndMethods(); + for (ReferenceBinding memberType : this.memberTypes) + ((SourceTypeBinding) memberType).internalFaultInTypeForFieldsAndMethods(); } // NOTE: the type of each field of a source type is resolved when needed @Override @@ -1601,8 +1601,8 @@ public char[] genericSignature() { if (this.typeVariables != Binding.NO_TYPE_VARIABLES) { sig = new StringBuilder(10); sig.append('<'); - for (int i = 0, length = this.typeVariables.length; i < length; i++) - sig.append(this.typeVariables[i].genericSignature()); + for (TypeVariableBinding typeVariable : this.typeVariables) + sig.append(typeVariable.genericSignature()); sig.append('>'); } else { // could still need a signature if any of supertypes is parameterized @@ -1618,8 +1618,8 @@ public char[] genericSignature() { sig.append(this.superclass.genericTypeSignature()); else // interface scenario only (as Object cannot be generic) - 65953 sig.append(this.scope.getJavaLangObject().genericTypeSignature()); - for (int i = 0, length = this.superInterfaces.length; i < length; i++) - sig.append(this.superInterfaces[i].genericTypeSignature()); + for (ReferenceBinding superInterface : this.superInterfaces) + sig.append(superInterface.genericTypeSignature()); return sig.toString().toCharArray(); } @@ -1865,8 +1865,7 @@ public FieldBinding getField(char[] fieldName, boolean needResolve) { } else { FieldBinding[] newFields = new FieldBinding[newSize]; int index = 0; - for (int i = 0, length = this.fields.length; i < length; i++) { - FieldBinding f = this.fields[i]; + for (FieldBinding f : this.fields) { if (f == field) continue; newFields[index++] = f; } @@ -1905,8 +1904,7 @@ public RecordComponentBinding getComponent(char[] componentName, boolean needRes } else { RecordComponentBinding[] newComponents = new RecordComponentBinding[newSize]; int index = 0; - for (int i = 0, length = this.components.length; i < length; i++) { - RecordComponentBinding rcb = this.components[i]; + for (RecordComponentBinding rcb : this.components) { if (rcb == component) continue; newComponents[index++] = rcb; } @@ -2546,8 +2544,7 @@ public MethodBinding[] methods() { this.tagBits |= TagBits.AreMethodsComplete; if (this.isRecordDeclaration) { /* https://github.com/eclipse-jdt/eclipse.jdt.core/issues/365 */ - for (int i = 0; i < this.methods.length; i++) { - MethodBinding method = this.methods[i]; + for (MethodBinding method : this.methods) { if ((method.tagBits & TagBits.AnnotationSafeVarargs) == 0 && method.sourceMethod() != null) { checkAndFlagHeapPollution(method, method.sourceMethod()); } @@ -2793,8 +2790,8 @@ private MethodBinding resolveTypesWithSuspendedTempErrorHandlingPolicy(MethodBin if (typeParameters != null) { methodDecl.scope.connectTypeVariables(typeParameters, true); // Perform deferred bound checks for type variables (only done after type variable hierarchy is connected) - for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) - typeParameters[i].checkBounds(methodDecl.scope); + for (TypeParameter typeParameter : typeParameters) + typeParameter.checkBounds(methodDecl.scope); } TypeReference[] exceptionTypes = methodDecl.thrownExceptions; if (exceptionTypes != null) { @@ -3056,11 +3053,11 @@ public void evaluateNullAnnotations() { if ((this.tagBits & TagBits.AnnotationNullMASK) != 0) { Annotation[] annotations = this.scope.referenceContext.annotations; - for (int i = 0; i < annotations.length; i++) { - ReferenceBinding annotationType = annotations[i].getCompilerAnnotation().getAnnotationType(); + for (Annotation annotation : annotations) { + ReferenceBinding annotationType = annotation.getCompilerAnnotation().getAnnotationType(); if (annotationType != null) { if (annotationType.hasNullBit(TypeIds.BitNonNullAnnotation|TypeIds.BitNullableAnnotation)) { - this.scope.problemReporter().nullAnnotationUnsupportedLocation(annotations[i]); + this.scope.problemReporter().nullAnnotationUnsupportedLocation(annotation); this.tagBits &= ~TagBits.AnnotationNullMASK; } } @@ -3377,12 +3374,12 @@ public SyntheticMethodBinding[] syntheticMethods() { Iterator methodArrayIterator = this.synthetics[SourceTypeBinding.METHOD_EMUL].values().iterator(); while (methodArrayIterator.hasNext()) { SyntheticMethodBinding[] methodAccessors = (SyntheticMethodBinding[]) methodArrayIterator.next(); - for (int i = 0, max = methodAccessors.length; i < max; i++) { - if (methodAccessors[i] != null) { + for (SyntheticMethodBinding methodAccessor : methodAccessors) { + if (methodAccessor != null) { if (index+1 > bindings.length) { System.arraycopy(bindings, 0, (bindings = new SyntheticMethodBinding[index + 1]), 0, index); } - bindings[index++] = methodAccessors[i]; + bindings[index++] = methodAccessor; } } } @@ -3496,8 +3493,8 @@ public String toString() { if (this.fields != null) { if (this.fields != Binding.NO_FIELDS) { buffer.append("\n/* fields */"); //$NON-NLS-1$ - for (int i = 0, length = this.fields.length; i < length; i++) - buffer.append('\n').append((this.fields[i] != null) ? this.fields[i].toString() : "NULL FIELD"); //$NON-NLS-1$ + for (FieldBinding field : this.fields) + buffer.append('\n').append((field != null) ? field.toString() : "NULL FIELD"); //$NON-NLS-1$ } } else { buffer.append("NULL FIELDS"); //$NON-NLS-1$ @@ -3506,8 +3503,8 @@ public String toString() { if (this.methods != null) { if (this.methods != Binding.NO_METHODS) { buffer.append("\n/* methods */"); //$NON-NLS-1$ - for (int i = 0, length = this.methods.length; i < length; i++) - buffer.append('\n').append((this.methods[i] != null) ? this.methods[i].toString() : "NULL METHOD"); //$NON-NLS-1$ + for (MethodBinding method : this.methods) + buffer.append('\n').append((method != null) ? method.toString() : "NULL METHOD"); //$NON-NLS-1$ } } else { buffer.append("NULL METHODS"); //$NON-NLS-1$ @@ -3516,8 +3513,8 @@ public String toString() { if (this.memberTypes != null) { if (this.memberTypes != Binding.NO_MEMBER_TYPES) { buffer.append("\n/* members */"); //$NON-NLS-1$ - for (int i = 0, length = this.memberTypes.length; i < length; i++) - buffer.append('\n').append((this.memberTypes[i] != null) ? this.memberTypes[i].toString() : "NULL TYPE"); //$NON-NLS-1$ + for (ReferenceBinding memberType : this.memberTypes) + buffer.append('\n').append((memberType != null) ? memberType.toString() : "NULL TYPE"); //$NON-NLS-1$ } } else { buffer.append("NULL MEMBER TYPES"); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java index 668797d2d0e..b9b47f410b8 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java @@ -158,9 +158,9 @@ public SyntheticMethodBinding(FieldBinding targetField, boolean isReadAccess, bo // retrieve sourceStart position for the target field for line number attributes FieldDeclaration[] fieldDecls = declaringSourceType.scope.referenceContext.fields; if (fieldDecls != null) { - for (int i = 0, max = fieldDecls.length; i < max; i++) { - if (fieldDecls[i].binding == targetField) { - this.sourceStart = fieldDecls[i].sourceStart; + for (FieldDeclaration fieldDecl : fieldDecls) { + if (fieldDecl.binding == targetField) { + this.sourceStart = fieldDecl.sourceStart; return; } } @@ -572,9 +572,9 @@ public void initializeConstructorAccessor(MethodBinding accessedConstructor) { AbstractMethodDeclaration[] methodDecls = sourceType.scope.referenceContext.methods; if (methodDecls != null) { - for (int i = 0, length = methodDecls.length; i < length; i++) { - if (methodDecls[i].binding == accessedConstructor) { - this.sourceStart = methodDecls[i].sourceStart; + for (AbstractMethodDeclaration methodDecl : methodDecls) { + if (methodDecl.binding == accessedConstructor) { + this.sourceStart = methodDecl.sourceStart; return; } } @@ -647,9 +647,9 @@ public void initializeMethodAccessor(MethodBinding accessedMethod, boolean isSup // retrieve sourceStart position for the target method for line number attributes AbstractMethodDeclaration[] methodDecls = declaringSourceType.scope.referenceContext.methods; if (methodDecls != null) { - for (int i = 0, length = methodDecls.length; i < length; i++) { - if (methodDecls[i].binding == accessedMethod) { - this.sourceStart = methodDecls[i].sourceStart; + for (AbstractMethodDeclaration methodDecl : methodDecls) { + if (methodDecl.binding == accessedMethod) { + this.sourceStart = methodDecl.sourceStart; return; } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java index 32a9a657392..891aa6e88b9 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java @@ -499,8 +499,8 @@ public TypeBinding findSuperTypeOriginatingFrom(TypeBinding otherType) { case Binding.INTERSECTION_TYPE18: IntersectionTypeBinding18 itb18 = (IntersectionTypeBinding18) this; ReferenceBinding[] intersectingTypes = itb18.getIntersectingTypes(); - for (int i = 0, length = intersectingTypes.length; i < length; i++) { - TypeBinding superType = intersectingTypes[i].findSuperTypeOriginatingFrom(otherType); + for (ReferenceBinding intersectingType : intersectingTypes) { + TypeBinding superType = intersectingType.findSuperTypeOriginatingFrom(otherType); if (superType != null) return superType; } @@ -563,8 +563,7 @@ public TypeBinding getErasureCompatibleType(TypeBinding declaringClass) { if (variable.superclass != null && variable.superclass.findSuperTypeOriginatingFrom(declaringClass) != null) { return variable.superclass.getErasureCompatibleType(declaringClass); } - for (int i = 0, otherLength = variable.superInterfaces.length; i < otherLength; i++) { - ReferenceBinding superInterface = variable.superInterfaces[i]; + for (ReferenceBinding superInterface : variable.superInterfaces) { if (superInterface.findSuperTypeOriginatingFrom(declaringClass) != null) { return superInterface.getErasureCompatibleType(declaringClass); } @@ -578,8 +577,7 @@ public TypeBinding getErasureCompatibleType(TypeBinding declaringClass) { if (intersection.superclass != null && intersection.superclass.findSuperTypeOriginatingFrom(declaringClass) != null) { return intersection.superclass.getErasureCompatibleType(declaringClass); } - for (int i = 0, otherLength = intersection.superInterfaces.length; i < otherLength; i++) { - ReferenceBinding superInterface = intersection.superInterfaces[i]; + for (ReferenceBinding superInterface : intersection.superInterfaces) { if (superInterface.findSuperTypeOriginatingFrom(declaringClass) != null) { return superInterface.getErasureCompatibleType(declaringClass); } @@ -1349,8 +1347,8 @@ public boolean isTypeArgumentContainedBy(TypeBinding otherType) { case Wildcard.EXTENDS: if (otherBound instanceof IntersectionTypeBinding18) { TypeBinding [] intersectingTypes = ((IntersectionTypeBinding18) otherBound).intersectingTypes; - for (int i = 0, length = intersectingTypes.length; i < length; i++) - if (TypeBinding.equalsEquals(intersectingTypes[i], this)) + for (TypeBinding intersectingType : intersectingTypes) + if (TypeBinding.equalsEquals(intersectingType, this)) return true; } if (TypeBinding.equalsEquals(otherBound, this)) @@ -1367,8 +1365,8 @@ public boolean isTypeArgumentContainedBy(TypeBinding otherType) { case Wildcard.SUPER: if (otherBound instanceof IntersectionTypeBinding18) { TypeBinding [] intersectingTypes = ((IntersectionTypeBinding18) otherBound).intersectingTypes; - for (int i = 0, length = intersectingTypes.length; i < length; i++) - if (TypeBinding.equalsEquals(intersectingTypes[i], this)) + for (TypeBinding intersectingType : intersectingTypes) + if (TypeBinding.equalsEquals(intersectingType, this)) return true; } if (TypeBinding.equalsEquals(otherBound, this)) @@ -1617,8 +1615,7 @@ public void setTypeAnnotations(AnnotationBinding[] annotations, boolean evalNull return; this.typeAnnotations = annotations; if (evalNullAnnotations) { - for (int i = 0, length = annotations.length; i < length; i++) { - AnnotationBinding annotation = annotations[i]; + for (AnnotationBinding annotation : annotations) { if (annotation != null) { if (annotation.type.hasNullBit(TypeIds.BitNullableAnnotation)) this.tagBits |= TagBits.AnnotationNullable | TagBits.HasNullTypeAnnotation; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java index 78e275e57fe..d1f7c9ac0ef 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java @@ -82,10 +82,10 @@ public PTBKey(ReferenceBinding type, TypeBinding[] arguments, ReferenceBinding e if (type instanceof UnresolvedReferenceBinding) ((UnresolvedReferenceBinding) type).addWrapper(this, environment); if (arguments != null) { - for (int i = 0, l = arguments.length; i < l; i++) { - if (arguments[i] instanceof UnresolvedReferenceBinding) - ((UnresolvedReferenceBinding) arguments[i]).addWrapper(this, environment); - if (arguments[i].hasNullTypeAnnotations()) + for (TypeBinding argument : arguments) { + if (argument instanceof UnresolvedReferenceBinding) + ((UnresolvedReferenceBinding) argument).addWrapper(this, environment); + if (argument.hasNullTypeAnnotations()) this.tagBits |= TagBits.HasNullTypeAnnotation; } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java index 857b03f16ac..2e5b6955bce 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java @@ -202,8 +202,8 @@ private TypeConstants.BoundCheckStatus internalBoundCheck(Substitution substitut } } boolean mustImplement = isArrayBound || ((ReferenceBinding)wildcardBound).isFinal(); - for (int i = 0, length = this.superInterfaces.length; i < length; i++) { - TypeBinding substitutedSuperType = hasSubstitution ? Scope.substitute(substitution, this.superInterfaces[i]) : this.superInterfaces[i]; + for (ReferenceBinding superInterface : this.superInterfaces) { + TypeBinding substitutedSuperType = hasSubstitution ? Scope.substitute(substitution, superInterface) : superInterface; if (!checkedAsOK) { if (isArrayBound) { if (!wildcardBound.isCompatibleWith(substitutedSuperType, scope)) @@ -277,8 +277,8 @@ private TypeConstants.BoundCheckStatus internalBoundCheck(Substitution substitut nullStatus = nullBoundCheck(scope, argumentType, substitutedSuperType, substitution, location, nullStatus); } } - for (int i = 0, length = this.superInterfaces.length; i < length; i++) { - TypeBinding substitutedSuperType = hasSubstitution ? Scope.substitute(substitution, this.superInterfaces[i]) : this.superInterfaces[i]; + for (ReferenceBinding superInterface : this.superInterfaces) { + TypeBinding substitutedSuperType = hasSubstitution ? Scope.substitute(substitution, superInterface) : superInterface; if (TypeBinding.notEquals(substitutedSuperType, argumentType)) { if (!argumentType.isCompatibleWith(substitutedSuperType, scope)) { return BoundCheckStatus.MISMATCH; @@ -514,8 +514,8 @@ TypeBound[] getTypeBounds(InferenceVariable variable, InferenceSubstitution thet int idx = 0; if (!this.firstBound.isInterface()) bounds[idx++] = TypeBound.createBoundOrDependency(theta, this.firstBound, variable); - for (int i = 0; i < this.superInterfaces.length; i++) - bounds[idx++] = TypeBound.createBoundOrDependency(theta, this.superInterfaces[i], variable); + for (ReferenceBinding superInterface : this.superInterfaces) + bounds[idx++] = TypeBound.createBoundOrDependency(theta, superInterface, variable); return bounds; } @@ -525,8 +525,8 @@ boolean hasOnlyRawBounds() { return false; if (this.superInterfaces != null) - for (int i = 0, l = this.superInterfaces.length; i < l; i++) - if (!this.superInterfaces[i].isRawType()) + for (ReferenceBinding superInterface : this.superInterfaces) + if (!superInterface.isRawType()) return false; return true; @@ -540,9 +540,9 @@ public boolean hasTypeBit(int bit) { if (this.superclass != null && this.superclass.hasTypeBit(~TypeIds.BitUninitialized)) this.typeBits |= (this.superclass.typeBits & TypeIds.InheritableBits); if (this.superInterfaces != null) - for (int i = 0, l = this.superInterfaces.length; i < l; i++) - if (this.superInterfaces[i].hasTypeBit(~TypeIds.BitUninitialized)) - this.typeBits |= (this.superInterfaces[i].typeBits & TypeIds.InheritableBits); + for (ReferenceBinding superInterface : this.superInterfaces) + if (superInterface.hasTypeBit(~TypeIds.BitUninitialized)) + this.typeBits |= (superInterface.typeBits & TypeIds.InheritableBits); } return (this.typeBits & bit) != 0; } @@ -553,8 +553,8 @@ public boolean hasTypeBit(int bit) { public boolean isErasureBoundTo(TypeBinding type) { if (TypeBinding.equalsEquals(this.superclass.erasure(), type)) return true; - for (int i = 0, length = this.superInterfaces.length; i < length; i++) { - if (TypeBinding.equalsEquals(this.superInterfaces[i].erasure(), type)) + for (ReferenceBinding superInterface : this.superInterfaces) { + if (TypeBinding.equalsEquals(superInterface.erasure(), type)) return true; } return false; @@ -598,8 +598,8 @@ public boolean isSubtypeOf(TypeBinding other, boolean simulatingBugJDK8026527) { if (this.superclass != null && this.superclass.isSubtypeOf(other, simulatingBugJDK8026527)) return true; if (this.superInterfaces != null) - for (int i = 0, l = this.superInterfaces.length; i < l; i++) - if (this.superInterfaces[i].isSubtypeOf(other, false)) + for (ReferenceBinding superInterface : this.superInterfaces) + if (superInterface.isSubtypeOf(other, false)) return true; return other.id == TypeIds.T_JavaLangObject; } @@ -644,8 +644,8 @@ public boolean isProperType(boolean admitCapture18) { return false; } if (this.superInterfaces != null) - for (int i = 0, l = this.superInterfaces.length; i < l; i++) - if (!this.superInterfaces[i].isProperType(admitCapture18)) { + for (ReferenceBinding superInterface : this.superInterfaces) + if (!superInterface.isProperType(admitCapture18)) { return false; } return true; @@ -741,8 +741,8 @@ public boolean mentionsAny(TypeBinding[] parameters, int idx) { if (this.superclass != null && this.superclass.mentionsAny(parameters, idx)) return true; if (this.superInterfaces != null) - for (int j = 0; j < this.superInterfaces.length; j++) { - if (this.superInterfaces[j].mentionsAny(parameters, idx)) + for (ReferenceBinding superInterface : this.superInterfaces) { + if (superInterface.mentionsAny(parameters, idx)) return true; } return false; @@ -760,8 +760,8 @@ void collectInferenceVariables(Set variables) { if (this.superclass != null) this.superclass.collectInferenceVariables(variables); if (this.superInterfaces != null) - for (int j = 0; j < this.superInterfaces.length; j++) { - this.superInterfaces[j].collectInferenceVariables(variables); + for (ReferenceBinding superInterface : this.superInterfaces) { + superInterface.collectInferenceVariables(variables); } } finally { this.inRecursiveFunction = false; @@ -1047,9 +1047,9 @@ private TypeReference findBound(TypeBinding bound, TypeParameter parameter) { return parameter.type; TypeReference[] bounds = parameter.bounds; if (bounds != null) { - for (int i = 0; i < bounds.length; i++) { - if (TypeBinding.equalsEquals(bounds[i].resolvedType, bound)) - return bounds[i]; + for (TypeReference ref : bounds) { + if (TypeBinding.equalsEquals(ref.resolvedType, bound)) + return ref; } } return null; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java index 543c23ae9af..d5ea8813c93 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java @@ -148,8 +148,8 @@ void setResolvedType(ReferenceBinding targetType, LookupEnvironment environment) // must ensure to update any other type bindings that can contain the resolved type // otherwise we could create 2 : 1 for this unresolved type & 1 for the resolved type if (this.wrappers != null) - for (int i = 0, l = this.wrappers.length; i < l; i++) - this.wrappers[i].swapUnresolved(this, targetType, environment); + for (TypeBinding wrapper : this.wrappers) + wrapper.swapUnresolved(this, targetType, environment); } @Override @@ -161,8 +161,8 @@ public void swapUnresolved(UnresolvedReferenceBinding unresolvedType, ReferenceB environment.updateCaches(this, annotatedType); if (this.wrappers != null) - for (int i = 0, l = this.wrappers.length; i < l; i++) - this.wrappers[i].swapUnresolved(this, annotatedType, environment); + for (TypeBinding wrapper : this.wrappers) + wrapper.swapUnresolved(this, annotatedType, environment); } @Override diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java index 94a303cb6e7..a2e14d3e1f6 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java @@ -136,8 +136,7 @@ public long determineNullBitsFromDeclaration(Scope scope, Wildcard wildcard) { long nullTagBits = 0L; AnnotationBinding [] annotations = this.typeAnnotations; if (annotations != null) { - for (int i = 0, length = annotations.length; i < length; i++) { - AnnotationBinding annotation = annotations[i]; + for (AnnotationBinding annotation : annotations) { if (annotation != null) { if (annotation.type.hasNullBit(TypeIds.BitNullableAnnotation)) { if ((nullTagBits & TagBits.AnnotationNonNull) == 0) { @@ -198,8 +197,8 @@ public long determineNullBitsFromDeclaration(Scope scope, Wildcard wildcard) { } } if (nullTagBits == 0L && this.otherBounds != null) { - for (int i = 0, length = this.otherBounds.length; i < length; i++) { - if ((this.otherBounds[i].tagBits & TagBits.AnnotationNonNull) != 0) { // can this happen? + for (TypeBinding otherBound : this.otherBounds) { + if ((otherBound.tagBits & TagBits.AnnotationNonNull) != 0) { // can this happen? nullTagBits = TagBits.AnnotationNonNull; break; } @@ -327,8 +326,8 @@ public void collectSubstitutes(Scope scope, TypeBinding actualType, InferenceCon case Binding.INTERSECTION_TYPE : // A={? extends V1&...&Vn} << F={? extends U} ---> V1 << U, ..., Vn << U WildcardBinding actualIntersection = (WildcardBinding) actualType; this.bound.collectSubstitutes(scope, actualIntersection.bound, inferenceContext, TypeConstants.CONSTRAINT_EXTENDS); - for (int i = 0, length = actualIntersection.otherBounds.length; i < length; i++) { - this.bound.collectSubstitutes(scope, actualIntersection.otherBounds[i], inferenceContext, TypeConstants.CONSTRAINT_EXTENDS); + for (TypeBinding otherBound : actualIntersection.otherBounds) { + this.bound.collectSubstitutes(scope, otherBound, inferenceContext, TypeConstants.CONSTRAINT_EXTENDS); } break; default : // A=V << F={? extends U} ---> V << U @@ -567,8 +566,8 @@ public String annotatedDebugName() { if (this.otherBounds == null) return buffer.append(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.annotatedDebugName().toCharArray())).toString(); buffer.append(this.bound.annotatedDebugName()); - for (int i = 0, length = this.otherBounds.length; i < length; i++) { - buffer.append(" & ").append(this.otherBounds[i].annotatedDebugName()); //$NON-NLS-1$ + for (TypeBinding otherBound : this.otherBounds) { + buffer.append(" & ").append(otherBound.annotatedDebugName()); //$NON-NLS-1$ } return buffer.toString(); default: // SUPER @@ -629,9 +628,9 @@ public boolean hasTypeBit(int bit) { if (this.superclass != null && this.superclass.hasTypeBit(~TypeIds.BitUninitialized)) this.typeBits |= (this.superclass.typeBits & TypeIds.InheritableBits); if (this.superInterfaces != null) - for (int i = 0, l = this.superInterfaces.length; i < l; i++) - if (this.superInterfaces[i].hasTypeBit(~TypeIds.BitUninitialized)) - this.typeBits |= (this.superInterfaces[i].typeBits & TypeIds.InheritableBits); + for (ReferenceBinding superInterface : this.superInterfaces) + if (superInterface.hasTypeBit(~TypeIds.BitUninitialized)) + this.typeBits |= (superInterface.typeBits & TypeIds.InheritableBits); } return (this.typeBits & bit) != 0; } @@ -648,8 +647,7 @@ void initialize(ReferenceBinding someGenericType, TypeBinding someBound, TypeBin TagBits.HasNullTypeAnnotation | TagBits.HasCapturedWildcard); } if (someOtherBounds != null) { - for (int i = 0, max = someOtherBounds.length; i < max; i++) { - TypeBinding someOtherBound = someOtherBounds[i]; + for (TypeBinding someOtherBound : someOtherBounds) { this.tagBits |= someOtherBound.tagBits & (TagBits.ContainsNestedTypeReferences | TagBits.HasNullTypeAnnotation | TagBits.HasCapturedWildcard); } } @@ -721,8 +719,8 @@ public boolean isProperType(boolean admitCapture18) { if (this.superclass != null && !this.superclass.isProperType(admitCapture18)) return false; if (this.superInterfaces != null) - for (int i = 0, l = this.superInterfaces.length; i < l; i++) - if (!this.superInterfaces[i].isProperType(admitCapture18)) + for (ReferenceBinding superInterface : this.superInterfaces) + if (!superInterface.isProperType(admitCapture18)) return false; return true; } finally { @@ -788,8 +786,8 @@ public char[] readableName() { return CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.readableName()); StringBuilder buffer = new StringBuilder(10); buffer.append(this.bound.readableName()); - for (int i = 0, length = this.otherBounds.length; i < length; i++) { - buffer.append('&').append(this.otherBounds[i].readableName()); + for (TypeBinding otherBound : this.otherBounds) { + buffer.append('&').append(otherBound.readableName()); } int length; char[] result = new char[length = buffer.length()]; @@ -814,8 +812,8 @@ public char[] nullAnnotatedReadableName(CompilerOptions options, boolean shortNa buffer.append(this.bound.nullAnnotatedReadableName(options, shortNames)); } else { buffer.append(this.bound.nullAnnotatedReadableName(options, shortNames)); - for (int i = 0, length = this.otherBounds.length; i < length; i++) { - buffer.append('&').append(this.otherBounds[i].nullAnnotatedReadableName(options, shortNames)); + for (TypeBinding otherBound : this.otherBounds) { + buffer.append('&').append(otherBound.nullAnnotatedReadableName(options, shortNames)); } } break; @@ -869,8 +867,8 @@ public char[] shortReadableName() { return CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.shortReadableName()); StringBuilder buffer = new StringBuilder(10); buffer.append(this.bound.shortReadableName()); - for (int i = 0, length = this.otherBounds.length; i < length; i++) { - buffer.append('&').append(this.otherBounds[i].shortReadableName()); + for (TypeBinding otherBound : this.otherBounds) { + buffer.append('&').append(otherBound.shortReadableName()); } int length; char[] result = new char[length = buffer.length()]; @@ -995,8 +993,8 @@ public String toString() { if (this.otherBounds == null) return new String(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.debugName().toCharArray())); StringBuilder buffer = new StringBuilder(this.bound.debugName()); - for (int i = 0, length = this.otherBounds.length; i < length; i++) { - buffer.append('&').append(this.otherBounds[i].debugName()); + for (TypeBinding otherBound : this.otherBounds) { + buffer.append('&').append(otherBound.debugName()); } return buffer.toString(); default: // SUPER @@ -1044,8 +1042,8 @@ void collectInferenceVariables(Set variables) { if (this.bound != null) this.bound.collectInferenceVariables(variables); if (this.otherBounds != null) - for (int i = 0, length = this.otherBounds.length; i < length; i++) - this.otherBounds[i].collectInferenceVariables(variables); + for (TypeBinding otherBound : this.otherBounds) + otherBound.collectInferenceVariables(variables); } @Override public boolean mentionsAny(TypeBinding[] parameters, int idx) { @@ -1058,8 +1056,8 @@ public boolean mentionsAny(TypeBinding[] parameters, int idx) { if (this.bound != null && this.bound.mentionsAny(parameters, -1)) return true; if (this.otherBounds != null) { - for (int i = 0, length = this.otherBounds.length; i < length; i++) - if (this.otherBounds[i].mentionsAny(parameters, -1)) + for (TypeBinding otherBound : this.otherBounds) + if (otherBound.mentionsAny(parameters, -1)) return true; } } finally { @@ -1081,8 +1079,8 @@ public long updateTagBits() { if (this.bound != null) this.tagBits |= this.bound.updateTagBits(); if (this.otherBounds != null) { - for (int i = 0, length = this.otherBounds.length; i < length; i++) - this.tagBits |= this.otherBounds[i].updateTagBits(); + for (TypeBinding otherBound : this.otherBounds) + this.tagBits |= otherBound.updateTagBits(); } } finally { this.inRecursiveFunction = false; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java index 69e065a0c85..2a81d0a1947 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java @@ -203,9 +203,9 @@ public static char[][][] levelTagsToChar3d(LevelTags[] input) { for( int i = 0; i < ret.length; i++ ) { ret[i] = new char[][] {}; } - for( int i = 0; i < input.length; i++ ) { - int nextLevel = input[i].level - ClassFileConstants.MAJOR_VERSION_0; - ret[nextLevel] = input[i].tags; + for (LevelTags tag : input) { + int nextLevel = tag.level - ClassFileConstants.MAJOR_VERSION_0; + ret[nextLevel] = tag.tags; } return ret; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java index 0e940d0f143..8a649573031 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java @@ -42,7 +42,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -57,7 +56,6 @@ import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.ast.*; -import org.eclipse.jdt.internal.compiler.ast.StringTemplate; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.ConstantPool; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; @@ -192,8 +190,8 @@ public final static short base_check(int i) { } private final static void buildFile(String filename, List listToDump) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) { - for (Iterator iterator = listToDump.iterator(); iterator.hasNext(); ) { - writer.write(String.valueOf(iterator.next())); + for (Object o : listToDump) { + writer.write(String.valueOf(o)); } writer.flush(); } catch(IOException e) { @@ -480,8 +478,8 @@ private static void buildFilesForRecoveryTemplates( terminalNames[t++] = st.nextToken(); } - for (int j = 0; j < terminalNames.length; j++) { - int symbol = getSymbol(terminalNames[j], newName, newReverse); + for (String terminalName : terminalNames) { + int symbol = getSymbol(terminalName, newName, newReverse); if(symbol > -1) { length = newRecoveyTemplates.length; if(length == newRecoveyTemplatesPtr + 1) { @@ -2618,8 +2616,8 @@ protected void consumeClassHeaderImplements() { 0, length); TypeReference[] superinterfaces = typeDecl.superInterfaces; - for (int i = 0, max = superinterfaces.length; i < max; i++) { - TypeReference typeReference = superinterfaces[i]; + for (TypeReference superinterface : superinterfaces) { + TypeReference typeReference = superinterface; typeDecl.bits |= (typeReference.bits & ASTNode.HasTypeAnnotations); typeReference.bits |= ASTNode.IsSuperType; } @@ -4684,8 +4682,8 @@ protected void consumeInterfaceHeaderExtends() { 0, length); TypeReference[] superinterfaces = typeDecl.superInterfaces; - for (int i = 0, max = superinterfaces.length; i < max; i++) { - TypeReference typeReference = superinterfaces[i]; + for (TypeReference superinterface : superinterfaces) { + TypeReference typeReference = superinterface; typeDecl.bits |= (typeReference.bits & ASTNode.HasTypeAnnotations); typeReference.bits |= ASTNode.IsSuperType; } @@ -4777,8 +4775,7 @@ private void populatePermittedTypes() { 0, length); TypeReference[] permittedTypes = typeDecl.permittedTypes; - for (int i = 0, max = permittedTypes.length; i < max; i++) { - TypeReference typeReference = permittedTypes[i]; + for (TypeReference typeReference : permittedTypes) { typeDecl.bits |= (typeReference.bits & ASTNode.HasTypeAnnotations); // TODO: Confirm with spec // typeReference.bits |= ASTNode.IsSuperType; // TODO: Check equivalent required } @@ -5452,8 +5449,8 @@ protected void consumeMethodHeaderRightParen() { md.arguments = new Argument[length], 0, length); - for (int i = 0, max = md.arguments.length; i < max; i++) { - if ((md.arguments[i].bits & ASTNode.HasTypeAnnotations) != 0) { + for (Argument argument : md.arguments) { + if ((argument.bits & ASTNode.HasTypeAnnotations) != 0) { md.bits |= ASTNode.HasTypeAnnotations; break; } @@ -9256,8 +9253,7 @@ protected void consumeStatementTry(boolean withFinally, boolean hasResources) { problemReporter().autoManagedResourcesNotBelow17(stmts); } if (this.options.sourceLevel < ClassFileConstants.JDK9) { - for (int i = 0, l = stmts.length; i < l; ++i) { - Statement stmt = stmts[i]; + for (Statement stmt : stmts) { if (stmt instanceof FieldReference || stmt instanceof NameReference) { problemReporter().autoManagedVariableResourcesNotBelow9((Expression) stmt); } @@ -10228,8 +10224,8 @@ protected void consumeTypeParameter1WithExtendsAndBounds() { typeParameter.bits |= (superType.bits & ASTNode.HasTypeAnnotations); superType.bits |= ASTNode.IsSuperType; typeParameter.bounds = bounds; - for (int i = 0, max = bounds.length; i < max; i++) { - TypeReference bound = bounds[i]; + for (TypeReference bound2 : bounds) { + TypeReference bound = bound2; bound.bits |= ASTNode.IsSuperType; typeParameter.bits |= (bound.bits & ASTNode.HasTypeAnnotations); } @@ -10311,8 +10307,8 @@ protected void consumeTypeParameterWithExtendsAndBounds() { superType.bits |= ASTNode.IsSuperType; typeParameter.bounds = bounds; typeParameter.declarationSourceEnd = bounds[additionalBoundsLength - 1].sourceEnd; - for (int i = 0, max = bounds.length; i < max; i++) { - TypeReference bound = bounds[i]; + for (TypeReference bound2 : bounds) { + TypeReference bound = bound2; bound.bits |= ASTNode.IsSuperType; typeParameter.bits |= (bound.bits & ASTNode.HasTypeAnnotations); } @@ -11131,8 +11127,7 @@ private void checkForRecordMemberErrors(TypeDeclaration typeDecl, int nCreatedFi } } if (typeDecl.methods != null) { - for (int i = 0; i < typeDecl.methods.length; i++) { - AbstractMethodDeclaration method = typeDecl.methods[i]; + for (AbstractMethodDeclaration method : typeDecl.methods) { if ((method.modifiers & ClassFileConstants.AccNative) != 0) { problemReporter().recordIllegalNativeModifierInRecord(method); } @@ -11641,8 +11636,8 @@ public void getMethodBodies(CompilationUnitDeclaration unit) { this.javadocParser.scanner.setSource(contents); } if (unit.types != null) { - for (int i = 0, length = unit.types.length; i < length; i++) - unit.types[i].parseMethods(this, unit); + for (TypeDeclaration type : unit.types) + type.parseMethods(this, unit); } // tag unit has having read bodies @@ -13120,9 +13115,7 @@ public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { } boolean containsInitializers = false; TypeDeclaration typeDeclaration = null; - for (int i = 0, max = result.length; i < max; i++) { - // parse each class or record body declaration - ASTNode node = result[i]; + for (ASTNode node : result) { if (node instanceof TypeDeclaration type) { type.parseMethods(this, unit); } else if (node instanceof AbstractMethodDeclaration method) { @@ -13153,8 +13146,8 @@ public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { } if (containsInitializers) { FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; - for (int i = 0, max = fieldDeclarations.length; i < max; i++) { - Initializer initializer = (Initializer) fieldDeclarations[i]; + for (FieldDeclaration fieldDeclaration : fieldDeclarations) { + Initializer initializer = (Initializer) fieldDeclaration; initializer.parseStatements(this, typeDeclaration , unit); if (((initializer.bits & ASTNode.HasSyntaxErrors) != 0) && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) { return null; @@ -13859,16 +13852,15 @@ protected void reportSyntaxErrors(boolean isDietParse, int oldFirstToken) { } private void reportSyntaxErrorsForSkippedMethod(TypeDeclaration[] types){ if(types != null) { - for (int i = 0; i < types.length; i++) { - TypeDeclaration[] memberTypes = types[i].memberTypes; + for (TypeDeclaration type : types) { + TypeDeclaration[] memberTypes = type.memberTypes; if(memberTypes != null) { reportSyntaxErrorsForSkippedMethod(memberTypes); } - AbstractMethodDeclaration[] methods = types[i].methods; + AbstractMethodDeclaration[] methods = type.methods; if(methods != null) { - for (int j = 0; j < methods.length; j++) { - AbstractMethodDeclaration method = methods[j]; + for (AbstractMethodDeclaration method : methods) { if((method.bits & ASTNode.ErrorInSignature) != 0) { if(method.isAnnotationMethod()) { DiagnoseParser diagnoseParser = new DiagnoseParser(this, TokenNameQUESTION, method.declarationSourceStart, method.declarationSourceEnd, this.options); @@ -13882,7 +13874,7 @@ private void reportSyntaxErrorsForSkippedMethod(TypeDeclaration[] types){ } } - FieldDeclaration[] fields = types[i].fields; + FieldDeclaration[] fields = type.fields; if (fields != null) { int length = fields.length; for (int j = 0; j < length; j++) { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java index 2fb91b24a85..16b46aceb6e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java @@ -162,8 +162,8 @@ protected void addBlockStatement(RecoveredBlock recoveredBlock) { Block block = recoveredBlock.blockDeclaration; if(block.statements != null) { Statement[] statements = block.statements; - for (int i = 0; i < statements.length; i++) { - recoveredBlock.add(statements[i], 0); + for (Statement statement : statements) { + recoveredBlock.add(statement, 0); } } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java index 6298a67c299..6af3c43bc65 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java @@ -149,8 +149,8 @@ public void attach(RecoveredAnnotation[] annots, int annotCount, int mods, int m this.annotations = new RecoveredAnnotation[annotCount]; this.annotationCount = 0; next : for (int i = 0; i < annotCount; i++) { - for (int j = 0; j < existingAnnotations.length; j++) { - if (annots[i].annotation == existingAnnotations[j]) continue next; + for (Annotation existingAnnotation : existingAnnotations) { + if (annots[i].annotation == existingAnnotation) continue next; } this.annotations[this.annotationCount++] = annots[i]; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredLocalVariable.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredLocalVariable.java index 73840513e6a..3a2a178f907 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredLocalVariable.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredLocalVariable.java @@ -65,8 +65,8 @@ public void attach(RecoveredAnnotation[] annots, int annotCount, int mods, int m this.annotations = new RecoveredAnnotation[annotCount]; this.annotationCount = 0; next : for (int i = 0; i < annotCount; i++) { - for (int j = 0; j < existingAnnotations.length; j++) { - if (annots[i].annotation == existingAnnotations[j]) continue next; + for (Annotation existingAnnotation : existingAnnotations) { + if (annots[i].annotation == existingAnnotation) continue next; } this.annotations[this.annotationCount++] = annots[i]; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java index 2a348db14ea..af2ff69e7e3 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java @@ -674,8 +674,8 @@ public void attach(RecoveredAnnotation[] annots, int annotCount, int mods, int m this.annotations = new RecoveredAnnotation[annotCount]; this.annotationCount = 0; next : for (int i = 0; i < annotCount; i++) { - for (int j = 0; j < existingAnnotations.length; j++) { - if (annots[i].annotation == existingAnnotations[j]) continue next; + for (Annotation existingAnnotation : existingAnnotations) { + if (annots[i].annotation == existingAnnotation) continue next; } this.annotations[this.annotationCount++] = annots[i]; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredType.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredType.java index 09535ab11da..47eaa522042 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredType.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/RecoveredType.java @@ -317,8 +317,8 @@ public void attach(RecoveredAnnotation[] annots, int annotCount, int mods, int m this.annotations = new RecoveredAnnotation[annotCount]; this.annotationCount = 0; next : for (int i = 0; i < annotCount; i++) { - for (int j = 0; j < existingAnnotations.length; j++) { - if (annots[i].annotation == existingAnnotations[j]) continue next; + for (Annotation existingAnnotation : existingAnnotations) { + if (annots[i].annotation == existingAnnotation) continue next; } this.annotations[this.annotationCount++] = annots[i]; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser.java index 382860a16be..b24d9b84b9e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser.java @@ -2275,12 +2275,12 @@ private void reportPrimaryError(int msgCode, int nameIndex, int token, int scope } else { int[] template = getNTermTemplate(-tmpAddedToken); if(template != null) { - for (int j = 0; j < template.length; j++) { + for (int t : template) { int length = addedTokens.length; if(addedTokenCount == length) { System.arraycopy(addedTokens, 0, addedTokens = new int[length * 2], 0, length); } - addedTokens[addedTokenCount++] = template[j]; + addedTokens[addedTokenCount++] = t; } } else { addedTokenCount = 0; @@ -2496,12 +2496,12 @@ private void reportSecondaryError(int msgCode, int nameIndex, int leftToken, int } else { int[] template = getNTermTemplate(-tmpAddedToken); if(template != null) { - for (int j = 0; j < template.length; j++) { + for (int t : template) { int length = addedTokens.length; if(addedTokenCount == length) { System.arraycopy(addedTokens, 0, addedTokens = new int[length * 2], 0, length); } - addedTokens[addedTokenCount++] = template[j]; + addedTokens[addedTokenCount++] = t; } } else { addedTokenCount = 0; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/diagnose/RangeUtil.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/diagnose/RangeUtil.java index 1556ac73025..8d6e565e774 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/diagnose/RangeUtil.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/diagnose/RangeUtil.java @@ -131,14 +131,14 @@ public static int[][] computeDietRange(TypeDeclaration[] types) { } private static void computeDietRange0(TypeDeclaration[] types, RangeResult result) { - for (int j = 0; j < types.length; j++) { + for (TypeDeclaration type : types) { //members - TypeDeclaration[] memberTypeDeclarations = types[j].memberTypes; + TypeDeclaration[] memberTypeDeclarations = type.memberTypes; if(memberTypeDeclarations != null && memberTypeDeclarations.length > 0) { - computeDietRange0(types[j].memberTypes, result); + computeDietRange0(type.memberTypes, result); } //methods - AbstractMethodDeclaration[] methods = types[j].methods; + AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { int length = methods.length; for (int i = 0; i < length; i++) { @@ -156,7 +156,7 @@ private static void computeDietRange0(TypeDeclaration[] types, RangeResult resul } //initializers - FieldDeclaration[] fields = types[j].fields; + FieldDeclaration[] fields = type.fields; if (fields != null) { int length = fields.length; for (int i = 0; i < length; i++) { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java index f32c3141bc6..cec4dfd1b50 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java @@ -277,8 +277,8 @@ public String toString() { s += this.message; } else { if (this.arguments != null) - for (int i = 0; i < this.arguments.length; i++) - s += " " + this.arguments[i]; //$NON-NLS-1$ + for (String argument : this.arguments) + s += " " + argument; //$NON-NLS-1$ } return s; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index 06aa2adf154..0e15c5d650e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -82,7 +82,6 @@ import java.io.CharConversionException; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -4868,9 +4867,9 @@ else if (type instanceof ArrayBinding) { List missingTypes = type.collectMissingTypes(null); if (missingTypes != null) { ReferenceContext savedContext = this.referenceContext; - for (Iterator iterator = missingTypes.iterator(); iterator.hasNext(); ) { + for (TypeBinding missingType : missingTypes) { try { - invalidType(location, iterator.next()); + invalidType(location, missingType); } finally { this.referenceContext = savedContext; // nested reporting will have reset referenceContext } @@ -5281,8 +5280,8 @@ private boolean isRecoveredName(char[] simpleName) { private boolean isRecoveredName(char[][] qualifiedName) { if(qualifiedName == null) return false; - for (int i = 0; i < qualifiedName.length; i++) { - if(qualifiedName[i] == RecoveryScanner.FAKE_IDENTIFIER) return true; + for (char[] segment : qualifiedName) { + if(segment == RecoveryScanner.FAKE_IDENTIFIER) return true; } return false; } @@ -10473,8 +10472,7 @@ public void nullityMismatchVariableIsFreeTypeVariable(VariableBinding variable, public void illegalRedefinitionToNonNullParameter(Argument argument, ReferenceBinding declaringClass, char[][] inheritedAnnotationName) { int sourceStart = argument.type.sourceStart; if (argument.annotations != null) { - for (int i=0; i getPlatformLocations(File file) { @Override protected void loggingExtraProblems() { super.loggingExtraProblems(); - for (@SuppressWarnings("rawtypes") - Iterator iterator = this.extraProblems.iterator(); iterator.hasNext(); ) { - final CategorizedProblem problem = (CategorizedProblem) iterator.next(); - if (this.diagnosticListener != null && !isIgnored(problem)) { - Diagnostic diagnostic = new Diagnostic<>() { - @Override - public String getCode() { - return null; - } - @Override - public long getColumnNumber() { - if (problem instanceof DefaultProblem) { - return ((DefaultProblem) problem).column; - } - return Diagnostic.NOPOS; + for (CategorizedProblem problem : this.extraProblems) { + if (this.diagnosticListener != null && !isIgnored(problem)) { + Diagnostic diagnostic = new Diagnostic<>() { + @Override + public String getCode() { + return null; + } + @Override + public long getColumnNumber() { + if (problem instanceof DefaultProblem) { + return ((DefaultProblem) problem).column; } - @Override - public long getEndPosition() { - if (problem instanceof DefaultProblem) { - return ((DefaultProblem) problem).getSourceEnd(); - } - return Diagnostic.NOPOS; + return Diagnostic.NOPOS; + } + @Override + public long getEndPosition() { + if (problem instanceof DefaultProblem) { + return ((DefaultProblem) problem).getSourceEnd(); } - @Override - public Kind getKind() { - if (problem.isError()) { - return Diagnostic.Kind.ERROR; - } - if (problem.isWarning()) { - return Diagnostic.Kind.WARNING; - } else if (problem instanceof DefaultProblem && ((DefaultProblem) problem).isInfo()) { - return Diagnostic.Kind.NOTE; - } - return Diagnostic.Kind.OTHER; + return Diagnostic.NOPOS; + } + @Override + public Kind getKind() { + if (problem.isError()) { + return Diagnostic.Kind.ERROR; } - @Override - public long getLineNumber() { - if (problem instanceof DefaultProblem) { - return ((DefaultProblem) problem).getSourceLineNumber(); - } - return Diagnostic.NOPOS; + if (problem.isWarning()) { + return Diagnostic.Kind.WARNING; + } else if (problem instanceof DefaultProblem && ((DefaultProblem) problem).isInfo()) { + return Diagnostic.Kind.NOTE; } - @Override - public String getMessage(Locale locale) { - return problem.getMessage(); + return Diagnostic.Kind.OTHER; + } + @Override + public long getLineNumber() { + if (problem instanceof DefaultProblem) { + return ((DefaultProblem) problem).getSourceLineNumber(); } - @Override - public long getPosition() { - if (problem instanceof DefaultProblem) { - return ((DefaultProblem) problem).getSourceStart(); - } - return Diagnostic.NOPOS; + return Diagnostic.NOPOS; + } + @Override + public String getMessage(Locale locale) { + return problem.getMessage(); + } + @Override + public long getPosition() { + if (problem instanceof DefaultProblem) { + return ((DefaultProblem) problem).getSourceStart(); } - @Override - public JavaFileObject getSource() { - if (problem instanceof DefaultProblem) { - char[] originatingName = ((DefaultProblem) problem).getOriginatingFileName(); - if (originatingName == null) { - return null; - } - File f = new File(new String(originatingName)); - if (f.exists()) { - Charset charset = (EclipseCompilerImpl.this.fileManager instanceof EclipseFileManager) ? - ((EclipseFileManager) EclipseCompilerImpl.this.fileManager).charset : Charset.defaultCharset(); - return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, charset); - } + return Diagnostic.NOPOS; + } + @Override + public JavaFileObject getSource() { + if (problem instanceof DefaultProblem) { + char[] originatingName = ((DefaultProblem) problem).getOriginatingFileName(); + if (originatingName == null) { return null; } + File f = new File(new String(originatingName)); + if (f.exists()) { + Charset charset = (EclipseCompilerImpl.this.fileManager instanceof EclipseFileManager) ? + ((EclipseFileManager) EclipseCompilerImpl.this.fileManager).charset : Charset.defaultCharset(); + return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, charset); + } return null; } - @Override - public long getStartPosition() { - return getPosition(); - } - }; - this.diagnosticListener.report(diagnostic); - } + return null; + } + @Override + public long getStartPosition() { + return getPosition(); + } + }; + this.diagnosticListener.report(diagnostic); } +} } class Jsr199ProblemWrapper extends DefaultProblem { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java index 36c51b0aee7..9979e9938fa 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java @@ -231,11 +231,11 @@ private void collectAllMatchingFiles(Location location, File file, String normal private Iterable concatFiles(Iterable iterable, Iterable iterable2) { ArrayList list = new ArrayList<>(); if (iterable2 == null) return iterable; - for (Iterator iterator = iterable.iterator(); iterator.hasNext(); ) { - list.add(iterator.next()); + for (File file : iterable) { + list.add(file); } - for (Iterator iterator = iterable2.iterator(); iterator.hasNext(); ) { - list.add(iterator.next()); + for (File file : iterable2) { + list.add(file); } return list; } @@ -1018,12 +1018,12 @@ private Iterable prependFiles(Iterable iterable, Iterable iterable2) { if (iterable2 == null) return iterable; ArrayList list = new ArrayList<>(); - for (Iterator iterator = iterable2.iterator(); iterator.hasNext(); ) { - list.add(iterator.next()); + for (File file : iterable2) { + list.add(file); } if (iterable != null) { - for (Iterator iterator = iterable.iterator(); iterator.hasNext(); ) { - list.add(iterator.next()); + for (File file : iterable) { + list.add(file); } } return list; @@ -1039,8 +1039,7 @@ public void setLocation(Location location, Iterable files) throw if (location.isOutputLocation() && files != null) { // output location int count = 0; - for (Iterator iterator = files.iterator(); iterator.hasNext(); ) { - iterator.next(); + for (@SuppressWarnings("unused") File file : files) { count++; } if (count != 1) { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/HashtableOfModule.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/HashtableOfModule.java index f382a76ff4d..ce0af579a2f 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/HashtableOfModule.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/HashtableOfModule.java @@ -102,8 +102,8 @@ public int size() { public String toString() { String s = ""; //$NON-NLS-1$ ModuleBinding pkg; - for (int i = 0, length = this.valueTable.length; i < length; i++) - if ((pkg = this.valueTable[i]) != null) + for (ModuleBinding binding : this.valueTable) + if ((pkg = binding) != null) s += pkg.toString() + "\n"; //$NON-NLS-1$ return s; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/HashtableOfObjectToInt.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/HashtableOfObjectToInt.java index 20611d36a2f..74e49474665 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/HashtableOfObjectToInt.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/HashtableOfObjectToInt.java @@ -86,9 +86,9 @@ public int get(Object key) { public void keysToArray(Object[] array) { int index = 0; - for (int i=0, length=this.keyTable.length; i collectPlatformLibraries(File javaHome) } File[][] systemLibrariesJars = Main.getLibrariesFiles(directoriesToCheck); if (systemLibrariesJars != null) { - for (int i = 0, max = systemLibrariesJars.length; i < max; i++) { - File[] current = systemLibrariesJars[i]; + for (File[] current : systemLibrariesJars) { if (current != null) { - for (int j = 0, max2 = current.length; j < max2; j++) { - filePaths.add(current[j].getAbsolutePath()); + for (File file : current) { + filePaths.add(file.getAbsolutePath()); } } }