Skip to content

Commit

Permalink
dogfooding batch: cleanup Java 5: Convert to enhanced 'for' loops
Browse files Browse the repository at this point in the history
org.eclipse.jdt.core.compiler.batch
  • Loading branch information
EcljpseB0T committed Mar 5, 2024
1 parent c1875a1 commit 2a78d2f
Show file tree
Hide file tree
Showing 135 changed files with 1,186 additions and 1,406 deletions.
Expand Up @@ -245,8 +245,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 entry2 : entries) {
Map.Entry entry = (Map.Entry) entry2;
if (!(entry.getKey() instanceof String))
continue;
if (!(entry.getValue() instanceof String))
Expand Down Expand Up @@ -383,10 +383,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) {
Expand Down Expand Up @@ -550,8 +550,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 element : this.compileList) {
String arg = element.getAbsolutePath();
boolean encoded = false;
if (encodedFiles != null) {
//check for file level custom encoding
Expand Down
Expand Up @@ -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[] element : array) {
if (equals(element, sequence))
return true;
}
return false;
Expand Down Expand Up @@ -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 element : array)
if (toBeFound == element)
count++;
return count;
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 element : superInterfaces) {
this.missingTypes = element.collectMissingTypes(this.missingTypes);
}
attributesNumber += generateHierarchyInconsistentAttribute();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 element : markerInterfaces) {
int classTypeIndex = this.constantPool.literalIndexForType(element);
this.contents[localContentsOffset++] = (byte)(classTypeIndex>>8);
this.contents[localContentsOffset++] = (byte)(classTypeIndex);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 annotation2 : annotations) {
Annotation annotation;
if ((annotation = annotations[j].getPersistibleAnnotation()) == null) continue; // already packaged into container.
if ((annotation = annotation2.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()) {
Expand Down Expand Up @@ -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 annotation2 : annotations) {
Annotation annotation;
if ((annotation = annotations[j].getPersistibleAnnotation()) == null) continue; // already packaged into container.
if ((annotation = annotation2.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()) {
Expand Down Expand Up @@ -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 annotation2 : annotations) {
Annotation annotation;
if ((annotation = annotations[j].getPersistibleAnnotation()) == null) continue; // already packaged into container.
if ((annotation = annotation2.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()) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -6565,8 +6555,7 @@ private List<StackMapFrame> filterFakeFrames(Set<Integer> realJumpTargets, Map<I
// filter out "fake" frames
realJumpTargets.remove(Integer.valueOf(codeLength));
List<StackMapFrame> result = new ArrayList<>();
for (Iterator<Integer> iterator = realJumpTargets.iterator(); iterator.hasNext(); ) {
Integer jumpTarget = iterator.next();
for (Integer jumpTarget : realJumpTargets) {
StackMapFrame frame = frames.get(jumpTarget);
if (frame != null) {
result.add(frame);
Expand Down
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -337,9 +337,9 @@ private Object getReflectionValue(Object actualValue, TypeBinding actualType, Cl

if(bindings != null) {
List<TypeMirror> 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);
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit 2a78d2f

Please sign in to comment.