Skip to content

Commit c588cde

Browse files
committed
Modernize examples with newer Java constructs
1 parent 75c97fd commit c588cde

File tree

18 files changed

+155
-79
lines changed

18 files changed

+155
-79
lines changed

examples/.settings_shared/org.eclipse.jdt.core.prefs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=
131131
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
132132
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
133133
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
134-
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
134+
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
135135
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
136136
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
137137
org.eclipse.jdt.core.compiler.release=enabled

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
eclipse.preferences.version=1
22
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
3+
sp_cleanup.add_all=false
34
sp_cleanup.add_default_serial_version_id=true
45
sp_cleanup.add_generated_serial_version_id=false
56
sp_cleanup.add_missing_annotations=true
@@ -9,52 +10,143 @@ sp_cleanup.add_missing_nls_tags=false
910
sp_cleanup.add_missing_override_annotations=true
1011
sp_cleanup.add_missing_override_annotations_interface_methods=true
1112
sp_cleanup.add_serial_version_id=false
13+
sp_cleanup.also_simplify_lambda=false
1214
sp_cleanup.always_use_blocks=true
1315
sp_cleanup.always_use_parentheses_in_expressions=false
1416
sp_cleanup.always_use_this_for_non_static_field_access=false
1517
sp_cleanup.always_use_this_for_non_static_method_access=false
18+
sp_cleanup.array_with_curly=false
19+
sp_cleanup.arrays_fill=false
20+
sp_cleanup.bitwise_conditional_expression=false
21+
sp_cleanup.boolean_literal=false
22+
sp_cleanup.boolean_value_rather_than_comparison=false
23+
sp_cleanup.break_loop=false
24+
sp_cleanup.collection_cloning=false
25+
sp_cleanup.comparing_on_criteria=false
26+
sp_cleanup.comparison_statement=false
27+
sp_cleanup.controlflow_merge=false
1628
sp_cleanup.convert_functional_interfaces=false
1729
sp_cleanup.convert_to_enhanced_for_loop=false
30+
sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false
31+
sp_cleanup.convert_to_switch_expressions=false
1832
sp_cleanup.correct_indentation=false
33+
sp_cleanup.do_while_rather_than_while=false
34+
sp_cleanup.double_negation=false
35+
sp_cleanup.else_if=false
36+
sp_cleanup.embedded_if=false
37+
sp_cleanup.evaluate_nullable=false
38+
sp_cleanup.extract_increment=false
1939
sp_cleanup.format_source_code=false
2040
sp_cleanup.format_source_code_changes_only=false
41+
sp_cleanup.hash=false
42+
sp_cleanup.if_condition=false
2143
sp_cleanup.insert_inferred_type_arguments=false
44+
sp_cleanup.instanceof=false
45+
sp_cleanup.instanceof_keyword=false
46+
sp_cleanup.invert_equals=false
47+
sp_cleanup.join=false
48+
sp_cleanup.lazy_logical_operator=false
2249
sp_cleanup.make_local_variable_final=true
2350
sp_cleanup.make_parameters_final=false
2451
sp_cleanup.make_private_fields_final=true
2552
sp_cleanup.make_type_abstract_if_missing_method=false
2653
sp_cleanup.make_variable_declarations_final=false
54+
sp_cleanup.map_cloning=false
55+
sp_cleanup.merge_conditional_blocks=false
56+
sp_cleanup.multi_catch=false
2757
sp_cleanup.never_use_blocks=false
2858
sp_cleanup.never_use_parentheses_in_expressions=true
59+
sp_cleanup.no_string_creation=true
60+
sp_cleanup.no_super=false
61+
sp_cleanup.number_suffix=false
62+
sp_cleanup.objects_equals=false
2963
sp_cleanup.on_save_use_additional_actions=true
64+
sp_cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=false
65+
sp_cleanup.operand_factorization=false
3066
sp_cleanup.organize_imports=true
67+
sp_cleanup.overridden_assignment=false
68+
sp_cleanup.overridden_assignment_move_decl=false
69+
sp_cleanup.plain_replacement=false
70+
sp_cleanup.precompile_regex=false
71+
sp_cleanup.primitive_comparison=false
72+
sp_cleanup.primitive_parsing=false
73+
sp_cleanup.primitive_rather_than_wrapper=false
74+
sp_cleanup.primitive_serialization=false
75+
sp_cleanup.pull_out_if_from_if_else=false
76+
sp_cleanup.pull_up_assignment=false
77+
sp_cleanup.push_down_negation=false
3178
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
3279
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
3380
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
3481
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
3582
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
83+
sp_cleanup.reduce_indentation=false
84+
sp_cleanup.redundant_comparator=false
85+
sp_cleanup.redundant_falling_through_block_end=false
3686
sp_cleanup.remove_private_constructors=true
87+
sp_cleanup.remove_redundant_modifiers=false
88+
sp_cleanup.remove_redundant_semicolons=true
3789
sp_cleanup.remove_redundant_type_arguments=true
3890
sp_cleanup.remove_trailing_whitespaces=true
3991
sp_cleanup.remove_trailing_whitespaces_all=true
4092
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
93+
sp_cleanup.remove_unnecessary_array_creation=true
4194
sp_cleanup.remove_unnecessary_casts=true
4295
sp_cleanup.remove_unnecessary_nls_tags=false
96+
sp_cleanup.remove_unnecessary_suppress_warnings=false
4397
sp_cleanup.remove_unused_imports=false
4498
sp_cleanup.remove_unused_local_variables=false
99+
sp_cleanup.remove_unused_method_parameters=false
45100
sp_cleanup.remove_unused_private_fields=true
46101
sp_cleanup.remove_unused_private_members=false
47102
sp_cleanup.remove_unused_private_methods=true
48103
sp_cleanup.remove_unused_private_types=true
104+
sp_cleanup.replace_deprecated_calls=false
105+
sp_cleanup.replace_deprecated_fields=false
106+
sp_cleanup.return_expression=false
107+
sp_cleanup.simplify_boolean_if_else=false
108+
sp_cleanup.simplify_lambda_expression_and_method_ref=false
109+
sp_cleanup.single_used_field=false
49110
sp_cleanup.sort_members=false
50111
sp_cleanup.sort_members_all=false
112+
sp_cleanup.standard_comparison=false
113+
sp_cleanup.static_inner_class=false
114+
sp_cleanup.strictly_equal_or_different=false
115+
sp_cleanup.stringbuffer_to_stringbuilder=false
116+
sp_cleanup.stringbuilder=false
117+
sp_cleanup.stringbuilder_for_local_vars=false
118+
sp_cleanup.stringconcat_stringbuffer_stringbuilder=false
119+
sp_cleanup.stringconcat_to_textblock=false
120+
sp_cleanup.substring=false
121+
sp_cleanup.switch=false
122+
sp_cleanup.switch_for_instanceof_pattern=false
123+
sp_cleanup.system_property=false
124+
sp_cleanup.system_property_boolean=false
125+
sp_cleanup.system_property_file_encoding=false
126+
sp_cleanup.system_property_file_separator=false
127+
sp_cleanup.system_property_javaspecversion=false
128+
sp_cleanup.system_property_javaversion=false
129+
sp_cleanup.system_property_line_separator=false
130+
sp_cleanup.system_property_path_separator=false
131+
sp_cleanup.ternary_operator=false
132+
sp_cleanup.try_with_resource=false
133+
sp_cleanup.unlooped_while=false
134+
sp_cleanup.unreachable_block=false
51135
sp_cleanup.use_anonymous_class_creation=false
136+
sp_cleanup.use_autoboxing=false
52137
sp_cleanup.use_blocks=false
53138
sp_cleanup.use_blocks_only_for_return_and_throw=false
139+
sp_cleanup.use_directly_map_method=false
54140
sp_cleanup.use_lambda=true
55141
sp_cleanup.use_parentheses_in_expressions=false
142+
sp_cleanup.use_string_is_blank=false
56143
sp_cleanup.use_this_for_non_static_field_access=false
57144
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
58145
sp_cleanup.use_this_for_non_static_method_access=false
59146
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
60147
sp_cleanup.use_type_arguments=false
148+
sp_cleanup.use_unboxing=false
149+
sp_cleanup.use_var=false
150+
sp_cleanup.useless_continue=false
151+
sp_cleanup.useless_return=true
152+
sp_cleanup.valueof_rather_than_instantiation=false

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 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
@@ -410,8 +410,8 @@ public void clear (int [] indices) {
410410
checkWidget ();
411411
if (indices == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
412412
if (indices.length == 0) return;
413-
for (int i = 0; i < indices.length; i++) {
414-
if (!(0 <= indices [i] && indices [i] < itemsCount)) {
413+
for (int index : indices) {
414+
if (!(0 <= index && index < itemsCount)) {
415415
SWT.error (SWT.ERROR_INVALID_RANGE);
416416
}
417417
}

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/FindListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2003 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
@@ -16,6 +16,6 @@
1616

1717
public interface FindListener {
1818

19-
public boolean find();
19+
boolean find();
2020

2121
}

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/MyTypeTransfer.java

Lines changed: 2 additions & 3 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
@@ -100,8 +100,7 @@ protected int[] getTypeIds(){
100100
return new int[] {MYTYPEID};
101101
}
102102
boolean checkMyType(Object object) {
103-
if (object == null || !(object instanceof MyType[]) || ((MyType[])object).length == 0) return false;
104-
MyType[] myTypes = (MyType[])object;
103+
if (object == null || !(object instanceof MyType[] myTypes) || myTypes.length == 0) return false;
105104
for (MyType myType : myTypes) {
106105
if (myType == null ||
107106
myType.firstName == null ||

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java

Lines changed: 2 additions & 3 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
@@ -205,8 +205,7 @@ void createExampleWidgets () {
205205
Control control = coolItem.getControl();
206206
Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
207207
Point coolSize = coolItem.computeSize(size.x, size.y);
208-
if (control instanceof ToolBar) {
209-
ToolBar bar = (ToolBar)control;
208+
if (control instanceof ToolBar bar) {
210209
if (bar.getItemCount() > 0) {
211210
if (vertical) {
212211
size.y = bar.getItem(0).getBounds().height;

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashFormTab.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 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
@@ -81,7 +81,7 @@ void createExampleWidgets () {
8181
list2.setItems (ListData1);
8282
text = new Text (form, SWT.MULTI | SWT.BORDER);
8383
text.setText (ControlExample.getResourceString("Multi_line")); //$NON-NLS-1$
84-
form.setWeights(new int[] {1, 1, 1});
84+
form.setWeights(1, 1, 1);
8585
}
8686
/**
8787
* Creates the "Style" group.

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 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
@@ -1019,7 +1019,7 @@ String parameterInfo(String methodRoot) {
10191019
if (isArray) {
10201020
typeNameString += "[]";
10211021
}
1022-
return ControlExample.getResourceString("Parameter_Info", new Object[] {typeNameString, info});
1022+
return ControlExample.getResourceString("Parameter_Info", typeNameString, info);
10231023
}
10241024

10251025
void getValue() {

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java

Lines changed: 2 additions & 2 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
@@ -255,7 +255,7 @@ private void createShellContents() {
255255
sashForm.setLayoutData(gridData);
256256
createTreeView(sashForm);
257257
createTableView(sashForm);
258-
sashForm.setWeights(new int[] { 2, 5 });
258+
sashForm.setWeights(2, 5);
259259

260260
numObjectsLabel = new Label(shell, SWT.BORDER);
261261
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006 IBM Corporation and others.
2+
* Copyright (c) 2006, 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
@@ -22,6 +22,6 @@
2222
*/
2323
public interface ColorListener {
2424

25-
public void setColor(GraphicsBackground gb);
25+
void setColor(GraphicsBackground gb);
2626

2727
}

0 commit comments

Comments
 (0)