Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2019-08-07 19:56:30 +0000
committerRoland Grunberg2019-08-13 16:34:15 +0000
commit6083bf5d64c52e97f96e57bf9b118e57001b5f0c (patch)
treebc55cff6e0e0ba4977d813e4896f4de126286998
parent706f8bc8875b955f6ce2c055c26526c196a2d1a1 (diff)
downloadeclipse.jdt.ui-6083bf5d64c52e97f96e57bf9b118e57001b5f0c.tar.gz
eclipse.jdt.ui-6083bf5d64c52e97f96e57bf9b118e57001b5f0c.tar.xz
eclipse.jdt.ui-6083bf5d64c52e97f96e57bf9b118e57001b5f0c.zip
Use addAll instead of looping through a collection
Change only for org.eclipse.jdt.ui/core refactoring and org.eclipse.jdt.ui/core extension to make review easier. Using Collections.addAll simplifies reading the code. Change-Id: I39993be2143413f73393bd68fba1e9766821bf5b Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r--org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/fragments/ASTMatchingFragmentFinder.java5
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractConstantRefactoring.java4
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/generics/InferTypeArgumentsRefactoring.java8
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java5
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractSupertypeProcessor.java5
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/TypeVariableUtil.java4
6 files changed, 13 insertions, 18 deletions
diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/fragments/ASTMatchingFragmentFinder.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/fragments/ASTMatchingFragmentFinder.java
index 77fea1af36..58299a0d0a 100644
--- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/fragments/ASTMatchingFragmentFinder.java
+++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/fragments/ASTMatchingFragmentFinder.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.jdt.internal.corext.dom.fragments;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -51,9 +52,7 @@ class ASTMatchingFragmentFinder extends GenericVisitor {
@Override
protected boolean visitNode(ASTNode node) {
IASTFragment[] localMatches= fFragmentToMatch.getMatchingFragmentsWithNode(node);
- for(int i= 0; i < localMatches.length; i++) {
- fMatches.add(localMatches[i]);
- }
+ Collections.addAll(fMatches, localMatches);
return true;
}
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractConstantRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractConstantRefactoring.java
index 2c61306831..9f829a5ea3 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractConstantRefactoring.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractConstantRefactoring.java
@@ -16,6 +16,7 @@ package org.eclipse.jdt.internal.corext.refactoring.code;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -789,8 +790,7 @@ public class ExtractConstantRefactoring extends Refactoring {
ASTNode scope= replacementScope.next();
IASTFragment[] allMatches= ASTFragmentFactory.createFragmentForFullSubtree(scope).getSubFragmentsMatching(getSelectedExpression());
IASTFragment[] replaceableMatches = retainOnlyReplacableMatches(allMatches);
- for(int i = 0; i < replaceableMatches.length; i++)
- toReplace.add(replaceableMatches[i]);
+ Collections.addAll(toReplace, replaceableMatches);
}
} else if (canReplace(getSelectedExpression()))
toReplace.add(getSelectedExpression());
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/generics/InferTypeArgumentsRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/generics/InferTypeArgumentsRefactoring.java
index 4bac28d38b..2ac34de98f 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/generics/InferTypeArgumentsRefactoring.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/generics/InferTypeArgumentsRefactoring.java
@@ -15,6 +15,7 @@ package org.eclipse.jdt.internal.corext.refactoring.generics;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -394,9 +395,7 @@ public class InferTypeArgumentsRefactoring extends Refactoring {
Type movingType= (Type) rewrite.getASTRewrite().createMoveTarget(originalType);
ParameterizedType newType= rewrite.getAST().newParameterizedType(movingType);
- for (int i= 0; i < typeArguments.length; i++) {
- newType.typeArguments().add(typeArguments[i]);
- }
+ Collections.addAll(newType.typeArguments(), typeArguments);
rewrite.getASTRewrite().replace(originalType, newType, rewrite.createGroupDescription(RefactoringCoreMessages.InferTypeArgumentsRefactoring_addTypeArguments));
return newType;
@@ -442,8 +441,7 @@ public class InferTypeArgumentsRefactoring extends Refactoring {
Type[] nestedTypeArguments= getTypeArguments(typeArgument, nestedTypeArgumentCvs, rewrite, tCModel, leaveUnconstraindRaw); //recursion
if (nestedTypeArguments != null) {
ParameterizedType parameterizedType= rewrite.getAST().newParameterizedType(typeArgument);
- for (int j= 0; j < nestedTypeArguments.length; j++)
- parameterizedType.typeArguments().add(nestedTypeArguments[j]);
+ Collections.addAll(parameterizedType.typeArguments(), nestedTypeArguments);
typeArgument= parameterizedType;
}
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java
index ef506e43f6..fe7ea6f452 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/participants/RefactoringProcessors.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.jdt.internal.corext.refactoring.participants;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -26,9 +27,7 @@ public class RefactoringProcessors {
Set<String> result= new HashSet<>();
for (int i= 0; i < projects.length; i++) {
String[] pns= projects[i].getDescription().getNatureIds();
- for (int p = 0; p < pns.length; p++) {
- result.add(pns[p]);
- }
+ Collections.addAll(result, pns);
}
return result.toArray(new String[result.size()]);
}
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractSupertypeProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractSupertypeProcessor.java
index 1dbfb7c6de..d5b0984c1e 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractSupertypeProcessor.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractSupertypeProcessor.java
@@ -16,6 +16,7 @@ package org.eclipse.jdt.internal.corext.refactoring.structure;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -513,9 +514,7 @@ public final class ExtractSupertypeProcessor extends PullUpRefactoringProcessor
if (superBinding != null)
fTypeBindings.add(superBinding);
final ITypeBinding[] bindings= binding.getInterfaces();
- for (int i= 0; i < bindings.length; i++) {
- fTypeBindings.add(bindings[i]);
- }
+ Collections.addAll(fTypeBindings, bindings);
}
final String imports= createTypeImports(extractedWorkingCopy, monitor);
if (imports != null && !"".equals(imports)) { //$NON-NLS-1$
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/TypeVariableUtil.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/TypeVariableUtil.java
index 5bfdfd390c..e332f72cf1 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/TypeVariableUtil.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/TypeVariableUtil.java
@@ -15,6 +15,7 @@ package org.eclipse.jdt.internal.corext.refactoring.structure;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -134,8 +135,7 @@ public final class TypeVariableUtil {
extractTypeVariables(types[index], set);
extractTypeVariables(method.getReturnType(), set);
final String[] arguments= parametersToVariables(((IMethod) member).getTypeParameters());
- for (int index= 0; index < arguments.length; index++)
- set.add(arguments[index]);
+ Collections.addAll(set, arguments);
result= new String[set.size()];
set.toArray(result);
} else if (member instanceof IType)

Back to the top