Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2017-02-02 10:54:24 -0500
committerLars Vogel2017-02-03 03:14:55 -0500
commit88a51667c841267a5a7076c649890a356bde0822 (patch)
tree17092d5f489d014e56b48ad75a073cc0d336640d /org.eclipse.text
parent7a0eb42a180d25360a95657e2727e17b7d6d2132 (diff)
downloadeclipse.platform.text-88a51667c841267a5a7076c649890a356bde0822.tar.gz
eclipse.platform.text-88a51667c841267a5a7076c649890a356bde0822.tar.xz
eclipse.platform.text-88a51667c841267a5a7076c649890a356bde0822.zip
Bug 493304 - Prefer usage of enhanced for loop in eclipse.platform.text
repo This change is for the for org.eclipse.text plug-in Change-Id: I9a02ba945e91d7e1361627239c3617010453c571 Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
Diffstat (limited to 'org.eclipse.text')
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java7
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java4
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java16
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java20
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java15
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java51
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java33
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java12
-rw-r--r--org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java4
-rw-r--r--org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java7
-rw-r--r--org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java3
-rw-r--r--org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java20
-rw-r--r--org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java8
-rw-r--r--org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java7
-rw-r--r--org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java4
15 files changed, 81 insertions, 130 deletions
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
index f0f24411a..8145fb437 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
@@ -838,8 +838,8 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$
String[] delimiters= getLegalLineDelimiters();
Assert.isTrue(delimiters.length > 0);
- for (int i= 0; i < delimiters.length; i++) {
- if (delimiters[i].equals(sysLineDelimiter)) {
+ for (String delimiter : delimiters) {
+ if (delimiter.equals(sysLineDelimiter)) {
lineDelimiter= sysLineDelimiter;
break;
}
@@ -1613,8 +1613,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
Position region= new Position(offset, length);
- for (Iterator<Position> iterator= documentPositions.iterator(); iterator.hasNext();) {
- Position position= iterator.next();
+ for (Position position : documentPositions) {
if (isWithinRegion(region, position, canStartBefore, canEndAfter)) {
list.add(position);
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java b/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java
index e9de513d3..ef03ed55c 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java
@@ -212,9 +212,9 @@ public class DefaultPositionUpdater implements IPositionUpdater {
fDocument= event.getDocument();
Position[] category= fDocument.getPositions(fCategory);
- for (int i= 0; i < category.length; i++) {
+ for (Position element : category) {
- fPosition= category[i];
+ fPosition= element;
fOriginalPosition.offset= fPosition.offset;
fOriginalPosition.length= fPosition.length;
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java b/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java
index 5d1de092e..17803e649 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java
@@ -11,7 +11,6 @@
package org.eclipse.jface.text;
-import java.util.Iterator;
import java.util.LinkedList;
@@ -88,8 +87,7 @@ public class SequentialRewriteTextStore implements ITextStore {
if (offset + length <= firstReplace.newOffset) {
int delta= text.length() - length;
if (delta != 0) {
- for (Iterator<Replace> i= fReplaceList.iterator(); i.hasNext(); ) {
- Replace replace= i.next();
+ for (Replace replace : fReplaceList) {
replace.newOffset += delta;
}
}
@@ -142,9 +140,7 @@ public class SequentialRewriteTextStore implements ITextStore {
} else {
int delta= 0;
- for (Iterator<Replace> i= fReplaceList.iterator(); i.hasNext(); ) {
- Replace replace= i.next();
-
+ for (Replace replace : fReplaceList) {
if (offset + length < replace.newOffset) {
return fSource.get(offset - delta, length);
@@ -200,9 +196,7 @@ public class SequentialRewriteTextStore implements ITextStore {
} else {
int delta= 0;
- for (Iterator<Replace> i= fReplaceList.iterator(); i.hasNext(); ) {
- Replace replace= i.next();
-
+ for (Replace replace : fReplaceList) {
if (offset < replace.newOffset)
return fSource.get(offset - delta);
@@ -244,9 +238,7 @@ public class SequentialRewriteTextStore implements ITextStore {
StringBuffer buffer= new StringBuffer();
int delta= 0;
- for (Iterator<Replace> i= fReplaceList.iterator(); i.hasNext(); ) {
- Replace replace= i.next();
-
+ for (Replace replace : fReplaceList) {
int offset= buffer.length() - delta;
buffer.append(fSource.get(offset, replace.offset - offset));
buffer.append(replace.text);
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
index 9ccd5e9ab..4cc1c9cdf 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
@@ -310,12 +310,12 @@ public class TextUtilities {
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3= (IDocumentExtension3) document;
String[] partitionings= extension3.getPartitionings();
- for (int i= 0; i < partitionings.length; i++) {
- IDocumentPartitioner partitioner= extension3.getDocumentPartitioner(partitionings[i]);
+ for (String partitioning : partitionings) {
+ IDocumentPartitioner partitioner= extension3.getDocumentPartitioner(partitioning);
if (partitioner != null) {
- extension3.setDocumentPartitioner(partitionings[i], null);
+ extension3.setDocumentPartitioner(partitioning, null);
partitioner.disconnect();
- partitioners.put(partitionings[i], partitioner);
+ partitioners.put(partitioning, partitioner);
}
}
} else {
@@ -450,14 +450,14 @@ public class TextUtilities {
String[] partitionings= extension3.getPartitionings();
if (partitionings != null) {
Set<String> categories= new HashSet<>();
- for (int i= 0; i < partitionings.length; i++) {
- IDocumentPartitioner p= extension3.getDocumentPartitioner(partitionings[i]);
+ for (String partitioning : partitionings) {
+ IDocumentPartitioner p= extension3.getDocumentPartitioner(partitioning);
if (p instanceof IDocumentPartitionerExtension2) {
IDocumentPartitionerExtension2 extension2= (IDocumentPartitionerExtension2) p;
String[] c= extension2.getManagingPositionCategories();
if (c != null) {
- for (int j= 0; j < c.length; j++)
- categories.add(c[j]);
+ for (String element : c)
+ categories.add(element);
}
}
}
@@ -500,8 +500,8 @@ public class TextUtilities {
String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$
String[] delimiters= document.getLegalLineDelimiters();
Assert.isTrue(delimiters.length > 0);
- for (int i= 0; i < delimiters.length; i++) {
- if (delimiters[i].equals(sysLineDelimiter)) {
+ for (String delimiter : delimiters) {
+ if (delimiter.equals(sysLineDelimiter)) {
lineDelimiter= sysLineDelimiter;
break;
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java
index 8334798e9..5c3d4d1a3 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java
@@ -74,8 +74,8 @@ class LinkedModeManager {
* @return <code>true</code> if there exists a <code>LinkedModeManager</code> on any of the <code>documents</code>, <code>false</code> otherwise
*/
public static boolean hasManager(IDocument[] documents) {
- for (int i= 0; i < documents.length; i++) {
- if (hasManager(documents[i]))
+ for (IDocument document : documents) {
+ if (hasManager(document))
return true;
}
return false;
@@ -96,15 +96,14 @@ class LinkedModeManager {
Set<LinkedModeManager> mgrs= new HashSet<>();
LinkedModeManager mgr= null;
- for (int i= 0; i < documents.length; i++) {
- mgr= fgManagers.get(documents[i]);
+ for (IDocument document : documents) {
+ mgr= fgManagers.get(document);
if (mgr != null)
mgrs.add(mgr);
}
if (mgrs.size() > 1)
if (force) {
- for (Iterator<LinkedModeManager> it= mgrs.iterator(); it.hasNext(); ) {
- LinkedModeManager m= it.next();
+ for (LinkedModeManager m : mgrs) {
m.closeAllEnvironments();
}
} else {
@@ -114,8 +113,8 @@ class LinkedModeManager {
if (mgrs.size() == 0)
mgr= new LinkedModeManager();
- for (int i= 0; i < documents.length; i++)
- fgManagers.put(documents[i], mgr);
+ for (IDocument document : documents)
+ fgManagers.put(document, mgr);
return mgr;
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java
index 0a19721ca..cad71b6d0 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java
@@ -13,7 +13,6 @@ package org.eclipse.jface.text.link;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -182,8 +181,7 @@ public class LinkedModeModel {
if (fParentEnvironment != null && fParentEnvironment.isChanging())
return;
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup group= it.next();
+ for (LinkedPositionGroup group : fGroups) {
if (!group.isLegalEvent(event)) {
fExit= true;
return;
@@ -210,9 +208,7 @@ public class LinkedModeModel {
// collect all results
Map<IDocument, TextEdit> result= null;
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext();) {
- LinkedPositionGroup group= it.next();
-
+ for (LinkedPositionGroup group : fGroups) {
Map<IDocument, TextEdit> map= group.handleEvent(event);
if (result != null && map != null) {
// exit if more than one position was changed
@@ -225,8 +221,7 @@ public class LinkedModeModel {
if (result != null) {
// edit all documents
- for (Iterator<IDocument> it2= result.keySet().iterator(); it2.hasNext(); ) {
- IDocument doc= it2.next();
+ for (IDocument doc : result.keySet()) {
TextEdit edit= result.get(doc);
Replace replace= new Replace(edit);
@@ -301,8 +296,7 @@ public class LinkedModeModel {
* model's groups
*/
private void enforceDisjoint(LinkedPositionGroup group) throws BadLocationException {
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup g= it.next();
+ for (LinkedPositionGroup g : fGroups) {
g.enforceDisjoint(group);
}
}
@@ -319,8 +313,7 @@ public class LinkedModeModel {
fIsActive= false;
- for (Iterator<IDocument> it= fDocuments.iterator(); it.hasNext(); ) {
- IDocument doc= it.next();
+ for (IDocument doc : fDocuments) {
try {
doc.removePositionCategory(getCategory());
} catch (BadPositionCategoryException e) {
@@ -336,8 +329,7 @@ public class LinkedModeModel {
List<ILinkedModeListener> listeners= new ArrayList<>(fListeners);
fListeners.clear();
- for (Iterator<ILinkedModeListener> it= listeners.iterator(); it.hasNext(); ) {
- ILinkedModeListener listener= it.next();
+ for (ILinkedModeListener listener : listeners) {
listener.left(this, flags);
}
@@ -507,8 +499,7 @@ public class LinkedModeModel {
// register positions
try {
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup group= it.next();
+ for (LinkedPositionGroup group : fGroups) {
group.register(this);
}
return true;
@@ -525,8 +516,8 @@ public class LinkedModeModel {
*/
private void enforceNotEmpty() {
boolean hasPosition= false;
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); )
- if (!it.next().isEmpty()) {
+ for (LinkedPositionGroup linkedPositionGroup : fGroups)
+ if (!linkedPositionGroup.isEmpty()) {
hasPosition= true;
break;
}
@@ -541,8 +532,7 @@ public class LinkedModeModel {
*/
private IDocument[] getDocuments() {
Set<IDocument> docs= new HashSet<>();
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup group= it.next();
+ for (LinkedPositionGroup group : fGroups) {
docs.addAll(Arrays.asList(group.getDocuments()));
}
return docs.toArray(new IDocument[docs.size()]);
@@ -557,8 +547,7 @@ public class LinkedModeModel {
* @return <code>true</code> if the receiver can be nested into <code>parent</code>, <code>false</code> otherwise
*/
boolean canNestInto(LinkedModeModel parent) {
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup group= it.next();
+ for (LinkedPositionGroup group : fGroups) {
if (!enforceNestability(group, parent)) {
fParentPosition= null;
return false;
@@ -584,8 +573,7 @@ public class LinkedModeModel {
Assert.isNotNull(group);
try {
- for (Iterator<LinkedPositionGroup> it= model.fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup pg= it.next();
+ for (LinkedPositionGroup pg : model.fGroups) {
LinkedPosition pos;
pos= pg.adopt(group);
if (pos != null && fParentPosition != null && fParentPosition != pos)
@@ -670,8 +658,7 @@ public class LinkedModeModel {
*/
public LinkedPosition findPosition(LinkedPosition toFind) {
LinkedPosition position= null;
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup group= it.next();
+ for (LinkedPositionGroup group : fGroups) {
position= group.getPosition(toFind);
if (position != null)
break;
@@ -709,8 +696,7 @@ public class LinkedModeModel {
*/
private void suspend() {
List<ILinkedModeListener> l= new ArrayList<>(fListeners);
- for (Iterator<ILinkedModeListener> it= l.iterator(); it.hasNext(); ) {
- ILinkedModeListener listener= it.next();
+ for (ILinkedModeListener listener : l) {
listener.suspend(this);
}
}
@@ -723,8 +709,7 @@ public class LinkedModeModel {
*/
private void resume(int flags) {
List<ILinkedModeListener> l= new ArrayList<>(fListeners);
- for (Iterator<ILinkedModeListener> it= l.iterator(); it.hasNext(); ) {
- ILinkedModeListener listener= it.next();
+ for (ILinkedModeListener listener : l) {
listener.resume(this, flags);
}
}
@@ -739,8 +724,7 @@ public class LinkedModeModel {
* model, <code>false</code> otherwise
*/
public boolean anyPositionContains(int offset) {
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup group= it.next();
+ for (LinkedPositionGroup group : fGroups) {
if (group.contains(offset))
// take the first hit - exclusion is guaranteed by enforcing
// disjointness when adding positions
@@ -767,8 +751,7 @@ public class LinkedModeModel {
* or <code>null</code> if no group contains <code>position</code>
*/
public LinkedPositionGroup getGroupForPosition(Position position) {
- for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) {
- LinkedPositionGroup group= it.next();
+ for (LinkedPositionGroup group : fGroups) {
if (group.contains(position))
return group;
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java
index 49f39fd2d..0d3f47f9b 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java
@@ -153,8 +153,7 @@ public class LinkedPositionGroup {
* @throws BadLocationException if the disjointness check fails
*/
private void enforceDisjoint(LinkedPosition position) throws BadLocationException {
- for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition p= it.next();
+ for (LinkedPosition p : fPositions) {
if (p.overlapsWith(position))
throw new BadLocationException();
}
@@ -168,8 +167,7 @@ public class LinkedPositionGroup {
*/
void enforceDisjoint(LinkedPositionGroup group) throws BadLocationException {
Assert.isNotNull(group);
- for (Iterator<LinkedPosition> it= group.fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition p= it.next();
+ for (LinkedPosition p : group.fPositions) {
enforceDisjoint(p);
}
}
@@ -186,8 +184,7 @@ public class LinkedPositionGroup {
fLastPosition= null;
fLastRegion= null;
- for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition pos= it.next();
+ for (LinkedPosition pos : fPositions) {
if (overlapsOrTouches(pos, event)) {
if (fLastPosition != null) {
fLastPosition= null;
@@ -250,8 +247,7 @@ public class LinkedPositionGroup {
if (text == null)
text= ""; //$NON-NLS-1$
- for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition p= it.next();
+ for (LinkedPosition p : fPositions) {
if (p == fLastPosition || p.isDeleted())
continue; // don't re-update the origin of the change
@@ -275,8 +271,7 @@ public class LinkedPositionGroup {
try {
Map<IDocument, TextEdit> result= new HashMap<>();
- for (Iterator<IDocument> it= map.keySet().iterator(); it.hasNext();) {
- IDocument d= it.next();
+ for (IDocument d : map.keySet()) {
TextEdit edit= new MultiTextEdit(0, d.getLength());
edit.addChildren(map.get(d).toArray(new TextEdit[0]));
result.put(d, edit);
@@ -321,8 +316,7 @@ public class LinkedPositionGroup {
}
void register(LinkedModeModel model) throws BadLocationException {
- for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition pos= it.next();
+ for (LinkedPosition pos : fPositions) {
model.register(pos);
}
}
@@ -339,11 +333,9 @@ public class LinkedPositionGroup {
*/
LinkedPosition adopt(LinkedPositionGroup group) throws BadLocationException {
LinkedPosition found= null;
- for (Iterator<LinkedPosition> it= group.fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition pos= it.next();
+ for (LinkedPosition pos : group.fPositions) {
LinkedPosition localFound= null;
- for (Iterator<LinkedPosition> it2= fPositions.iterator(); it2.hasNext(); ) {
- LinkedPosition myPos= it2.next();
+ for (LinkedPosition myPos : fPositions) {
if (myPos.includes(pos)) {
if (found == null)
found= myPos;
@@ -367,8 +359,7 @@ public class LinkedPositionGroup {
* @return the closest position to <code>toFind</code>.
*/
LinkedPosition getPosition(LinkedPosition toFind) {
- for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition p= it.next();
+ for (LinkedPosition p : fPositions) {
if (p.includes(toFind))
return p;
}
@@ -383,8 +374,7 @@ public class LinkedPositionGroup {
* @return <code>true</code> if offset is contained by this group
*/
boolean contains(int offset) {
- for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition pos= it.next();
+ for (LinkedPosition pos : fPositions) {
if (pos.includes(offset)) {
return true;
}
@@ -431,8 +421,7 @@ public class LinkedPositionGroup {
* @return <code>true</code> if the receiver contains <code>position</code>
*/
boolean contains(Position position) {
- for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) {
- LinkedPosition p= it.next();
+ for (LinkedPosition p : fPositions) {
if (position.equals(p))
return true;
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
index d3ae54c0c..6ede6aec6 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
@@ -387,8 +387,8 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
protected void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd, boolean fireModelChanged) throws BadLocationException {
if (annotationsToRemove != null) {
- for (int i= 0, length= annotationsToRemove.length; i < length; i++)
- removeAnnotation(annotationsToRemove[i], false);
+ for (Annotation element : annotationsToRemove)
+ removeAnnotation(element, false);
}
if (annotationsToAdd != null) {
@@ -493,8 +493,8 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
connected();
}
- for (Iterator<Object> it= fAttachments.keySet().iterator(); it.hasNext();) {
- IAnnotationModel model= fAttachments.get(it.next());
+ for (Object object : fAttachments.keySet()) {
+ IAnnotationModel model= fAttachments.get(object);
model.connect(document);
}
}
@@ -518,8 +518,8 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
Assert.isTrue(fDocument == document);
- for (Iterator<Object> it= fAttachments.keySet().iterator(); it.hasNext();) {
- IAnnotationModel model= fAttachments.get(it.next());
+ for (Object object : fAttachments.keySet()) {
+ IAnnotationModel model= fAttachments.get(object);
model.disconnect(document);
}
diff --git a/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java
index 03daeb57d..0a5127d6b 100644
--- a/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java
+++ b/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java
@@ -301,8 +301,8 @@ public final class CopySourceEdit extends TextEdit {
private void applyTransformation(IDocument document) throws MalformedTreeException {
TextEdit newEdit= new MultiTextEdit(0, document.getLength());
ReplaceEdit[] replaces= fModifier.getModifications(document.get());
- for (int i= 0; i < replaces.length; i++) {
- newEdit.addChild(replaces[i]);
+ for (ReplaceEdit replace : replaces) {
+ newEdit.addChild(replace);
}
try {
newEdit.apply(document, TextEdit.NONE);
diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java
index b02307032..9fda25800 100644
--- a/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java
+++ b/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java
@@ -305,8 +305,8 @@ public final class MoveSourceEdit extends TextEdit {
} else {
MultiTextEdit newEdit= new MultiTextEdit(0, document.getLength());
TextEdit[] replaces= fModifier.getModifications(document.get());
- for (int i= 0; i < replaces.length; i++) {
- newEdit.addChild(replaces[i]);
+ for (TextEdit replace : replaces) {
+ newEdit.addChild(replace);
}
try {
newEdit.apply(document, style);
@@ -325,8 +325,7 @@ public final class MoveSourceEdit extends TextEdit {
private static void createEdit(TextEdit source, TextEdit target, Map<TextEdit, TextEdit> editMap) {
TextEdit[] children= source.getChildren();
- for (int i= 0; i < children.length; i++) {
- TextEdit child= children[i];
+ for (TextEdit child : children) {
// a deleted child remains deleted even if the temporary buffer
// gets modified.
if (child.isDeleted())
diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java
index 3efb0064a..7527f3531 100644
--- a/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java
+++ b/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java
@@ -164,8 +164,7 @@ public final class MoveTargetEdit extends TextEdit {
sourceRoot.internalMoveTree(getOffset());
TextEdit[] sourceChildren= sourceRoot.removeChildren();
List<TextEdit> children= new ArrayList<>(sourceChildren.length);
- for (int i= 0; i < sourceChildren.length; i++) {
- TextEdit child= sourceChildren[i];
+ for (TextEdit child : sourceChildren) {
child.internalSetParent(this);
children.add(child);
}
diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java
index 4806d620d..2181283db 100644
--- a/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java
+++ b/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java
@@ -343,8 +343,8 @@ public abstract class TextEdit {
* @see #addChild(TextEdit)
*/
public final void addChildren(TextEdit[] edits) throws MalformedTreeException {
- for (int i= 0; i < edits.length; i++) {
- internalAdd(edits[i]);
+ for (TextEdit edit : edits) {
+ internalAdd(edit);
}
}
@@ -459,8 +459,7 @@ public abstract class TextEdit {
int offset= Integer.MAX_VALUE;
int end= Integer.MIN_VALUE;
int deleted= 0;
- for (int i= 0; i < edits.length; i++) {
- TextEdit edit= edits[i];
+ for (TextEdit edit : edits) {
if (edit.isDeleted()) {
deleted++;
} else {
@@ -563,8 +562,7 @@ public abstract class TextEdit {
private void toStringWithChildren(StringBuffer buffer, int indent) {
internalToString(buffer, indent);
if (fChildren != null) {
- for (Iterator<TextEdit> iterator= fChildren.iterator(); iterator.hasNext();) {
- TextEdit child= iterator.next();
+ for (TextEdit child : fChildren) {
buffer.append('\n');
child.toStringWithChildren(buffer, indent + 1);
}
@@ -939,8 +937,7 @@ public abstract class TextEdit {
performRegionUpdating(accumulatedDelta, delete);
if (fChildren != null) {
boolean childDelete= delete || deleteChildren();
- for (Iterator<TextEdit> iter= fChildren.iterator(); iter.hasNext();) {
- TextEdit child= iter.next();
+ for (TextEdit child : fChildren) {
accumulatedDelta= child.traverseRegionUpdating(processor, document, accumulatedDelta, childDelete);
childRegionUpdated();
}
@@ -975,8 +972,8 @@ public abstract class TextEdit {
void internalMoveTree(int delta) {
adjustOffset(delta);
if (fChildren != null) {
- for (Iterator<TextEdit> iter= fChildren.iterator(); iter.hasNext();) {
- iter.next().internalMoveTree(delta);
+ for (TextEdit textEdit : fChildren) {
+ textEdit.internalMoveTree(delta);
}
}
}
@@ -984,8 +981,7 @@ public abstract class TextEdit {
void deleteTree() {
markAsDeleted();
if (fChildren != null) {
- for (Iterator<TextEdit> iter= fChildren.iterator(); iter.hasNext();) {
- TextEdit child= iter.next();
+ for (TextEdit child : fChildren) {
child.deleteTree();
}
}
diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java
index eea20c077..34bca2c5a 100644
--- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java
+++ b/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java
@@ -12,7 +12,6 @@ package org.eclipse.text.edits;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -55,8 +54,7 @@ public final class TextEditCopier {
public TextEdit perform() {
TextEdit result= doCopy(fEdit);
if (result != null) {
- for (Iterator<TextEdit> iter= fCopies.keySet().iterator(); iter.hasNext();) {
- TextEdit edit= iter.next();
+ for (TextEdit edit : fCopies.keySet()) {
edit.postProcessCopy(this);
}
}
@@ -83,8 +81,8 @@ public final class TextEditCopier {
List<TextEdit> children= edit.internalGetChildren();
if (children != null) {
List<TextEdit> newChildren= new ArrayList<>(children.size());
- for (Iterator<TextEdit> iter= children.iterator(); iter.hasNext();) {
- TextEdit childCopy= doCopy(iter.next());
+ for (TextEdit textEdit : children) {
+ TextEdit childCopy= doCopy(textEdit);
childCopy.internalSetParent(result);
newChildren.add(childCopy);
}
diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java
index 73c7e6dd0..e480c4d84 100644
--- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java
+++ b/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java
@@ -11,7 +11,6 @@
package org.eclipse.text.edits;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.Assert;
@@ -202,11 +201,9 @@ public class TextEditProcessor {
}
private void computeSources() {
- for (Iterator<List<TextEdit>> iter= fSourceEdits.iterator(); iter.hasNext();) {
- List<TextEdit> list= iter.next();
+ for (List<TextEdit> list : fSourceEdits) {
if (list != null) {
- for (Iterator<TextEdit> edits= list.iterator(); edits.hasNext();) {
- TextEdit edit= edits.next();
+ for (TextEdit edit : list) {
edit.traverseSourceComputation(this, fDocument);
}
}
diff --git a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
index aef594799..a4755de51 100644
--- a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
+++ b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
@@ -1190,9 +1190,9 @@ public class DocumentUndoManager implements IDocumentUndoManager {
IUndoContext oldUndoContext= manager.getUndoContext();
// Get the history for the old undo context.
IUndoableOperation [] operations= OperationHistoryFactory.getOperationHistory().getUndoHistory(oldUndoContext);
- for (int i= 0; i < operations.length; i++) {
+ for (IUndoableOperation operation : operations) {
// First replace the undo context
- IUndoableOperation op= operations[i];
+ IUndoableOperation op= operation;
if (op instanceof IContextReplacingOperation) {
((IContextReplacingOperation)op).replaceContext(oldUndoContext, getUndoContext());
} else {

Back to the top