Skip to content

Commit 8dc46be

Browse files
committed
Fix all new non-deprecation warnings and resolve suppressed warnings
1 parent 1d4e668 commit 8dc46be

File tree

17 files changed

+106
-120
lines changed

17 files changed

+106
-120
lines changed

bundles/org.eclipse.swt/Eclipse SWT Accessibility/cocoa/org/eclipse/swt/accessibility/Accessible.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
*
4646
* @since 2.0
4747
*/
48-
@SuppressWarnings({"rawtypes", "unchecked"})
4948
public class Accessible {
5049

5150
static boolean DEBUG = false;
@@ -87,7 +86,7 @@ public class Accessible {
8786
Control control;
8887
int currentRole = -1;
8988

90-
Map /*<Integer, SWTAccessibleDelegate>*/ childToIdMap = new HashMap();
89+
Map<Integer, SWTAccessibleDelegate> childToIdMap = new HashMap<>();
9190
SWTAccessibleDelegate delegate;
9291

9392
int index = -1;
@@ -3099,10 +3098,7 @@ void release(boolean destroy) {
30993098
relations = null;
31003099

31013100
if (childToIdMap != null) {
3102-
Collection delegates = childToIdMap.values();
3103-
Iterator iter = delegates.iterator();
3104-
while (iter.hasNext()) {
3105-
SWTAccessibleDelegate childDelegate = (SWTAccessibleDelegate)iter.next();
3101+
for (SWTAccessibleDelegate childDelegate : childToIdMap.values()) {
31063102
childDelegate.internal_dispose_SWTAccessibleDelegate();
31073103
childDelegate.release();
31083104
}

bundles/org.eclipse.swt/Eclipse SWT Accessibility/cocoa/org/eclipse/swt/accessibility/SWTAccessibleDelegate.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.eclipse.swt.internal.*;
1919
import org.eclipse.swt.internal.cocoa.*;
2020

21-
@SuppressWarnings("rawtypes")
2221
class SWTAccessibleDelegate extends NSObject {
2322

2423
/**
@@ -42,7 +41,7 @@ class SWTAccessibleDelegate extends NSObject {
4241
NSArray actionNames = null;
4342

4443
static {
45-
Class clazz = SWTAccessibleDelegate.class;
44+
Class<?> clazz = SWTAccessibleDelegate.class;
4645

4746
accessible2Args = new Callback(clazz, "accessibleProc", 2);
4847
proc2Args = accessible2Args.getAddress();

bundles/org.eclipse.swt/Eclipse SWT Accessibility/cocoa/org/eclipse/swt/accessibility/TableAccessibleDelegate.java

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
* and column objects and a header as its children, and identifies which cell the mouse is
3232
* over.
3333
*/
34-
@SuppressWarnings({"rawtypes", "unchecked"})
3534
class TableAccessibleDelegate {
3635

37-
Map /*<Integer, AccessibleTableColumn>*/ childColumnToIdMap = new HashMap();
38-
Map /*<Integer, AccessibleTableRow>*/ childRowToIdMap = new HashMap();
36+
Map<Integer, AccessibleTableColumn> childColumnToIdMap = new HashMap<>();
37+
Map<Integer, AccessibleTableRow> childRowToIdMap = new HashMap<>();
3938
Accessible tableAccessible;
4039
AccessibleTableHeader headerAccessible;
4140

@@ -59,15 +58,10 @@ public void getChildren(AccessibleControlEvent e) {
5958
Accessible[] children = new Accessible[childCount];
6059
int childIndex = 0;
6160

62-
Iterator iter = childRowToIdMap.values().iterator();
63-
while (iter.hasNext()) {
64-
AccessibleTableRow row = (AccessibleTableRow)iter.next();
61+
for (AccessibleTableRow row : childRowToIdMap.values()) {
6562
children[childIndex++] = row;
6663
}
67-
68-
iter = childColumnToIdMap.values().iterator();
69-
while (iter.hasNext()) {
70-
AccessibleTableColumn col = (AccessibleTableColumn)iter.next();
64+
for (AccessibleTableColumn col : childColumnToIdMap.values()) {
7165
children[childIndex++] = col;
7266
}
7367

@@ -83,10 +77,7 @@ public void getChildAtPoint(AccessibleControlEvent e) {
8377
Monitor primaryMonitor = Display.getCurrent().getPrimaryMonitor();
8478
testPoint.y = primaryMonitor.getBounds().height - e.y;
8579

86-
Iterator iter = childRowToIdMap.values().iterator();
87-
88-
while (iter.hasNext()) {
89-
AccessibleTableRow row = (AccessibleTableRow) iter.next();
80+
for (AccessibleTableRow row : childRowToIdMap.values()) {
9081
NSValue locationValue = new NSValue(row.getPositionAttribute(ACC.CHILDID_SELF).id);
9182
NSPoint location = locationValue.pointValue();
9283

@@ -172,7 +163,7 @@ public void getColumns(AccessibleTableEvent e) {
172163
int columnCount = childColumnToIdMap.size() > 0 ? childColumnToIdMap.size() : 1;
173164
Accessible[] accessibles = new Accessible[columnCount];
174165
for (int i = 0; i < columnCount; i++) {
175-
accessibles[i] = (Accessible) childColumnToIdMap.get(Integer.valueOf(i));
166+
accessibles[i] = childColumnToIdMap.get(i);
176167
}
177168
e.accessibles = accessibles;
178169
}
@@ -218,7 +209,7 @@ public void getRows(AccessibleTableEvent e) {
218209
int columnCount = childRowToIdMap.size() > 0 ? childRowToIdMap.size() : 1;
219210
Accessible[] accessibles = new Accessible[columnCount];
220211
for (int i = 0; i < columnCount; i++) {
221-
accessibles[i] = (Accessible) childRowToIdMap.get(Integer.valueOf(i));
212+
accessibles[i] = childRowToIdMap.get(i);
222213
}
223214
e.accessibles = accessibles;
224215
}
@@ -232,11 +223,11 @@ Accessible childColumnToOs(int childID) {
232223
}
233224

234225
/* Check cache for childID, if found, return corresponding osChildID. */
235-
AccessibleTableColumn childRef = (AccessibleTableColumn) childColumnToIdMap.get(Integer.valueOf(childID));
226+
AccessibleTableColumn childRef = childColumnToIdMap.get(childID);
236227

237228
if (childRef == null) {
238229
childRef = new AccessibleTableColumn(tableAccessible, childID);
239-
childColumnToIdMap.put(Integer.valueOf(childID), childRef);
230+
childColumnToIdMap.put(childID, childRef);
240231
}
241232

242233
return childRef;
@@ -248,7 +239,7 @@ Accessible childRowToOs(int childID) {
248239
}
249240

250241
/* Check cache for childID, if found, return corresponding osChildID. */
251-
AccessibleTableRow childRef = (AccessibleTableRow) childRowToIdMap.get(Integer.valueOf(childID));
242+
AccessibleTableRow childRef = childRowToIdMap.get(childID);
252243

253244
if (childRef == null) {
254245
childRef = new AccessibleTableRow(tableAccessible, childID);
@@ -265,10 +256,8 @@ AccessibleTableHeader headerAccessible() {
265256

266257
void release() {
267258
if (childRowToIdMap != null) {
268-
Collection delegates = childRowToIdMap.values();
269-
Iterator iter = delegates.iterator();
270-
while (iter.hasNext()) {
271-
SWTAccessibleDelegate childDelegate = ((Accessible)iter.next()).delegate;
259+
for (AccessibleTableRow delegate : childRowToIdMap.values()) {
260+
SWTAccessibleDelegate childDelegate = delegate.delegate;
272261
if (childDelegate != null) {
273262
childDelegate.internal_dispose_SWTAccessibleDelegate();
274263
childDelegate.release();
@@ -280,10 +269,8 @@ void release() {
280269
}
281270

282271
if (childColumnToIdMap != null) {
283-
Collection delegates = childColumnToIdMap.values();
284-
Iterator iter = delegates.iterator();
285-
while (iter.hasNext()) {
286-
SWTAccessibleDelegate childDelegate = ((Accessible)iter.next()).delegate;
272+
for (AccessibleTableColumn delegate : childColumnToIdMap.values()) {
273+
SWTAccessibleDelegate childDelegate = delegate.delegate;
287274
if (childDelegate != null) {
288275
childDelegate.internal_dispose_SWTAccessibleDelegate();
289276
childDelegate.release();
@@ -297,7 +284,7 @@ void release() {
297284

298285
void reset() {
299286
release();
300-
childColumnToIdMap = new HashMap();
301-
childRowToIdMap = new HashMap();
287+
childColumnToIdMap = new HashMap<>();
288+
childRowToIdMap = new HashMap<>();
302289
}
303290
}

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DragSource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
102102
* @noextend This class is not intended to be subclassed by clients.
103103
*/
104-
@SuppressWarnings({"rawtypes"})
105104
public class DragSource extends Widget {
106105

107106
// TODO: These should either move out of Display or be accessible to this class.
@@ -118,7 +117,7 @@ public class DragSource extends Widget {
118117
static {
119118
String className = "SWTDragSourceDelegate";
120119

121-
Class clazz = DragSource.class;
120+
Class<?> clazz = DragSource.class;
122121

123122
dragSource2Args = new Callback(clazz, "dragSourceProc", 2);
124123
proc2 = dragSource2Args.getAddress();

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/cocoa/org/eclipse/swt/dnd/DropTarget.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.swt.dnd;
1515

1616
import java.util.*;
17+
import java.util.List;
1718

1819
import org.eclipse.swt.*;
1920
import org.eclipse.swt.graphics.*;
@@ -77,15 +78,14 @@
7778
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
7879
* @noextend This class is not intended to be subclassed by clients.
7980
*/
80-
@SuppressWarnings({"rawtypes", "unchecked"})
8181
public class DropTarget extends Widget {
8282

8383
static Callback dropTarget2Args, dropTarget3Args, dropTarget6Args;
8484
static long proc2Args, proc3Args, proc6Args;
8585
static final String LOCK_CURSOR = "org.eclipse.swt.internal.lockCursor"; //$NON-NLS-1$
8686

8787
static {
88-
Class clazz = DropTarget.class;
88+
Class<?> clazz = DropTarget.class;
8989

9090
dropTarget2Args = new Callback(clazz, "dropTargetProc", 2);
9191
proc2Args = dropTarget2Args.getAddress();
@@ -916,7 +916,7 @@ public void setTransfer(Transfer... transferAgents){
916916

917917
// Register the types as valid drop types in Cocoa.
918918
// Accumulate all of the transfer types into a list.
919-
ArrayList typeStrings = new ArrayList();
919+
List<String> typeStrings = new ArrayList<>();
920920

921921
for (int i = 0; i < this.transferAgents.length; i++) {
922922
String[] types = transferAgents[i].getTypeNames();

bundles/org.eclipse.swt/Eclipse SWT WebKit/cocoa/org/eclipse/swt/browser/WebKit.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.eclipse.swt.layout.*;
2424
import org.eclipse.swt.widgets.*;
2525

26-
@SuppressWarnings({"rawtypes"})
2726
class WebKit extends WebBrowser {
2827
WebView webView;
2928
WebPreferences preferences;
@@ -121,7 +120,7 @@ class WebKit extends WebBrowser {
121120
@Override
122121
public void create (Composite parent, int style) {
123122
if (delegateClass == 0) {
124-
Class webKitClass = this.getClass();
123+
Class<?> webKitClass = this.getClass();
125124
Callback3 = new Callback(webKitClass, "browserProc", 3); //$NON-NLS-1$
126125
long proc3 = Callback3.getAddress();
127126
Callback4 = new Callback(webKitClass, "browserProc", 4); //$NON-NLS-1$

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.lang.Runtime.*;
1818
import java.util.*;
1919
import java.util.concurrent.*;
20+
import java.util.concurrent.atomic.*;
2021
import java.util.function.*;
2122

2223
import org.eclipse.swt.*;
@@ -103,7 +104,6 @@
103104
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
104105
* @noextend This class is not intended to be subclassed by clients.
105106
*/
106-
@SuppressWarnings({"rawtypes", "unchecked"})
107107
public class Display extends Device implements Executor {
108108

109109
static byte[] types = {'*','\0'};
@@ -362,7 +362,7 @@ enum APPEARANCE {
362362
Object data;
363363
String [] keys;
364364
Object [] values;
365-
static Map/*<NSObject, LONG>*/ dynamicObjectMap;
365+
static Map<NSObject, LONG> dynamicObjectMap;
366366

367367
/*
368368
* TEMPORARY CODE. Install the runnable that
@@ -579,7 +579,7 @@ void addWidget (NSObject view, Widget widget) {
579579

580580
if (ivar == 0) {
581581
if (dynamicObjectMap == null) {
582-
dynamicObjectMap = new HashMap();
582+
dynamicObjectMap = new HashMap<>();
583583
}
584584
LONG JNIRef = new LONG(widget.jniRef);
585585
dynamicObjectMap.put(view, JNIRef);
@@ -999,7 +999,7 @@ void createDisplay (DeviceData data) {
999999
String className = "SWTApplication";
10001000
long cls;
10011001
if ((cls = OS.objc_lookUpClass (className)) == 0) {
1002-
Class clazz = getClass();
1002+
Class<?> clazz = getClass();
10031003
applicationCallback2 = new Callback(clazz, "applicationProc", 2);
10041004
long proc2 = applicationCallback2.getAddress();
10051005
applicationCallback3 = new Callback(clazz, "applicationProc", 3);
@@ -2354,7 +2354,7 @@ static Widget GetWidget (long id) {
23542354
if (iVar == 0) {
23552355
if (dynamicObjectMap != null) {
23562356
NSObject key = new NSObject(id);
2357-
LONG dynJNIRef = (LONG) dynamicObjectMap.get(key);
2357+
LONG dynJNIRef = dynamicObjectMap.get(key);
23582358
if (dynJNIRef != null) jniRef[0] = dynJNIRef.value;
23592359
}
23602360
}
@@ -2683,7 +2683,7 @@ long createMenuItemSubclass(long baseClass, String newClass, boolean isDynamic)
26832683
void initClasses () {
26842684
if (OS.objc_lookUpClass ("SWTView") != 0) return;
26852685

2686-
Class clazz = getClass ();
2686+
Class<?> clazz = getClass ();
26872687
dialogCallback3 = new Callback(clazz, "dialogProc", 3);
26882688
long dialogProc3 = dialogCallback3.getAddress();
26892689
dialogCallback4 = new Callback(clazz, "dialogProc", 4);
@@ -3424,7 +3424,7 @@ boolean isBundled () {
34243424
return false;
34253425
}
34263426

3427-
static boolean isValidClass (Class clazz) {
3427+
static boolean isValidClass (Class<?> clazz) {
34283428
String name = clazz.getName ();
34293429
int index = name.lastIndexOf ('.');
34303430
return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
@@ -4312,7 +4312,7 @@ Widget removeWidget (NSObject view) {
43124312

43134313
if (iVar == 0) {
43144314
if (dynamicObjectMap != null) {
4315-
LONG dynJNIRef = (LONG) dynamicObjectMap.get(view);
4315+
LONG dynJNIRef = dynamicObjectMap.get(view);
43164316
if (dynJNIRef != null) jniRef[0] = dynJNIRef.value;
43174317
dynamicObjectMap.remove(view);
43184318
}
@@ -5277,22 +5277,21 @@ public void syncExec (Runnable runnable) {
52775277
*/
52785278
public <T, E extends Exception> T syncCall(SwtCallable<T, E> callable) throws E {
52795279
Objects.nonNull(callable);
5280-
@SuppressWarnings("unchecked")
5281-
T[] t = (T[]) new Object[1];
5282-
Object[] ex = new Object[1];
5280+
AtomicReference<T> result = new AtomicReference<>();
5281+
AtomicReference<Exception> ex = new AtomicReference<>();
52835282
syncExec(() -> {
52845283
try {
5285-
t[0] = callable.call();
5284+
result.setPlain(callable.call());
52865285
} catch (Exception e) {
5287-
ex[0] = e;
5286+
ex.setPlain(e);
52885287
}
52895288
});
5290-
if (ex[0] != null) {
5289+
if (ex.getPlain() != null) {
52915290
@SuppressWarnings("unchecked")
5292-
E e = (E) ex[0];
5291+
E e = (E) ex.getPlain();
52935292
throw e;
52945293
}
5295-
return t[0];
5294+
return result.getPlain();
52965295
}
52975296

52985297
/**

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
121121
* @noextend This class is not intended to be subclassed by clients.
122122
*/
123-
@SuppressWarnings({"rawtypes", "unchecked"})
124123
public class Shell extends Decorations {
125124
NSWindow window;
126125
SWTWindowDelegate windowDelegate;
@@ -135,7 +134,7 @@ public class Shell extends Decorations {
135134
NSRect currentFrame;
136135
NSRect fullScreenFrame;
137136
ToolBar toolBar;
138-
Map windowEmbedCounts;
137+
Map<NSWindow, Integer> windowEmbedCounts;
139138
MenuItem escMenuItem;
140139

141140
static int DEFAULT_CLIENT_WIDTH = -1;
@@ -501,8 +500,8 @@ void attachObserversToWindow(NSWindow newWindow) {
501500
display.addWidget (hostWindow, this);
502501
hostWindowClass = newHostWindowClass;
503502

504-
if (windowEmbedCounts == null) windowEmbedCounts = new HashMap();
505-
Integer embedCount = (Integer) windowEmbedCounts.get(hostWindow);
503+
if (windowEmbedCounts == null) windowEmbedCounts = new HashMap<>();
504+
Integer embedCount = windowEmbedCounts.get(hostWindow);
506505
if (embedCount == null) {
507506
embedCount = Integer.valueOf(0);
508507
}

0 commit comments

Comments
 (0)