Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2020-01-11 10:11:37 +0000
committerJeff Johnston2020-01-14 18:53:57 +0000
commit2196f300b56584e5da6009cb5618d6d63564fda3 (patch)
tree22ce66fd9373fdcfd7e3fa7799d9fa17686fa5b0
parentdcd7bfa823c79b5573f06e6c3d6bfebeeea66d8e (diff)
downloadeclipse.jdt.ui-2196f300b56584e5da6009cb5618d6d63564fda3.tar.gz
eclipse.jdt.ui-2196f300b56584e5da6009cb5618d6d63564fda3.tar.xz
eclipse.jdt.ui-2196f300b56584e5da6009cb5618d6d63564fda3.zip
Bug 548309 - Use jdk 5 for-each loop (org.eclipse.jdt.core.manipulation)
Replace simple uses of Iterator with a corresponding for-loop. Also add missing braces on loops as necessary. This reverts commit 9fbf05c8daa1f6c442fb7a3688e534f072e25ab2. Original gerrit was https://git.eclipse.org/r/#/c/144548/ that had been merged to late before release freeze. Change-Id: Id154ac0ecb742194b1e7f138bb3e1eff6b9326b2 Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
-rw-r--r--org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/TypeNameMatchCollector.java4
-rw-r--r--org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContextType.java4
-rw-r--r--org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java3
-rw-r--r--org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/ProjectTemplateStore.java14
-rw-r--r--org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java26
-rw-r--r--org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ProblemLocationCore.java5
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java28
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java19
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CalleeAnalyzerVisitor.java5
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/MethodWrapper.java5
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddDelegateMethodsOperation.java6
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddUnimplementedConstructorsOperation.java8
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java32
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java58
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java156
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java59
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java5
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java5
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java5
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java10
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java3
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java13
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java136
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/LinkedNodeFinder.java6
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java52
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CompilationUnitRewriteOperationsFixCore.java6
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java63
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/JDTRefactoringDescriptorComment.java18
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/SearchResultGroup.java4
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/CompilationUnitChange.java6
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/TextChangeCompatibility.java3
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java9
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java24
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java15
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/AbstractTypeVariable.java10
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/HierarchyType.java5
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/ParameterizedType.java5
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java7
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeVariable.java3
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java29
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/ResourceUtil.java4
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/StatementAnalyzer.java16
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/SurroundWithAnalyzer.java4
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TextEditUtil.java9
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java12
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/SignatureUtil.java11
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java50
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodOverrideTester.java24
-rw-r--r--org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/Resources.java10
-rw-r--r--org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/ExtractClassDescriptor.java7
-rw-r--r--org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/IntroduceParameterObjectDescriptor.java3
-rw-r--r--org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/MoveStaticMembersDescriptor.java4
52 files changed, 445 insertions, 583 deletions
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/TypeNameMatchCollector.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/TypeNameMatchCollector.java
index 4eabad20a1..aa8ab1ae6f 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/TypeNameMatchCollector.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/TypeNameMatchCollector.java
@@ -61,9 +61,7 @@ public class TypeNameMatchCollector extends TypeNameMatchRequestor {
}
private boolean filter(String fullTypeName) {
- Pattern[] matchers= getStringMatchers();
- for (int i= 0; i < matchers.length; i++) {
- Pattern curr= matchers[i];
+ for (Pattern curr : getStringMatchers()) {
if (curr.matcher(fullTypeName).matches()) {
return true;
}
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContextType.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContextType.java
index 9fe59992a8..9cb87bf06c 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContextType.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContextType.java
@@ -298,8 +298,8 @@ public class CodeTemplateContextType extends TemplateContextType {
required.add(PACKAGE_DECLARATION);
required.add(TYPE_DECLARATION);
}
- for (int i= 0; i < variables.length; i++) {
- String type= variables[i].getType();
+ for (TemplateVariable variable : variables) {
+ String type= variable.getType();
if (getResolver(type) == null) {
String unknown= BasicElementLabels.getJavaElementName(type);
throw new TemplateException(Messages.format(JavaManipulationMessages.CodeTemplateContextType_validate_unknownvariable, unknown));
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java
index ba38419613..19f0d4a433 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java
@@ -476,8 +476,7 @@ public class JavaElementLabelComposerCore {
protected void appendAnnotationLabels(IAnnotation[] annotations, long flags) throws JavaModelException {
- for (int j= 0; j < annotations.length; j++) {
- IAnnotation annotation= annotations[j];
+ for (IAnnotation annotation : annotations) {
appendAnnotationLabel(annotation, flags);
fBuffer.append(' ');
}
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/ProjectTemplateStore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/ProjectTemplateStore.java
index 1c87f5e11c..598ae39984 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/ProjectTemplateStore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/ProjectTemplateStore.java
@@ -65,9 +65,8 @@ public final class ProjectTemplateStore {
@Override
public void save() throws IOException {
- TemplatePersistenceData[] templateData= ProjectTemplateStore.this.getTemplateData();
- for (int i= 0; i < templateData.length; i++) {
- if (isProjectSpecific(templateData[i].getId())) {
+ for (TemplatePersistenceData templateData : ProjectTemplateStore.this.getTemplateData()) {
+ if (isProjectSpecific(templateData.getId())) {
StringWriter output= new StringWriter();
TemplateReaderWriter writer= new TemplateReaderWriter();
writer.save(getTemplateData(false), output);
@@ -133,14 +132,11 @@ public final class ProjectTemplateStore {
fProjectStore.load();
Set<String> datas= new HashSet<>();
- TemplatePersistenceData[] data= fProjectStore.getTemplateData(false);
- for (int i= 0; i < data.length; i++) {
- datas.add(data[i].getId());
+ for (TemplatePersistenceData d : fProjectStore.getTemplateData(false)) {
+ datas.add(d.getId());
}
- data= fInstanceStore.getTemplateData(false);
- for (int i= 0; i < data.length; i++) {
- TemplatePersistenceData orig= data[i];
+ for (TemplatePersistenceData orig : fInstanceStore.getTemplateData(false)) {
if (!datas.contains(orig.getId())) {
TemplatePersistenceData copy= new TemplatePersistenceData(new Template(orig.getTemplate()), orig.isEnabled(), orig.getId());
fProjectStore.add(copy);
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java
index 4624f6d411..bacbefeaed 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java
@@ -487,8 +487,8 @@ public class StubUtility {
int nLines= doc.getNumberOfLines();
MultiTextEdit edit= new MultiTextEdit();
HashSet<Integer> removedLines= new HashSet<>();
- for (int i= 0; i < variables.length; i++) {
- TemplateVariable position= findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
+ for (String variable : variables) {
+ TemplateVariable position= findVariable(buffer, variable); // look if Javadoc tags have to be added
if (position == null || position.getLength() > 0) {
continue;
}
@@ -811,9 +811,7 @@ public class StubUtility {
private static TemplateVariable findVariable(TemplateBuffer buffer, String variable) {
- TemplateVariable[] positions= buffer.getVariables();
- for (int i= 0; i < positions.length; i++) {
- TemplateVariable curr= positions[i];
+ for (TemplateVariable curr : buffer.getVariables()) {
if (variable.equals(curr.getType())) {
return curr;
}
@@ -830,17 +828,17 @@ public class StubUtility {
String lineStart= textBuffer.get(region.getOffset(), offset - region.getOffset());
StringBuilder buf= new StringBuilder();
- for (int i= 0; i < typeParameterNames.length; i++) {
+ for (String typeParameterName : typeParameterNames) {
if (buf.length() > 0) {
buf.append(lineDelimiter).append(lineStart);
}
- buf.append("@param <").append(typeParameterNames[i]).append('>'); //$NON-NLS-1$
+ buf.append("@param <").append(typeParameterName).append('>'); //$NON-NLS-1$
}
- for (int i= 0; i < paramNames.length; i++) {
+ for (String paramName : paramNames) {
if (buf.length() > 0) {
buf.append(lineDelimiter).append(lineStart);
}
- buf.append("@param ").append(paramNames[i]); //$NON-NLS-1$
+ buf.append("@param ").append(paramName); //$NON-NLS-1$
}
if (returnType != null && !returnType.equals("void")) { //$NON-NLS-1$
if (buf.length() > 0) {
@@ -849,11 +847,11 @@ public class StubUtility {
buf.append("@return"); //$NON-NLS-1$
}
if (exceptionNames != null) {
- for (int i= 0; i < exceptionNames.length; i++) {
+ for (String exceptionName : exceptionNames) {
if (buf.length() > 0) {
buf.append(lineDelimiter).append(lineStart);
}
- buf.append("@throws ").append(exceptionNames[i]); //$NON-NLS-1$
+ buf.append("@throws ").append(exceptionName); //$NON-NLS-1$
}
}
if (isDeprecated) {
@@ -1190,8 +1188,7 @@ public class StubUtility {
}
}
if (name != null) {
- for (int i= 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) {
- String curr= KNOWN_METHOD_NAME_PREFIXES[i];
+ for (String curr : KNOWN_METHOD_NAME_PREFIXES) {
if (name.startsWith(curr)) {
if (name.equals(curr)) {
return null; // don't suggest 'get' as variable name
@@ -1359,8 +1356,7 @@ public class StubUtility {
String[] namesArray= EMPTY;
ArrayList<String> newNames= new ArrayList<>(paramNames.length);
// Ensure that the code generation preferences are respected
- for (int i= 0; i < paramNames.length; i++) {
- String curr= paramNames[i];
+ for (String curr : paramNames) {
String baseName= NamingConventions.getBaseName(NamingConventions.VK_PARAMETER, curr, method.getJavaProject());
if (!curr.equals(baseName)) {
// make the existing name the favorite
diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ProblemLocationCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ProblemLocationCore.java
index 55698dc2a0..c874493700 100644
--- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ProblemLocationCore.java
+++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ProblemLocationCore.java
@@ -99,9 +99,8 @@ public class ProblemLocationCore implements IProblemLocationCore {
StringBuilder buf= new StringBuilder();
buf.append("Id: ").append(getErrorCode(fId)).append('\n'); //$NON-NLS-1$
buf.append('[').append(fOffset).append(", ").append(fLength).append(']').append('\n'); //$NON-NLS-1$
- String[] arg= fArguments;
- for (int i= 0; i < arg.length; i++) {
- buf.append(arg[i]);
+ for (String arg : fArguments) {
+ buf.append(arg);
buf.append('\n');
}
return buf.toString();
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
index cd7fa46857..6cf52cfc9e 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java
@@ -506,9 +506,7 @@ public class ASTResolving {
// test if selector is a object method
ITypeBinding binding= searchRoot.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
- IMethodBinding[] objectMethods= binding.getDeclaredMethods();
- for (int i= 0; i < objectMethods.length; i++) {
- IMethodBinding meth= objectMethods[i];
+ for (IMethodBinding meth : binding.getDeclaredMethods()) {
if (meth.getName().equals(selector) && meth.getParameterTypes().length == nArgs) {
return new ITypeBinding[] { binding };
}
@@ -534,9 +532,7 @@ public class ASTResolving {
return true;
}
- IMethodBinding[] methods= node.getDeclaredMethods();
- for (int i= 0; i < methods.length; i++) {
- IMethodBinding meth= methods[i];
+ for (IMethodBinding meth : node.getDeclaredMethods()) {
if (meth.getName().equals(selector) && meth.getParameterTypes().length == nArgs) {
result.add(node);
}
@@ -873,12 +869,12 @@ public class ASTResolving {
} else if (type.isPrimitive()) {
Code code= PrimitiveType.toCode(type.getName());
boolean found= false;
- for (int i= 0; i < CODE_ORDER.length; i++) {
+ for (Code order : CODE_ORDER) {
if (found) {
- String typeName= CODE_ORDER[i].toString();
+ String typeName= order.toString();
res.add(ast.resolveWellKnownType(typeName));
}
- if (code == CODE_ORDER[i]) {
+ if (code == order) {
found= true;
}
}
@@ -889,9 +885,7 @@ public class ASTResolving {
}
private static void collectRelaxingTypes(Collection<ITypeBinding> res, ITypeBinding type) {
- ITypeBinding[] interfaces= type.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- ITypeBinding curr= interfaces[i];
+ for (ITypeBinding curr : type.getInterfaces()) {
if (!res.contains(curr)) {
res.add(curr);
}
@@ -953,18 +947,16 @@ public class ASTResolving {
return isVariableDefinedInContext(context, type);
}
if (type.isGenericType()) {
- ITypeBinding[] typeParameters= type.getTypeParameters();
- for (int i= 0; i < typeParameters.length; i++) {
- if (!isUseableTypeInContext(typeParameters[i], context, noWildcards)) {
+ for (ITypeBinding typeParameter : type.getTypeParameters()) {
+ if (!isUseableTypeInContext(typeParameter, context, noWildcards)) {
return false;
}
}
return true;
}
if (type.isParameterizedType()) {
- ITypeBinding[] typeArguments= type.getTypeArguments();
- for (int i= 0; i < typeArguments.length; i++) {
- if (!isUseableTypeInContext(typeArguments[i], context, noWildcards)) {
+ for (ITypeBinding typeArgument : type.getTypeArguments()) {
+ if (!isUseableTypeInContext(typeArgument, context, noWildcards)) {
return false;
}
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java
index 5e8c6cf1e5..78145544a5 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java
@@ -112,8 +112,7 @@ public class CallHierarchyCore {
private MethodWrapper[] getRoots(IMember[] members, boolean callers) {
ArrayList<MethodWrapper> roots= new ArrayList<>();
- for (int i= 0; i < members.length; i++) {
- IMember member= members[i];
+ for (IMember member : members) {
if (member instanceof IType) {
IType type= (IType) member;
try {
@@ -122,8 +121,7 @@ public class CallHierarchyCore {
if (constructors.length == 0) {
addRoot(member, roots, callers); // IType is a stand-in for the non-existing default constructor
} else {
- for (int j= 0; j < constructors.length; j++) {
- IMethod constructor= constructors[j];
+ for (IMethod constructor : constructors) {
addRoot(constructor, roots, callers);
}
}
@@ -189,13 +187,12 @@ public class CallHierarchyCore {
*/
public boolean isIgnored(String fullyQualifiedName) {
if ((getIgnoreFilters() != null) && (getIgnoreFilters().length > 0)) {
- for (int i= 0; i < getIgnoreFilters().length; i++) {
- String fullyQualifiedName1= fullyQualifiedName;
-
- if (getIgnoreFilters()[i].match(fullyQualifiedName1)) {
- return true;
- }
- }
+ for (StringMatcher ignoreFilter : getIgnoreFilters()) {
+ String fullyQualifiedName1= fullyQualifiedName;
+ if (ignoreFilter.match(fullyQualifiedName1)) {
+ return true;
+ }
+ }
}
return false;
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CalleeAnalyzerVisitor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CalleeAnalyzerVisitor.java
index aea1ce848b..723109440b 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CalleeAnalyzerVisitor.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CalleeAnalyzerVisitor.java
@@ -282,9 +282,8 @@ class CalleeAnalyzerVisitor extends HierarchicalASTVisitor {
IMethod inThisType= Bindings.findMethod(method, type);
if (inThisType != null)
return inThisType;
- IType[] superTypes= JavaModelUtil.getAllSuperTypes(type, pm);
- for (int i= 0; i < superTypes.length; i++) {
- IMethod m= Bindings.findMethod(method, superTypes[i]);
+ for (IType superType : JavaModelUtil.getAllSuperTypes(type, pm)) {
+ IMethod m= Bindings.findMethod(method, superType);
if (m != null)
return m;
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/MethodWrapper.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/MethodWrapper.java
index 8fbb6f8181..f25523a289 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/MethodWrapper.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/MethodWrapper.java
@@ -313,9 +313,8 @@ public abstract class MethodWrapper extends PlatformObject {
visitor.preVisit(this);
if (visitor.visit(this)) {
- MethodWrapper[] methodWrappers= getCalls(progressMonitor);
- for (int i= 0; i < methodWrappers.length; i++) {
- methodWrappers[i].accept(visitor, progressMonitor);
+ for (MethodWrapper methodWrapper : getCalls(progressMonitor)) {
+ methodWrapper.accept(visitor, progressMonitor);
}
}
visitor.postVisit(this);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddDelegateMethodsOperation.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddDelegateMethodsOperation.java
index a40048b61c..ce9b7f8273 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddDelegateMethodsOperation.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddDelegateMethodsOperation.java
@@ -181,9 +181,9 @@ public final class AddDelegateMethodsOperation implements IWorkspaceRunnable {
Arrays.sort(fDelegatesToCreate, new DelegateEntryComparator());
- for (int i= 0; i < fDelegatesToCreate.length; i++) {
- IMethodBinding delegateMethod= fDelegatesToCreate[i].delegateMethod;
- IVariableBinding field= fDelegatesToCreate[i].field;
+ for (DelegateEntry delegateEntry : fDelegatesToCreate) {
+ IMethodBinding delegateMethod= delegateEntry.delegateMethod;
+ IVariableBinding field= delegateEntry.field;
MethodDeclaration newMethod= StubUtility2Core.createDelegationStub(cu, astRewrite, importRewrite, context, delegateMethod, field, fSettings);
if (newMethod != null) {
fCreated.add(delegateMethod);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddUnimplementedConstructorsOperation.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddUnimplementedConstructorsOperation.java
index f99b81ccd3..a4b248c6d2 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddUnimplementedConstructorsOperation.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/AddUnimplementedConstructorsOperation.java
@@ -247,13 +247,13 @@ public final class AddUnimplementedConstructorsOperation implements IWorkspaceRu
}
int deprecationCount= 0;
- for (int i= 0; i < toImplement.length; i++) {
- if (toImplement[i].isDeprecated())
+ for (IMethodBinding curr : toImplement) {
+ if (curr.isDeprecated()) {
deprecationCount++;
+ }
}
boolean createDeprecated= deprecationCount == toImplement.length;
- for (int i= 0; i < toImplement.length; i++) {
- IMethodBinding curr= toImplement[i];
+ for (IMethodBinding curr : toImplement) {
if (!curr.isDeprecated() || createDeprecated) {
ImportRewriteContext context= new ContextSensitiveImportRewriteContext(node, importRewrite);
MethodDeclaration stub= StubUtility2Core.createConstructorStub(cu, astRewrite, importRewrite, context, curr, currTypeBinding.getName(), fVisibility, fOmitSuper, true, settings, fFormatSettings);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java
index b742e8e1f9..df70e59e85 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java
@@ -94,26 +94,24 @@ public class ContextSensitiveImportRewriteContext extends ImportRewriteContext {
@Override
public int findInContext(String qualifier, String name, int kind) {
- IBinding[] declarationsInScope= getDeclarationsInScope();
- for (int i= 0; i < declarationsInScope.length; i++) {
- if (declarationsInScope[i] instanceof ITypeBinding) {
- ITypeBinding typeBinding= (ITypeBinding)declarationsInScope[i];
+ for (IBinding declaration : getDeclarationsInScope()) {
+ if (declaration instanceof ITypeBinding) {
+ ITypeBinding typeBinding= (ITypeBinding) declaration;
if (isSameType(typeBinding, qualifier, name)) {
return RES_NAME_FOUND;
} else if (isConflicting(typeBinding, name)) {
return RES_NAME_CONFLICT;
}
- } else if (declarationsInScope[i] != null) {
- if (isConflicting(declarationsInScope[i], name)) {
+ } else if (declaration != null) {
+ if (isConflicting(declaration, name)) {
return RES_NAME_CONFLICT;
}
}
}
- Name[] names= getImportedNames();
- for (int i= 0; i < names.length; i++) {
- IBinding binding= names[i].resolveBinding();
+ for (Name importedName : getImportedNames()) {
+ IBinding binding= importedName.resolveBinding();
if (binding instanceof ITypeBinding && !binding.isRecovered()) {
ITypeBinding typeBinding= (ITypeBinding)binding;
if (isConflictingType(typeBinding, qualifier, name)) {
@@ -141,10 +139,8 @@ public class ContextSensitiveImportRewriteContext extends ImportRewriteContext {
}
}
- String[] addedImports= fImportRewrite.getAddedImports();
String qualifiedName= JavaModelUtil.concatenateName(qualifier, name);
- for (int i= 0; i < addedImports.length; i++) {
- String addedImport= addedImports[i];
+ for (String addedImport : fImportRewrite.getAddedImports()) {
if (qualifiedName.equals(addedImport)) {
return RES_NAME_FOUND;
} else {
@@ -159,12 +155,8 @@ public class ContextSensitiveImportRewriteContext extends ImportRewriteContext {
if (typeRoot != null) {
IPackageFragment packageFragment= (IPackageFragment) typeRoot.getParent();
try {
- ICompilationUnit[] compilationUnits= packageFragment.getCompilationUnits();
- for (int i= 0; i < compilationUnits.length; i++) {
- ICompilationUnit cu= compilationUnits[i];
- IType[] allTypes= cu.getAllTypes();
- for (int j= 0; j < allTypes.length; j++) {
- IType type= allTypes[j];
+ for (ICompilationUnit cu : packageFragment.getCompilationUnits()) {
+ for (IType type : cu.getAllTypes()) {
String packageTypeName= type.getFullyQualifiedName();
if (isConflicting(name, packageTypeName))
return RES_NAME_CONFLICT;
@@ -193,9 +185,7 @@ public class ContextSensitiveImportRewriteContext extends ImportRewriteContext {
}
private ITypeBinding containingDeclaration(ITypeBinding binding, String qualifier, String name) {
- ITypeBinding[] declaredTypes= binding.getDeclaredTypes();
- for (int i= 0; i < declaredTypes.length; i++) {
- ITypeBinding childBinding= declaredTypes[i];
+ for (ITypeBinding childBinding : binding.getDeclaredTypes()) {
if (isSameType(childBinding, qualifier, name)) {
return childBinding;
} else {
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java
index 93a8fad971..212eab3f5e 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java
@@ -69,6 +69,7 @@ import org.eclipse.jdt.core.dom.ParenthesizedExpression;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.PrimitiveType.Code;
import org.eclipse.jdt.core.dom.ReturnStatement;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Statement;
@@ -471,25 +472,26 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable
}
MethodInvocation j7Invoc= fAst.newMethodInvocation();
- for (int i= 0; i < fFields.length; i++) {
- if (fFields[i].getType().isArray())
- body.statements().add(createAddArrayHashCode(fFields[i]));
- else if (fUseJ7HashEquals)
- j7Invoc.arguments().add(fAst.newSimpleName(fFields[i].getName()));
- else if (fFields[i].getType().isPrimitive()) {
- Statement[] sts= createAddSimpleHashCode(fFields[i].getType(), new IHashCodeAccessProvider() {
+ for (IVariableBinding field : fFields) {
+ if (field.getType().isArray()) {
+ body.statements().add(createAddArrayHashCode(field));
+ } else if (fUseJ7HashEquals) {
+ j7Invoc.arguments().add(fAst.newSimpleName(field.getName()));
+ } else if (field.getType().isPrimitive()) {
+ Statement[] sts= createAddSimpleHashCode(field.getType(), new IHashCodeAccessProvider() {
@Override
public Expression getThisAccess(String name) {
return getThisAccessForHashCode(name);
}
- }, fFields[i].getName(), false);
- for (int j= 0; j < sts.length; j++) {
- body.statements().add(sts[j]);
+ }, field.getName(), false);
+ for (Statement st : sts) {
+ body.statements().add(st);
}
- } else
- body.statements().add(createAddQualifiedHashCode(fFields[i]));
+ } else {
+ body.statements().add(createAddQualifiedHashCode(field));
+ }
}
if (!j7Invoc.arguments().isEmpty()) {
j7Invoc.setExpression(getQualifiedName(JAVA_UTIL_OBJECTS));
@@ -505,11 +507,11 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable
// method comment
if (fSettings != null) {
ITypeBinding object= fAst.resolveWellKnownType(JAVA_LANG_OBJECT);
- IMethodBinding[] objms= object.getDeclaredMethods();
IMethodBinding objectMethod= null;
- for (int i= 0; i < objms.length; i++) {
- if (objms[i].getName().equals(METHODNAME_HASH_CODE) && objms[i].getParameterTypes().length == 0)
- objectMethod= objms[i];
+ for (IMethodBinding objm : object.getDeclaredMethods()) {
+ if (objm.getName().equals(METHODNAME_HASH_CODE) && objm.getParameterTypes().length == 0) {
+ objectMethod= objm;
+ }
}
createMethodComment(hashCodeMethod, objectMethod);
}
@@ -523,8 +525,8 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable
private MethodInvocation createStandaloneJ7HashCall() {
MethodInvocation j7Invoc= fAst.newMethodInvocation();
- for (int i= 0; i < fFields.length; i++) {
- j7Invoc.arguments().add(fAst.newSimpleName(fFields[i].getName()));
+ for (IVariableBinding field : fFields) {
+ j7Invoc.arguments().add(fAst.newSimpleName(field.getName()));
}
j7Invoc.setExpression(getQualifiedName(JAVA_UTIL_OBJECTS));
j7Invoc.setName(fAst.newSimpleName(METHODNAME_HASH));
@@ -743,8 +745,8 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable
return a;
}
}, VARIABLE_NAME_INDEX, true);
- for (int index= 0; index < statements.length; index++) {
- forBody.statements().add(statements[index]);
+ for (Statement statement : statements) {
+ forBody.statements().add(statement);
}
forStatement.setBody(forBody);
@@ -936,8 +938,7 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable
if (fUseJ7HashEquals && fFields.length > 0) {
body.statements().add(createJ7EqualsStatement());
} else {
- for (int i= 0; i < fFields.length; i++) {
- IVariableBinding field= fFields[i];
+ for (IVariableBinding field : fFields) {
ITypeBinding type= field.getType();
if (type.isPrimitive() || type.isEnum())
body.statements().add(createSimpleComparison(field));
@@ -950,7 +951,6 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable
}
} else
body.statements().add(createQualifiedComparison(field.getName()));
-
}
// the last return true:
@@ -963,12 +963,11 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable
// method comment
if (fSettings != null) {
ITypeBinding object= fAst.resolveWellKnownType(JAVA_LANG_OBJECT);
- IMethodBinding[] objms= object.getDeclaredMethods();
IMethodBinding objectMethod= null;
- for (int i= 0; i < objms.length; i++) {
- if (objms[i].getName().equals(METHODNAME_EQUALS) && objms[i].getParameterTypes().length == 1
- && objms[i].getParameterTypes()[0].getQualifiedName().equals(JAVA_LANG_OBJECT))
- objectMethod= objms[i];
+ for (IMethodBinding objm : object.getDeclaredMethods()) {
+ if (objm.getName().equals(METHODNAME_EQUALS) && objm.getParameterTypes().length == 1 && objm.getParameterTypes()[0].getQualifiedName().equals(JAVA_LANG_OBJECT)) {
+ objectMethod= objm;
+ }
}
createMethodComment(equalsMethodDeclaration, objectMethod);
}
@@ -1239,8 +1238,7 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable
}
private boolean isPrimitiveType(ITypeBinding type, PrimitiveType.Code[] codes) {
- for (int i= 0; i < codes.length; i++) {
- PrimitiveType.Code code= codes[i];
+ for (Code code : codes) {
if (isPrimitiveType(type, code))
return true;
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java
index f0caaef05b..5e28bb7dc4 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java
@@ -179,24 +179,24 @@ public final class StubUtility2Core {
String param= null;
List<String> list= new ArrayList<>(prohibited);
String[] excluded= null;
- for (int i= 0; i < variableBindings.length; i++) {
+ for (IVariableBinding variableBinding : variableBindings) {
SingleVariableDeclaration var= ast.newSingleVariableDeclaration();
- var.setType(imports.addImport(variableBindings[i].getType(), ast, context, TypeLocation.PARAMETER));
+ var.setType(imports.addImport(variableBinding.getType(), ast, context, TypeLocation.PARAMETER));
excluded= new String[list.size()];
list.toArray(excluded);
- param= suggestParameterName(unit, variableBindings[i], excluded);
+ param= suggestParameterName(unit, variableBinding, excluded);
list.add(param);
var.setName(ast.newSimpleName(param));
parameters.add(var);
}
list= new ArrayList<>(prohibited);
- for (int i= 0; i < variableBindings.length; i++) {
+ for (IVariableBinding variableBinding : variableBindings) {
excluded= new String[list.size()];
list.toArray(excluded);
- final String paramName= suggestParameterName(unit, variableBindings[i], excluded);
+ final String paramName= suggestParameterName(unit, variableBinding, excluded);
list.add(paramName);
- final String fieldName= variableBindings[i].getName();
+ final String fieldName= variableBinding.getName();
Expression expression= null;
if (paramName.equals(fieldName) || settings.useKeywordThis) {
FieldAccess access= ast.newFieldAccess();
@@ -441,17 +441,15 @@ public final class StubUtility2Core {
}
public static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) {
- ITypeBinding[] typeParams= binding.getTypeParameters();
List<TypeParameter> typeParameters= decl.typeParameters();
- for (int i= 0; i < typeParams.length; i++) {
- ITypeBinding curr= typeParams[i];
+ for (ITypeBinding curr : binding.getTypeParameters()) {
TypeParameter newTypeParam= ast.newTypeParameter();
newTypeParam.setName(ast.newSimpleName(curr.getName()));
ITypeBinding[] typeBounds= curr.getTypeBounds();
- if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$
+ if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) { //$NON-NLS-1$
List<Type> newTypeBounds= newTypeParam.typeBounds();
- for (int k= 0; k < typeBounds.length; k++) {
- newTypeBounds.add(imports.addImport(typeBounds[k], ast, context, TypeLocation.TYPE_BOUND));
+ for (ITypeBinding typeBound : typeBounds) {
+ newTypeBounds.add(imports.addImport(typeBound, ast, context, TypeLocation.TYPE_BOUND));
}
}
typeParameters.add(newTypeParam);
@@ -528,14 +526,14 @@ public final class StubUtility2Core {
ITypeBinding[] excTypes= method.getExceptionTypes();
if (ast.apiLevel() >= AST.JLS8) {
List<Type> thrownExceptions= decl.thrownExceptionTypes();
- for (int i= 0; i < excTypes.length; i++) {
- Type excType= imports.addImport(excTypes[i], ast, context, TypeLocation.EXCEPTION);
+ for (ITypeBinding t : excTypes) {
+ Type excType= imports.addImport(t, ast, context, TypeLocation.EXCEPTION);
thrownExceptions.add(excType);
}
} else {
List<Name> thrownExceptions= getThrownExceptions(decl);
- for (int i= 0; i < excTypes.length; i++) {
- String excTypeName= imports.addImport(excTypes[i], context);
+ for (ITypeBinding excType : excTypes) {
+ String excTypeName= imports.addImport(excType, context);
thrownExceptions.add(ASTNodeFactory.newName(ast, excTypeName));
}
}
@@ -574,10 +572,7 @@ public final class StubUtility2Core {
ArrayList<IMethodBinding> allMethods, IPackageBinding currPack, ArrayList<IMethodBinding> toImplement) {
if (visited.add(typeBinding)) {
- IMethodBinding[] typeMethods= typeBinding.getDeclaredMethods();
-
- nextMethod: for (int i= 0; i < typeMethods.length; i++) {
- IMethodBinding curr= typeMethods[i];
+ nextMethod: for (IMethodBinding curr : typeBinding.getDeclaredMethods()) {
for (Iterator<IMethodBinding> allIter= allMethods.iterator(); allIter.hasNext();) {
IMethodBinding oneMethod= allIter.next();
if (Bindings.isSubsignature(oneMethod, curr)) {
@@ -589,7 +584,7 @@ public final class StubUtility2Core {
// Subsignatures are equivalent.
// Check visibility and return types ('getErasure()' tries to achieve effect of "rename type variables")
if (Bindings.isVisibleInHierarchy(oneMethod, currPack)
- && oneMethod.getReturnType().getErasure().isSubTypeCompatible(curr.getReturnType().getErasure())) {
+ && oneMethod.getReturnType().getErasure().isSubTypeCompatible(curr.getReturnType().getErasure())) {
// oneMethod is visible and curr doesn't have a stricter return type; let's go with oneMethod
continue nextMethod;
}
@@ -610,9 +605,9 @@ public final class StubUtility2Core {
}
}
}
- ITypeBinding[] superInterfaces= typeBinding.getInterfaces();
- for (int i= 0; i < superInterfaces.length; i++)
- findUnimplementedInterfaceMethods(superInterfaces[i], visited, allMethods, currPack, toImplement);
+ for (ITypeBinding superInterface : typeBinding.getInterfaces()) {
+ findUnimplementedInterfaceMethods(superInterface, visited, allMethods, currPack, toImplement);
+ }
}
}
@@ -687,9 +682,7 @@ public final class StubUtility2Core {
final List<IMethodBinding> declared= new ArrayList<>();
IMethodBinding[] typeMethods= binding.getDeclaredMethods();
declared.addAll(Arrays.asList(typeMethods));
- IVariableBinding[] typeFields= binding.getDeclaredFields();
- for (int index= 0; index < typeFields.length; index++) {
- IVariableBinding fieldBinding= typeFields[index];
+ for (IVariableBinding fieldBinding : binding.getDeclaredFields()) {
if (fieldBinding.isField() && !fieldBinding.isEnumConstant() && !fieldBinding.isSynthetic())
getDelegatableMethods(new ArrayList<>(declared), fieldBinding, fieldBinding.getType(), binding, tuples);
}
@@ -702,8 +695,8 @@ public final class StubUtility2Core {
if (typeBinding.isTypeVariable()) {
ITypeBinding[] typeBounds= typeBinding.getTypeBounds();
if (typeBounds.length > 0) {
- for (int i= 0; i < typeBounds.length; i++) {
- getDelegatableMethods(methods, fieldBinding, typeBounds[i], binding, result);
+ for (ITypeBinding typeBound : typeBounds) {
+ getDelegatableMethods(methods, fieldBinding, typeBound, binding, result);
}
} else {
ITypeBinding objectBinding= Bindings.findTypeInHierarchy(binding, "java.lang.Object"); //$NON-NLS-1$
@@ -712,10 +705,9 @@ public final class StubUtility2Core {
}
}
} else {
- IMethodBinding[] candidates= getDelegateCandidates(typeBinding, binding);
- for (int index= 0; index < candidates.length; index++) {
+ for (IMethodBinding candidate : getDelegateCandidates(typeBinding, binding)) {
match= false;
- final IMethodBinding methodBinding= candidates[index];
+ final IMethodBinding methodBinding= candidate;
for (int offset= 0; offset < methods.size() && !match; offset++) {
if (Bindings.areOverriddenMethods(methods.get(offset), methodBinding))
match= true;
@@ -728,30 +720,31 @@ public final class StubUtility2Core {
final ITypeBinding superclass= typeBinding.getSuperclass();
if (superclass != null)
getDelegatableMethods(methods, fieldBinding, superclass, binding, result);
- ITypeBinding[] superInterfaces= typeBinding.getInterfaces();
- for (int offset= 0; offset < superInterfaces.length; offset++)
- getDelegatableMethods(methods, fieldBinding, superInterfaces[offset], binding, result);
+ for (ITypeBinding superInterface : typeBinding.getInterfaces()) {
+ getDelegatableMethods(methods, fieldBinding, superInterface, binding, result);
+ }
}
}
private static IMethodBinding[] getDelegateCandidates(ITypeBinding binding, ITypeBinding hierarchy) {
List<IMethodBinding> allMethods= new ArrayList<>();
boolean isInterface= binding.isInterface();
- IMethodBinding[] typeMethods= binding.getDeclaredMethods();
- for (int index= 0; index < typeMethods.length; index++) {
- final int modifiers= typeMethods[index].getModifiers();
- if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && (isInterface || Modifier.isPublic(modifiers))) {
- IMethodBinding result= Bindings.findOverriddenMethodInHierarchy(hierarchy, typeMethods[index]);
+ for (IMethodBinding typeMethod : binding.getDeclaredMethods()) {
+ final int modifiers= typeMethod.getModifiers();
+ if (!typeMethod.isConstructor() && !Modifier.isStatic(modifiers) && (isInterface || Modifier.isPublic(modifiers))) {
+ IMethodBinding result= Bindings.findOverriddenMethodInHierarchy(hierarchy, typeMethod);
if (result != null && Flags.isFinal(result.getModifiers()))
continue;
- ITypeBinding[] parameterBindings= typeMethods[index].getParameterTypes();
+ ITypeBinding[] parameterBindings= typeMethod.getParameterTypes();
boolean upper= false;
- for (int offset= 0; offset < parameterBindings.length; offset++) {
- if (parameterBindings[offset].isWildcardType() && parameterBindings[offset].isUpperbound())
+ for (ITypeBinding parameterBinding : parameterBindings) {
+ if (parameterBinding.isWildcardType() && parameterBinding.isUpperbound()) {
upper= true;
+ }
+ }
+ if (!upper) {
+ allMethods.add(typeMethod);
}
- if (!upper)
- allMethods.add(typeMethods[index]);
}
}
return allMethods.toArray(new IMethodBinding[allMethods.size()]);
@@ -760,28 +753,28 @@ public final class StubUtility2Core {
public static IMethodBinding[] getOverridableMethods(AST ast, ITypeBinding typeBinding, boolean isSubType) {
List<IMethodBinding> allMethods= new ArrayList<>();
IMethodBinding[] typeMethods= typeBinding.getDeclaredMethods();
- for (int index= 0; index < typeMethods.length; index++) {
- final int modifiers= typeMethods[index].getModifiers();
- if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers))
- allMethods.add(typeMethods[index]);
+ for (IMethodBinding typeMethod : typeMethods) {
+ final int modifiers= typeMethod.getModifiers();
+ if (!typeMethod.isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
+ allMethods.add(typeMethod);
+ }
}
ITypeBinding clazz= typeBinding.getSuperclass();
while (clazz != null) {
- IMethodBinding[] methods= clazz.getDeclaredMethods();
- for (int offset= 0; offset < methods.length; offset++) {
- final int modifiers= methods[offset].getModifiers();
- if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
- if (findOverridingMethod(methods[offset], allMethods) == null)
- allMethods.add(methods[offset]);
+ for (IMethodBinding method : clazz.getDeclaredMethods()) {
+ final int modifiers= method.getModifiers();
+ if (!method.isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
+ if (findOverridingMethod(method, allMethods) == null) {
+ allMethods.add(method);
+ }
}
}
clazz= clazz.getSuperclass();
}
clazz= typeBinding;
while (clazz != null) {
- ITypeBinding[] superInterfaces= clazz.getInterfaces();
- for (int index= 0; index < superInterfaces.length; index++) {
- getOverridableMethods(ast, superInterfaces[index], allMethods);
+ for (ITypeBinding superInterface : clazz.getInterfaces()) {
+ getOverridableMethods(ast, superInterface, allMethods);
}
clazz= clazz.getSuperclass();
}
@@ -798,17 +791,16 @@ public final class StubUtility2Core {
}
private static void getOverridableMethods(AST ast, ITypeBinding superBinding, List<IMethodBinding> allMethods) {
- IMethodBinding[] methods= superBinding.getDeclaredMethods();
- for (int offset= 0; offset < methods.length; offset++) {
- final int modifiers= methods[offset].getModifiers();
- if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
- if (findOverridingMethod(methods[offset], allMethods) == null)
- allMethods.add(methods[offset]);
+ for (IMethodBinding method : superBinding.getDeclaredMethods()) {
+ final int modifiers= method.getModifiers();
+ if (!method.isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
+ if (findOverridingMethod(method, allMethods) == null) {
+ allMethods.add(method);
+ }
}
}
- ITypeBinding[] superInterfaces= superBinding.getInterfaces();
- for (int index= 0; index < superInterfaces.length; index++) {
- getOverridableMethods(ast, superInterfaces[index], allMethods);
+ for (ITypeBinding superInterface : superBinding.getInterfaces()) {
+ getOverridableMethods(ast, superInterface, allMethods);
}
}
@@ -825,9 +817,7 @@ public final class StubUtility2Core {
ArrayList<IMethodBinding> allMethods= new ArrayList<>();
ArrayList<IMethodBinding> toImplement= new ArrayList<>();
- IMethodBinding[] typeMethods= typeBinding.getDeclaredMethods();
- for (int i= 0; i < typeMethods.length; i++) {
- IMethodBinding curr= typeMethods[i];
+ for (IMethodBinding curr : typeBinding.getDeclaredMethods()) {
int modifiers= curr.getModifiers();
if (!curr.isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
allMethods.add(curr);
@@ -836,9 +826,7 @@ public final class StubUtility2Core {
ITypeBinding superClass= typeBinding.getSuperclass();
while (superClass != null) {
- typeMethods= superClass.getDeclaredMethods();
- for (int i= 0; i < typeMethods.length; i++) {
- IMethodBinding curr= typeMethods[i];
+ for (IMethodBinding curr : superClass.getDeclaredMethods()) {
int modifiers= curr.getModifiers();
if (!curr.isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
if (findMethodBinding(curr, allMethods) == null) {
@@ -849,8 +837,7 @@ public final class StubUtility2Core {
superClass= superClass.getSuperclass();
}
- for (int i= 0; i < allMethods.size(); i++) {
- IMethodBinding curr= allMethods.get(i);
+ for (IMethodBinding curr : allMethods) {
int modifiers= curr.getModifiers();
if ((Modifier.isAbstract(modifiers) || curr.getDeclaringClass().isInterface()) && (implementAbstractsOfInput || typeBinding != curr.getDeclaringClass())) {
// implement all abstract methods
@@ -861,9 +848,8 @@ public final class StubUtility2Core {
HashSet<ITypeBinding> visited= new HashSet<>();
ITypeBinding curr= typeBinding;
while (curr != null) {
- ITypeBinding[] superInterfaces= curr.getInterfaces();
- for (int i= 0; i < superInterfaces.length; i++) {
- findUnimplementedInterfaceMethods(superInterfaces[i], visited, allMethods, typeBinding.getPackage(), toImplement);
+ for (ITypeBinding superInterface : curr.getInterfaces()) {
+ findUnimplementedInterfaceMethods(superInterface, visited, allMethods, typeBinding.getPackage(), toImplement);
}
curr= curr.getSuperclass();
}
@@ -880,8 +866,7 @@ public final class StubUtility2Core {
if (accountExisting) {
IMethodBinding[] methods= binding.getDeclaredMethods();
existingConstructors= new ArrayList<>(methods.length);
- for (int index= 0; index < methods.length; index++) {
- IMethodBinding method= methods[index];
+ for (IMethodBinding method : methods) {
if (method.isConstructor() && !method.isDefaultConstructor())
existingConstructors.add(method);
}
@@ -889,9 +874,7 @@ public final class StubUtility2Core {
if (existingConstructors != null)
constructorMethods.addAll(existingConstructors);
IMethodBinding[] methods= binding.getDeclaredMethods();
- IMethodBinding[] superMethods= superType.getDeclaredMethods();
- for (int index= 0; index < superMethods.length; index++) {
- IMethodBinding method= superMethods[index];
+ for (IMethodBinding method : superType.getDeclaredMethods()) {
if (method.isConstructor()) {
if (Bindings.isVisibleInHierarchy(method, binding.getPackage()) && (!accountExisting || !Bindings.containsSignatureEquivalentConstructor(methods, method)))
constructorMethods.add(method);
@@ -930,9 +913,7 @@ public final class StubUtility2Core {
}
int insertPos= sourceRange.getOffset();
- List<? extends ASTNode> members= listRewrite.getOriginalList();
- for (int i= 0; i < members.size(); i++) {
- ASTNode curr= members.get(i);
+ for (ASTNode curr : (List<? extends ASTNode>)listRewrite.getOriginalList()) {
if (curr.getStartPosition() >= insertPos) {
return curr;
}
@@ -999,8 +980,7 @@ public final class StubUtility2Core {
}
public static Annotation findAnnotation(String qualifiedTypeName, List<IExtendedModifier> modifiers) {
- for (int i= 0; i < modifiers.size(); i++) {
- IExtendedModifier curr= modifiers.get(i);
+ for (IExtendedModifier curr : modifiers) {
if (curr instanceof Annotation) {
Annotation annot= (Annotation) curr;
ITypeBinding binding= annot.getTypeName().resolveTypeBinding();
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java
index 0906d1f72a..c7e72698ca 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java
@@ -187,12 +187,11 @@ public abstract class AbstractToStringGenerator {
public MethodDeclaration generateToStringMethod() throws CoreException {
initialize();
- String[] stringArray= fContext.getTemplateParser().getBeginning();
- for (int i= 0; i < stringArray.length; i++) {
- addElement(processElement(stringArray[i], null));
+ for (String element : fContext.getTemplateParser().getBeginning()) {
+ addElement(processElement(element, null));
}
- stringArray= fContext.getTemplateParser().getBody();
+ fContext.getTemplateParser().getBody();
Object[] members= fContext.getSelectedMembers();
for (int i= 0; i < members.length; i++) {
if (!fContext.isSkipNulls() || getMemberType(members[i]).isPrimitive())
@@ -201,9 +200,8 @@ public abstract class AbstractToStringGenerator {
addMemberCheckNull(members[i], i != members.length - 1);
}
- stringArray= fContext.getTemplateParser().getEnding();
- for (int i= 0; i < stringArray.length; i++) {
- addElement(processElement(stringArray[i], null));
+ for (String element : fContext.getTemplateParser().getEnding()) {
+ addElement(processElement(element, null));
}
complete();
@@ -230,11 +228,11 @@ public abstract class AbstractToStringGenerator {
*/
protected void createMethodComment() throws CoreException {
ITypeBinding object= fAst.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
- IMethodBinding[] objms= object.getDeclaredMethods();
IMethodBinding objectMethod= null;
- for (int i= 0; i < objms.length; i++) {
- if (objms[i].getName().equals(METHODNAME_TO_STRING) && objms[i].getParameterTypes().length == 0)
- objectMethod= objms[i];
+ for (IMethodBinding objm : object.getDeclaredMethods()) {
+ if (objm.getName().equals(METHODNAME_TO_STRING) && objm.getParameterTypes().length == 0) {
+ objectMethod= objm;
+ }
}
if (fContext.isCreateComments()) {
String docString= CodeGeneration.getMethodComment(fContext.getCompilationUnit(), fContext.getTypeBinding().getQualifiedName(), toStringMethod, objectMethod, StubUtility
@@ -500,13 +498,12 @@ public abstract class AbstractToStringGenerator {
return;
boolean isNonPrimitive= false;
- for (int i= 0; i < fContext.getSelectedMembers().length; i++) {
- ITypeBinding memberType= getMemberType(fContext.getSelectedMembers()[i]);
+ for (Object selectedMember : fContext.getSelectedMembers()) {
+ ITypeBinding memberType= getMemberType(selectedMember);
boolean[] implementsInterfaces= implementsInterfaces(memberType.getErasure(), new String[] { "java.util.Collection", "java.util.List", "java.util.Map" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean isCollection= implementsInterfaces[0];
boolean isList= implementsInterfaces[1];
boolean isMap= implementsInterfaces[2];
-
if (fContext.isLimitItems() && (isCollection || isMap) && !isList) {
needCollectionToStringMethod= true;
}
@@ -593,9 +590,8 @@ public abstract class AbstractToStringGenerator {
* last member)
*/
protected void addMember(Object member, boolean addSeparator) {
- String[] stringArray= fContext.getTemplateParser().getBody();
- for (int i= 0; i < stringArray.length; i++) {
- addElement(processElement(stringArray[i], member));
+ for (String element : fContext.getTemplateParser().getBody()) {
+ addElement(processElement(element, member));
}
if (addSeparator)
addElement(fContext.getTemplateParser().getSeparator());
@@ -861,30 +857,26 @@ public abstract class AbstractToStringGenerator {
protected String createNameSuggestion(String baseName, int variableKind) {
if (excluded == null) {
excluded= new HashSet<>();
- IVariableBinding[] fields= fContext.getTypeBinding().getDeclaredFields();
- for (int i= 0; i < fields.length; i++) {
- excluded.add(fields[i].getName());
+ for (IVariableBinding field : fContext.getTypeBinding().getDeclaredFields()) {
+ excluded.add(field.getName());
}
ITypeBinding superType= fContext.getTypeBinding().getSuperclass();
while (superType != null) {
- fields= superType.getDeclaredFields();
- for (int i= 0; i < fields.length; i++) {
- if (!Modifier.isPrivate(fields[i].getModifiers())) {
- excluded.add(fields[i].getName());
+ for (IVariableBinding field : superType.getDeclaredFields()) {
+ if (!Modifier.isPrivate(field.getModifiers())) {
+ excluded.add(field.getName());
}
}
superType= superType.getSuperclass();
}
- ITypeBinding[] types= fContext.getTypeBinding().getDeclaredTypes();
- for (int i= 0; i < types.length; i++) {
- excluded.add(types[i].getName());
+ for (ITypeBinding type : fContext.getTypeBinding().getDeclaredTypes()) {
+ excluded.add(type.getName());
}
superType= fContext.getTypeBinding().getSuperclass();
while (superType != null) {
- types= superType.getDeclaredTypes();
- for (int i= 0; i < types.length; i++) {
- if (!Modifier.isPrivate(types[i].getModifiers())) {
- excluded.add(types[i].getName());
+ for (ITypeBinding type : superType.getDeclaredTypes()) {
+ if (!Modifier.isPrivate(type.getModifiers())) {
+ excluded.add(type.getName());
}
}
superType= superType.getSuperclass();
@@ -907,9 +899,8 @@ public abstract class AbstractToStringGenerator {
if (memberType.getQualifiedName().equals(interfaceNames[i]))
result[i]= true;
}
- ITypeBinding[] interfaces= memberType.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- boolean[] deeper= implementsInterfaces(interfaces[i].getErasure(), interfaceNames);
+ for (ITypeBinding intf : memberType.getInterfaces()) {
+ boolean[] deeper= implementsInterfaces(intf.getErasure(), interfaceNames);
for (int j= 0; j < interfaceNames.length; j++) {
result[j]= result[j] || deeper[j];
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java
index 55c613dda8..b0fb3367c9 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java
@@ -101,9 +101,8 @@ public class StringBuilderChainGenerator extends StringBuilderGenerator {
ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
Block thenBlock= fAst.newBlock();
flushTemporaryExpression();
- String[] arrayString= getContext().getTemplateParser().getBody();
- for (int i= 0; i < arrayString.length; i++) {
- addElement(processElement(arrayString[i], member), thenBlock);
+ for (String s : getContext().getTemplateParser().getBody()) {
+ addElement(processElement(s, member), thenBlock);
}
if (addSeparator)
addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java
index 6f4bce431f..f982199a67 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java
@@ -113,9 +113,8 @@ public class StringBuilderGenerator extends AbstractToStringGenerator {
ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
Block thenBlock= fAst.newBlock();
flushBuffer(null);
- String[] arrayString= getContext().getTemplateParser().getBody();
- for (int i= 0; i < arrayString.length; i++) {
- addElement(processElement(arrayString[i], member), thenBlock);
+ for (String s : getContext().getTemplateParser().getBody()) {
+ addElement(processElement(s, member), thenBlock);
}
if (addSeparator)
addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java
index 36fa6924ae..251ea57af0 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java
@@ -138,9 +138,8 @@ public class StringConcatenationGenerator extends AbstractToStringGenerator {
cExpression.setExpression(infExpression);
SumExpressionBuilder builder= new SumExpressionBuilder(null);
- String[] arrayString= getContext().getTemplateParser().getBody();
- for (int i= 0; i < arrayString.length; i++) {
- addElement(processElement(arrayString[i], member), builder);
+ for (String s : getContext().getTemplateParser().getBody()) {
+ addElement(processElement(s, member), builder);
}
if (addSeparator)
addElement(getContext().getTemplateParser().getSeparator(), builder);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java
index 7ec9101a53..753b129580 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java
@@ -183,8 +183,8 @@ public class ToStringTemplateParser {
protected int firstOccuranceOf(String template, String[] wantedVariables) {
int result= -1;
- for (int i= 0; i < wantedVariables.length; i++) {
- int indexOf= template.indexOf(wantedVariables[i]);
+ for (String wantedVariable : wantedVariables) {
+ int indexOf= template.indexOf(wantedVariable);
if (result == -1 || (indexOf > 0 && indexOf < result))
result= indexOf;
}
@@ -198,11 +198,11 @@ public class ToStringTemplateParser {
break;
String foundVariable= null;
int variablePosition= template.length();
- for (int i= 0; i < wantedVariables.length; i++) {
- int position= template.indexOf(wantedVariables[i]);
+ for (String wantedVariable : wantedVariables) {
+ int position= template.indexOf(wantedVariable);
if (position >= 0 && position < variablePosition) {
variablePosition= position;
- foundVariable= wantedVariables[i];
+ foundVariable= wantedVariable;
}
}
if (variablePosition == template.length()) {
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java
index 8fe95facf5..a73a840dff 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java
@@ -141,8 +141,7 @@ public class ASTFlattener extends GenericVisitor {
}
void printAnnotationsList(List<? extends Annotation> annotations) {
- for (Iterator<? extends Annotation> it = annotations.iterator(); it.hasNext(); ) {
- Annotation annotation = it.next();
+ for (Annotation annotation : annotations) {
annotation.accept(this);
this.fBuffer.append(' ');
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java
index c3b9a84061..9c7cfbe139 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java
@@ -984,9 +984,7 @@ public class ASTNodes {
@Override
public boolean visit(ITypeBinding type) {
- IMethodBinding[] methods= type.getDeclaredMethods();
- for (int i= 0; i < methods.length; i++) {
- IMethodBinding candidate= methods[i];
+ for (IMethodBinding candidate : type.getDeclaredMethods()) {
if (candidate.getMethodDeclaration() == fOriginalMethod.getMethodDeclaration()) {
continue;
}
@@ -1261,8 +1259,7 @@ public class ASTNodes {
}
public static ASTNode findParent(ASTNode node, StructuralPropertyDescriptor[][] pathes) {
- for (int p= 0; p < pathes.length; p++) {
- StructuralPropertyDescriptor[] path= pathes[p];
+ for (StructuralPropertyDescriptor[] path : pathes) {
ASTNode current= node;
int d= path.length - 1;
for (; d >= 0 && current != null; d--) {
@@ -1407,8 +1404,7 @@ public class ASTNodes {
return problems;
final int iterations= computeIterations(scope);
List<IProblem> result= new ArrayList<>(5);
- for (int i= 0; i < problems.length; i++) {
- IProblem problem= problems[i];
+ for (IProblem problem : problems) {
boolean consider= false;
if ((severity & PROBLEMS) == PROBLEMS)
consider= true;
@@ -1445,8 +1441,7 @@ public class ASTNodes {
return messages;
final int iterations= computeIterations(flags);
List<Message> result= new ArrayList<>(5);
- for (int i= 0; i < messages.length; i++) {
- Message message= messages[i];
+ for (Message message : messages) {
ASTNode temp= node;
int count= iterations;
do {
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java
index ebe49c65c0..31041a21a3 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/Bindings.java
@@ -309,9 +309,7 @@ public class Bindings {
public static IVariableBinding findFieldInType(ITypeBinding type, String fieldName) {
if (type.isPrimitive())
return null;
- IVariableBinding[] fields= type.getDeclaredFields();
- for (int i= 0; i < fields.length; i++) {
- IVariableBinding field= fields[i];
+ for (IVariableBinding field : type.getDeclaredFields()) {
if (field.getName().equals(fieldName))
return field;
}
@@ -337,9 +335,8 @@ public class Bindings {
if (field != null)
return field;
}
- ITypeBinding[] interfaces= type.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- field= findFieldInHierarchy(interfaces[i], fieldName);
+ for (ITypeBinding intf : type.getInterfaces()) {
+ field= findFieldInHierarchy(intf, fieldName);
if (field != null) // no private fields in interfaces
return field;
}
@@ -358,14 +355,15 @@ public class Bindings {
public static IMethodBinding findMethodInType(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
if (type.isPrimitive())
return null;
- IMethodBinding[] methods= type.getDeclaredMethods();
- for (int i= 0; i < methods.length; i++) {
+ for (IMethodBinding method : type.getDeclaredMethods()) {
if (parameters == null) {
- if (methodName.equals(methods[i].getName()))
- return methods[i];
+ if (methodName.equals(method.getName())) {
+ return method;
+ }
} else {
- if (isEqualMethod(methods[i], methodName, parameters))
- return methods[i];
+ if (isEqualMethod(method, methodName, parameters)) {
+ return method;
+ }
}
}
return null;
@@ -392,9 +390,8 @@ public class Bindings {
if (method != null)
return method;
}
- ITypeBinding[] interfaces= type.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- method= findMethodInHierarchy(interfaces[i], methodName, parameters);
+ for (ITypeBinding intf : type.getInterfaces()) {
+ method= findMethodInHierarchy(intf, methodName, parameters);
if (method != null)
return method;
}
@@ -412,14 +409,15 @@ public class Bindings {
public static IMethodBinding findMethodInType(ITypeBinding type, String methodName, String[] parameters) {
if (type.isPrimitive())
return null;
- IMethodBinding[] methods= type.getDeclaredMethods();
- for (int i= 0; i < methods.length; i++) {
+ for (IMethodBinding method : type.getDeclaredMethods()) {
if (parameters == null) {
- if (methodName.equals(methods[i].getName()))
- return methods[i];
+ if (methodName.equals(method.getName())) {
+ return method;
+ }
} else {
- if (isEqualMethod(methods[i], methodName, parameters))
- return methods[i];
+ if (isEqualMethod(method, methodName, parameters)) {
+ return method;
+ }
}
}
return null;
@@ -442,14 +440,15 @@ public class Bindings {
public static IMethodBinding findMethodWithDeclaredParameterTypesInType(ITypeBinding type, String methodName, String[] parameters) {
if (type.isPrimitive())
return null;
- IMethodBinding[] methods= type.getDeclaredMethods();
- for (int i= 0; i < methods.length; i++) {
+ for (IMethodBinding method : type.getDeclaredMethods()) {
if (parameters == null) {
- if (methodName.equals(methods[i].getName()))
- return methods[i];
+ if (methodName.equals(method.getName())) {
+ return method;
+ }
} else {
- if (isEqualMethod(methods[i].getMethodDeclaration(), methodName, parameters))
- return methods[i];
+ if (isEqualMethod(method.getMethodDeclaration(), methodName, parameters)) {
+ return method;
+ }
}
}
return null;
@@ -475,9 +474,8 @@ public class Bindings {
if (method != null)
return method;
}
- ITypeBinding[] interfaces= type.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- method= findMethodInHierarchy(interfaces[i], methodName, parameters);
+ for (ITypeBinding intf : type.getInterfaces()) {
+ method= findMethodInHierarchy(intf, methodName, parameters);
if (method != null)
return method;
}
@@ -492,10 +490,10 @@ public class Bindings {
* @return the method binding of the method that is overridden by the specified <code>method</code>, or <code>null</code>
*/
public static IMethodBinding findOverriddenMethodInType(ITypeBinding type, IMethodBinding method) {
- IMethodBinding[] methods= type.getDeclaredMethods();
- for (int i= 0; i < methods.length; i++) {
- if (isSubsignature(method, methods[i]))
- return methods[i];
+ for (IMethodBinding curr : type.getDeclaredMethods()) {
+ if (isSubsignature(method, curr)) {
+ return curr;
+ }
}
return null;
}
@@ -518,9 +516,8 @@ public class Bindings {
if (method != null)
return method;
}
- ITypeBinding[] interfaces= type.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- method= findOverriddenMethodInHierarchy(interfaces[i], binding);
+ for (ITypeBinding intf : type.getInterfaces()) {
+ method= findOverriddenMethodInHierarchy(intf, binding);
if (method != null)
return method;
}
@@ -575,9 +572,8 @@ public class Bindings {
}
}
}
- ITypeBinding[] interfaces= type.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- IMethodBinding res= findOverriddenMethodInHierarchy(interfaces[i], overriding);
+ for (ITypeBinding intf : type.getInterfaces()) {
+ IMethodBinding res= findOverriddenMethodInHierarchy(intf, overriding);
if (res != null) {
methodList.add(res); // methods from interfaces are always public and therefore visible
if (firstOnly) {
@@ -614,9 +610,8 @@ public class Bindings {
private static void collectSuperTypes(ITypeBinding curr, Set<ITypeBinding> collection) {
if (collection.add(curr)) {
- ITypeBinding[] interfaces= curr.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- collectSuperTypes(interfaces[i], collection);
+ for (ITypeBinding intf : curr.getInterfaces()) {
+ collectSuperTypes(intf, collection);
}
ITypeBinding superClass= curr.getSuperclass();
if (superClass != null) {
@@ -661,12 +656,11 @@ public class Bindings {
boolean unvisited= visited.add(type);
if (!unvisited)
return true;
- ITypeBinding[] interfaces= type.getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- if (!visitor.visit(interfaces[i])) {
+ for (ITypeBinding intf : type.getInterfaces()) {
+ if (!visitor.visit(intf)) {
return false;
}
- if (!visitInterfaces(interfaces[i], visitor, visited)) {
+ if (!visitInterfaces(intf, visitor, visited)) {
return false;
}
}
@@ -812,9 +806,11 @@ public class Bindings {
}
private static boolean containsTypeVariables(ITypeBinding[] types) {
- for (int i= 0; i < types.length; i++)
- if (containsTypeVariables(types[i]))
+ for (ITypeBinding type : types) {
+ if (containsTypeVariables(type)) {
return true;
+ }
+ }
return false;
}
@@ -825,8 +821,7 @@ public class Bindings {
return Collections.emptySet();
Set<ITypeBinding> result= new HashSet<>(typeBounds.length);
- for (int i= 0; i < typeBounds.length; i++) {
- ITypeBinding bound= typeBounds[i];
+ for (ITypeBinding bound : typeBounds) {
if ("java.lang.Object".equals(typeBounds[0].getQualifiedName())) //$NON-NLS-1$
continue;
else if (containsTypeVariables(bound))
@@ -902,8 +897,8 @@ public class Bindings {
}
}
ITypeBinding[] superInterfaces= hierarchyType.getInterfaces();
- for (int i= 0; i < superInterfaces.length; i++) {
- ITypeBinding res= findTypeInHierarchy(superInterfaces[i], fullyQualifiedTypeName);
+ for (ITypeBinding superInterface : superInterfaces) {
+ ITypeBinding res= findTypeInHierarchy(superInterface, fullyQualifiedTypeName);
if (res != null) {
return res;
}
@@ -929,11 +924,10 @@ public class Bindings {
return superClass;
}
}
- ITypeBinding[] superInterfaces= hierarchyType.getInterfaces();
- for (int i= 0; i < superInterfaces.length; i++) {
- ITypeBinding res= findTypeInHierarchy(superInterfaces[i], fullyQualifiedTypeName);
+ for (ITypeBinding superInterface : hierarchyType.getInterfaces()) {
+ ITypeBinding res= findTypeInHierarchy(superInterface, fullyQualifiedTypeName);
if (res != null) {
- return superInterfaces[i];
+ return superInterface;
}
}
return null;
@@ -1006,9 +1000,8 @@ public class Bindings {
}
if (possibleSuperType.isInterface()) {
- ITypeBinding[] superInterfaces= type.getInterfaces();
- for (int i= 0; i < superInterfaces.length; i++) {
- if (isSuperType(possibleSuperType, superInterfaces[i], considerTypeArguments)) {
+ for (ITypeBinding superInterface : type.getInterfaces()) {
+ if (isSuperType(possibleSuperType, superInterface, considerTypeArguments)) {
return true;
}
}
@@ -1046,9 +1039,7 @@ public class Bindings {
public static IMethod findMethod(IMethodBinding method, IType type) throws JavaModelException {
method= method.getMethodDeclaration();
- IMethod[] candidates= type.getMethods();
- for (int i= 0; i < candidates.length; i++) {
- IMethod candidate= candidates[i];
+ for (IMethod candidate : type.getMethods()) {
if (candidate.getElementName().equals(method.getName()) && sameParameters(method, candidate)) {
return candidate;
}
@@ -1101,10 +1092,9 @@ public class Bindings {
return false;
String packageName= type.getPackage().isUnnamed() ? "" : type.getPackage().getName(); //$NON-NLS-1$
String typeName= getTypeQualifiedName(type);
- for (int i= 0; i < qualifiedCandidates.length; i++) {
- String[] qualifiedCandidate= qualifiedCandidates[i];
+ for (String[] qualifiedCandidate : qualifiedCandidates) {
if ( qualifiedCandidate[0].equals(packageName) &&
- qualifiedCandidate[1].equals(typeName))
+ qualifiedCandidate[1].equals(typeName))
return true;
}
}
@@ -1329,9 +1319,10 @@ public class Bindings {
*/
@Deprecated
public static boolean containsSignatureEquivalentConstructor(IMethodBinding[] candidates, IMethodBinding overridable) {
- for (int index= 0; index < candidates.length; index++) {
- if (isSignatureEquivalentConstructor(candidates[index], overridable))
+ for (IMethodBinding candidate : candidates) {
+ if (isSignatureEquivalentConstructor(candidate, overridable)) {
return true;
+ }
}
return false;
}
@@ -1386,14 +1377,13 @@ public class Bindings {
if (!overridableErasure.isSubTypeCompatible(overriddenErasure) || !overridableErasure.getKey().equals(overriddenErasure.getKey()))
return false;
}
- ITypeBinding[] overriddenExceptions= overridden.getExceptionTypes();
- ITypeBinding[] overridableExceptions= overridable.getExceptionTypes();
boolean checked= false;
- for (int index= 0; index < overriddenExceptions.length; index++) {
+ for (ITypeBinding overriddenException : overridden.getExceptionTypes()) {
checked= false;
- for (int offset= 0; offset < overridableExceptions.length; offset++) {
- if (overriddenExceptions[index].isSubTypeCompatible(overridableExceptions[offset]))
+ for (ITypeBinding overridableException : overridable.getExceptionTypes()) {
+ if (overriddenException.isSubTypeCompatible(overridableException)) {
checked= true;
+ }
}
if (!checked)
return false;
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/LinkedNodeFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/LinkedNodeFinder.java
index f91e609028..c49519eed0 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/LinkedNodeFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/LinkedNodeFinder.java
@@ -114,8 +114,7 @@ public class LinkedNodeFinder {
int nameOffset= nameNode.getStartPosition();
int nameInclEnd= nameOffset + nameNode.getLength() - 1;
- for (int i= 0; i < problems.length; i++) {
- IProblem curr= problems[i];
+ for (IProblem curr : problems) {
if (curr.getSourceStart() == nameOffset && curr.getSourceEnd() == nameInclEnd) {
int kind= getProblemKind(curr);
if (kind != 0) {
@@ -149,8 +148,7 @@ public class LinkedNodeFinder {
String name= nameNode.getIdentifier();
- for (int i= 0; i < problems.length; i++) {
- IProblem curr= problems[i];
+ for (IProblem curr : problems) {
int probStart= curr.getSourceStart();
int probEnd= curr.getSourceEnd() + 1;
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java
index ddecc5f667..790cee8f5c 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java
@@ -209,17 +209,15 @@ public class ScopeAnalyzer {
return false;
}
if (hasFlag(VARIABLES, flags)) {
- IVariableBinding[] variableBindings= binding.getDeclaredFields();
- for (int i= 0; i < variableBindings.length; i++) {
- if (requestor.acceptBinding(variableBindings[i]))
+ for (IVariableBinding variableBinding : binding.getDeclaredFields()) {
+ if (requestor.acceptBinding(variableBinding)) {
return true;
+ }
}
}
if (hasFlag(METHODS, flags)) {
- IMethodBinding[] methodBindings= binding.getDeclaredMethods();
- for (int i= 0; i < methodBindings.length; i++) {
- IMethodBinding curr= methodBindings[i];
+ for (IMethodBinding curr : binding.getDeclaredMethods()) {
if (isSuperInterfaceBinding && Modifier.isStatic(curr.getModifiers())) {
continue;
}
@@ -231,9 +229,7 @@ public class ScopeAnalyzer {
}
if (hasFlag(TYPES, flags)) {
- ITypeBinding[] typeBindings= binding.getDeclaredTypes();
- for (int i= 0; i < typeBindings.length; i++) {
- ITypeBinding curr= typeBindings[i];
+ for (ITypeBinding curr : binding.getDeclaredTypes()) {
if (requestor.acceptBinding(curr))
return true;
}
@@ -249,10 +245,10 @@ public class ScopeAnalyzer {
return true;
}
- ITypeBinding[] interfaces= binding.getInterfaces(); // includes looking for methods: abstract, unimplemented methods
- for (int i= 0; i < interfaces.length; i++) {
- if (addInherited(interfaces[i], true, flags, requestor)) // recursive
+ for (ITypeBinding intf : binding.getInterfaces()) {// includes looking for methods: abstract, unimplemented methods
+ if (addInherited(intf, true, flags, requestor)) {
return true;
+ }
}
return false;
}
@@ -270,10 +266,10 @@ public class ScopeAnalyzer {
if (requestor.acceptBinding(binding))
return true;
- ITypeBinding[] typeParameters= binding.getTypeParameters();
- for (int i= 0; i < typeParameters.length; i++) {
- if (requestor.acceptBinding(typeParameters[i]))
+ for (ITypeBinding typeParameter : binding.getTypeParameters()) {
+ if (requestor.acceptBinding(typeParameter)) {
return true;
+ }
}
}
@@ -516,8 +512,7 @@ public class ScopeAnalyzer {
private IVariableBinding[] getEnumContants(ITypeBinding binding) {
IVariableBinding[] declaredFields= binding.getDeclaredFields();
ArrayList<IVariableBinding> res= new ArrayList<>(declaredFields.length);
- for (int i= 0; i < declaredFields.length; i++) {
- IVariableBinding curr= declaredFields[i];
+ for (IVariableBinding curr : declaredFields) {
if (curr.isEnumConstant()) {
res.add(curr);
}
@@ -526,9 +521,7 @@ public class ScopeAnalyzer {
}
private boolean hasEnumContants(IBinding declaration, ITypeBinding binding) {
- IVariableBinding[] declaredFields= binding.getDeclaredFields();
- for (int i= 0; i < declaredFields.length; i++) {
- IVariableBinding curr= declaredFields[i];
+ for (IVariableBinding curr : binding.getDeclaredFields()) {
if (curr == declaration)
return true;
}
@@ -638,9 +631,8 @@ public class ScopeAnalyzer {
}
}
if (possibleSuperTypeDecl.isInterface()) {
- ITypeBinding[] superInterfaces= type.getInterfaces();
- for (int i= 0; i < superInterfaces.length; i++) {
- if (isInSuperTypeHierarchy(possibleSuperTypeDecl, superInterfaces[i].getTypeDeclaration())) {
+ for (ITypeBinding superInterface : type.getInterfaces()) {
+ if (isInSuperTypeHierarchy(possibleSuperTypeDecl, superInterface.getTypeDeclaration())) {
return true;
}
}
@@ -748,9 +740,7 @@ public class ScopeAnalyzer {
binding= switchExpression.getExpression().resolveTypeBinding();
}
if (binding != null && binding.isEnum()) {
- IVariableBinding[] declaredFields= binding.getDeclaredFields();
- for (int i= 0; i < declaredFields.length; i++) {
- IVariableBinding curr= declaredFields[i];
+ for (IVariableBinding curr : binding.getDeclaredFields()) {
if (curr.isEnumConstant()) {
fBreak= fRequestor.acceptBinding(curr);
if (fBreak)
@@ -913,13 +903,11 @@ public class ScopeAnalyzer {
public Collection<String> getUsedVariableNames(int offset, int length) {
HashSet<String> result= new HashSet<>();
- IBinding[] bindingsBefore= getDeclarationsInScope(offset, VARIABLES | CHECK_VISIBILITY);
- for (int i= 0; i < bindingsBefore.length; i++) {
- result.add(bindingsBefore[i].getName());
+ for (IBinding b : getDeclarationsInScope(offset, VARIABLES | CHECK_VISIBILITY)) {
+ result.add(b.getName());
}
- IBinding[] bindingsAfter= getDeclarationsAfter(offset + length, VARIABLES | CHECK_VISIBILITY);
- for (int i= 0; i < bindingsAfter.length; i++) {
- result.add(bindingsAfter[i].getName());
+ for (IBinding b : getDeclarationsAfter(offset + length, VARIABLES | CHECK_VISIBILITY)) {
+ result.add(b.getName());
}
List<ImportDeclaration> imports= fRoot.imports();
for (int i= 0; i < imports.size(); i++) {
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CompilationUnitRewriteOperationsFixCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CompilationUnitRewriteOperationsFixCore.java
index d3c32df6ea..0f3202631d 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CompilationUnitRewriteOperationsFixCore.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CompilationUnitRewriteOperationsFixCore.java
@@ -94,8 +94,7 @@ public class CompilationUnitRewriteOperationsFixCore extends AbstractFix {
CompilationUnitRewrite cuRewrite= new CompilationUnitRewrite((ICompilationUnit)fCompilationUnit.getJavaElement(), fCompilationUnit);
fLinkedProposalModel.clear();
- for (int i= 0; i < fOperations.length; i++) {
- CompilationUnitRewriteOperation operation= fOperations[i];
+ for (CompilationUnitRewriteOperation operation : fOperations) {
operation.rewriteAST(cuRewrite, fLinkedProposalModel);
}
@@ -109,8 +108,7 @@ public class CompilationUnitRewriteOperationsFixCore extends AbstractFix {
@Override
public String getAdditionalProposalInfo(){
StringBuilder sb= new StringBuilder();
- for (int i= 0; i < fOperations.length; i++) {
- CompilationUnitRewriteOperation operation= fOperations[i];
+ for (CompilationUnitRewriteOperation operation : fOperations) {
String info= operation.getAdditionalInfo();
if (info != null)
sb.append(info);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java
index 42a66879a7..7c1bb5ffdc 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java
@@ -271,8 +271,9 @@ public class Checks {
public static RefactoringStatus checkForMainAndNativeMethods(IType[] types) throws JavaModelException {
RefactoringStatus result= new RefactoringStatus();
- for (int i= 0; i < types.length; i++)
- result.merge(checkForMainAndNativeMethods(types[i]));
+ for (IType type : types) {
+ result.merge(checkForMainAndNativeMethods(type));
+ }
return result;
}
@@ -285,18 +286,17 @@ public class Checks {
private static RefactoringStatus checkForMainAndNativeMethods(IMethod[] methods) throws JavaModelException {
RefactoringStatus result= new RefactoringStatus();
- for (int i= 0; i < methods.length; i++) {
- if (JdtFlags.isNative(methods[i])){
- String typeName= JavaElementLabelsCore.getElementLabel(methods[i].getDeclaringType(), JavaElementLabelsCore.ALL_FULLY_QUALIFIED);
- String methodName= JavaElementLabelsCore.getElementLabel(methods[i], JavaElementLabelsCore.ALL_DEFAULT);
+ for (IMethod method : methods) {
+ if (JdtFlags.isNative(method)) {
+ String typeName= JavaElementLabelsCore.getElementLabel(method.getDeclaringType(), JavaElementLabelsCore.ALL_FULLY_QUALIFIED);
+ String methodName= JavaElementLabelsCore.getElementLabel(method, JavaElementLabelsCore.ALL_DEFAULT);
String msg= Messages.format(RefactoringCoreMessages.Checks_method_native,
- new String[]{typeName, methodName, "UnsatisfiedLinkError"});//$NON-NLS-1$
- result.addEntry(RefactoringStatus.ERROR, msg, JavaStatusContext.create(methods[i]), JavaManipulation.getPreferenceNodeId(), RefactoringStatusCodes.NATIVE_METHOD);
+ new String[]{typeName, methodName, "UnsatisfiedLinkError"});//$NON-NLS-1$
+ result.addEntry(RefactoringStatus.ERROR, msg, JavaStatusContext.create(method), JavaManipulation.getPreferenceNodeId(), RefactoringStatusCodes.NATIVE_METHOD);
}
- if (methods[i].isMainMethod()) {
- String msg= Messages.format(RefactoringCoreMessages.Checks_has_main,
- JavaElementLabelsCore.getElementLabel(methods[i].getDeclaringType(), JavaElementLabelsCore.ALL_FULLY_QUALIFIED));
- result.addEntry(RefactoringStatus.WARNING, msg, JavaStatusContext.create(methods[i]), JavaManipulation.getPreferenceNodeId(), RefactoringStatusCodes.MAIN_METHOD);
+ if (method.isMainMethod()) {
+ String msg= Messages.format(RefactoringCoreMessages.Checks_has_main, JavaElementLabelsCore.getElementLabel(method.getDeclaringType(), JavaElementLabelsCore.ALL_FULLY_QUALIFIED));
+ result.addEntry(RefactoringStatus.WARNING, msg, JavaStatusContext.create(method), JavaManipulation.getPreferenceNodeId(), RefactoringStatusCodes.MAIN_METHOD);
}
}
return result;
@@ -542,8 +542,7 @@ public class Checks {
*/
public static IMethod findSimilarMethod(IMethod method, IMethod[] methods) throws JavaModelException {
boolean isConstructor= method.isConstructor();
- for (int i= 0; i < methods.length; i++) {
- IMethod otherMethod= methods[i];
+ for (IMethod otherMethod : methods) {
if (otherMethod.isConstructor() == isConstructor && method.isSimilar(otherMethod))
return otherMethod;
}
@@ -593,8 +592,8 @@ public class Checks {
public static SearchResultGroup[] excludeCompilationUnits(SearchResultGroup[] grouped, RefactoringStatus status) throws JavaModelException{
List<SearchResultGroup> result= new ArrayList<>();
boolean wasEmpty= grouped.length == 0;
- for (int i= 0; i < grouped.length; i++){
- IResource resource= grouped[i].getResource();
+ for (SearchResultGroup g : grouped) {
+ IResource resource= g.getResource();
IJavaElement element= JavaCore.create(resource);
if (! (element instanceof ICompilationUnit))
continue;
@@ -604,7 +603,7 @@ public class Checks {
status.addError(Messages.format(RefactoringCoreMessages.Checks_cannot_be_parsed, BasicElementLabels.getPathLabel(cu.getPath(), false)));
continue; //removed, go to the next one
}
- result.add(grouped[i]);
+ result.add(g);
}
if ((!wasEmpty) && result.isEmpty())
@@ -615,8 +614,9 @@ public class Checks {
public static RefactoringStatus checkCompileErrorsInAffectedFiles(SearchResultGroup[] grouped) throws JavaModelException {
RefactoringStatus result= new RefactoringStatus();
- for (int i= 0; i < grouped.length; i++)
- checkCompileErrorsInAffectedFile(result, grouped[i].getResource());
+ for (SearchResultGroup g : grouped) {
+ checkCompileErrorsInAffectedFile(result, g.getResource());
+ }
return result;
}
@@ -627,8 +627,8 @@ public class Checks {
public static RefactoringStatus checkCompileErrorsInAffectedFiles(SearchResultGroup[] references, IResource declaring) throws JavaModelException {
RefactoringStatus result= new RefactoringStatus();
- for (int i= 0; i < references.length; i++){
- IResource resource= references[i].getResource();
+ for (SearchResultGroup reference : references) {
+ IResource resource= reference.getResource();
if (resource.equals(declaring))
declaring= null;
checkCompileErrorsInAffectedFile(result, resource);
@@ -640,10 +640,10 @@ public class Checks {
private static boolean hasCompileErrors(IResource resource) throws JavaModelException {
try {
- IMarker[] problemMarkers= resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
- for (int i= 0; i < problemMarkers.length; i++) {
- if (problemMarkers[i].getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR)
+ for (IMarker problemMarker : resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE)) {
+ if (problemMarker.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR) {
return true;
+ }
}
return false;
} catch (JavaModelException e){
@@ -678,10 +678,10 @@ public class Checks {
IContainer container= (IContainer)res;
try {
- IResource[] children= container.members();
- for (int i= 0; i < children.length; i++) {
- if (isReadOnly(children[i]))
+ for (IResource child : container.members()) {
+ if (isReadOnly(child)) {
return true;
+ }
}
return false;
} catch (JavaModelException e){
@@ -724,8 +724,8 @@ public class Checks {
ResourceChangeChecker checker= context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory();
- for (int i= 0; i < filesToModify.length; i++) {
- deltaFactory.change(filesToModify[i]);
+ for (IFile file : filesToModify) {
+ deltaFactory.change(file);
}
}
@@ -850,9 +850,10 @@ public class Checks {
if (! iType.isClass())
return false;
IType[] superTypes= iType.newSupertypeHierarchy(pm).getAllSupertypes(iType);
- for (int i= 0; i < superTypes.length; i++) {
- if ("java.lang.Throwable".equals(superTypes[i].getFullyQualifiedName())) //$NON-NLS-1$
+ for (IType superType : superTypes) {
+ if ("java.lang.Throwable".equals(superType.getFullyQualifiedName())) { //$NON-NLS-1$
return true;
+ }
}
return false;
} finally{
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/JDTRefactoringDescriptorComment.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/JDTRefactoringDescriptorComment.java
index 4de039323a..8e3f5b5d08 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/JDTRefactoringDescriptorComment.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/JDTRefactoringDescriptorComment.java
@@ -64,11 +64,11 @@ public final class JDTRefactoringDescriptorComment {
Assert.isNotNull(caption);
Assert.isNotNull(settings);
final StringBuilder buffer= new StringBuilder(128);
- for (int index= 0; index < settings.length; index++) {
- if (settings[index] != null && !"".equals(settings[index])) { //$NON-NLS-1$
+ for (String setting : settings) {
+ if (setting != null && !"".equals(setting)) { //$NON-NLS-1$
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
- buffer.append(settings[index]);
+ buffer.append(setting);
} else {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
@@ -193,11 +193,11 @@ public final class JDTRefactoringDescriptorComment {
else if (elements.length > 1) {
final StringBuilder buffer= new StringBuilder(128);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_original_elements);
- for (int index= 0; index < elements.length; index++) {
- if (elements[index] != null) {
+ for (Object element : elements) {
+ if (element != null) {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
- buffer.append(JavaElementLabelsCore.getTextLabel(elements[index], JavaElementLabelsCore.ALL_FULLY_QUALIFIED));
+ buffer.append(JavaElementLabelsCore.getTextLabel(element, JavaElementLabelsCore.ALL_FULLY_QUALIFIED));
} else {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
@@ -227,11 +227,11 @@ public final class JDTRefactoringDescriptorComment {
else if (elements.length > 1) {
final StringBuilder buffer= new StringBuilder(128);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_original_elements);
- for (int index= 0; index < elements.length; index++) {
- if (elements[index] != null) {
+ for (Object element : elements) {
+ if (element != null) {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
- buffer.append(JavaElementLabelsCore.getTextLabel(elements[index], JavaElementLabelsCore.ALL_FULLY_QUALIFIED));
+ buffer.append(JavaElementLabelsCore.getTextLabel(element, JavaElementLabelsCore.ALL_FULLY_QUALIFIED));
} else {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/SearchResultGroup.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/SearchResultGroup.java
index 2138faea42..26ad9391e8 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/SearchResultGroup.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/SearchResultGroup.java
@@ -55,8 +55,8 @@ public class SearchResultGroup {
public static IResource[] getResources(SearchResultGroup[] searchResultGroups){
Set<IResource> resourceSet= new HashSet<>(searchResultGroups.length);
- for (int i= 0; i < searchResultGroups.length; i++) {
- resourceSet.add(searchResultGroups[i].getResource());
+ for (SearchResultGroup searchResultGroup : searchResultGroups) {
+ resourceSet.add(searchResultGroup.getResource());
}
return resourceSet.toArray(new IResource[resourceSet.size()]);
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/CompilationUnitChange.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/CompilationUnitChange.java
index 8c936a2aa9..3e4a4275e8 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/CompilationUnitChange.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/CompilationUnitChange.java
@@ -56,9 +56,9 @@ public class CompilationUnitChange extends org.eclipse.jdt.core.refactoring.Comp
setKeepPreviewEdits(change.getKeepPreviewEdits());
setSaveMode(change.getSaveMode());
setTextType(change.getTextType());
- TextEditBasedChangeGroup[] groups= change.getChangeGroups();
- for (int i= 0; i < groups.length; i++)
- addChangeGroup(groups[i]);
+ for (TextEditBasedChangeGroup group : change.getChangeGroups()) {
+ addChangeGroup(group);
+ }
}
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/TextChangeCompatibility.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/TextChangeCompatibility.java
index 5168fd2360..17d1f20bb6 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/TextChangeCompatibility.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/TextChangeCompatibility.java
@@ -68,8 +68,7 @@ public class TextChangeCompatibility {
}
TextEdit[] children= parent.getChildren();
// First dive down to find the right parent.
- for (int i= 0; i < children.length; i++) {
- TextEdit child= children[i];
+ for (TextEdit child : children) {
if (covers(child, edit)) {
insert(child, edit);
return;
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java
index 8ed162a6a9..9657219079 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java
@@ -339,13 +339,10 @@ public class InlineTempRefactoring extends Refactoring {
}
private void inlineTemp(CompilationUnitRewrite cuRewrite) throws JavaModelException {
- SimpleName[] references= getReferences();
-
TextEditGroup groupDesc= cuRewrite.createGroupDescription(RefactoringCoreMessages.InlineTempRefactoring_inline_edit_name);
ASTRewrite rewrite= cuRewrite.getASTRewrite();
- for (int i= 0; i < references.length; i++){
- SimpleName curr= references[i];
+ for (SimpleName curr : getReferences()) {
ASTNode initializerCopy= getInitializerSource(cuRewrite, curr);
rewrite.replace(curr, initializerCopy, groupDesc);
}
@@ -430,8 +427,8 @@ public class InlineTempRefactoring extends Refactoring {
ASTRewrite rewrite= ASTRewrite.create(invocation.getAST());
ListRewrite typeArgsRewrite= Invocations.getInferredTypeArgumentsRewrite(rewrite, invocation);
- for (int i= 0; i < typeArguments.length; i++) {
- Type typeArgumentNode= cuRewrite.getImportRewrite().addImport(typeArguments[i], cuRewrite.getAST());
+ for (ITypeBinding typeArgument : typeArguments) {
+ Type typeArgumentNode = cuRewrite.getImportRewrite().addImport(typeArgument, cuRewrite.getAST());
typeArgsRewrite.insertLast(typeArgumentNode, null);
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java
index 1047e0f4fd..b601a515e7 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/rename/RenamingNameSuggestor.java
@@ -465,8 +465,8 @@ public class RenamingNameSuggestor {
private String concat(String[] suffixesNewEqual) {
StringBuilder returner= new StringBuilder();
- for (int j= 0; j < suffixesNewEqual.length; j++) {
- returner.append(suffixesNewEqual[j]);
+ for (String s : suffixesNewEqual) {
+ returner.append(s);
}
return returner.toString();
}
@@ -503,11 +503,11 @@ public class RenamingNameSuggestor {
private String findLongestPrefix(String name, String[] prefixes) {
String usedPrefix= ""; //$NON-NLS-1$
int bestLen= 0;
- for (int i= 0; i < prefixes.length; i++) {
- if (name.startsWith(prefixes[i])) {
- if (prefixes[i].length() > bestLen) {
- bestLen= prefixes[i].length();
- usedPrefix= prefixes[i];
+ for (String prefix : prefixes) {
+ if (name.startsWith(prefix)) {
+ if (prefix.length() > bestLen) {
+ bestLen= prefix.length();
+ usedPrefix= prefix;
}
}
}
@@ -517,11 +517,11 @@ public class RenamingNameSuggestor {
private String findLongestSuffix(String name, String[] suffixes) {
String usedPrefix= ""; //$NON-NLS-1$
int bestLen= 0;
- for (int i= 0; i < suffixes.length; i++) {
- if (name.endsWith(suffixes[i])) {
- if (suffixes[i].length() > bestLen) {
- bestLen= suffixes[i].length();
- usedPrefix= suffixes[i];
+ for (String suffix : suffixes) {
+ if (name.endsWith(suffix)) {
+ if (suffix.length() > bestLen) {
+ bestLen= suffix.length();
+ usedPrefix= suffix;
}
}
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java
index 6ccda62daf..c006eab70e 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java
@@ -307,16 +307,15 @@ public class ImportRemover {
}
public void applyRemoves(ImportRewrite importRewrite) {
- IBinding[] bindings= getImportsToRemove();
- for (int i= 0; i < bindings.length; i++) {
- if (bindings[i] instanceof ITypeBinding) {
- ITypeBinding typeBinding= (ITypeBinding) bindings[i];
+ for (IBinding b : getImportsToRemove()) {
+ if (b instanceof ITypeBinding) {
+ ITypeBinding typeBinding= (ITypeBinding) b;
importRewrite.removeImport(typeBinding.getTypeDeclaration().getQualifiedName());
- } else if (bindings[i] instanceof IMethodBinding) {
- IMethodBinding binding= (IMethodBinding) bindings[i];
+ } else if (b instanceof IMethodBinding) {
+ IMethodBinding binding= (IMethodBinding) b;
importRewrite.removeStaticImport(binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName());
- } else if (bindings[i] instanceof IVariableBinding) {
- IVariableBinding binding= (IVariableBinding) bindings[i];
+ } else if (b instanceof IVariableBinding) {
+ IVariableBinding binding= (IVariableBinding) b;
importRewrite.removeStaticImport(binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName());
}
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/AbstractTypeVariable.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/AbstractTypeVariable.java
index ada2529639..3aacdddcf8 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/AbstractTypeVariable.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/AbstractTypeVariable.java
@@ -66,9 +66,10 @@ public abstract class AbstractTypeVariable extends TType {
protected final boolean checkAssignmentBound(TType rhs) {
if (fBounds.length == 0)
return true;
- for (int i= 0; i < fBounds.length; i++) {
- if (rhs.canAssignTo(fBounds[i]))
+ for (TType bound : fBounds) {
+ if (rhs.canAssignTo(bound)) {
return true;
+ }
}
return false;
}
@@ -76,9 +77,10 @@ public abstract class AbstractTypeVariable extends TType {
protected final boolean canAssignOneBoundTo(TType lhs) {
if (fBounds.length == 0)
return lhs.isJavaLangObject();
- for (int i= 0; i < fBounds.length; i++) {
- if (fBounds[i].canAssignTo(lhs))
+ for (TType bound : fBounds) {
+ if (bound.canAssignTo(lhs)) {
return true;
+ }
}
return false;
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/HierarchyType.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/HierarchyType.java
index a52ecb72bb..fad41f9157 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/HierarchyType.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/HierarchyType.java
@@ -78,9 +78,10 @@ public abstract class HierarchyType extends TType {
private boolean doIsSubType(HierarchyType other) {
if (fSuperclass != null && (other.isTypeEquivalentTo(fSuperclass) || fSuperclass.doIsSubType(other)))
return true;
- for (int i= 0; i < fInterfaces.length; i++) {
- if (other.isTypeEquivalentTo(fInterfaces[i]) || fInterfaces[i].doIsSubType(other))
+ for (HierarchyType intf : fInterfaces) {
+ if (other.isTypeEquivalentTo(intf) || intf.doIsSubType(other)) {
return true;
+ }
}
return false;
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/ParameterizedType.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/ParameterizedType.java
index b9068cf87e..1a138a8c4c 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/ParameterizedType.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/ParameterizedType.java
@@ -141,9 +141,8 @@ public final class ParameterizedType extends HierarchyType {
if (result != null)
return result;
}
- TType[] interfaces= getInterfaces();
- for (int i= 0; i < interfaces.length; i++) {
- type= interfaces[i];
+ for (TType intf : getInterfaces()) {
+ type= intf;
if (type != null && type.getKind() == PARAMETERIZED_TYPE) {
result= ((ParameterizedType)type).findSameDeclaration(targetDeclaration);
if (result != null)
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java
index 246aae3348..3ef28048c0 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java
@@ -140,8 +140,7 @@ public class TypeEnvironment {
public static ITypeBinding[] createTypeBindings(TType[] types, IJavaProject project) {
final Map<String, Object> mapping= new HashMap<>();
List<String> keys= new ArrayList<>();
- for (int i= 0; i < types.length; i++) {
- TType type= types[i];
+ for (TType type : types) {
String bindingKey= type.getBindingKey();
mapping.put(bindingKey, type);
keys.add(bindingKey);
@@ -309,8 +308,8 @@ public class TypeEnvironment {
}
private void cacheSubTypes(TType[] interfaces, TType result) {
- for (int i= 0; i < interfaces.length; i++) {
- cacheSubType(interfaces[i], result);
+ for (TType intf : interfaces) {
+ cacheSubType(intf, result);
}
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeVariable.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeVariable.java
index 2164e85d00..b7b410c50e 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeVariable.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeVariable.java
@@ -80,8 +80,7 @@ public final class TypeVariable extends AbstractTypeVariable {
}
private boolean doExtends(TypeVariable other) {
- for (int i= 0; i < fBounds.length; i++) {
- TType bound= fBounds[i];
+ for (TType bound : fBounds) {
if (other.equals(bound) || (bound.getKind() == TYPE_VARIABLE && ((TypeVariable)bound).doExtends(other)))
return true;
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java
index 1fd7267c0a..feeae6b426 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java
@@ -88,8 +88,7 @@ public class JavaElementUtil {
public static IJavaElement[] getElementsOfType(IJavaElement[] elements, int type){
Set<IJavaElement> result= new HashSet<>(elements.length);
- for (int i= 0; i < elements.length; i++) {
- IJavaElement element= elements[i];
+ for (IJavaElement element : elements) {
if (element.getElementType() == type)
result.add(element);
}
@@ -97,10 +96,10 @@ public class JavaElementUtil {
}
public static IType getMainType(ICompilationUnit cu) throws JavaModelException{
- IType[] types= cu.getTypes();
- for (int i = 0; i < types.length; i++) {
- if (isMainType(types[i]))
- return types[i];
+ for (IType type : cu.getTypes()) {
+ if (isMainType(type)) {
+ return type;
+ }
}
return null;
}
@@ -144,9 +143,7 @@ public class JavaElementUtil {
if (JavaModelUtil.isInterfaceOrAnnotation(type))
return new IMethod[0];
List<IMethod> result= new ArrayList<>();
- IMethod[] methods= type.getMethods();
- for (int i= 0; i < methods.length; i++) {
- IMethod iMethod= methods[i];
+ for (IMethod iMethod : type.getMethods()) {
if (iMethod.isConstructor())
result.add(iMethod);
}
@@ -164,8 +161,7 @@ public class JavaElementUtil {
cpe= root.getResolvedClasspathEntry();
IJavaProject[] allJavaProjects= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
List<IJavaProject> result= new ArrayList<>(allJavaProjects.length);
- for (int i= 0; i < allJavaProjects.length; i++) {
- IJavaProject project= allJavaProjects[i];
+ for (IJavaProject project : allJavaProjects) {
IPackageFragmentRoot[] roots= project.findPackageFragmentRoots(cpe);
if (roots.length > 0)
result.add(project);
@@ -176,13 +172,11 @@ public class JavaElementUtil {
public static IMember[] merge(IMember[] a1, IMember[] a2) {
// Don't use hash sets since ordering is important for some refactorings.
List<IMember> result= new ArrayList<>(a1.length + a2.length);
- for (int i= 0; i < a1.length; i++) {
- IMember member= a1[i];
+ for (IMember member : a1) {
if (!result.contains(member))
result.add(member);
}
- for (int i= 0; i < a2.length; i++) {
- IMember member= a2[i];
+ for (IMember member : a2) {
if (!result.contains(member))
result.add(member);
}
@@ -203,12 +197,11 @@ public class JavaElementUtil {
return new IPackageFragment[] { pack };
IPackageFragmentRoot root= (IPackageFragmentRoot) pack.getParent();
- IJavaElement[] allPackages= root.getChildren();
ArrayList<IPackageFragment> subpackages= new ArrayList<>();
subpackages.add(pack);
String prefix= pack.getElementName() + '.';
- for (int i= 0; i < allPackages.length; i++) {
- IPackageFragment currentPackage= (IPackageFragment) allPackages[i];
+ for (IJavaElement packageFragment : root.getChildren()) {
+ IPackageFragment currentPackage = (IPackageFragment) packageFragment;
if (currentPackage.getElementName().startsWith(prefix))
subpackages.add(currentPackage);
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/ResourceUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/ResourceUtil.java
index 1d4c038ba8..d58b77a3e1 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/ResourceUtil.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/ResourceUtil.java
@@ -31,8 +31,8 @@ public class ResourceUtil {
public static IFile[] getFiles(ICompilationUnit[] cus) {
List<IResource> files= new ArrayList<>(cus.length);
- for (int i= 0; i < cus.length; i++) {
- IResource resource= cus[i].getResource();
+ for (ICompilationUnit cu : cus) {
+ IResource resource= cu.getResource();
if (resource != null && resource.getType() == IResource.FILE)
files.add(resource);
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/StatementAnalyzer.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/StatementAnalyzer.java
index 3ca9ffef33..885533da8d 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/StatementAnalyzer.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/StatementAnalyzer.java
@@ -163,8 +163,7 @@ public class StatementAnalyzer extends SelectionAnalyzer {
ASTNode[] selectedNodes= getSelectedNodes();
if (doAfterValidation(node, selectedNodes)) {
List<SwitchCase> cases= getSwitchCases(node);
- for (int i= 0; i < selectedNodes.length; i++) {
- ASTNode topNode= selectedNodes[i];
+ for (ASTNode topNode : selectedNodes) {
if (cases.contains(topNode)) {
invalidSelection(JavaManipulationMessages.StatementAnalyzer_switch_statement);
break;
@@ -179,8 +178,7 @@ public class StatementAnalyzer extends SelectionAnalyzer {
ASTNode[] selectedNodes= getSelectedNodes();
if (doAfterValidation(node, selectedNodes)) {
List<SwitchCase> cases= getSwitchCases(node);
- for (int i= 0; i < selectedNodes.length; i++) {
- ASTNode topNode= selectedNodes[i];
+ for (ASTNode topNode : selectedNodes) {
if (cases.contains(topNode)) {
invalidSelection(JavaManipulationMessages.StatementAnalyzer_switch_expression);
break;
@@ -264,17 +262,19 @@ public class StatementAnalyzer extends SelectionAnalyzer {
}
protected static boolean contains(ASTNode[] nodes, ASTNode node) {
- for (int i = 0; i < nodes.length; i++) {
- if (nodes[i] == node)
+ for (ASTNode n : nodes) {
+ if (n == node) {
return true;
+ }
}
return false;
}
protected static boolean contains(ASTNode[] nodes, List<Expression> list) {
- for (int i = 0; i < nodes.length; i++) {
- if (list.contains(nodes[i]))
+ for (ASTNode node : nodes) {
+ if (list.contains(node)) {
return true;
+ }
}
return false;
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/SurroundWithAnalyzer.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/SurroundWithAnalyzer.java
index 87e8fe2bab..deef29de8d 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/SurroundWithAnalyzer.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/SurroundWithAnalyzer.java
@@ -141,9 +141,7 @@ public class SurroundWithAnalyzer extends CodeAnalyzer {
}
private boolean validSelectedNodes() {
- ASTNode[] nodes= getSelectedNodes();
- for (int i= 0; i < nodes.length; i++) {
- ASTNode node= nodes[i];
+ for (ASTNode node : getSelectedNodes()) {
boolean isValidNode= node instanceof Statement;
if (fSurroundWithTryCatch) { // allow method reference and lambda's expression body also
isValidNode= isValidNode || node instanceof MethodReference || node.getLocationInParent() == LambdaExpression.BODY_PROPERTY;
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TextEditUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TextEditUtil.java
index 5868ad9116..3f235d455e 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TextEditUtil.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TextEditUtil.java
@@ -68,9 +68,10 @@ public class TextEditUtil {
if (edit.getExclusiveEnd() != children[children.length - 1].getExclusiveEnd())
return false;
- for (int i= 0; i < children.length; i++) {
- if (!isPacked(children[i]))
+ for (TextEdit child : children) {
+ if (!isPacked(child)) {
return false;
+ }
}
return true;
@@ -95,9 +96,7 @@ public class TextEditUtil {
if (!edit.hasChildren()) {
result.addChild(edit);
} else {
- TextEdit[] children= edit.getChildren();
- for (int i= 0; i < children.length; i++) {
- TextEdit child= children[i];
+ for (TextEdit child : edit.getChildren()) {
child.getParent().removeChild(0);
flatten(child, result);
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java
index c8e4deeaea..f6b3796ea4 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java
@@ -57,13 +57,11 @@ public class TightSourceRangeComputer extends TargetSourceRangeComputer {
addTightSourceNode(child);
}
} else if (descriptor.isChildListProperty()) {
- List<? extends ASTNode> children= ASTNodes.getChildListProperty(reference, (ChildListPropertyDescriptor) descriptor);
- for (Iterator<? extends ASTNode> iterator2= children.iterator(); iterator2.hasNext();) {
- ASTNode child= iterator2.next();
- if (isExtending(child, reference)) {
- addTightSourceNode(child);
- }
- }
+ for (ASTNode child : ASTNodes.getChildListProperty(reference, (ChildListPropertyDescriptor) descriptor)) {
+ if (isExtending(child, reference)) {
+ addTightSourceNode(child);
+ }
+ }
}
}
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/SignatureUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/SignatureUtil.java
index 34ab17780f..5ce78b9ac8 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/SignatureUtil.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/template/java/SignatureUtil.java
@@ -169,10 +169,11 @@ public final class SignatureUtil {
return NULL_TYPE_SIGNATURE_ARRAY;
}
- char[][] typeArguments= Signature.getTypeArguments(signature);
- for (int i= 0; i < typeArguments.length; i++)
- if (Arrays.equals(typeArguments[i], NULL_TYPE_SIGNATURE_ARRAY))
+ for (char[] typeArgument : Signature.getTypeArguments(signature)) {
+ if (Arrays.equals(typeArgument, NULL_TYPE_SIGNATURE_ARRAY)) {
return NULL_TYPE_SIGNATURE_ARRAY;
+ }
+ }
if (signature[0] == Signature.C_SUPER) {
char[] type= new char[signature.length - 1];
@@ -275,9 +276,7 @@ public final class SignatureUtil {
}
StringBuilder res= new StringBuilder("("); //$NON-NLS-1$
- char[][] parameters= Signature.getParameterTypes(signature);
- for (int i= 0; i < parameters.length; i++) {
- char[] param= parameters[i];
+ for (char[] param : Signature.getParameterTypes(signature)) {
res.append(getLowerBound(param));
}
res.append(')');
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java
index 93c2211b5f..d71c00f57c 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java
@@ -168,11 +168,10 @@ public final class JavaModelUtil {
* @throws JavaModelException thrown when the cu can not be accessed
*/
public static IType findTypeInCompilationUnit(ICompilationUnit cu, String typeQualifiedName) throws JavaModelException {
- IType[] types= cu.getAllTypes();
- for (int i= 0; i < types.length; i++) {
- String currName= types[i].getTypeQualifiedName('.');
+ for (IType type : cu.getAllTypes()) {
+ String currName= type.getTypeQualifiedName('.');
if (typeQualifiedName.equals(currName)) {
- return types[i];
+ return type;
}
}
return null;
@@ -352,10 +351,9 @@ public final class JavaModelUtil {
* @throws JavaModelException thrown when the type can not be accessed
*/
public static IMethod findMethod(String name, String[] paramTypes, boolean isConstructor, IType type) throws JavaModelException {
- IMethod[] methods= type.getMethods();
- for (int i= 0; i < methods.length; i++) {
- if (isSameMethodSignature(name, paramTypes, isConstructor, methods[i])) {
- return methods[i];
+ for (IMethod method : type.getMethods()) {
+ if (isSameMethodSignature(name, paramTypes, isConstructor, method)) {
+ return method;
}
}
return null;
@@ -388,9 +386,8 @@ public final class JavaModelUtil {
}
}
if (!isConstructor) {
- IType[] superInterfaces= hierarchy.getSuperInterfaces(type);
- for (int i= 0; i < superInterfaces.length; i++) {
- IMethod res= findMethodInHierarchy(hierarchy, superInterfaces[i], name, paramTypes, false);
+ for (IType superInterface : hierarchy.getSuperInterfaces(type)) {
+ IMethod res= findMethodInHierarchy(hierarchy, superInterface, name, paramTypes, false);
if (res != null) {
return res;
}
@@ -448,9 +445,8 @@ public final class JavaModelUtil {
* @throws JavaModelException thrown when the type can not be accessed
*/
public static boolean hasMainMethod(IType type) throws JavaModelException {
- IMethod[] methods= type.getMethods();
- for (int i= 0; i < methods.length; i++) {
- if (methods[i].isMainMethod()) {
+ for (IMethod method : type.getMethods()) {
+ if (method.isMainMethod()) {
return true;
}
}
@@ -597,9 +593,7 @@ public final class JavaModelUtil {
return true;
}
if (Flags.isInterface(hierarchy.getCachedFlags(possibleSuperType))) {
- IType[] superInterfaces= hierarchy.getSuperInterfaces(type);
- for (int i= 0; i < superInterfaces.length; i++) {
- IType curr= superInterfaces[i];
+ for (IType curr : hierarchy.getSuperInterfaces(type)) {
if (possibleSuperType.equals(curr) || isSuperType(hierarchy, possibleSuperType, curr)) {
return true;
}
@@ -681,9 +675,7 @@ public final class JavaModelUtil {
* <code>null</code> if the container can not be modified.
*/
public static IClasspathEntry findEntryInContainer(IClasspathContainer container, IPath libPath) {
- IClasspathEntry[] entries= container.getClasspathEntries();
- for (int i= 0; i < entries.length; i++) {
- IClasspathEntry curr= entries[i];
+ for (IClasspathEntry curr : container.getClasspathEntries()) {
IClasspathEntry resolved= JavaCore.getResolvedClasspathEntry(curr);
if (resolved != null && libPath.equals(resolved.getPath())) {
return curr; // return the real entry
@@ -729,8 +721,8 @@ public final class JavaModelUtil {
*/
public static ICompilationUnit[] getAllCompilationUnits(IJavaElement[] javaElements) throws JavaModelException {
HashSet<ICompilationUnit> result= new HashSet<>();
- for (int i= 0; i < javaElements.length; i++) {
- addAllCus(result, javaElements[i]);
+ for (IJavaElement javaElement : javaElements) {
+ addAllCus(result, javaElement);
}
return result.toArray(new ICompilationUnit[result.size()]);
}
@@ -739,20 +731,22 @@ public final class JavaModelUtil {
switch (javaElement.getElementType()) {
case IJavaElement.JAVA_PROJECT:
IJavaProject javaProject= (IJavaProject) javaElement;
- IPackageFragmentRoot[] packageFragmentRoots= javaProject.getPackageFragmentRoots();
- for (int i= 0; i < packageFragmentRoots.length; i++)
- addAllCus(collector, packageFragmentRoots[i]);
+ for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) {
+ addAllCus(collector, packageFragmentRoot);
+ }
return;
+
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
IPackageFragmentRoot packageFragmentRoot= (IPackageFragmentRoot) javaElement;
if (packageFragmentRoot.getKind() != IPackageFragmentRoot.K_SOURCE)
return;
- IJavaElement[] packageFragments= packageFragmentRoot.getChildren();
- for (int j= 0; j < packageFragments.length; j++)
- addAllCus(collector, packageFragments[j]);
+ for (IJavaElement packageFragment : packageFragmentRoot.getChildren()) {
+ addAllCus(collector, packageFragment);
+ }
return;
+
case IJavaElement.PACKAGE_FRAGMENT:
IPackageFragment packageFragment= (IPackageFragment) javaElement;
collector.addAll(Arrays.asList(packageFragment.getCompilationUnits()));
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodOverrideTester.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodOverrideTester.java
index 1f26e3db59..00a5374046 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodOverrideTester.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodOverrideTester.java
@@ -143,9 +143,8 @@ public class MethodOverrideTester {
}
}
}
- IType[] interfaces= fHierarchy.getSuperInterfaces(type);
- for (int i= 0; i < interfaces.length; i++) {
- IMethod res= findOverriddenMethodInHierarchy(interfaces[i], overriding);
+ for (IType intf : fHierarchy.getSuperInterfaces(type)) {
+ IMethod res= findOverriddenMethodInHierarchy(intf, overriding);
if (res != null) {
return res; // methods from interfaces are always public and therefore visible
}
@@ -173,9 +172,8 @@ public class MethodOverrideTester {
return res;
}
}
- IType[] superInterfaces= fHierarchy.getSuperInterfaces(type);
- for (int i= 0; i < superInterfaces.length; i++) {
- IMethod res= findOverriddenMethodInHierarchy(superInterfaces[i], overriding);
+ for (IType superInterface : fHierarchy.getSuperInterfaces(type)) {
+ IMethod res= findOverriddenMethodInHierarchy(superInterface, overriding);
if (res != null) {
return res;
}
@@ -195,9 +193,7 @@ public class MethodOverrideTester {
int flags= overriding.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor())
return null;
- IMethod[] overriddenMethods= overriddenType.getMethods();
- for (int i= 0; i < overriddenMethods.length; i++) {
- IMethod overridden= overriddenMethods[i];
+ for (IMethod overridden : overriddenType.getMethods()) {
flags= overridden.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor())
continue;
@@ -219,9 +215,7 @@ public class MethodOverrideTester {
int flags= overridden.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor())
return null;
- IMethod[] overridingMethods= overridingType.getMethods();
- for (int i= 0; i < overridingMethods.length; i++) {
- IMethod overriding= overridingMethods[i];
+ for (IMethod overriding : overridingType.getMethods()) {
flags= overriding.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor())
continue;
@@ -410,8 +404,7 @@ public class MethodOverrideTester {
ITypeParameter[] typeParameters= instantiatedType.getTypeParameters();
if (instantiatingType == null) { // the focus type
- for (int i= 0; i < typeParameters.length; i++) {
- ITypeParameter curr= typeParameters[i];
+ for (ITypeParameter curr : typeParameters) {
// use star to make type variables different from type refs
s.addSubstitution(curr.getElementName(), '*' + curr.getElementName(), getTypeParameterErasure(curr, instantiatedType));
}
@@ -424,8 +417,7 @@ public class MethodOverrideTester {
s.addSubstitution(curr.getElementName(), substString, erasure);
}
} else if (typeArguments.length == 0) { // raw type reference
- for (int i= 0; i < typeParameters.length; i++) {
- ITypeParameter curr= typeParameters[i];
+ for (ITypeParameter curr : typeParameters) {
String erasure= getTypeParameterErasure(curr, instantiatedType);
s.addSubstitution(curr.getElementName(), erasure, erasure);
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/Resources.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/Resources.java
index 757137f248..c3474f67f1 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/Resources.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/Resources.java
@@ -70,8 +70,7 @@ public class Resources {
*/
public static IStatus checkInSync(IResource[] resources) {
IStatus result= null;
- for (int i= 0; i < resources.length; i++) {
- IResource resource= resources[i];
+ for (IResource resource : resources) {
if (!resource.isSynchronized(IResource.DEPTH_INFINITE)) {
result= addOutOfSync(result, resource);
}
@@ -112,8 +111,7 @@ public class Resources {
*/
public static IStatus makeCommittable(IResource[] resources, Object context) {
List<IResource> readOnlyFiles= new ArrayList<>();
- for (int i= 0; i < resources.length; i++) {
- IResource resource= resources[i];
+ for (IResource resource : resources) {
if (resource.getType() == IResource.FILE && isReadOnly(resource))
readOnlyFiles.add(resource);
}
@@ -200,8 +198,8 @@ public class Resources {
*/
public static String[] getLocationOSStrings(IResource[] resources) {
List<String> result= new ArrayList<>(resources.length);
- for (int i= 0; i < resources.length; i++) {
- IPath location= resources[i].getLocation();
+ for (IResource resource : resources) {
+ IPath location= resource.getLocation();
if (location != null)
result.add(location.toOSString());
}
diff --git a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/ExtractClassDescriptor.java b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/ExtractClassDescriptor.java
index 198b6b2326..d515e5d528 100644
--- a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/ExtractClassDescriptor.java
+++ b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/ExtractClassDescriptor.java
@@ -217,10 +217,8 @@ public class ExtractClassDescriptor extends JavaRefactoringDescriptor {
* @throws JavaModelException if the type does not exist or if an exception occurs while accessing its corresponding resource.
*/
public static Field[] getFields(IType type) throws JavaModelException {
- IField[] fields= type.getFields();
ArrayList<Field> result= new ArrayList<>();
- for (int i= 0; i < fields.length; i++) {
- IField field= fields[i];
+ for (IField field : type.getFields()) {
if (!Flags.isStatic(field.getFlags()) && !field.isEnumConstant())
result.add(new Field(field.getElementName()));
}
@@ -238,8 +236,7 @@ public class ExtractClassDescriptor extends JavaRefactoringDescriptor {
* @throws IllegalArgumentException if one of the fields is <code>null</code>
*/
public void setFields(Field[] fields) throws IllegalArgumentException {
- for (int i= 0; i < fields.length; i++) {
- Field field= fields[i];
+ for (Field field : fields) {
if (field == null)
throw new IllegalArgumentException("Field can not be null"); //$NON-NLS-1$
}
diff --git a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/IntroduceParameterObjectDescriptor.java b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/IntroduceParameterObjectDescriptor.java
index 9acda950eb..b7b62c2e0f 100644
--- a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/IntroduceParameterObjectDescriptor.java
+++ b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/IntroduceParameterObjectDescriptor.java
@@ -528,8 +528,7 @@ public class IntroduceParameterObjectDescriptor extends JavaRefactoringDescripto
result.addFatalError("The number of parameters does not match the number of parameters of the method"); //$NON-NLS-1$
}
boolean hasParameterObject= false;
- for (int i= 0; i < fParameters.length; i++) {
- Parameter parameter= fParameters[i];
+ for (Parameter parameter : fParameters) {
if (parameter.isCreateField()) {
String fieldName= parameter.getFieldName();
if (fieldName == null)
diff --git a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/MoveStaticMembersDescriptor.java b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/MoveStaticMembersDescriptor.java
index fb42d81842..4dfdc6fdcc 100644
--- a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/MoveStaticMembersDescriptor.java
+++ b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/descriptors/MoveStaticMembersDescriptor.java
@@ -165,8 +165,8 @@ public final class MoveStaticMembersDescriptor extends JavaRefactoringDescriptor
if (fMembers == null)
status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.MoveStaticMembersDescriptor_no_members));
else {
- for (int index= 0; index < fMembers.length; index++) {
- if (fMembers[index] == null) {
+ for (IMember member : fMembers) {
+ if (member == null) {
status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.MoveStaticMembersDescriptor_invalid_members));
break;
}

Back to the top