diff options
author | Carsten Hammer | 2020-02-23 09:37:15 +0000 |
---|---|---|
committer | Fabrice Tiercelin | 2020-03-23 16:30:46 +0000 |
commit | e698acce70986f66ffa643b5e694972fce535416 (patch) | |
tree | eb118e74c649c333ffee253be226bbb1763de4b3 | |
parent | 8d9cbaa85554eb4315af5f659696b6476dd0667a (diff) | |
download | eclipse.jdt.ui-e698acce70986f66ffa643b5e694972fce535416.tar.gz eclipse.jdt.ui-e698acce70986f66ffa643b5e694972fce535416.tar.xz eclipse.jdt.ui-e698acce70986f66ffa643b5e694972fce535416.zip |
Bug 548309 - Use jdk 5 for-each loopI20200323-1800
org.eclipse.jdt.ui
Replace simple uses of Iterator with a corresponding for-loop. Also add
missing braces on loops as necessary.
Change-Id: I3a7ceb7eff56c4469c9048de47aaa80f7ee5db69
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
25 files changed, 251 insertions, 393 deletions
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/TypeContextChecker.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/TypeContextChecker.java index 2b4941ac04..c07f4b041d 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/TypeContextChecker.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/TypeContextChecker.java @@ -17,7 +17,6 @@ package org.eclipse.jdt.internal.corext.refactoring; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -344,8 +343,7 @@ public class TypeContextChecker { new SearchEngine().searchAllTypeNames(null, matchMode, typeName.toCharArray(), matchMode, IJavaSearchConstants.TYPE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, pm); List<TypeNameMatch> result= new ArrayList<>(); - for (Iterator<TypeNameMatch> iter= collectedInfos.iterator(); iter.hasNext();) { - TypeNameMatch curr= iter.next(); + for (TypeNameMatch curr : collectedInfos) { IType type= curr.getType(); if (type != null) { boolean visible=true; @@ -410,8 +408,8 @@ public class TypeContextChecker { return null; RefactoringStatus result= new RefactoringStatus(); - for (Iterator<String> iter= problemsCollector.iterator(); iter.hasNext();) { - String[] keys= new String[]{ BasicElementLabels.getJavaElementName(newTypeName), BasicElementLabels.getJavaElementName(iter.next())}; + for (String problem : problemsCollector) { + String[] keys= new String[]{ BasicElementLabels.getJavaElementName(newTypeName), BasicElementLabels.getJavaElementName(problem)}; String msg= Messages.format(RefactoringCoreMessages.TypeContextChecker_invalid_return_type_syntax, keys); result.addError(msg); } @@ -511,9 +509,9 @@ public class TypeContextChecker { return null; RefactoringStatus result= new RefactoringStatus(); - for (Iterator<String> iter= problemsCollector.iterator(); iter.hasNext();) { + for (String problem : problemsCollector) { String msg= Messages.format(RefactoringCoreMessages.TypeContextChecker_invalid_type_syntax, - new String[]{BasicElementLabels.getJavaElementName(newTypeName), BasicElementLabels.getJavaElementName(iter.next())}); + new String[]{BasicElementLabels.getJavaElementName(newTypeName), BasicElementLabels.getJavaElementName(problem)}); result.addError(msg); } return result; @@ -640,8 +638,7 @@ public class TypeContextChecker { } private static void appendModifiers(StringBuilder buf, List<IExtendedModifier> modifiers) { - for (Iterator<IExtendedModifier> iterator= modifiers.iterator(); iterator.hasNext();) { - IExtendedModifier extendedModifier= iterator.next(); + for (IExtendedModifier extendedModifier : modifiers) { if (extendedModifier.isModifier()) { Modifier modifier= (Modifier) extendedModifier; buf.append(modifier.getKeyword().toString()).append(' '); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/TypedSource.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/TypedSource.java index d44efb4795..b560022214 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/TypedSource.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/TypedSource.java @@ -16,7 +16,6 @@ package org.eclipse.jdt.internal.corext.refactoring; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -120,11 +119,11 @@ public class TypedSource { //Map<ICompilationUnit, List<IJavaElement>> Map<ICompilationUnit, List<IJavaElement>> grouped= ReorgUtils.groupByCompilationUnit(Arrays.asList(javaElements)); List<TypedSource> result= new ArrayList<>(javaElements.length); - for (Iterator<ICompilationUnit> iter= grouped.keySet().iterator(); iter.hasNext();) { - ICompilationUnit cu= iter.next(); - for (Iterator<IJavaElement> iterator= grouped.get(cu).iterator(); iterator.hasNext();) { + for (Map.Entry<ICompilationUnit, List<IJavaElement>> entry : grouped.entrySet()) { + ICompilationUnit cu= entry.getKey(); + for (IJavaElement javaElement : entry.getValue()) { SourceTuple tuple= new SourceTuple(cu); - TypedSource[] ts= createTypedSources(iterator.next(), tuple); + TypedSource[] ts= createTypedSources(javaElement, tuple); if (ts != null) result.addAll(Arrays.asList(ts)); } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/binary/AbstractCodeCreationOperation.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/binary/AbstractCodeCreationOperation.java index dfb3a21f08..afc683de36 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/binary/AbstractCodeCreationOperation.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/binary/AbstractCodeCreationOperation.java @@ -17,7 +17,6 @@ import java.io.BufferedOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URI; -import java.util.Iterator; import java.util.List; import org.eclipse.core.filesystem.EFS; @@ -146,8 +145,7 @@ public abstract class AbstractCodeCreationOperation implements IWorkspaceRunnabl monitor.beginTask(getOperationLabel(), 100 * fPackages.size()); try { final StringBuilder builder= new StringBuilder(128); - for (final Iterator<IPackageFragment> iterator= fPackages.iterator(); iterator.hasNext();) { - final IPackageFragment fragment= iterator.next(); + for (IPackageFragment fragment : fPackages) { final IProgressMonitor subMonitor= new SubProgressMonitor(monitor, 100); final IClassFile[] files= fragment.getClassFiles(); // safe, but implies this operation cannot create module-info CU, which it probably should. final int size= files.length; @@ -171,10 +169,10 @@ public abstract class AbstractCodeCreationOperation implements IWorkspaceRunnabl final IProgressMonitor subsubMonitor= new SubProgressMonitor(subMonitor, 30); try { subsubMonitor.beginTask(getOperationLabel(), size * 100); - for (int index= 0; index < size; index++) { + for (IClassFile file : files) { if (subMonitor.isCanceled()) throw new OperationCanceledException(); - run(files[index], store, new SubProgressMonitor(subsubMonitor, 100)); + run(file, store, new SubProgressMonitor(subsubMonitor, 100)); } } finally { subsubMonitor.done(); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java index c2fe5d8ded..795e3f475e 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java @@ -972,8 +972,7 @@ public class ExtractMethodRefactoring extends Refactoring { } List<Expression> arguments= invocation.arguments(); - for (int i= 0; i < fParameterInfos.size(); i++) { - ParameterInfo parameter= fParameterInfos.get(i); + for (ParameterInfo parameter : fParameterInfos) { arguments.add(ASTNodeFactory.newName(fAST, getMappedName(duplicate, parameter))); } if (fLinkedProposalModel != null) { @@ -1136,8 +1135,7 @@ public class ExtractMethodRefactoring extends Refactoring { ImportRewriteContext context= new ContextSensitiveImportRewriteContext(enclosingBodyDeclaration, fImportRewriter); List<SingleVariableDeclaration> parameters= result.parameters(); - for (int i= 0; i < fParameterInfos.size(); i++) { - ParameterInfo info= fParameterInfos.get(i); + for (ParameterInfo info : fParameterInfos) { VariableDeclaration infoDecl= getVariableDeclaration(info); SingleVariableDeclaration parameter= fAST.newSingleVariableDeclaration(); parameter.modifiers().addAll(ASTNodeFactory.newModifiers(fAST, ASTNodes.getModifiers(infoDecl))); @@ -1156,8 +1154,7 @@ public class ExtractMethodRefactoring extends Refactoring { private ITypeBinding[] computeLocalTypeVariables(int modifier) { List<ITypeBinding> result= new ArrayList<>(Arrays.asList(fAnalyzer.getTypeVariables())); - for (int i= 0; i < fParameterInfos.size(); i++) { - ParameterInfo info= fParameterInfos.get(i); + for (ParameterInfo info : fParameterInfos) { processVariable(result, info.getOldBinding(), modifier); } for (IVariableBinding methodLocal : fAnalyzer.getMethodLocals()) { diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java index 74391a253c..29d196683f 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceFactoryRefactoring.java @@ -521,12 +521,10 @@ public class IntroduceFactoryRefactoring extends Refactoring { SearchResultGroup[] groups= (SearchResultGroup[]) engine.getResults(); - if (groups.length != 0) { - for (SearchResultGroup rg : groups) { - for (SearchMatch match : rg.getSearchResults()) { - if (match.getAccuracy() == SearchMatch.A_ACCURATE) { - return (IType) match.getElement(); - } + for (SearchResultGroup rg : groups) { + for (SearchMatch match : rg.getSearchResults()) { + if (match.getAccuracy() == SearchMatch.A_ACCURATE) { + return (IType) match.getElement(); } } } @@ -861,9 +859,7 @@ public class IntroduceFactoryRefactoring extends Refactoring { factoryMethodCall.setName(ast.newSimpleName(fNewMethodName)); List<Expression> actualCtorArgsList= actualCtorArgs.getRewrittenList(); - for (int i=0; i < actualCtorArgsList.size(); i++) { - Expression actualCtorArg= actualCtorArgsList.get(i); - + for (Expression actualCtorArg : actualCtorArgsList) { ASTNode movedArg; if (ASTNodes.isExistingNode(actualCtorArg)) { movedArg= unitRewriter.createMoveTarget(actualCtorArg); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceIndirectionRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceIndirectionRefactoring.java index 73b4c91088..69614b3cb4 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceIndirectionRefactoring.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/IntroduceIndirectionRefactoring.java @@ -19,7 +19,6 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -486,8 +485,8 @@ public class IntroduceIndirectionRefactoring extends Refactoring { fTextChangeManager= new TextChangeManager(); fIntermediaryFirstParameterType= null; fIntermediaryTypeBinding= null; - for (Iterator<CompilationUnitRewrite> iter= fRewrites.values().iterator(); iter.hasNext();) - iter.next().clearASTAndImportRewrites(); + for (CompilationUnitRewrite compilationUnitRewrite : fRewrites.values()) + compilationUnitRewrite.clearASTAndImportRewrites(); int startupTicks= 5; int hierarchyTicks= 5; @@ -600,9 +599,8 @@ public class IntroduceIndirectionRefactoring extends Refactoring { // Need to adjust the overridden methods of the target method. ITypeHierarchy hierarchy= fTargetMethod.getDeclaringType().newTypeHierarchy(null); MethodOverrideTester tester= new MethodOverrideTester(fTargetMethod.getDeclaringType(), hierarchy); - IType[] subtypes= hierarchy.getAllSubtypes(fTargetMethod.getDeclaringType()); - for (int i= 0; i < subtypes.length; i++) { - IMethod method= tester.findOverridingMethodInType(subtypes[i], fTargetMethod); + for (IType subtype : hierarchy.getAllSubtypes(fTargetMethod.getDeclaringType())) { + IMethod method= tester.findOverridingMethodInType(subtype, fTargetMethod); if (method != null && method.exists()) { result.merge(adjustVisibility(method, neededVisibility, monitor)); if (monitor.isCanceled()) diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/LocalTypeAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/LocalTypeAnalyzer.java index b43bec31a8..8b88521524 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/LocalTypeAnalyzer.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/LocalTypeAnalyzer.java @@ -14,7 +14,6 @@ package org.eclipse.jdt.internal.corext.refactoring.code; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.eclipse.ltk.core.refactoring.RefactoringStatus; @@ -111,8 +110,7 @@ public class LocalTypeAnalyzer extends ASTVisitor { } private boolean checkBinding(List<AbstractTypeDeclaration> declarations, ITypeBinding binding) { - for (Iterator<AbstractTypeDeclaration> iter= declarations.iterator(); iter.hasNext();) { - AbstractTypeDeclaration declaration= iter.next(); + for (AbstractTypeDeclaration declaration : declarations) { if (declaration.resolveBinding() == binding) { return true; } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/nls/AccessorClassModifier.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/nls/AccessorClassModifier.java index f81237b263..b63119f50c 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/nls/AccessorClassModifier.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/nls/AccessorClassModifier.java @@ -15,7 +15,6 @@ package org.eclipse.jdt.internal.corext.refactoring.nls; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -182,8 +181,7 @@ public class AccessorClassModifier { MultiTextEdit multiTextEdit= new MultiTextEdit(); change.setEdit(multiTextEdit); - for (int i= 0; i < fields.size(); i++) { - String field= fields.get(i); + for (String field : fields) { NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null); sourceModification.addKey(substitution, change); } @@ -204,8 +202,7 @@ public class AccessorClassModifier { MultiTextEdit multiTextEdit= new MultiTextEdit(); change.setEdit(multiTextEdit); - for (int i= 0; i < fields.size(); i++) { - String field= fields.get(i); + for (String field : fields) { NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null); sourceModification.removeKey(substitution, change); } @@ -292,8 +289,7 @@ public class AccessorClassModifier { fFields.add(fieldDeclaration); } else { ArrayList<String> identifiers= new ArrayList<>(); - for (Iterator<FieldDeclaration> iterator= fFields.iterator(); iterator.hasNext();) { - FieldDeclaration field= iterator.next(); + for (FieldDeclaration field : fFields) { VariableDeclarationFragment fragment= (VariableDeclarationFragment) field.fragments().get(0); identifiers.add(fragment.getName().getIdentifier()); } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java index fe7ea6f452..a72eb83c8c 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java @@ -25,8 +25,8 @@ public class RefactoringProcessors { public static String[] getNatures(IProject[] projects) throws CoreException { Set<String> result= new HashSet<>(); - for (int i= 0; i < projects.length; i++) { - String[] pns= projects[i].getDescription().getNatureIds(); + for (IProject project : projects) { + String[] pns= project.getDescription().getNatureIds(); Collections.addAll(result, pns); } return result.toArray(new String[result.size()]); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java index 179bc4ce52..6ea42249f2 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameTypeProcessor.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -41,6 +40,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.text.edits.ReplaceEdit; +import org.eclipse.text.edits.TextEdit; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.GroupCategory; @@ -176,9 +176,7 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd @Override public boolean select(IConfigurationElement element, RefactoringStatus status) { - IConfigurationElement[] params= element.getChildren(PARAM); - for (int i= 0; i < params.length; i++) { - IConfigurationElement param= params[i]; + for (IConfigurationElement param : element.getChildren(PARAM)) { if ("handlesSimilarDeclarations".equals(param.getAttribute(NAME)) && //$NON-NLS-1$ "false".equals(param.getAttribute(VALUE))) { //$NON-NLS-1$ return false; @@ -644,19 +642,19 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd RenamingNameSuggestor sugg= new RenamingNameSuggestor(fRenamingStrategy); - for (int i= 0; i < fReferences.length; i++) { - final ICompilationUnit cu= fReferences[i].getCompilationUnit(); + for (SearchResultGroup reference : fReferences) { + final ICompilationUnit cu= reference.getCompilationUnit(); if (cu == null) continue; - final SearchMatch[] results= fReferences[i].getSearchResults(); + final SearchMatch[] results= reference.getSearchResults(); - for (int j= 0; j < results.length; j++) { + for (SearchMatch result : results) { - if (! (results[j] instanceof TypeReferenceMatch)) + if (! (result instanceof TypeReferenceMatch)) continue; - final TypeReferenceMatch match= (TypeReferenceMatch) results[j]; + final TypeReferenceMatch match= (TypeReferenceMatch) result; final List<IJavaElement> matches= new ArrayList<>(); if (match.getLocalElement() != null) { @@ -672,9 +670,7 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd if (others != null) matches.addAll(Arrays.asList(others)); - for (Iterator<IJavaElement> iter= matches.iterator(); iter.hasNext();) { - final IJavaElement element= iter.next(); - + for (IJavaElement element : matches) { if (! (element instanceof IMethod) && ! (element instanceof IField) && ! (element instanceof ILocalVariable)) continue; @@ -716,8 +712,7 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd } } - for (Iterator<IJavaElement> iter= fPreloadedElementToName.keySet().iterator(); iter.hasNext();) { - IJavaElement element= iter.next(); + for (IJavaElement element : fPreloadedElementToName.keySet()) { fPreloadedElementToSelection.put(element, Boolean.TRUE); } fPreloadedElementToNameDefault= new LinkedHashMap<>(fPreloadedElementToName); @@ -829,10 +824,9 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd } private static IType findEnclosedType(IType type, String newName) throws CoreException { - IType[] enclosedTypes= type.getTypes(); - for (int i= 0; i < enclosedTypes.length; i++){ - if (newName.equals(enclosedTypes[i].getElementName()) || findEnclosedType(enclosedTypes[i], newName) != null) - return enclosedTypes[i]; + for (IType enclosedType : type.getTypes()) { + if (newName.equals(enclosedType.getElementName()) || findEnclosedType(enclosedType, newName) != null) + return enclosedType; } return null; } @@ -849,21 +843,19 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd } private static IImportDeclaration getImportedType(ICompilationUnit cu, String typeName) throws CoreException { - IImportDeclaration[] imports= cu.getImports(); String dotTypeName= "." + typeName; //$NON-NLS-1$ - for (int i= 0; i < imports.length; i++){ - if (imports[i].getElementName().endsWith(dotTypeName)) - return imports[i]; + for (IImportDeclaration _import : cu.getImports()) { + if (_import.getElementName().endsWith(dotTypeName)) + return _import; } return null; } private RefactoringStatus checkForMethodsWithConstructorNames() throws CoreException{ - IMethod[] methods= fType.getMethods(); - for (int i= 0; i < methods.length; i++){ - if (methods[i].isConstructor()) + for (IMethod method : fType.getMethods()) { + if (method.isConstructor()) continue; - RefactoringStatus check= Checks.checkIfConstructorName(methods[i], methods[i].getElementName(), getNewElementName()); + RefactoringStatus check= Checks.checkIfConstructorName(method, method.getElementName(), getNewElementName()); if (check != null) return check; } @@ -872,9 +864,8 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd private RefactoringStatus checkImportedTypes() throws CoreException { RefactoringStatus result= new RefactoringStatus(); - IImportDeclaration[] imports= fType.getCompilationUnit().getImports(); - for (int i= 0; i < imports.length; i++) - analyzeImportDeclaration(imports[i], result); + for (IImportDeclaration _import : fType.getCompilationUnit().getImports()) + analyzeImportDeclaration(_import, result); return result; } @@ -919,10 +910,9 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd result.addError(msg, context); } - MethodDeclaration[] methods= node.getMethods(); - for (int i= 0; i < methods.length; i++) { - if (Modifier.isNative(methods[i].getModifiers())){ - RefactoringStatusContext context= JavaStatusContext.create(fType.getCompilationUnit(), methods[i]); + for (MethodDeclaration method : node.getMethods()) { + if (Modifier.isNative(method.getModifiers())){ + RefactoringStatusContext context= JavaStatusContext.create(fType.getCompilationUnit(), method); String msg= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_enclosed_type_native, BasicElementLabels.getJavaElementName(node.getName().getIdentifier())); result.addWarning(msg, context); } @@ -938,11 +928,11 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd } private void analyzeImportedTypes(IType[] types, RefactoringStatus result, IImportDeclaration imp) throws CoreException { - for (int i= 0; i < types.length; i++) { + for (IType type : types) { //could this be a problem (same package imports)? - if (JdtFlags.isPublic(types[i]) && types[i].getElementName().equals(getNewElementName())){ + if (JdtFlags.isPublic(type) && type.getElementName().equals(getNewElementName())){ String msg= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_name_conflict1, - new Object[]{ JavaElementLabels.getElementLabel(types[i], JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getPathLabel(getCompilationUnit(imp).getPath(), false)}); + new Object[]{ JavaElementLabels.getElementLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getPathLabel(getCompilationUnit(imp).getPath(), false)}); result.addError(msg, JavaStatusContext.create(imp)); } } @@ -965,9 +955,8 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd return; if (imported instanceof IPackageFragment){ - ICompilationUnit[] cus= ((IPackageFragment)imported).getCompilationUnits(); - for (int i= 0; i < cus.length; i++) { - analyzeImportedTypes(cus[i].getTypes(), result, imp); + for (ICompilationUnit cu : ((IPackageFragment)imported).getCompilationUnits()) { + analyzeImportedTypes(cu.getTypes(), result, imp); } } else { //cast safe: see JavaModelUtility.convertFromImportDeclaration @@ -1044,8 +1033,8 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd private static ICompilationUnit[] getCus(SearchResultGroup[] searchResultGroups){ List<ICompilationUnit> cus= new ArrayList<>(searchResultGroups.length); - for (int i= 0; i < searchResultGroups.length; i++) { - ICompilationUnit cu= searchResultGroups[i].getCompilationUnit(); + for (SearchResultGroup searchResultGroup : searchResultGroups) { + ICompilationUnit cu= searchResultGroup.getCompilationUnit(); if (cu != null) cus.add(cu); } @@ -1187,10 +1176,9 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd private void addConstructorRenames(TextChangeManager manager) throws CoreException { ICompilationUnit cu= fType.getCompilationUnit(); - IMethod[] methods= fType.getMethods(); int typeNameLength= fType.getElementName().length(); - for (int i= 0; i < methods.length; i++){ - if (methods[i].isConstructor()) { + for (IMethod method : fType.getMethods()) { + if (method.isConstructor()) { /* * constructor declarations cannot be fully qualified so we can use simple replace here * @@ -1198,23 +1186,21 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd * (checked as a precondition) */ String name= RefactoringCoreMessages.RenameTypeRefactoring_rename_constructor; - TextChangeCompatibility.addTextEdit(manager.get(cu), name, new ReplaceEdit(methods[i].getNameRange().getOffset(), typeNameLength, getNewElementName())); + TextChangeCompatibility.addTextEdit(manager.get(cu), name, new ReplaceEdit(method.getNameRange().getOffset(), typeNameLength, getNewElementName())); } } } private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) { pm.beginTask("", fReferences.length); //$NON-NLS-1$ - for (int i= 0; i < fReferences.length; i++){ - ICompilationUnit cu= fReferences[i].getCompilationUnit(); + for (SearchResultGroup reference : fReferences) { + ICompilationUnit cu= reference.getCompilationUnit(); if (cu == null) continue; String name= RefactoringCoreMessages.RenameTypeRefactoring_update_reference; - SearchMatch[] results= fReferences[i].getSearchResults(); - for (int j= 0; j < results.length; j++){ - SearchMatch match= results[j]; + for (SearchMatch match : reference.getSearchResults()) { ReplaceEdit replaceEdit= new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName()); TextChangeCompatibility.addTextEdit(manager.get(cu), name, replaceEdit, CATEGORY_TYPE_RENAME); } @@ -1311,10 +1297,9 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd progressMonitor.beginTask("", max * 3); //$NON-NLS-1$ progressMonitor.setTaskName(RefactoringCoreMessages.RenameTypeProcessor_checking_similarly_named_declarations_refactoring_conditions); - for (Iterator<IJavaElement> iter= fPreloadedElementToName.keySet().iterator(); iter.hasNext();) { - - final IJavaElement element= iter.next(); + for (Entry<IJavaElement, String> entry : fPreloadedElementToName.entrySet()) { + IJavaElement element= entry.getKey(); current++; progressMonitor.worked(3); @@ -1342,7 +1327,7 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd processors.clear(); } - final String newName= fPreloadedElementToName.get(element); + final String newName= entry.getValue(); RefactoringProcessor processor= null; if (element instanceof ILocalVariable) { @@ -1394,8 +1379,8 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd processor= createVirtualMethodRenameProcessor(currentMethod, newName, ripples, hierarchy); fFinalSimilarElementToName.put(currentMethod, newName); - for (int i= 0; i < ripples.length; i++) { - fFinalSimilarElementToName.put(ripples[i], newName); + for (IMethod ripple : ripples) { + fFinalSimilarElementToName.put(ripple, newName); } } else { @@ -1448,12 +1433,12 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd int current= 0; TextChange textChange= manager.get(currentCU); textChange.setKeepPreviewEdits(true); - for (Iterator<RefactoringProcessor> iterator= locals.iterator(); iterator.hasNext();) { - RenameLocalVariableProcessor localProcessor= (RenameLocalVariableProcessor) iterator.next(); + for (RefactoringProcessor refactoringProcessor : locals) { + RenameLocalVariableProcessor localProcessor= (RenameLocalVariableProcessor) refactoringProcessor; RenameAnalyzeUtil.LocalAnalyzePackage analyzePackage= localProcessor.getLocalAnalyzePackage(); analyzePackages[current]= analyzePackage; - for (int i= 0; i < analyzePackage.fOccurenceEdits.length; i++) { - TextChangeCompatibility.addTextEdit(textChange, "", analyzePackage.fOccurenceEdits[i], GroupCategorySet.NONE); //$NON-NLS-1$ + for (TextEdit occurenceEdit : analyzePackage.fOccurenceEdits) { + TextChangeCompatibility.addTextEdit(textChange, "", occurenceEdit, GroupCategorySet.NONE); //$NON-NLS-1$ } current++; } @@ -1470,8 +1455,7 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd private List<RefactoringProcessor> getProcessorsOfType(List<RefactoringProcessor> processors, Class<RenameLocalVariableProcessor> type) { List<RefactoringProcessor> tmp= new ArrayList<>(); - for (Iterator<RefactoringProcessor> iter= processors.iterator(); iter.hasNext();) { - RefactoringProcessor element= iter.next(); + for (RefactoringProcessor element : processors) { if (element.getClass().equals(type)) tmp.add(element); } @@ -1492,13 +1476,12 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd */ private RefactoringStatus checkForConflictingRename(IMethod[] methods, String newName) { RefactoringStatus status= new RefactoringStatus(); - for (Iterator<IJavaElement> iter= fFinalSimilarElementToName.keySet().iterator(); iter.hasNext();) { - IJavaElement element= iter.next(); + for (Entry<IJavaElement, String> entry : fFinalSimilarElementToName.entrySet()) { + IJavaElement element= entry.getKey(); if (element instanceof IMethod) { IMethod alreadyRegisteredMethod= (IMethod) element; - String alreadyRegisteredMethodName= fFinalSimilarElementToName.get(element); - for (int i= 0; i < methods.length; i++) { - IMethod method2= methods[i]; + String alreadyRegisteredMethodName= entry.getValue(); + for (IMethod method2 : methods) { if ( (alreadyRegisteredMethodName.equals(newName)) && (method2.getDeclaringType().equals(alreadyRegisteredMethod.getDeclaringType())) && (sameParams(alreadyRegisteredMethod, method2))) { String message= Messages.format(RefactoringCoreMessages.RenameTypeProcessor_cannot_rename_methods_same_new_name, @@ -1572,8 +1555,7 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd RefactoringStatus status= new RefactoringStatus(); // Remove deleted ripple methods from user selection and add warnings - for (Iterator<Warning> iter= warnings.iterator(); iter.hasNext();) { - final Warning warning= iter.next(); + for (Warning warning : warnings) { final IMethod[] elements= warning.getRipple(); if (warning.isSelectionWarning()) { String message= Messages.format(RefactoringCoreMessages.RenameTypeProcessor_deselected_method_is_overridden, @@ -1588,8 +1570,8 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd JavaElementLabels.getElementLabel(elements[0].getDeclaringType(), JavaElementLabels.ALL_DEFAULT) }); status.addWarning(message); } - for (int i= 0; i < elements.length; i++) - fPreloadedElementToSelection.put(elements[i], Boolean.FALSE); + for (IMethod element : elements) + fPreloadedElementToSelection.put(element, Boolean.FALSE); } return status; } @@ -1602,9 +1584,9 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd boolean addSelectionWarning= false; boolean addNameWarning= false; - for (int i= 0; i < ripples.length; i++) { - String newNameOfRipple= fPreloadedElementToName.get(ripples[i]); - Boolean selected= fPreloadedElementToSelection.get(ripples[i]); + for (IMethod ripple : ripples) { + String newNameOfRipple= fPreloadedElementToName.get(ripple); + Boolean selected= fPreloadedElementToSelection.get(ripple); // selected may be null here due to supermethods like // setSomeClass(Object class) (subsignature match) @@ -1704,15 +1686,15 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd final Map<String, String> simpleNames= new HashMap<>(); final List<String> forbiddenSimpleNames= new ArrayList<>(); - for (Iterator<IJavaElement> iter= fFinalSimilarElementToName.keySet().iterator(); iter.hasNext();) { - final IJavaElement element= iter.next(); + for (Entry<IJavaElement, String> entry : fFinalSimilarElementToName.entrySet()) { + IJavaElement element= entry.getKey(); if (element instanceof IField) { if (forbiddenSimpleNames.contains(element.getElementName())) continue; final String registeredNewName= simpleNames.get(element.getElementName()); - final String newNameToCheck= fFinalSimilarElementToName.get(element); + final String newNameToCheck= entry.getValue(); if (registeredNewName == null) simpleNames.put(element.getElementName(), newNameToCheck); else if (!registeredNewName.equals(newNameToCheck)) @@ -1720,11 +1702,11 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd } } - for (Iterator<IJavaElement> iter= fFinalSimilarElementToName.keySet().iterator(); iter.hasNext();) { - final IJavaElement element= iter.next(); + for (Entry<IJavaElement, String> entry : fFinalSimilarElementToName.entrySet()) { + IJavaElement element= entry.getKey(); if (element instanceof IField) { final IField field= (IField) element; - final String newName= fFinalSimilarElementToName.get(field); + final String newName= entry.getValue(); TextMatchUpdater.perform(monitor, RefactoringScopeFactory.create(field), field.getElementName(), field.getDeclaringType().getFullyQualifiedName(), newName, manager, new SearchResultGroup[0], forbiddenSimpleNames.contains(field.getElementName())); } @@ -1759,9 +1741,9 @@ public class RenameTypeProcessor extends JavaRenameProcessor implements ITextUpd */ public void resetSelectedSimilarElements() { Assert.isNotNull(fPreloadedElementToName); - for (Iterator<IJavaElement> iter= fPreloadedElementToNameDefault.keySet().iterator(); iter.hasNext();) { - final IJavaElement element= iter.next(); - fPreloadedElementToName.put(element, fPreloadedElementToNameDefault.get(element)); + for (Entry<IJavaElement, String> entry : fPreloadedElementToNameDefault.entrySet()) { + IJavaElement element= entry.getKey(); + fPreloadedElementToName.put(element, entry.getValue()); fPreloadedElementToSelection.put(element, Boolean.TRUE); } } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RippleMethodFinder2.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RippleMethodFinder2.java index f94a53e7d7..17b9d70160 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RippleMethodFinder2.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RippleMethodFinder2.java @@ -206,8 +206,7 @@ public class RippleMethodFinder2 { fRootTypes= null; Map<IType, List<IType>> partitioning= new HashMap<>(); - for (Iterator<IType> iter= fTypeToMethod.keySet().iterator(); iter.hasNext();) { - IType type= iter.next(); + for (IType type : fTypeToMethod.keySet()) { IType rep= fUnionFind.find(type); List<IType> types= partitioning.get(rep); if (types == null) @@ -225,8 +224,7 @@ public class RippleMethodFinder2 { List<IType> relatedTypes= partitioning.get(methodTypeRep); boolean hasRelatedInterfaces= false; List<IMethod> relatedMethods= new ArrayList<>(); - for (Iterator<IType> iter= relatedTypes.iterator(); iter.hasNext();) { - IType relatedType= iter.next(); + for (IType relatedType : relatedTypes) { relatedMethods.add(fTypeToMethod.get(relatedType)); if (relatedType.isInterface()) hasRelatedInterfaces= true; @@ -241,8 +239,7 @@ public class RippleMethodFinder2 { alienDeclarations.removeAll(relatedMethods); Set<IType> alienTypes= new LinkedHashSet<>(); boolean hasAlienInterfaces= false; - for (Iterator<IMethod> iter= alienDeclarations.iterator(); iter.hasNext();) { - IMethod alienDeclaration= iter.next(); + for (IMethod alienDeclaration : alienDeclarations) { IType alienType= alienDeclaration.getDeclaringType(); alienTypes.add(alienType); if (alienType.isInterface()) @@ -275,9 +272,8 @@ public class RippleMethodFinder2 { List<IType> relatedTypesToProcess= new ArrayList<>(relatedTypes); while (relatedTypesToProcess.size() > 0) { //TODO: would only need subtype hierarchies of all top-of-ripple relatedTypesToProcess - for (Iterator<IType> iter= relatedTypesToProcess.iterator(); iter.hasNext();) { + for (IType relatedType : relatedTypesToProcess) { checkCanceled(pm); - IType relatedType= iter.next(); ITypeHierarchy hierarchy= hierarchy(pm, owner, relatedType); IType[] allSubTypes= hierarchy.getAllSubtypes(relatedType); relatedSubTypes.addAll(Arrays.asList(allSubTypes)); @@ -285,9 +281,8 @@ public class RippleMethodFinder2 { relatedTypesToProcess.clear(); //processed; make sure loop terminates HashSet<IType> marriedAlienTypeReps= new HashSet<>(); - for (Iterator<IType> iter= alienTypes.iterator(); iter.hasNext();) { + for (IType alienType : alienTypes) { checkCanceled(pm); - IType alienType= iter.next(); IMethod alienMethod= fTypeToMethod.get(alienType); ITypeHierarchy hierarchy= hierarchy(pm, owner, alienType); @@ -305,11 +300,9 @@ public class RippleMethodFinder2 { if (marriedAlienTypeReps.isEmpty()) return toArray(relatedMethods); - for (Iterator<IType> iter= marriedAlienTypeReps.iterator(); iter.hasNext();) { - IType marriedAlienTypeRep= iter.next(); + for (IType marriedAlienTypeRep : marriedAlienTypeReps) { List<IType> marriedAlienTypes= partitioning.get(marriedAlienTypeRep); - for (Iterator<IType> iterator= marriedAlienTypes.iterator(); iterator.hasNext();) { - IType marriedAlienInterfaceType= iterator.next(); + for (IType marriedAlienInterfaceType : marriedAlienTypes) { relatedMethods.add(fTypeToMethod.get(marriedAlienInterfaceType)); } alienTypes.removeAll(marriedAlienTypes); //not alien any more @@ -396,9 +389,7 @@ public class RippleMethodFinder2 { private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { IType rep= fUnionFind.find(type); if (rep != null) { - Collection<IType> collection= fRootReps.get(rep); - for (Iterator<IType> iter= collection.iterator(); iter.hasNext();) { - IType root= iter.next(); + for (IType root : fRootReps.get(rep)) { ITypeHierarchy hierarchy= fRootHierarchies.get(root); if (hierarchy == null) { hierarchy= root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1)); @@ -460,8 +451,7 @@ public class RippleMethodFinder2 { private void createTypeToMethod() { fTypeToMethod= new HashMap<>(); - for (Iterator<IMethod> iter= fDeclarations.iterator(); iter.hasNext();) { - IMethod declaration= iter.next(); + for (IMethod declaration : fDeclarations) { fTypeToMethod.put(declaration.getDeclaringType(), declaration); } } @@ -469,17 +459,14 @@ public class RippleMethodFinder2 { private void createUnionFind() throws JavaModelException { fRootTypes= new HashSet<>(fTypeToMethod.keySet()); fUnionFind= new UnionFind(); - for (Iterator<IType> iter= fTypeToMethod.keySet().iterator(); iter.hasNext();) { - IType type= iter.next(); + for (IType type : fTypeToMethod.keySet()) { fUnionFind.init(type); } - for (Iterator<IType> iter= fTypeToMethod.keySet().iterator(); iter.hasNext();) { - IType type= iter.next(); + for (IType type : fTypeToMethod.keySet()) { uniteWithSupertypes(type, type); } fRootReps= new MultiMap<>(); - for (Iterator<IType> iter= fRootTypes.iterator(); iter.hasNext();) { - IType type= iter.next(); + for (IType type : fRootTypes) { IType rep= fUnionFind.find(type); if (rep != null) fRootReps.put(rep, type); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java index e7ec447e18..3095e10274 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/HierarchyProcessor.java @@ -174,11 +174,7 @@ public abstract class HierarchyProcessor extends SuperTypeRefactoringProcessor { } protected static boolean areAllFragmentsDeleted(final FieldDeclaration declaration, final List<ASTNode> declarationNodes) { - for (final Iterator<VariableDeclarationFragment> iterator= declaration.fragments().iterator(); iterator.hasNext();) { - if (!declarationNodes.contains(iterator.next())) - return false; - } - return true; + return declarationNodes.containsAll(declaration.fragments()); } protected static RefactoringStatus checkProjectCompliance(CompilationUnitRewrite sourceRewriter, IType destination, IMember[] members) { @@ -217,20 +213,22 @@ public abstract class HierarchyProcessor extends SuperTypeRefactoringProcessor { protected static void copyExtraDimensions(final VariableDeclaration oldVarDeclaration, final VariableDeclaration newVarDeclaration) { final AST ast= newVarDeclaration.getAST(); - for (int index= 0, n= oldVarDeclaration.extraDimensions().size(); index < n; index++) - newVarDeclaration.extraDimensions().add(ASTNode.copySubtree(ast, (Dimension) oldVarDeclaration.extraDimensions().get(index))); + for (Object extraDimension : oldVarDeclaration.extraDimensions()) { + newVarDeclaration.extraDimensions().add(ASTNode.copySubtree(ast, (Dimension) extraDimension)); + } } protected static void copyExtraDimensions(final MethodDeclaration oldMethod, final MethodDeclaration newMethod) { final AST ast= newMethod.getAST(); - for (int index= 0, n= oldMethod.extraDimensions().size(); index < n; index++) - newMethod.extraDimensions().add(ASTNode.copySubtree(ast, (Dimension) oldMethod.extraDimensions().get(index))); + for (Object extraDimension : oldMethod.extraDimensions()) { + newMethod.extraDimensions().add(ASTNode.copySubtree(ast, (Dimension) extraDimension)); + } } protected static void copyAnnotations(final FieldDeclaration oldField, final FieldDeclaration newField) { final AST ast= newField.getAST(); - for (int index= 0, n= oldField.modifiers().size(); index < n; index++) { - final IExtendedModifier modifier= (IExtendedModifier) oldField.modifiers().get(index); + for (Object element : oldField.modifiers()) { + final IExtendedModifier modifier= (IExtendedModifier) element; final List<IExtendedModifier> modifiers= newField.modifiers(); if (modifier.isAnnotation() && !modifiers.contains(modifier)) modifiers.add((IExtendedModifier) ASTNode.copySubtree(ast, (Annotation) modifier)); @@ -239,8 +237,8 @@ public abstract class HierarchyProcessor extends SuperTypeRefactoringProcessor { protected static void copyAnnotations(final MethodDeclaration oldMethod, final MethodDeclaration newMethod) { final AST ast= newMethod.getAST(); - for (int index= 0, n= oldMethod.modifiers().size(); index < n; index++) { - final IExtendedModifier modifier= (IExtendedModifier) oldMethod.modifiers().get(index); + for (Object element : oldMethod.modifiers()) { + final IExtendedModifier modifier= (IExtendedModifier) element; final List<IExtendedModifier> modifiers= newMethod.modifiers(); if (modifier.isAnnotation() && !modifiers.contains(modifier)) modifiers.add((IExtendedModifier) ASTNode.copySubtree(ast, (Annotation) modifier)); @@ -259,14 +257,16 @@ public abstract class HierarchyProcessor extends SuperTypeRefactoringProcessor { protected static void copyThrownExceptions(final MethodDeclaration oldMethod, final MethodDeclaration newMethod) { final AST ast= newMethod.getAST(); - for (int index= 0, n= oldMethod.thrownExceptionTypes().size(); index < n; index++) - newMethod.thrownExceptionTypes().add(ASTNode.copySubtree(ast, (Type) oldMethod.thrownExceptionTypes().get(index))); + for (Object thrownExceptionType : oldMethod.thrownExceptionTypes()) { + newMethod.thrownExceptionTypes().add(ASTNode.copySubtree(ast, (Type) thrownExceptionType)); + } } protected static void copyTypeParameters(final MethodDeclaration oldMethod, final MethodDeclaration newMethod) { final AST ast= newMethod.getAST(); - for (int index= 0, n= oldMethod.typeParameters().size(); index < n; index++) - newMethod.typeParameters().add(ASTNode.copySubtree(ast, (TypeParameter) oldMethod.typeParameters().get(index))); + for (Object typeParameter : oldMethod.typeParameters()) { + newMethod.typeParameters().add(ASTNode.copySubtree(ast, (TypeParameter) typeParameter)); + } } protected static String createLabel(final IMember member) { @@ -446,8 +446,7 @@ public abstract class HierarchyProcessor extends SuperTypeRefactoringProcessor { protected static void deleteDeclarationNodes(final CompilationUnitRewrite sourceRewriter, final boolean sameCu, final CompilationUnitRewrite unitRewriter, final List<IMember> members, final GroupCategorySet set) throws JavaModelException { final List<ASTNode> declarationNodes= getDeclarationNodes(unitRewriter.getRoot(), members); - for (final Iterator<ASTNode> iterator= declarationNodes.iterator(); iterator.hasNext();) { - final ASTNode node= iterator.next(); + for (ASTNode node : declarationNodes) { final ASTRewrite rewriter= unitRewriter.getASTRewrite(); final ImportRemover remover= unitRewriter.getImportRemover(); if (node instanceof VariableDeclarationFragment) { @@ -473,8 +472,7 @@ public abstract class HierarchyProcessor extends SuperTypeRefactoringProcessor { protected static List<ASTNode> getDeclarationNodes(final CompilationUnit cuNode, final List<IMember> members) throws JavaModelException { final List<ASTNode> result= new ArrayList<>(members.size()); - for (final Iterator<IMember> iterator= members.iterator(); iterator.hasNext();) { - final IMember member= iterator.next(); + for (IMember member : members) { ASTNode node= null; if (member instanceof IField) { if (Flags.isEnum(member.getFlags())) @@ -624,8 +622,8 @@ public abstract class HierarchyProcessor extends SuperTypeRefactoringProcessor { protected void copyParameters(final ASTRewrite rewrite, final ICompilationUnit unit, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping) throws JavaModelException { SingleVariableDeclaration newDeclaration= null; - for (int index= 0, size= oldMethod.parameters().size(); index < size; index++) { - final SingleVariableDeclaration oldDeclaration= (SingleVariableDeclaration) oldMethod.parameters().get(index); + for (Object parameter : oldMethod.parameters()) { + final SingleVariableDeclaration oldDeclaration= (SingleVariableDeclaration) parameter; if (mapping.length > 0) newDeclaration= createPlaceholderForSingleVariableDeclaration(oldDeclaration, unit, mapping, rewrite); else diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/IntroduceParameterObjectProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/IntroduceParameterObjectProcessor.java index bb980bc27e..2f0bb26bae 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/IntroduceParameterObjectProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/IntroduceParameterObjectProcessor.java @@ -79,6 +79,9 @@ import org.eclipse.jdt.core.refactoring.descriptors.IntroduceParameterObjectDesc import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor; import org.eclipse.jdt.core.refactoring.participants.IRefactoringProcessorIds; +import org.eclipse.jdt.internal.core.manipulation.StubUtility; +import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving; +import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels; import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory; import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; import org.eclipse.jdt.internal.corext.dom.ASTNodes; @@ -91,10 +94,6 @@ import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.internal.ui.JavaPlugin; -import org.eclipse.jdt.internal.core.manipulation.StubUtility; -import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving; -import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels; - public class IntroduceParameterObjectProcessor extends ChangeSignatureProcessor { private final class ParameterObjectCreator implements IDefaultValueAdvisor { @@ -237,10 +236,8 @@ public class IntroduceParameterObjectProcessor extends ChangeSignatureProcessor if (body != null) { // abstract methods don't have bodies final ASTRewrite rewriter= cuRewrite.getASTRewrite(); ListRewrite bodyStatements= rewriter.getListRewrite(body, Block.STATEMENTS_PROPERTY); - List<ParameterInfo> managedParams= getParameterInfos(); ImportRewriteContext context=new ContextSensitiveImportRewriteContext(body, cuRewrite.getImportRewrite()); - for (Iterator<ParameterInfo> iter= managedParams.iterator(); iter.hasNext();) { - final ParameterInfo pi= iter.next(); + for (ParameterInfo pi : getParameterInfos()) { if (isValidField(pi)) { if (isReadOnly(pi, body, parameters, null)) { body.accept(new ASTVisitor(false) { diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java index d2b8efc8f8..8dfc0a1663 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PullUpRefactoringProcessor.java @@ -106,6 +106,7 @@ import org.eclipse.jdt.core.refactoring.IJavaRefactorings; import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor; import org.eclipse.jdt.core.refactoring.descriptors.PullUpDescriptor; +import org.eclipse.jdt.internal.core.manipulation.StubUtility; import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels; import org.eclipse.jdt.internal.core.manipulation.util.Strings; import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory; @@ -148,8 +149,6 @@ import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; import org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager; -import org.eclipse.jdt.internal.core.manipulation.StubUtility; - /** * Refactoring processor for the pull up refactoring. * @@ -335,8 +334,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { if (isInterface) { final Collection<IType> remove= new ArrayList<>(); final List<IType> list= new ArrayList<>(Arrays.asList(hierarchy.getSubtypes(type))); - for (final Iterator<IType> iterator= list.iterator(); iterator.hasNext();) { - final IType element= iterator.next(); + for (IType element : list) { if (element.isInterface()) remove.add(element); } @@ -345,11 +343,11 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { } else types= hierarchy.getSubclasses(type); final Set<IType> result= new HashSet<>(); - for (int index= 0; index < types.length; index++) { - if (!isInterface && JdtFlags.isAbstract(types[index])) - result.addAll(getAffectedSubTypes(hierarchy, types[index])); + for (IType type2 : types) { + if (!isInterface && JdtFlags.isAbstract(type2)) + result.addAll(getAffectedSubTypes(hierarchy, type2)); else - result.add(types[index]); + result.add(type2); } return result; } @@ -473,8 +471,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { try { sub.beginTask(RefactoringCoreMessages.PullUpRefactoring_calculating_required, requiredMethods.length); isStatic= JdtFlags.isStatic(member); - for (int index= 0; index < requiredMethods.length; index++) { - final IMethod requiredMethod= requiredMethods[index]; + for (IMethod requiredMethod : requiredMethods) { if (isStatic && !JdtFlags.isStatic(requiredMethod)) continue; if (isRequiredPullableMember(queue, requiredMethod) && !(MethodChecks.isVirtual(requiredMethod) && isAvailableInDestination(requiredMethod, new SubProgressMonitor(sub, 1)))) @@ -488,8 +485,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { try { sub.beginTask(RefactoringCoreMessages.PullUpRefactoring_calculating_required, requiredFields.length); isStatic= JdtFlags.isStatic(member); - for (int index= 0; index < requiredFields.length; index++) { - final IField requiredField= requiredFields[index]; + for (final IField requiredField : requiredFields) { if (isStatic && !JdtFlags.isStatic(requiredField)) continue; if (isRequiredPullableMember(queue, requiredField)) @@ -503,8 +499,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { try { sub.beginTask(RefactoringCoreMessages.PullUpRefactoring_calculating_required, requiredMethods.length); isStatic= JdtFlags.isStatic(member); - for (int index= 0; index < requiredTypes.length; index++) { - final IType requiredType= requiredTypes[index]; + for (final IType requiredType : requiredTypes) { if (isStatic && !JdtFlags.isStatic(requiredType)) continue; if (isRequiredPullableMember(queue, requiredType)) @@ -553,8 +548,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final IMethod[] methods= getAbstractMethods(); try { monitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, affected.size()); - for (final Iterator<IType> iter= affected.iterator(); iter.hasNext();) { - final IType type= iter.next(); + for (IType type : affected) { if (type.equals(declaringType)) continue; final AbstractTypeDeclaration declaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(type, unitRewriter.getRoot()); @@ -562,8 +556,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final IProgressMonitor subMonitor= new SubProgressMonitor(monitor, 1); try { subMonitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, methods.length); - for (int j= 0; j < methods.length; j++) { - final IMethod method= methods[j]; + for (final IMethod method : methods) { if (null == JavaModelUtil.findMethod(method.getElementName(), method.getParameterTypes(), method.isConstructor(), type)) { addMethodStubForAbstractMethod(method, root, declaration, unit, unitRewriter, adjustments, new SubProgressMonitor(subMonitor, 1), status); } @@ -626,8 +619,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final IField[] accessedFields= ReferenceFinderUtil.getFieldsReferencedIn(fMembersToMove, fOwner, new SubProgressMonitor(monitor, 1)); final IType destination= getDestinationType(); - for (int i= 0; i < accessedFields.length; i++) { - final IField field= accessedFields[i]; + for (final IField field : accessedFields) { if (!field.exists()) continue; @@ -654,8 +646,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final IMethod[] accessedMethods= ReferenceFinderUtil.getMethodsReferencedIn(fMembersToMove, fOwner, new SubProgressMonitor(monitor, 1)); final IType destination= getDestinationType(); - for (int index= 0; index < accessedMethods.length; index++) { - final IMethod method= accessedMethods[index]; + for (final IMethod method : accessedMethods) { if (!method.exists()) continue; boolean isAccessible= pulledUpList.contains(method) || deletedList.contains(method) || declaredAbstractList.contains(method) || canBeAccessedFrom(method, destination, hierarchy); @@ -674,11 +665,9 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { private RefactoringStatus checkAccessedTypes(final IProgressMonitor monitor, final ITypeHierarchy hierarchy) throws JavaModelException { final RefactoringStatus result= new RefactoringStatus(); - final IType[] accessedTypes= getTypesReferencedInMovedMembers(monitor); final IType destination= getDestinationType(); final List<IMember> pulledUpList= Arrays.asList(fMembersToMove); - for (int index= 0; index < accessedTypes.length; index++) { - final IType type= accessedTypes[index]; + for (final IType type : getTypesReferencedInMovedMembers(monitor)) { if (!type.exists()) continue; @@ -709,8 +698,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { if (fDestinationType.isInterface()) return; final List<IMethod> toDeclareAbstract= Arrays.asList(fAbstractMethods); - for (final Iterator<IMember> iter= notDeletedMembersInSubtypes.iterator(); iter.hasNext();) { - final IMember member= iter.next(); + for (IMember member : notDeletedMembersInSubtypes) { if (member.getElementType() == IJavaElement.METHOD && !toDeclareAbstract.contains(member)) { final IMethod method= ((IMethod) member); if (method.getDeclaringType().getPackageFragment().equals(fDestinationType.getPackageFragment())) { @@ -742,14 +730,14 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { private void checkFieldTypes(final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException { final Map<IMember, Set<IMember>> mapping= getMatchingMembers(getDestinationTypeHierarchy(monitor), getDestinationType(), true); - for (int i= 0; i < fMembersToMove.length; i++) { - if (fMembersToMove[i].getElementType() != IJavaElement.FIELD) + for (IMember element : fMembersToMove) { + if (element.getElementType() != IJavaElement.FIELD) continue; - final IField field= (IField) fMembersToMove[i]; + final IField field= (IField) element; final String type= Signature.toString(field.getTypeSignature()); Assert.isTrue(mapping.containsKey(field)); - for (final Iterator<IMember> iter= mapping.get(field).iterator(); iter.hasNext();) { - final IField matchingField= (IField) iter.next(); + for (IMember member : mapping.get(field)) { + final IField matchingField= (IField) member; if (field.equals(matchingField)) continue; if (type.equals(Signature.toString(matchingField.getTypeSignature()))) @@ -804,8 +792,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { private RefactoringStatus checkFinalFields(final IProgressMonitor monitor) throws JavaModelException { final RefactoringStatus result= new RefactoringStatus(); monitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, fMembersToMove.length); - for (int index= 0; index < fMembersToMove.length; index++) { - final IMember member= fMembersToMove[index]; + for (final IMember member : fMembersToMove) { if (member.getElementType() == IJavaElement.FIELD) { if (!JdtFlags.isStatic(member)) { if (JdtFlags.isFinal(member)) { @@ -839,8 +826,8 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final TypeVariableMaplet[] mapping= TypeVariableUtil.subTypeToInheritedType(declaring); IMember member= null; int length= 0; - for (int index= 0; index < pullables.length; index++) { - member= pullables[index]; + for (IMember pullable : pullables) { + member= pullable; final String[] unmapped= TypeVariableUtil.getUnmappedVariables(mapping, declaring, member); length= unmapped.length; @@ -909,10 +896,9 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final Set<IType> skippedTypes= getSkippedSuperTypes(new SubProgressMonitor(monitor, 1)); final IType[] skipped= skippedTypes.toArray(new IType[skippedTypes.size()]); final RefactoringStatus result= new RefactoringStatus(); - for (int i= 0; i < fMembersToMove.length; i++) { - final IMember element= fMembersToMove[i]; - for (int j= 0; j < skipped.length; j++) { - result.merge(checkIfDeclaredIn(element, skipped[j])); + for (final IMember element : fMembersToMove) { + for (IType element2 : skipped) { + result.merge(checkIfDeclaredIn(element, element2)); } } return result; @@ -964,8 +950,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final Set<IMember> notDeletedMembers= getNotDeletedMembers(new SubProgressMonitor(monitor, 1)); final Set<IMember> notDeletedMembersInTargetType= new HashSet<>(); final Set<IMember> notDeletedMembersInSubtypes= new HashSet<>(); - for (final Iterator<IMember> iter= notDeletedMembers.iterator(); iter.hasNext();) { - final IMember member= iter.next(); + for (IMember member : notDeletedMembers) { if (getDestinationType().equals(member.getDeclaringType())) notDeletedMembersInTargetType.add(member); else @@ -981,17 +966,16 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { private void checkMethodReturnTypes(final IProgressMonitor monitor, final RefactoringStatus status, final Set<IMember> notDeletedMembersInSubtypes) throws JavaModelException { final Map<IMember, Set<IMember>> mapping= getMatchingMembers(getDestinationTypeHierarchy(monitor), getDestinationType(), true); - final IMember[] members= getCreatedDestinationMembers(); - for (int i= 0; i < members.length; i++) { - if (members[i].getElementType() != IJavaElement.METHOD) + for (IMember member : getCreatedDestinationMembers()) { + if (member.getElementType() != IJavaElement.METHOD) continue; - final IMethod method= (IMethod) members[i]; + final IMethod method= (IMethod) member; if (mapping.containsKey(method)) { final Set<IMember> set= mapping.get(method); if (set != null) { final String returnType= Signature.toString(Signature.getReturnType(method.getSignature()).toString()); - for (final Iterator<IMember> iter= set.iterator(); iter.hasNext();) { - final IMethod matchingMethod= (IMethod) iter.next(); + for (IMember iMember : set) { + final IMethod matchingMethod= (IMethod) iMember; if (method.equals(matchingMethod)) continue; if (!notDeletedMembersInSubtypes.contains(matchingMethod)) @@ -1134,8 +1118,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final IProgressMonitor sub= new SubProgressMonitor(monitor, 1); try { sub.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, units.length * 11); - for (int index= 0; index < units.length; index++) { - ICompilationUnit unit= units[index]; + for (ICompilationUnit unit : units) { if (!(source.equals(unit) || target.equals(unit) || deleteMap.containsKey(unit) || affectedMap.containsKey(unit))) { sub.worked(10); continue; @@ -1255,16 +1238,14 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { subsub.worked(1); } subsub.done(); - for (int offset= 0; offset < fAbstractMethods.length; offset++) - createAbstractMethod(fAbstractMethods[offset], sourceRewriter, root, declaration, mapping, rewrite, adjustments, new SubProgressMonitor(sub, 1), status); + for (IMethod abstractMethod : fAbstractMethods) + createAbstractMethod(abstractMethod, sourceRewriter, root, declaration, mapping, rewrite, adjustments, new SubProgressMonitor(sub, 1), status); } else sub.worked(2); if (unit.equals(sourceRewriter.getCu())) { final IProgressMonitor subsub= new SubProgressMonitor(sub, 1); subsub.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, fAbstractMethods.length * 2); - IMethod method= null; - for (int offset= 0; offset < fAbstractMethods.length; offset++) { - method= fAbstractMethods[offset]; + for (IMethod method : fAbstractMethods) { adjustor= new MemberVisibilityAdjustor(destination, method); adjustor.setRewrite(sourceRewriter.getASTRewrite(), root); adjustor.setRewrites(fCompilationUnitRewrites); @@ -1328,9 +1309,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { rewriteTypeOccurrences(manager, sourceRewriter, current, new HashSet<String>(), status, new SubProgressMonitor(monitor, 16)); } finally { subMonitor.done(); - ICompilationUnit[] cus= manager.getAllCompilationUnits(); - for (int index= 0; index < cus.length; index++) { - ICompilationUnit unit= cus[index]; + for (ICompilationUnit unit : manager.getAllCompilationUnits()) { CompilationUnitChange current= (CompilationUnitChange) manager.get(unit); if (change != null && current.getEdit() == null) manager.remove(unit); @@ -1350,8 +1329,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { return new HashMap<>(0); final Set<IType> affected= getAffectedSubTypes(getDestinationTypeHierarchy(monitor), getDestinationType()); final Map<ICompilationUnit, ArrayList<IType>> result= new HashMap<>(); - for (final Iterator<IType> iterator= affected.iterator(); iterator.hasNext();) { - final IType type= iterator.next(); + for (IType type : affected) { final ICompilationUnit unit= type.getCompilationUnit(); if (!result.containsKey(unit)) result.put(unit, new ArrayList<IType>(1)); @@ -1379,10 +1357,8 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { } private Map<ICompilationUnit, ArrayList<IMember>> createMembersToDeleteMap(final IProgressMonitor monitor) throws JavaModelException { - final IMember[] membersToDelete= getMembersToDelete(monitor); final Map<ICompilationUnit, ArrayList<IMember>> result= new HashMap<>(); - for (int i= 0; i < membersToDelete.length; i++) { - final IMember member= membersToDelete[i]; + for (final IMember member : getMembersToDelete(monitor)) { final ICompilationUnit cu= member.getCompilationUnit(); if (!result.containsKey(cu)) result.put(cu, new ArrayList<IMember>(1)); @@ -1481,9 +1457,9 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final IMethod[] abstractPulledUp= getAbstractMethodsToPullUp(); final Set<IMember> result= new LinkedHashSet<>(toDeclareAbstract.length + abstractPulledUp.length + fMembersToMove.length); if (fDestinationType.isInterface()) { - for (int i= 0; i < fMembersToMove.length; i++) { - if (fMembersToMove[i].getElementType() == IJavaElement.METHOD) { - result.add(fMembersToMove[i]); + for (IMember element : fMembersToMove) { + if (element.getElementType() == IJavaElement.METHOD) { + result.add(element); } } } @@ -1494,8 +1470,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { private IMethod[] getAbstractMethodsToPullUp() throws JavaModelException { final List<IMember> result= new ArrayList<>(fMembersToMove.length); - for (int i= 0; i < fMembersToMove.length; i++) { - final IMember member= fMembersToMove[i]; + for (final IMember member : fMembersToMove) { if (member instanceof IMethod && JdtFlags.isAbstract(member)) result.add(member); } @@ -1530,8 +1505,8 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { private ICompilationUnit[] getAffectedCompilationUnits(final IProgressMonitor monitor) throws JavaModelException { final IType[] allSubtypes= getDestinationTypeHierarchy(monitor).getAllSubtypes(getDestinationType()); final Set<ICompilationUnit> result= new HashSet<>(allSubtypes.length); - for (int i= 0; i < allSubtypes.length; i++) { - ICompilationUnit cu= allSubtypes[i].getCompilationUnit(); + for (IType subtype : allSubtypes) { + ICompilationUnit cu= subtype.getCompilationUnit(); if (cu != null) result.add(cu); } @@ -1544,8 +1519,7 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final IType[] superTypes= declaring.newSupertypeHierarchy(fOwner, monitor).getAllSupertypes(declaring); final List<IType> list= new ArrayList<>(superTypes.length); int binary= 0; - for (int index= 0; index < superTypes.length; index++) { - final IType type= superTypes[index]; + for (final IType type : superTypes) { if (type != null && type.exists() && !type.isReadOnly() && !type.isBinary() && !"java.lang.Object".equals(type.getFullyQualifiedName())) { //$NON-NLS-1$ list.add(type); } else { @@ -1626,10 +1600,10 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { final Set<IMember> result= new HashSet<>(); final IType destination= getDestinationType(); final Map<IMember, Set<IMember>> matching= getMatchingMembers(getDestinationTypeHierarchy(monitor), getDestinationType(), includeAbstract); - for (final Iterator<IMember> iterator= matching.keySet().iterator(); iterator.hasNext();) { - final IMember key= iterator.next(); + for (Entry<IMember, Set<IMember>> entry : matching.entrySet()) { + IMember key= entry.getKey(); Assert.isTrue(!key.getDeclaringType().equals(destination)); - result.addAll(matching.get(key)); + result.addAll(entry.getValue()); } return result.toArray(new IMember[result.size()]); } finally { @@ -1640,27 +1614,24 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { private Map<IMember, Set<IMember>> getMatchingMembers(final ITypeHierarchy hierarchy, final IType type, final boolean includeAbstract) throws JavaModelException { final Map<IMember, Set<IMember>> result= new HashMap<>(); result.putAll(getMatchingMembersMapping(type)); - final IType[] subTypes= hierarchy.getAllSubtypes(type); - for (int i= 0; i < subTypes.length; i++) { - final Map<IMember, Set<IMember>> map= getMatchingMembersMapping(subTypes[i]); + for (IType subType : hierarchy.getAllSubtypes(type)) { + final Map<IMember, Set<IMember>> map= getMatchingMembersMapping(subType); mergeMaps(result, map); upgradeMap(result, map); } if (includeAbstract) return result; - for (int i= 0; i < fAbstractMethods.length; i++) { - if (result.containsKey(fAbstractMethods[i])) - result.remove(fAbstractMethods[i]); + for (IMethod abstractMethod : fAbstractMethods) { + if (result.containsKey(abstractMethod)) + result.remove(abstractMethod); } return result; } private Map<IMember, Set<IMember>> getMatchingMembersMapping(final IType initial) throws JavaModelException { final Map<IMember, Set<IMember>> result= new HashMap<>(); - final IMember[] members= getCreatedDestinationMembers(); - for (int i= 0; i < members.length; i++) { - final IMember member= members[i]; + for (final IMember member : getCreatedDestinationMembers()) { if (member instanceof IMethod) { final IMethod method= (IMethod) member; final IMethod found= MemberCheckUtil.findMethod(method, initial.getMethods()); @@ -1932,14 +1903,11 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { try { subMonitor.beginTask("", collection.size() * 10); //$NON-NLS-1$ subMonitor.setTaskName(RefactoringCoreMessages.ExtractInterfaceProcessor_creating); - TType estimate= null; - ISourceConstraintVariable variable= null; - ITypeConstraintVariable constraint= null; - for (final Iterator<ITypeConstraintVariable> iterator= collection.iterator(); iterator.hasNext();) { - variable= iterator.next(); + for (ITypeConstraintVariable iTypeConstraintVariable : collection) { + ISourceConstraintVariable variable= iTypeConstraintVariable; if (variable instanceof ITypeConstraintVariable) { - constraint= (ITypeConstraintVariable) variable; - estimate= (TType) constraint.getData(SuperTypeConstraintsSolver.DATA_TYPE_ESTIMATE); + ITypeConstraintVariable constraint= (ITypeConstraintVariable) variable; + TType estimate= (TType) constraint.getData(SuperTypeConstraintsSolver.DATA_TYPE_ESTIMATE); if (estimate != null) { final CompilationUnitRange range= constraint.getRange(); if (isTouched) @@ -1988,13 +1956,11 @@ public class PullUpRefactoringProcessor extends HierarchyProcessor { if (subDeclaration != null) { final ITypeBinding subBinding= subDeclaration.resolveBinding(); if (subBinding != null) { - String name= null; ITypeBinding superBinding= null; - final ITypeBinding[] superBindings= Bindings.getAllSuperTypes(subBinding); - for (int index= 0; index < superBindings.length; index++) { - name= superBindings[index].getName(); + for (ITypeBinding superBinding2 : Bindings.getAllSuperTypes(subBinding)) { + String name= superBinding2.getName(); if (name.startsWith(fDestinationType.getElementName())) - superBinding= superBindings[index]; + superBinding= superBinding2; } if (superBinding != null) { solveSuperTypeConstraints(unit, node, subType, subBinding, superBinding, new SubProgressMonitor(monitor, 80), status); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java index 7cab47ca8d..8f7f8021bf 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/PushDownRefactoringProcessor.java @@ -18,7 +18,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -747,9 +746,9 @@ public final class PushDownRefactoringProcessor extends HierarchyProcessor { adjustor.rewriteVisibility(new SubProgressMonitor(monitor, 1)); } final TextEditBasedChangeManager manager= new TextEditBasedChangeManager(); - for (final Iterator<ICompilationUnit> iterator= rewrites.keySet().iterator(); iterator.hasNext();) { - ICompilationUnit unit= iterator.next(); - rewrite= rewrites.get(unit); + for (Map.Entry<ICompilationUnit, CompilationUnitRewrite> entry : rewrites.entrySet()) { + ICompilationUnit unit= entry.getKey(); + rewrite= entry.getValue(); if (rewrite != null) manager.manage(unit, rewrite.createChange(true)); } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/UseSuperTypeProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/UseSuperTypeProcessor.java index 2f6b5eb4f2..fca2acbe0e 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/UseSuperTypeProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/UseSuperTypeProcessor.java @@ -15,7 +15,6 @@ package org.eclipse.jdt.internal.corext.refactoring.structure; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import org.eclipse.core.runtime.Assert; @@ -448,8 +447,8 @@ public final class UseSuperTypeProcessor extends SuperTypeRefactoringProcessor { currentRewrite= rewrite; else currentRewrite= new CompilationUnitRewrite(fOwner, unit, node); - for (final Iterator<ITypeConstraintVariable> iterator= collection.iterator(); iterator.hasNext();) { - variable= iterator.next(); + for (ITypeConstraintVariable iTypeConstraintVariable : collection) { + variable= iTypeConstraintVariable; estimate= (TType) variable.getData(SuperTypeConstraintsSolver.DATA_TYPE_ESTIMATE); if (estimate != null && variable instanceof ITypeConstraintVariable) { final ASTNode result= NodeFinder.perform(node, ((ITypeConstraintVariable) variable).getRange().getSourceRange()); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java index 99a6b28cd7..b36a4f6be4 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java @@ -15,7 +15,6 @@ package org.eclipse.jdt.internal.corext.refactoring.structure.constraints; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Stack; @@ -111,11 +110,11 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { for (IMethodBinding method : type.getDeclaredMethods()) { if (!binding.getKey().equals(method.getKey())) { boolean match= false; - IMethodBinding current= null; - for (final Iterator<IMethodBinding> iterator= originals.iterator(); iterator.hasNext();) { - current= iterator.next(); - if (Bindings.isSubsignature(method, current)) + for (IMethodBinding current : originals) { + if (Bindings.isSubsignature(method, current)) { match= true; + break; + } } if (!match && Bindings.isSubsignature(binding, method)) originals.add(method); @@ -178,11 +177,9 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { final ConstraintVariable2 ancestor= fModel.createIndependentTypeVariable(binding.getElementType()); if (ancestor != null) { node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor); - Expression expression= null; ConstraintVariable2 descendant= null; final List<Expression> expressions= node.expressions(); - for (int index= 0; index < expressions.size(); index++) { - expression= expressions.get(index); + for (Expression expression : expressions) { descendant= (ConstraintVariable2) expression.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (descendant != null) fModel.createSubtypeConstraint(descendant, ancestor); @@ -337,13 +334,11 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { * @param binding the method binding */ private void endVisit(final IMethodBinding binding) { - IMethodBinding method= null; - ConstraintVariable2 ancestor= null; final ConstraintVariable2 descendant= fModel.createReturnTypeVariable(binding); if (descendant != null) { final Collection<IMethodBinding> originals= getOriginalMethods(binding); - for (final Iterator<IMethodBinding> iterator= originals.iterator(); iterator.hasNext();) { - method= iterator.next(); + ConstraintVariable2 ancestor= null; + for (IMethodBinding method : originals) { if (!method.getKey().equals(binding.getKey())) { ancestor= fModel.createReturnTypeVariable(method); if (ancestor != null) @@ -361,10 +356,8 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { */ private void endVisit(final IMethodBinding binding, final ConstraintVariable2 descendant) { ITypeBinding declaring= null; - IMethodBinding method= null; final Collection<IMethodBinding> originals= getOriginalMethods(binding); - for (final Iterator<IMethodBinding> iterator= originals.iterator(); iterator.hasNext();) { - method= iterator.next(); + for (IMethodBinding method : originals) { declaring= method.getDeclaringClass(); if (declaring != null) { final ConstraintVariable2 ancestor= fModel.createDeclaringTypeVariable(declaring); @@ -438,15 +431,11 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { private void endVisit(final List<VariableDeclarationFragment> fragments, final Type type, final ASTNode parent) { final ConstraintVariable2 ancestor= (ConstraintVariable2) type.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (ancestor != null) { - IVariableBinding binding= null; - ConstraintVariable2 descendant= null; - VariableDeclarationFragment fragment= null; - for (int index= 0; index < fragments.size(); index++) { - fragment= fragments.get(index); - descendant= (ConstraintVariable2) fragment.getProperty(PROPERTY_CONSTRAINT_VARIABLE); + for (VariableDeclarationFragment fragment : fragments) { + ConstraintVariable2 descendant= (ConstraintVariable2) fragment.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (descendant != null) fModel.createSubtypeConstraint(descendant, ancestor); - binding= fragment.resolveBinding(); + IVariableBinding binding= fragment.resolveBinding(); if (binding != null) { descendant= fModel.createVariableVariable(binding); if (descendant != null) @@ -504,9 +493,7 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { if (descendant != null) fModel.createEqualityConstraint(ancestor, descendant); } - IMethodBinding method= null; - for (final Iterator<IMethodBinding> iterator= originals.iterator(); iterator.hasNext();) { - method= iterator.next(); + for (IMethodBinding method : originals) { if (!method.getKey().equals(binding.getKey())) { descendant= fModel.createMethodParameterVariable(method, index); if (descendant != null) @@ -560,9 +547,7 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { if (descendant != null) fModel.createEqualityConstraint(ancestor, descendant); } - IMethodBinding method= null; - for (final Iterator<IMethodBinding> iterator= originals.iterator(); iterator.hasNext();) { - method= iterator.next(); + for (IMethodBinding method : originals) { if (!method.getKey().equals(binding.getKey())) { descendant= fModel.createMethodParameterVariable(method, index); if (descendant != null) @@ -578,9 +563,7 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { if (throwable != null) { ancestor= fModel.createImmutableTypeVariable(throwable); if (ancestor != null) { - Type exception= null; - for (int index= 0; index < exceptions.size(); index++) { - exception= exceptions.get(index); + for (Type exception : exceptions) { descendant= (ConstraintVariable2) exception.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (descendant != null) fModel.createSubtypeConstraint(descendant, ancestor); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java index 2429049fd4..414685c2c9 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java @@ -327,9 +327,7 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor monitor.beginTask("", 100); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.ExtractInterfaceProcessor_creating); final ImportRewrite rewrite= StubUtility.createImportRewrite(unit, true); - ITypeBinding type= null; - for (final Iterator<ITypeBinding> iterator= fTypeBindings.iterator(); iterator.hasNext();) { - type= iterator.next(); + for (ITypeBinding type : fTypeBindings) { if (type.isTypeVariable()) { for (ITypeBinding bound : type.getTypeBounds()) { rewrite.addImport(bound); @@ -337,9 +335,7 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor } rewrite.addImport(type); } - IBinding binding= null; - for (final Iterator<IBinding> iterator= fStaticBindings.iterator(); iterator.hasNext();) { - binding= iterator.next(); + for (IBinding binding : fStaticBindings) { rewrite.addStaticImport(binding); } final IDocument document= new Document(); @@ -377,11 +373,9 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor Assert.isNotNull(sourceDeclaration); Assert.isNotNull(targetDeclaration); if (sourceDeclaration instanceof TypeDeclaration) { - TypeParameter parameter= null; final ListRewrite rewrite= targetRewrite.getListRewrite(targetDeclaration, TypeDeclaration.TYPE_PARAMETERS_PROPERTY); - for (final Iterator<TypeParameter> iterator= ((TypeDeclaration) sourceDeclaration).typeParameters().iterator(); iterator.hasNext();) { - parameter= iterator.next(); - rewrite.insertLast(ASTNode.copySubtree(targetRewrite.getAST(), parameter), null); + for (Object parameter : ((TypeDeclaration) sourceDeclaration).typeParameters()) { + rewrite.insertLast(ASTNode.copySubtree(targetRewrite.getAST(), (TypeParameter) parameter), null); ImportRewriteUtil.collectImports(subType.getJavaProject(), sourceDeclaration, fTypeBindings, fStaticBindings, false); } } @@ -543,9 +537,7 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor for (ASTNode node : nodes) { IJavaProject project= RefactoringASTParser.getCompilationUnit(node).getJavaProject(); if (project != null) { - final List<IField> fields= getReferencingFields(node, project); - for (int offset= 0; offset < fields.size(); offset++) { - IField field= fields.get(offset); + for (IField field : getReferencingFields(node, project)) { Set<ICompilationUnit> set= units.get(project); if (set == null) { set= new HashSet<>(); @@ -641,9 +633,7 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor if (parent instanceof FieldDeclaration) { final List<VariableDeclarationFragment> fragments= ((FieldDeclaration) parent).fragments(); result= new ArrayList<>(fragments.size()); - VariableDeclarationFragment fragment= null; - for (final Iterator<VariableDeclarationFragment> iterator= fragments.iterator(); iterator.hasNext();) { - fragment= iterator.next(); + for (VariableDeclarationFragment fragment : fragments) { final IField field= getCorrespondingField(fragment); if (field != null) result.add(field); @@ -1000,9 +990,7 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor final Map<IJavaProject, Collection<ICompilationUnit>> projects= new HashMap<>(); Collection<ICompilationUnit> collection= null; IJavaProject project= null; - ICompilationUnit current= null; - for (final Iterator<ICompilationUnit> iterator= units.iterator(); iterator.hasNext();) { - current= iterator.next(); + for (ICompilationUnit current : units) { project= current.getJavaProject(); collection= projects.get(project); if (collection == null) { diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/ExceptionAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/ExceptionAnalyzer.java index 5536211449..90c0e932d1 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/ExceptionAnalyzer.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/ExceptionAnalyzer.java @@ -93,8 +93,8 @@ public class ExceptionAnalyzer extends AbstractExceptionAnalyzer { List<ITypeBinding> exceptions= analyzer.getCurrentExceptions(); if (enclosingNode.getNodeType() == ASTNode.METHOD_DECLARATION) { List<Type> thrownExceptions= ((MethodDeclaration) enclosingNode).thrownExceptionTypes(); - for (Iterator<Type> thrown= thrownExceptions.iterator(); thrown.hasNext();) { - ITypeBinding thrownException= thrown.next().resolveBinding(); + for (Type type : thrownExceptions) { + ITypeBinding thrownException= type.resolveBinding(); if (thrownException != null && forceRemove) { updateExceptionsList(exceptions, thrownException); } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java index 1baa6a3398..b97fbc62d4 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java @@ -312,8 +312,7 @@ public class SurroundWithTryCatchRefactoring extends Refactoring { } } List<VariableDeclarationFragment> fragments= copy.fragments(); - for (Iterator<VariableDeclarationFragment> iter= fragments.iterator(); iter.hasNext();) { - VariableDeclarationFragment fragment= iter.next(); + for (VariableDeclarationFragment fragment : fragments) { fragment.setInitializer(null); } @@ -341,8 +340,7 @@ public class SurroundWithTryCatchRefactoring extends Refactoring { fragments= statement.fragments(); if (!fragments.isEmpty()) { List<ExpressionStatement> newExpressionStatements= new ArrayList<>(); - for (Iterator<VariableDeclarationFragment> iter= fragments.iterator(); iter.hasNext();) { - VariableDeclarationFragment fragment= iter.next(); + for (VariableDeclarationFragment fragment : fragments) { Expression initializer= fragment.getInitializer(); if (initializer != null) { Assignment assignment= ast.newAssignment(); @@ -426,8 +424,7 @@ public class SurroundWithTryCatchRefactoring extends Refactoring { for (Iterator<ITypeBinding> subtypeIterator= filteredExceptions.iterator(); subtypeIterator.hasNext();) { ITypeBinding iTypeBinding= subtypeIterator.next(); - for (Iterator<ITypeBinding> supertypeIterator= filteredExceptions.iterator(); supertypeIterator.hasNext();) { - ITypeBinding superTypeBinding= supertypeIterator.next(); + for (ITypeBinding superTypeBinding : filteredExceptions) { if (!iTypeBinding.equals(superTypeBinding) && iTypeBinding.isSubTypeCompatible(superTypeBinding)) { subtypeIterator.remove(); break; diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/ConstraintVariableFactory.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/ConstraintVariableFactory.java index b4d42cb7ca..c5c00046a3 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/ConstraintVariableFactory.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/ConstraintVariableFactory.java @@ -16,7 +16,6 @@ package org.eclipse.jdt.internal.corext.refactoring.typeconstraints; import java.util.HashMap; import java.util.Hashtable; -import java.util.Iterator; import java.util.Map; import org.eclipse.core.runtime.Assert; @@ -114,8 +113,7 @@ public class ConstraintVariableFactory implements IConstraintVariableFactory { if (fBindingMap.containsKey(binding)){ return fBindingMap.get(binding); } else { - for (Iterator<IBinding> it= fBindingMap.keySet().iterator(); it.hasNext(); ){ - IBinding b2= it.next(); + for (IBinding b2 : fBindingMap.keySet()) { if (Bindings.equals(binding, b2)){ fBindingMap.put(binding, b2); return b2; diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/FullConstraintCreator.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/FullConstraintCreator.java index 33fbf18b5f..eed21f295e 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/FullConstraintCreator.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/FullConstraintCreator.java @@ -111,8 +111,7 @@ public class FullConstraintCreator extends ConstraintCreator{ List<ITypeConstraint> constraints= new ArrayList<>(); Type type= getTypeParent(arrayInitializer); ConstraintVariable typeVariable= fConstraintVariableFactory.makeTypeVariable(type); - for (int i= 0; i < expressions.size(); i++) { - Expression each= expressions.get(i); + for (Expression each : expressions) { ITypeConstraint[] c= fTypeConstraintFactory.createSubtypeConstraint( fConstraintVariableFactory.makeExpressionOrTypeVariable(each, getContext()), typeVariable); @@ -463,10 +462,8 @@ public class FullConstraintCreator extends ConstraintCreator{ Collection<ITypeConstraint> result= new ArrayList<>(); IVariableBinding fieldBinding= fragment.resolveBinding(); Assert.isTrue(fieldBinding.isField()); - Set<ITypeBinding> declaringTypes= getDeclaringSuperTypes(fieldBinding); ConstraintVariable hiddingFieldVar= fConstraintVariableFactory.makeDeclaringTypeVariable(fieldBinding); - for (Iterator<ITypeBinding> iter= declaringTypes.iterator(); iter.hasNext();) { - ITypeBinding declaringSuperType= iter.next(); + for (ITypeBinding declaringSuperType : getDeclaringSuperTypes(fieldBinding)) { IVariableBinding hiddenField= findField(fieldBinding, declaringSuperType); Assert.isTrue(hiddenField.isField()); ConstraintVariable hiddenFieldVar= fConstraintVariableFactory.makeDeclaringTypeVariable(hiddenField); @@ -497,9 +494,7 @@ public class FullConstraintCreator extends ConstraintCreator{ private Collection<ITypeConstraint> getConstraintsForOverriding(IMethodBinding overridingMethod) { Collection<ITypeConstraint> result= new ArrayList<>(); - Set<ITypeBinding> declaringSupertypes= getDeclaringSuperTypes(overridingMethod); - for (Iterator<ITypeBinding> iter= declaringSupertypes.iterator(); iter.hasNext();) { - ITypeBinding superType= iter.next(); + for (ITypeBinding superType : getDeclaringSuperTypes(overridingMethod)) { IMethodBinding overriddenMethod= findMethod(overridingMethod, superType); Assert.isNotNull(overriddenMethod);//because we asked for declaring types if (Bindings.equals(overridingMethod, overriddenMethod)) @@ -674,8 +669,7 @@ public class FullConstraintCreator extends ConstraintCreator{ protected static IMethodBinding[] getRootDefs(IMethodBinding methodBinding) { Set<ITypeBinding> declaringSuperTypes= getDeclaringSuperTypes(methodBinding); Set<IMethodBinding> result= new LinkedHashSet<>(); - for (Iterator<ITypeBinding> iter= declaringSuperTypes.iterator(); iter.hasNext();) { - ITypeBinding type= iter.next(); + for (ITypeBinding type : declaringSuperTypes) { if (! containsASuperType(type, declaringSuperTypes)) result.add(findMethod(methodBinding, type)); } @@ -692,8 +686,7 @@ public class FullConstraintCreator extends ConstraintCreator{ * which is a strict supertype of <code>type</code> */ private static boolean containsASuperType(ITypeBinding type, Set<ITypeBinding> declaringSuperTypes) { - for (Iterator<ITypeBinding> iter= declaringSuperTypes.iterator(); iter.hasNext();) { - ITypeBinding maybeSuperType= iter.next(); + for (ITypeBinding maybeSuperType : declaringSuperTypes) { if (! Bindings.equals(maybeSuperType, type) && Bindings.isSuperType(maybeSuperType, type)) return true; } @@ -710,8 +703,7 @@ public class FullConstraintCreator extends ConstraintCreator{ if (allSuperTypes.isEmpty()) allSuperTypes.add(methodBinding.getDeclaringClass()); //TODO: Why only iff empty? The declaring class is not a supertype ... Set<ITypeBinding> result= new HashSet<>(); - for (Iterator<ITypeBinding> iter= allSuperTypes.iterator(); iter.hasNext();) { - ITypeBinding type= iter.next(); + for (ITypeBinding type : allSuperTypes) { if (findMethod(methodBinding, type) != null) result.add(type); } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/typesets/EnumeratedTypeSet.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/typesets/EnumeratedTypeSet.java index 23edf11421..66ea46d374 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/typesets/EnumeratedTypeSet.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/typesets/EnumeratedTypeSet.java @@ -107,8 +107,8 @@ public class EnumeratedTypeSet extends TypeSet { if (!fMembers.contains(otherIter.next())) return false; } - for(Iterator<TType> myIter= fMembers.iterator(); myIter.hasNext(); ) { - if (!other.contains(myIter.next())) + for (TType tType : fMembers) { + if (!other.contains(tType)) return false; } return true; @@ -322,9 +322,7 @@ public class EnumeratedTypeSet extends TypeSet { // Add to result each element of fMembers that has no proper supertype in fMembers result.fMembers.addAll(fMembers); - for(Iterator<TType> iter= fMembers.iterator(); iter.hasNext(); ) { - TType t= iter.next(); - + for (TType t : fMembers) { if (t.isArrayType()) { ArrayType at= (ArrayType) t; int numDims= at.getDimensions(); @@ -351,9 +349,7 @@ public class EnumeratedTypeSet extends TypeSet { // Add to result each element of fMembers that has no proper subtype in fMembers result.fMembers.addAll(fMembers); - for(Iterator<TType> iter= fMembers.iterator(); iter.hasNext(); ) { - TType t= iter.next(); - + for (TType t : fMembers) { // java.lang.Object is only in the lower bound if fMembers consists // of only java.lang.Object, but that case is handled above. if (t.equals(getJavaLangObject())) { diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/AbstractExceptionAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/AbstractExceptionAnalyzer.java index 19011171a7..f76c9b6a6a 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/AbstractExceptionAnalyzer.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/AbstractExceptionAnalyzer.java @@ -14,7 +14,6 @@ package org.eclipse.jdt.internal.corext.refactoring.util; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Stack; @@ -104,8 +103,8 @@ public abstract class AbstractExceptionAnalyzer extends ASTVisitor { node.getBody().accept(this); List<Expression> resources= node.resources(); - for (Iterator<Expression> iterator= resources.iterator(); iterator.hasNext();) { - iterator.next().accept(this); + for (Expression expression : resources) { + expression.accept(this); } // Remove those exceptions that get catch by following catch blocks @@ -114,13 +113,13 @@ public abstract class AbstractExceptionAnalyzer extends ASTVisitor { handleCatchArguments(catchClauses); List<ITypeBinding> current= fTryStack.pop(); fCurrentExceptions= fTryStack.peek(); - for (Iterator<ITypeBinding> iter= current.iterator(); iter.hasNext();) { - addException(iter.next(), node.getAST()); + for (ITypeBinding typeBinding : current) { + addException(typeBinding, node.getAST()); } // visit catch and finally - for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) { - iter.next().accept(this); + for (CatchClause catchClause : catchClauses) { + catchClause.accept(this); } if (node.getFinally() != null) node.getFinally().accept(this); @@ -164,12 +163,12 @@ public abstract class AbstractExceptionAnalyzer extends ASTVisitor { } private void handleCatchArguments(List<CatchClause> catchClauses) { - for (Iterator<CatchClause> iter= catchClauses.iterator(); iter.hasNext(); ) { - Type type= iter.next().getException().getType(); + for (CatchClause catchClause : catchClauses) { + Type type= catchClause.getException().getType(); if (type instanceof UnionType) { List<Type> types= ((UnionType) type).types(); - for (Iterator<Type> iterator= types.iterator(); iterator.hasNext();) { - removeCaughtExceptions(iterator.next().resolveBinding()); + for (Type type2 : types) { + removeCaughtExceptions(type2.resolveBinding()); } } else { removeCaughtExceptions(type.resolveBinding()); @@ -180,8 +179,7 @@ public abstract class AbstractExceptionAnalyzer extends ASTVisitor { private void removeCaughtExceptions(ITypeBinding catchTypeBinding) { if (catchTypeBinding == null) return; - for (Iterator<ITypeBinding> exceptions= new ArrayList<>(fCurrentExceptions).iterator(); exceptions.hasNext();) { - ITypeBinding throwTypeBinding= exceptions.next(); + for (ITypeBinding throwTypeBinding : new ArrayList<>(fCurrentExceptions)) { if (catches(catchTypeBinding, throwTypeBinding)) fCurrentExceptions.remove(throwTypeBinding); } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/QualifiedNameSearchResult.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/QualifiedNameSearchResult.java index a190f70c41..65a9cf8486 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/QualifiedNameSearchResult.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/QualifiedNameSearchResult.java @@ -16,7 +16,6 @@ package org.eclipse.jdt.internal.corext.refactoring.util; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -65,8 +64,8 @@ public class QualifiedNameSearchResult { CompositeChange result= new CompositeChange(RefactoringCoreMessages.QualifiedNameSearchResult_change_name); result.markAsSynthetic(); List<IFile> files= Arrays.asList(alreadyTouchedFiles); - for (Iterator<TextChange> iter= values.iterator(); iter.hasNext();) { - TextFileChange change= (TextFileChange)iter.next(); + for (TextChange textChange : values) { + TextFileChange change= (TextFileChange)textChange; if (!files.contains(change.getFile())) { result.add(change); } |