Use jdk 5 for-each loop
Replace simple uses of Iterator with a corresponding for-loop. Also add
missing braces on loops as necessary.
Change-Id: I15cee1c89c006d130822107137b7ae8867cb9451
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CBanner.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CBanner.java
index a975ccf..64a8840 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CBanner.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CBanner.java
@@ -126,8 +126,8 @@
}
};
int[] events = new int[] {SWT.Dispose, SWT.MouseDown, SWT.MouseExit, SWT.MouseMove, SWT.MouseUp, SWT.Paint, SWT.Resize};
- for (int i = 0; i < events.length; i++) {
- addListener(events[i], listener);
+ for (int event : events) {
+ addListener(event, listener);
}
}
static int[] bezier(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, int count) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
index 9656349..55a24c7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CCombo.java
@@ -153,11 +153,13 @@
};
int [] comboEvents = {SWT.Dispose, SWT.FocusIn, SWT.Move, SWT.Resize, SWT.FocusOut};
- for (int i=0; i<comboEvents.length; i++) this.addListener (comboEvents [i], listener);
+ for (int comboEvent : comboEvents)
+ this.addListener (comboEvent, listener);
int [] arrowEvents = {SWT.DragDetect, SWT.MouseDown, SWT.MouseEnter, SWT.MouseExit, SWT.MouseHover,
SWT.MouseMove, SWT.MouseUp, SWT.MouseWheel, SWT.Selection, SWT.FocusIn};
- for (int i=0; i<arrowEvents.length; i++) arrow.addListener (arrowEvents [i], listener);
+ for (int arrowEvent : arrowEvents)
+ arrow.addListener (arrowEvent, listener);
createPopup(null, -1);
if ((style & SWT.SIMPLE) == 0) {
@@ -220,7 +222,8 @@
int [] textEvents = {SWT.DefaultSelection, SWT.DragDetect, SWT.KeyDown, SWT.KeyUp, SWT.MenuDetect, SWT.Modify,
SWT.MouseDown, SWT.MouseUp, SWT.MouseDoubleClick, SWT.MouseEnter, SWT.MouseExit, SWT.MouseHover,
SWT.MouseMove, SWT.MouseWheel, SWT.Traverse, SWT.FocusIn, SWT.Verify};
- for (int i=0; i<textEvents.length; i++) text.addListener (textEvents [i], listener);
+ for (int textEvent : textEvents)
+ text.addListener (textEvent, listener);
}
/**
* Adds the argument to the end of the receiver's list.
@@ -486,12 +489,11 @@
public Point computeSize (int wHint, int hHint, boolean changed) {
checkWidget ();
int width = 0, height = 0;
- String[] items = list.getItems ();
GC gc = new GC (text);
int spacer = gc.stringExtent (" ").x; //$NON-NLS-1$
int textWidth = gc.stringExtent (text.getText ()).x;
- for (int i = 0; i < items.length; i++) {
- textWidth = Math.max (gc.stringExtent (items[i]).x, textWidth);
+ for (String item : list.getItems ()) {
+ textWidth = Math.max (gc.stringExtent (item).x, textWidth);
}
gc.dispose ();
Point textSize = text.computeSize (SWT.DEFAULT, SWT.DEFAULT, changed);
@@ -536,9 +538,11 @@
if (background != null) list.setBackground (background);
int [] popupEvents = {SWT.Close, SWT.Paint};
- for (int i=0; i<popupEvents.length; i++) popup.addListener (popupEvents [i], listener);
+ for (int popupEvent : popupEvents)
+ popup.addListener (popupEvent, listener);
int [] listEvents = {SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.FocusOut, SWT.Dispose};
- for (int i=0; i<listEvents.length; i++) list.addListener (listEvents [i], listener);
+ for (int listEvent : listEvents)
+ list.addListener (listEvent, listener);
if (items != null) list.setItems (items);
if (selectionIndex != -1) list.setSelection (selectionIndex);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CLabel.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CLabel.java
index 832db17..4706d06 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CLabel.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CLabel.java
@@ -583,19 +583,19 @@
// draw the text
if (lines != null) {
gc.setForeground(getForeground());
- for (int i = 0; i < lines.length; i++) {
+ for (String line : lines) {
int lineX = x;
if (lines.length > 1) {
if (align == SWT.CENTER) {
- int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
+ int lineWidth = gc.textExtent(line, DRAW_FLAGS).x;
lineX = x + Math.max(0, (extent.x - lineWidth) / 2);
}
if (align == SWT.RIGHT) {
- int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
+ int lineWidth = gc.textExtent(line, DRAW_FLAGS).x;
lineX = Math.max(x, rect.x + rect.width - rightMargin - lineWidth);
}
}
- gc.drawText(lines[i], lineX, lineY, DRAW_FLAGS);
+ gc.drawText(line, lineX, lineY, DRAW_FLAGS);
lineY += lineHeight;
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
index 63d9676..294c451 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
@@ -362,8 +362,8 @@
SWT.Activate,
SWT.Deactivate
};
- for (int i = 0; i < folderEvents.length; i++) {
- addListener(folderEvents[i], listener);
+ for (int folderEvent : folderEvents) {
+ addListener(folderEvent, listener);
}
initAccessible();
@@ -548,8 +548,8 @@
if (leftWidth > 0) leftWidth += SPACING * 2;
int itemWidth = 0;
- for (int i = 0; i < items.length; i++) {
- if (items[i].showing) itemWidth += items[i].width;
+ for (CTabItem item : items) {
+ if (item.showing) itemWidth += item.width;
}
int maxWidth = size.x - borderLeft - leftWidth - borderRight;
@@ -749,11 +749,11 @@
if (selectedIndex >= index) selectedIndex ++;
int[] newPriority = new int[priority.length + 1];
int next = 0, priorityIndex = priority.length;
- for (int i = 0; i < priority.length; i++) {
- if (!mru && priority[i] == index) {
+ for (int element : priority) {
+ if (!mru && element == index) {
priorityIndex = next++;
}
- newPriority[next++] = priority[i] >= index ? priority[i] + 1 : priority[i];
+ newPriority[next++] = element >= index ? element + 1 : element;
}
newPriority[priorityIndex] = index;
priority = newPriority;
@@ -794,9 +794,9 @@
int[] newPriority = new int[priority.length - 1];
int next = 0;
- for (int i = 0; i < priority.length; i++) {
- if (priority [i] == index) continue;
- newPriority[next++] = priority[i] > index ? priority[i] - 1 : priority [i];
+ for (int element : priority) {
+ if (element == index) continue;
+ newPriority[next++] = element > index ? element - 1 : element;
}
priority = newPriority;
@@ -927,8 +927,8 @@
Point size = getSize();
Rectangle trim = renderer.computeTrim(CTabFolderRenderer.PART_BORDER, SWT.NONE, 0, 0, 0, 0);
if (size.x <= trim.width) return null;
- for (int i = 0; i < priority.length; i++) {
- CTabItem item = items[priority[i]];
+ for (int element : priority) {
+ CTabItem item = items[element];
Rectangle rect = item.getBounds();
if (rect.contains(pt)) return item;
}
@@ -1632,8 +1632,8 @@
e.width = chevronRect.width;
e.height = chevronRect.height;
e.doit = true;
- for (int i = 0; i < folderListeners.length; i++) {
- folderListeners[i].showList(e);
+ for (CTabFolder2Listener folderListener : folderListeners) {
+ folderListener.showList(e);
}
if (e.doit && !isDisposed()) {
showList(chevronRect);
@@ -1716,8 +1716,8 @@
}
void onDragDetect(Event event) {
boolean consume = false;
- for (int i = 0; i < items.length; i++) {
- if (items[i].closeRect.contains(event.x, event.y)) {
+ for (CTabItem item : items) {
+ if (item.closeRect.contains(event.x, event.y)) {
consume = true;
break;
}
@@ -1822,10 +1822,10 @@
Control c = display.getCursorControl();
boolean reschedule = false;
if (c != null) {
- for (int i = 0; i < controls.length; i++) {
+ for (Control control : controls) {
Control temp = c;
do {
- if (temp.equals(controls[i])) {
+ if (temp.equals(control)) {
reschedule = true;
} else {
temp = temp.getParent();
@@ -1856,10 +1856,10 @@
}
}
} else {
- for (int i=0; i<items.length; i++) {
- Rectangle bounds = items[i].getBounds();
+ for (CTabItem tabItem : items) {
+ Rectangle bounds = tabItem.getBounds();
if (bounds.contains(x, y)){
- item = items[i];
+ item = tabItem;
}
}
}
@@ -1933,10 +1933,10 @@
}
}
} else {
- for (int i=0; i<items.length; i++) {
- Rectangle bounds = items[i].getBounds();
+ for (CTabItem tabItem : items) {
+ Rectangle bounds = tabItem.getBounds();
if (bounds.contains(x, y)){
- item = items[i];
+ item = tabItem;
}
}
}
@@ -1951,12 +1951,10 @@
e.time = event.time;
e.item = item;
e.doit = true;
- for (int j = 0; j < folderListeners.length; j++) {
- CTabFolder2Listener listener = folderListeners[j];
+ for (CTabFolder2Listener listener : folderListeners) {
listener.close(e);
}
- for (int j = 0; j < tabListeners.length; j++) {
- CTabFolderListener listener = tabListeners[j];
+ for (CTabFolderListener listener : tabListeners) {
listener.itemClosed(e);
}
if (e.doit) item.dispose();
@@ -2019,8 +2017,8 @@
e.width = chevronRect.width;
e.height = chevronRect.height;
e.doit = true;
- for (int i = 0; i < folderListeners.length; i++) {
- folderListeners[i].showList(e);
+ for (CTabFolder2Listener folderListener : folderListeners) {
+ folderListener.showList(e);
}
if (e.doit && !isDisposed()) {
showList(chevronRect);
@@ -2149,22 +2147,22 @@
CTabFolderEvent e = new CTabFolderEvent(this);
e.widget = CTabFolder.this;
e.time = event.time;
- for (int i = 0; i < folderListeners.length; i++) {
+ for (CTabFolder2Listener folderListener : folderListeners) {
if (maximized) {
- folderListeners[i].restore(e);
+ folderListener.restore(e);
} else {
- folderListeners[i].maximize(e);
+ folderListener.maximize(e);
}
}
} else if (event.widget == minItem) {
CTabFolderEvent e = new CTabFolderEvent(this);
e.widget = CTabFolder.this;
e.time = event.time;
- for (int i = 0; i < folderListeners.length; i++) {
+ for (CTabFolder2Listener folderListener : folderListeners) {
if (minimized) {
- folderListeners[i].restore(e);
+ folderListener.restore(e);
} else {
- folderListeners[i].minimize(e);
+ folderListener.minimize(e);
}
}
} else if (event.widget == chevronItem) {
@@ -2178,8 +2176,8 @@
e.width = chevronRect.width;
e.height = chevronRect.height;
e.doit = true;
- for (int i = 0; i < folderListeners.length; i++) {
- folderListeners[i].showList(e);
+ for (CTabFolder2Listener folderListener : folderListeners) {
+ folderListener.showList(e);
}
if (e.doit && !isDisposed()) {
showList(chevronRect);
@@ -2339,8 +2337,8 @@
@Override
public void reskin(int flags) {
super.reskin(flags);
- for (int i = 0; i < items.length; i++) {
- items[i].reskin(flags);
+ for (CTabItem item : items) {
+ item.reskin(flags);
}
}
@@ -2838,8 +2836,8 @@
// First, try the minimum tab size at full compression.
int minWidth = 0;
int[] minWidths = new int[items.length];
- for (int i = 0; i < priority.length; i++) {
- int index = priority[i];
+ for (int element : priority) {
+ int index = element;
int state = CTabFolderRenderer.MINIMUM_SIZE;
if (index == selectedIndex) state |= SWT.SELECTED;
minWidths[index] = renderer.computeSize(index, state, gc, SWT.DEFAULT, SWT.DEFAULT).x;
@@ -3662,14 +3660,12 @@
if (showMenu == null || showMenu.isDisposed()) {
showMenu = new Menu(getShell(), getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT));
} else {
- MenuItem[] items = showMenu.getItems();
- for (int i = 0; i < items.length; i++) {
- items[i].dispose();
+ for (MenuItem item : showMenu.getItems()) {
+ item.dispose();
}
}
final String id = "CTabFolder_showList_Index"; //$NON-NLS-1$
- for (int i = 0; i < items.length; i++) {
- CTabItem tab = items[i];
+ for (CTabItem tab : items) {
if (tab.showing) continue;
MenuItem item = new MenuItem(showMenu, SWT.NONE);
// Bug 533124 In the case where you have multi line tab text, we force the drop-down menu to have single line entries to ensure consistent behavior across platforms.
@@ -3947,8 +3943,8 @@
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
//check for duplicates
- for (int i = 0; i < controls.length; i++) {
- if (controls[i] == control) {
+ for (Control ctrl : controls) {
+ if (ctrl == control) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java
index 5b653a4..465b18c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolderLayout.java
@@ -86,8 +86,8 @@
int controlW = 0;
int controlH = 0;
// preferred size of controls in tab items
- for (int i = 0; i < items.length; i++) {
- Control control = items[i].control;
+ for (CTabItem item : items) {
+ Control control = item.control;
if (control != null && !control.isDisposed()){
Point size = control.computeSize (wHint, hHint, flushCache);
controlW = Math.max (controlW, size.x);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ControlEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ControlEditor.java
index 7ac70ed..d243d53 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ControlEditor.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ControlEditor.java
@@ -124,8 +124,8 @@
this.parent = parent;
controlListener = e -> layout ();
- for (int i=0; i<EVENTS.length; i++) {
- parent.addListener (EVENTS [i], controlListener);
+ for (int event : EVENTS) {
+ parent.addListener (event, controlListener);
}
scrollbarListener = e -> scroll (e);
@@ -178,8 +178,8 @@
*/
public void dispose () {
if (parent != null && !parent.isDisposed()) {
- for (int i=0; i<EVENTS.length; i++) {
- parent.removeListener (EVENTS [i], controlListener);
+ for (int event : EVENTS) {
+ parent.removeListener (event, controlListener);
}
ScrollBar hBar = parent.getHorizontalBar ();
if (hBar != null) hBar.removeListener (SWT.Selection, scrollbarListener);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultContent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultContent.java
index bd3d013..c49936e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultContent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultContent.java
@@ -806,8 +806,8 @@
* Sends the text listeners the TextChanged event.
*/
void sendTextEvent(StyledTextEvent event) {
- for (int i = 0; i < textListeners.size(); i++) {
- textListeners.get(i).handleEvent(event);
+ for (StyledTextListener textListener : textListeners) {
+ textListener.handleEvent(event);
}
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/PopupList.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/PopupList.java
index 65d0895..59c803d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/PopupList.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/PopupList.java
@@ -214,9 +214,9 @@
// find the first entry in the list that starts with the
// specified string
if (string != null){
- for (int i = 0; i < items.length; i++) {
- if (items[i].startsWith(string)){
- int index = list.indexOf(items[i]);
+ for (String item : items) {
+ if (item.startsWith(string)){
+ int index = list.indexOf(item);
list.select(index);
break;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java
index 90b067c..9faf855 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashForm.java
@@ -188,15 +188,14 @@
return ratios;
}
Control[] getControls(boolean onlyVisible) {
- Control[] children = getChildren();
Control[] result = new Control[0];
- for (int i = 0; i < children.length; i++) {
- if (children[i] instanceof Sash) continue;
- if (onlyVisible && !children[i].getVisible()) continue;
+ for (Control element : getChildren()) {
+ if (element instanceof Sash) continue;
+ if (onlyVisible && !element.getVisible()) continue;
Control[] newResult = new Control[result.length + 1];
System.arraycopy(result, 0, newResult, 0, result.length);
- newResult[result.length] = children[i];
+ newResult[result.length] = element;
result = newResult;
}
return result;
@@ -336,16 +335,16 @@
public void setBackground (Color color) {
super.setBackground(color);
background = color;
- for (int i = 0; i < sashes.length; i++) {
- sashes[i].setBackground(background);
+ for (Sash sash : sashes) {
+ sash.setBackground(background);
}
}
@Override
public void setForeground (Color color) {
super.setForeground(color);
foreground = color;
- for (int i = 0; i < sashes.length; i++) {
- sashes[i].setForeground(foreground);
+ for (Sash sash : sashes) {
+ sash.setForeground(foreground);
}
}
/**
@@ -388,15 +387,15 @@
if (maxControl != null) {
this.maxControl = null;
layout(false);
- for (int i= 0; i < sashes.length; i++){
- sashes[i].setVisible(true);
+ for (Sash sashe : sashes) {
+ sashe.setVisible(true);
}
}
return;
}
- for (int i= 0; i < sashes.length; i++){
- sashes[i].setVisible(false);
+ for (Sash sash : sashes) {
+ sash.setVisible(false);
}
maxControl = control;
layout(false);
@@ -424,8 +423,8 @@
@Override
public void setToolTipText(String string) {
super.setToolTipText(string);
- for (int i = 0; i < sashes.length; i++) {
- sashes[i].setToolTipText(string);
+ for (Sash sash : sashes) {
+ sash.setToolTipText(string);
}
}
/**
@@ -451,11 +450,11 @@
}
int total = 0;
- for (int i = 0; i < weights.length; i++) {
- if (weights[i] < 0) {
+ for (int weight : weights) {
+ if (weight < 0) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
- total += weights[i];
+ total += weight;
}
if (total == 0) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java
index 5fe4264..0df0dc5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/SashFormLayout.java
@@ -103,11 +103,11 @@
Control[] controls = sashForm.controls;
if (sashForm.maxControl != null && !sashForm.maxControl.isDisposed()) {
- for (int i= 0; i < controls.length; i++){
- if (controls[i] != sashForm.maxControl) {
- controls[i].setBounds(-200, -200, 0, 0);
+ for (Control control : controls) {
+ if (control != sashForm.maxControl) {
+ control.setBounds(-200, -200, 0, 0);
} else {
- controls[i].setBounds(area);
+ control.setBounds(area);
}
}
return;
@@ -124,8 +124,8 @@
}
if (sashForm.sashes.length > controls.length - 1) {
if (controls.length == 0) {
- for (int i = 0; i < sashForm.sashes.length; i++) {
- sashForm.sashes[i].dispose();
+ for (Sash sash : sashForm.sashes) {
+ sash.dispose();
}
sashForm.sashes = new Sash[0];
} else {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StackLayout.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StackLayout.java
index cf3c5f2..5490db5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StackLayout.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StackLayout.java
@@ -94,11 +94,10 @@
@Override
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
- Control children[] = composite.getChildren();
int maxWidth = 0;
int maxHeight = 0;
- for (int i = 0; i < children.length; i++) {
- Point size = children[i].computeSize(wHint, hHint, flushCache);
+ for (Control element : composite.getChildren()) {
+ Point size = element.computeSize(wHint, hHint, flushCache);
maxWidth = Math.max(size.x, maxWidth);
maxHeight = Math.max(size.y, maxHeight);
}
@@ -116,15 +115,14 @@
@Override
protected void layout(Composite composite, boolean flushCache) {
- Control children[] = composite.getChildren();
Rectangle rect = composite.getClientArea();
rect.x += marginWidth;
rect.y += marginHeight;
rect.width -= 2 * marginWidth;
rect.height -= 2 * marginHeight;
- for (int i = 0; i < children.length; i++) {
- children[i].setBounds(rect);
- children[i].setVisible(children[i] == topControl);
+ for (Control element : composite.getChildren()) {
+ element.setBounds(rect);
+ element.setVisible(element == topControl);
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
index 61453a5..8344e7c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
@@ -828,8 +828,7 @@
header.append(";");
}
header.append("}}\n{\\colortbl");
- for (int i = 0; i < colorTable.size(); i++) {
- Color color = colorTable.get(i);
+ for (Color color : colorTable) {
header.append("\\red");
header.append(color.getRed());
header.append("\\green");
@@ -4926,8 +4925,8 @@
}
}
if (hasSegmentsChars && !visualWrap) {
- for (int i= 0; i < segmentsChars.length; i++) {
- if (segmentsChars[i] == '\n' || segmentsChars[i] == '\r') {
+ for (char segmentsChar : segmentsChars) {
+ if (segmentsChar == '\n' || segmentsChar == '\r') {
visualWrap = true;
break;
}
@@ -5654,8 +5653,8 @@
lines[lineCount++] = text.substring(start);
if (fillWithSpaces) {
int maxLength = 0;
- for (int i = 0; i < lines.length; i++) {
- int length = lines[i].length();
+ for (String line : lines) {
+ int length = line.length();
maxLength = Math.max(maxLength, length);
}
for (int i = 0; i < lines.length; i++) {
@@ -7680,8 +7679,8 @@
if (redrawLines == null) return;
int topIndex = getPartialTopIndex();
int bottomIndex = getPartialBottomIndex();
- for (int i = 0; i < redrawLines.length; i++) {
- int lineIndex = redrawLines[i];
+ for (int redrawLine : redrawLines) {
+ int lineIndex = redrawLine;
if (!(topIndex <= lineIndex && lineIndex <= bottomIndex)) continue;
int width = -1;
Bullet bullet = renderer.getLineBullet(lineIndex, null);
@@ -8132,9 +8131,7 @@
super.scroll(destX, destY, x, y, width, height, false);
if (all) {
int deltaX = destX - x, deltaY = destY - y;
- Control[] children = getChildren();
- for (int i=0; i<children.length; i++) {
- Control child = children[i];
+ for (Control child : getChildren()) {
Rectangle rect = child.getBounds();
child.setLocation(rect.x + deltaX, rect.y + deltaY);
}
@@ -8219,8 +8216,7 @@
}
}
Control[] children = getChildren();
- for (int i=0; i<children.length; i++) {
- Control child = children[i];
+ for (Control child : children) {
Rectangle rect = child.getBounds();
child.setLocation(rect.x, rect.y + deltaY);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java
index d972777..20eec0a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java
@@ -411,8 +411,8 @@
}
void disposeTextLayout (TextLayout layout) {
if (layouts != null) {
- for (int i = 0; i < layouts.length; i++) {
- if (layouts[i] == layout) return;
+ for (TextLayout l : layouts) {
+ if (l == layout) return;
}
}
layout.dispose();
@@ -505,8 +505,8 @@
bulletIndex = bulletsIndices[index];
}
} else {
- for (int i = 0; i < bullets.length; i++) {
- bullet = bullets[i];
+ for (Bullet b : bullets) {
+ bullet = b;
bulletIndex = bullet.indexOf(lineIndex);
if (bulletIndex != -1) break;
}
@@ -561,8 +561,8 @@
}
FontData[] getFontData(int style) {
FontData[] fontDatas = regularFont.getFontData();
- for (int i = 0; i < fontDatas.length; i++) {
- fontDatas[i].setStyle(style);
+ for (FontData fontData : fontDatas) {
+ fontData.setStyle(style);
}
return fontDatas;
}
@@ -605,8 +605,7 @@
}
}
} else {
- for (int i = 0; i < styles.length; i++) {
- StyleRange style = styles[i];
+ for (StyleRange style : styles) {
if (style.start <= offset && offset < style.start + style.length && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) {
return true;
}
@@ -647,8 +646,7 @@
Bullet getLineBullet (int index, Bullet defaultBullet) {
if (bullets == null) return defaultBullet;
if (bulletsIndices != null) return defaultBullet;
- for (int i = 0; i < bullets.length; i++) {
- Bullet bullet = bullets[i];
+ for (Bullet bullet : bullets) {
if (bullet.indexOf(index) != -1) return bullet;
}
return defaultBullet;
@@ -1084,9 +1082,9 @@
bulletsIndices = null;
}
if (bullets != null) {
- for (int i = 0; i < bullets.length; i++) {
- if (bullets[i].indexOf(lineIndex) != -1) {
- bullet = bullets[i];
+ for (Bullet b : bullets) {
+ if (b.indexOf(lineIndex) != -1) {
+ bullet = b;
break;
}
}
@@ -1261,10 +1259,10 @@
ascent = metrics.getAscent() + metrics.getLeading();
descent = metrics.getDescent();
if (layouts != null) {
- for (int i = 0; i < layouts.length; i++) {
- if (layouts[i] != null && layouts[i] != layout) {
- layouts[i].setAscent(ascent);
- layouts[i].setDescent(descent);
+ for (TextLayout l : layouts) {
+ if (l != null && l != layout) {
+ l.setAscent(ascent);
+ l.setDescent(descent);
}
}
}
@@ -1294,8 +1292,7 @@
}
void reset() {
if (layouts != null) {
- for (int i = 0; i < layouts.length; i++) {
- TextLayout layout = layouts[i];
+ for (TextLayout layout : layouts) {
if (layout != null) layout.dispose();
}
layouts = null;
@@ -1637,8 +1634,8 @@
}
modifyEnd = modifyStart;
StyleRange[] mergeStyles = new StyleRange[3];
- for (int i = 0; i < newStyles.length; i++) {
- StyleRange newStyle = newStyles[i], style;
+ for (StyleRange newStyle : newStyles) {
+ StyleRange style;
int newStart = newStyle.start;
int newEnd = newStart + newStyle.length;
if (newStart == newEnd) continue;
@@ -1793,8 +1790,7 @@
void updateBullets(int startLine, int replaceLineCount, int newLineCount, boolean update) {
if (bullets == null) return;
if (bulletsIndices != null) return;
- for (int i = 0; i < bullets.length; i++) {
- Bullet bullet = bullets[i];
+ for (Bullet bullet : bullets) {
int[] lines = bullet.removeIndices(startLine, replaceLineCount, newLineCount, update);
if (lines != null) {
if (redrawLines == null) {
@@ -1808,8 +1804,8 @@
}
}
int removed = 0;
- for (int i = 0; i < bullets.length; i++) {
- if (bullets[i].size() == 0) removed++;
+ for (Bullet bullet : bullets) {
+ if (bullet.size() == 0) removed++;
}
if (removed > 0) {
if (removed == bullets.length) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableCursor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableCursor.java
index 48dead7..a1619c6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableCursor.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableCursor.java
@@ -115,8 +115,8 @@
}
};
int[] events = new int[] {SWT.Dispose, SWT.FocusIn, SWT.FocusOut, SWT.KeyDown, SWT.Paint, SWT.Traverse};
- for (int i = 0; i < events.length; i++) {
- addListener(events[i], listener);
+ for (int event : events) {
+ addListener(event, listener);
}
tableListener = event -> {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeCursor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeCursor.java
index 051dee6..a2cc0db 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeCursor.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeCursor.java
@@ -131,8 +131,8 @@
}
};
int[] events = new int[] { SWT.Dispose, SWT.FocusIn, SWT.FocusOut, SWT.KeyDown, SWT.Paint, SWT.Traverse };
- for (int i = 0; i < events.length; i++) {
- addListener(events[i], listener);
+ for (int event : events) {
+ addListener(event, listener);
}
treeListener = event -> {
@@ -280,9 +280,8 @@
if (root == null) return 0;
if (root.getItemCount() == 0) return 1;
if (!root.getExpanded()) return 1;
- TreeItem[] items = root.getItems();
- for (int i = 0; i < items.length; i++) {
- pages += countSubTreePages(items[i]);
+ for (TreeItem item : root.getItems()) {
+ pages += countSubTreePages(item);
}
return pages;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewForm.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewForm.java
index af2dde8..a1291fd 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewForm.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/ViewForm.java
@@ -171,8 +171,8 @@
int[] events = new int[] {SWT.Dispose, SWT.Paint, SWT.Resize};
- for (int i = 0; i < events.length; i++) {
- addListener(events[i], listener);
+ for (int event : events) {
+ addListener(event, listener);
}
}