Skip to content

Commit 0865865

Browse files
committed
Use newer Java language features in snippets
And enable more save actions.
1 parent 1460543 commit 0865865

File tree

8 files changed

+115
-30
lines changed

8 files changed

+115
-30
lines changed

examples/org.eclipse.swt.snippets/.settings/org.eclipse.jdt.ui.prefs

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ org.eclipse.jdt.ui.ignorelowercasenames=true
44
org.eclipse.jdt.ui.importorder=java;javax;org;com;
55
org.eclipse.jdt.ui.ondemandthreshold=1
66
org.eclipse.jdt.ui.staticondemandthreshold=1
7+
sp_cleanup.add_all=false
78
sp_cleanup.add_default_serial_version_id=true
89
sp_cleanup.add_generated_serial_version_id=false
910
sp_cleanup.add_missing_annotations=true
@@ -13,52 +14,143 @@ sp_cleanup.add_missing_nls_tags=false
1314
sp_cleanup.add_missing_override_annotations=true
1415
sp_cleanup.add_missing_override_annotations_interface_methods=true
1516
sp_cleanup.add_serial_version_id=false
17+
sp_cleanup.also_simplify_lambda=false
1618
sp_cleanup.always_use_blocks=true
1719
sp_cleanup.always_use_parentheses_in_expressions=false
1820
sp_cleanup.always_use_this_for_non_static_field_access=false
1921
sp_cleanup.always_use_this_for_non_static_method_access=false
20-
sp_cleanup.convert_functional_interfaces=false
21-
sp_cleanup.convert_to_enhanced_for_loop=false
22+
sp_cleanup.array_with_curly=false
23+
sp_cleanup.arrays_fill=false
24+
sp_cleanup.bitwise_conditional_expression=false
25+
sp_cleanup.boolean_literal=false
26+
sp_cleanup.boolean_value_rather_than_comparison=false
27+
sp_cleanup.break_loop=false
28+
sp_cleanup.collection_cloning=false
29+
sp_cleanup.comparing_on_criteria=false
30+
sp_cleanup.comparison_statement=false
31+
sp_cleanup.controlflow_merge=false
32+
sp_cleanup.convert_functional_interfaces=true
33+
sp_cleanup.convert_to_enhanced_for_loop=true
34+
sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false
35+
sp_cleanup.convert_to_switch_expressions=false
2236
sp_cleanup.correct_indentation=false
37+
sp_cleanup.do_while_rather_than_while=false
38+
sp_cleanup.double_negation=false
39+
sp_cleanup.else_if=false
40+
sp_cleanup.embedded_if=false
41+
sp_cleanup.evaluate_nullable=false
42+
sp_cleanup.extract_increment=false
2343
sp_cleanup.format_source_code=false
2444
sp_cleanup.format_source_code_changes_only=false
45+
sp_cleanup.hash=false
46+
sp_cleanup.if_condition=false
2547
sp_cleanup.insert_inferred_type_arguments=false
48+
sp_cleanup.instanceof=true
49+
sp_cleanup.instanceof_keyword=false
50+
sp_cleanup.invert_equals=false
51+
sp_cleanup.join=false
52+
sp_cleanup.lazy_logical_operator=false
2653
sp_cleanup.make_local_variable_final=true
2754
sp_cleanup.make_parameters_final=false
2855
sp_cleanup.make_private_fields_final=true
2956
sp_cleanup.make_type_abstract_if_missing_method=false
3057
sp_cleanup.make_variable_declarations_final=false
58+
sp_cleanup.map_cloning=false
59+
sp_cleanup.merge_conditional_blocks=false
60+
sp_cleanup.multi_catch=true
3161
sp_cleanup.never_use_blocks=false
3262
sp_cleanup.never_use_parentheses_in_expressions=true
63+
sp_cleanup.no_string_creation=false
64+
sp_cleanup.no_super=false
65+
sp_cleanup.number_suffix=false
66+
sp_cleanup.objects_equals=false
3367
sp_cleanup.on_save_use_additional_actions=true
68+
sp_cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=false
69+
sp_cleanup.operand_factorization=false
3470
sp_cleanup.organize_imports=true
71+
sp_cleanup.overridden_assignment=false
72+
sp_cleanup.overridden_assignment_move_decl=false
73+
sp_cleanup.plain_replacement=false
74+
sp_cleanup.precompile_regex=false
75+
sp_cleanup.primitive_comparison=false
76+
sp_cleanup.primitive_parsing=false
77+
sp_cleanup.primitive_rather_than_wrapper=false
78+
sp_cleanup.primitive_serialization=false
79+
sp_cleanup.pull_out_if_from_if_else=false
80+
sp_cleanup.pull_up_assignment=false
81+
sp_cleanup.push_down_negation=false
3582
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
3683
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
3784
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
3885
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
3986
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
87+
sp_cleanup.reduce_indentation=false
88+
sp_cleanup.redundant_comparator=false
89+
sp_cleanup.redundant_falling_through_block_end=false
4090
sp_cleanup.remove_private_constructors=true
91+
sp_cleanup.remove_redundant_modifiers=false
92+
sp_cleanup.remove_redundant_semicolons=true
4193
sp_cleanup.remove_redundant_type_arguments=true
4294
sp_cleanup.remove_trailing_whitespaces=true
4395
sp_cleanup.remove_trailing_whitespaces_all=true
4496
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
97+
sp_cleanup.remove_unnecessary_array_creation=true
4598
sp_cleanup.remove_unnecessary_casts=true
4699
sp_cleanup.remove_unnecessary_nls_tags=false
100+
sp_cleanup.remove_unnecessary_suppress_warnings=false
47101
sp_cleanup.remove_unused_imports=false
48102
sp_cleanup.remove_unused_local_variables=false
103+
sp_cleanup.remove_unused_method_parameters=false
49104
sp_cleanup.remove_unused_private_fields=true
50105
sp_cleanup.remove_unused_private_members=false
51106
sp_cleanup.remove_unused_private_methods=true
52107
sp_cleanup.remove_unused_private_types=true
108+
sp_cleanup.replace_deprecated_calls=false
109+
sp_cleanup.replace_deprecated_fields=false
110+
sp_cleanup.return_expression=false
111+
sp_cleanup.simplify_boolean_if_else=false
112+
sp_cleanup.simplify_lambda_expression_and_method_ref=false
113+
sp_cleanup.single_used_field=false
53114
sp_cleanup.sort_members=false
54115
sp_cleanup.sort_members_all=false
116+
sp_cleanup.standard_comparison=false
117+
sp_cleanup.static_inner_class=false
118+
sp_cleanup.strictly_equal_or_different=false
119+
sp_cleanup.stringbuffer_to_stringbuilder=false
120+
sp_cleanup.stringbuilder=false
121+
sp_cleanup.stringbuilder_for_local_vars=false
122+
sp_cleanup.stringconcat_stringbuffer_stringbuilder=false
123+
sp_cleanup.stringconcat_to_textblock=false
124+
sp_cleanup.substring=false
125+
sp_cleanup.switch=false
126+
sp_cleanup.switch_for_instanceof_pattern=true
127+
sp_cleanup.system_property=false
128+
sp_cleanup.system_property_boolean=false
129+
sp_cleanup.system_property_file_encoding=false
130+
sp_cleanup.system_property_file_separator=false
131+
sp_cleanup.system_property_javaspecversion=false
132+
sp_cleanup.system_property_javaversion=false
133+
sp_cleanup.system_property_line_separator=false
134+
sp_cleanup.system_property_path_separator=false
135+
sp_cleanup.ternary_operator=false
136+
sp_cleanup.try_with_resource=false
137+
sp_cleanup.unlooped_while=false
138+
sp_cleanup.unreachable_block=false
55139
sp_cleanup.use_anonymous_class_creation=false
140+
sp_cleanup.use_autoboxing=false
56141
sp_cleanup.use_blocks=false
57142
sp_cleanup.use_blocks_only_for_return_and_throw=false
143+
sp_cleanup.use_directly_map_method=false
58144
sp_cleanup.use_lambda=true
59145
sp_cleanup.use_parentheses_in_expressions=false
146+
sp_cleanup.use_string_is_blank=false
60147
sp_cleanup.use_this_for_non_static_field_access=false
61148
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
62149
sp_cleanup.use_this_for_non_static_method_access=false
63150
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
64151
sp_cleanup.use_type_arguments=false
152+
sp_cleanup.use_unboxing=false
153+
sp_cleanup.use_var=false
154+
sp_cleanup.useless_continue=false
155+
sp_cleanup.useless_return=false
156+
sp_cleanup.valueof_rather_than_instantiation=false

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet109.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2005 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -47,7 +47,7 @@ public static void main (String [] args) {
4747
child3.setLayout(new FillLayout());
4848
new Label(child3,SWT.PUSH).setText("Label in pane3");
4949

50-
form.setWeights(new int[] {30,40,30});
50+
form.setWeights(30, 40, 30);
5151
shell.open ();
5252
while (!shell.isDisposed ()) {
5353
if (!display.readAndDispatch ()) display.sleep ();

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet115.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -39,8 +39,7 @@ public static void main (String [] args) {
3939
for (Composite composite : composites) {
4040
Control [] children = composite.getChildren ();
4141
for (Control child : children) {
42-
if (child instanceof Button) {
43-
Button button1 = (Button) child;
42+
if (child instanceof Button button1) {
4443
if ((button1.getStyle () & SWT.RADIO) != 0) button1.setSelection (false);
4544
}
4645
}

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet319.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -102,8 +102,7 @@ public void dragSetData(DragSourceEvent event) {
102102
* in a different context then the drop will not be accepted.
103103
*/
104104
FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
105-
if (map instanceof SystemFlavorMap) {
106-
SystemFlavorMap systemMap = (SystemFlavorMap)map;
105+
if (map instanceof SystemFlavorMap systemMap) {
107106
systemMap.addFlavorForUnencodedNative(MIME_TYPE, flavor);
108107
}
109108

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet373.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
package org.eclipse.swt.snippets;
2-
31
/*******************************************************************************
42
* Copyright (c) 2018 IBM Corporation and others.
53
*
@@ -13,6 +11,7 @@
1311
* Contributors:
1412
* IBM Corporation - initial API and implementation
1513
*******************************************************************************/
14+
package org.eclipse.swt.snippets;
1615

1716
import org.eclipse.swt.*;
1817
import org.eclipse.swt.custom.*;
@@ -83,18 +82,15 @@ public static void main(String[] args) {
8382
shell.setLayout(new RowLayout(SWT.VERTICAL));
8483
shell.setLocation(100, 100);
8584
shell.setSize(500, 600);
86-
shell.addListener(SWT.ZoomChanged, new Listener() {
87-
@Override
88-
public void handleEvent(Event e) {
89-
if (display.getPrimaryMonitor().equals(shell.getMonitor())) {
90-
MessageBox box = new MessageBox(shell, SWT.PRIMARY_MODAL | SWT.OK | SWT.CANCEL);
91-
box.setText(shell.getText());
92-
box.setMessage("DPI changed, do you want to exit & restart ?");
93-
e.doit = (box.open() == SWT.OK);
94-
if (e.doit) {
95-
shell.close();
96-
System.out.println("Program exit.");
97-
}
85+
shell.addListener(SWT.ZoomChanged, e -> {
86+
if (display.getPrimaryMonitor().equals(shell.getMonitor())) {
87+
MessageBox box = new MessageBox(shell, SWT.PRIMARY_MODAL | SWT.OK | SWT.CANCEL);
88+
box.setText(shell.getText());
89+
box.setMessage("DPI changed, do you want to exit & restart ?");
90+
e.doit = (box.open() == SWT.OK);
91+
if (e.doit) {
92+
shell.close();
93+
System.out.println("Program exit.");
9894
}
9995
}
10096
});

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet384.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private static void updateImageRow(PixelTransformer transformer, Map<PixelTransf
243243
}
244244

245245
@FunctionalInterface
246-
public static interface PixelTransformer {
246+
public interface PixelTransformer {
247247
RGBA transform(RGBA originalRgba);
248248
}
249249

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet386.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private Cursor createCursor(int selection) {
199199
}
200200

201201
ImageData mask = new ImageData(IMAGE_SIZE_IN_POINTS, IMAGE_SIZE_IN_POINTS, 1,
202-
new PaletteData(new RGB[] { new RGB(0, 0, 0), new RGB(255, 255, 255) }));
202+
new PaletteData(new RGB(0, 0, 0), new RGB(255, 255, 255)));
203203
for (int x = 0; x < IMAGE_SIZE_IN_POINTS; x++) {
204204
for (int y = 0; y < IMAGE_SIZE_IN_POINTS; y++) {
205205
mask.setPixel(x, y, x % 2);

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet79.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -114,11 +114,10 @@ public Object nativeToJava (TransferData transferData) {
114114

115115
boolean checkMyType(Object object) {
116116
if (object == null ||
117-
!(object instanceof MyType[]) ||
118-
((MyType[])object).length == 0) {
117+
!(object instanceof MyType[] myTypes) ||
118+
myTypes.length == 0) {
119119
return false;
120120
}
121-
MyType[] myTypes = (MyType[])object;
122121
for (MyType myType : myTypes) {
123122
if (myType == null ||
124123
myType.fileName == null ||

0 commit comments

Comments
 (0)