diff --git a/examples/.settings_shared/org.eclipse.jdt.core.prefs b/examples/.settings_shared/org.eclipse.jdt.core.prefs index ac07fadb094..f10d95a29e9 100644 --- a/examples/.settings_shared/org.eclipse.jdt.core.prefs +++ b/examples/.settings_shared/org.eclipse.jdt.core.prefs @@ -131,7 +131,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference= org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning -org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=enabled diff --git a/examples/org.eclipse.swt.examples/.settings/org.eclipse.jdt.ui.prefs b/examples/org.eclipse.swt.examples/.settings/org.eclipse.jdt.ui.prefs index 0965ff6bf1a..7c206b36c44 100644 --- a/examples/org.eclipse.swt.examples/.settings/org.eclipse.jdt.ui.prefs +++ b/examples/org.eclipse.swt.examples/.settings/org.eclipse.jdt.ui.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +sp_cleanup.add_all=false sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true @@ -9,52 +10,143 @@ sp_cleanup.add_missing_nls_tags=false sp_cleanup.add_missing_override_annotations=true sp_cleanup.add_missing_override_annotations_interface_methods=true sp_cleanup.add_serial_version_id=false +sp_cleanup.also_simplify_lambda=false sp_cleanup.always_use_blocks=true sp_cleanup.always_use_parentheses_in_expressions=false sp_cleanup.always_use_this_for_non_static_field_access=false sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.array_with_curly=false +sp_cleanup.arrays_fill=false +sp_cleanup.bitwise_conditional_expression=false +sp_cleanup.boolean_literal=false +sp_cleanup.boolean_value_rather_than_comparison=false +sp_cleanup.break_loop=false +sp_cleanup.collection_cloning=false +sp_cleanup.comparing_on_criteria=false +sp_cleanup.comparison_statement=false +sp_cleanup.controlflow_merge=false sp_cleanup.convert_functional_interfaces=false sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false +sp_cleanup.convert_to_switch_expressions=false sp_cleanup.correct_indentation=false +sp_cleanup.do_while_rather_than_while=false +sp_cleanup.double_negation=false +sp_cleanup.else_if=false +sp_cleanup.embedded_if=false +sp_cleanup.evaluate_nullable=false +sp_cleanup.extract_increment=false sp_cleanup.format_source_code=false sp_cleanup.format_source_code_changes_only=false +sp_cleanup.hash=false +sp_cleanup.if_condition=false sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.instanceof=false +sp_cleanup.instanceof_keyword=false +sp_cleanup.invert_equals=false +sp_cleanup.join=false +sp_cleanup.lazy_logical_operator=false sp_cleanup.make_local_variable_final=true sp_cleanup.make_parameters_final=false sp_cleanup.make_private_fields_final=true sp_cleanup.make_type_abstract_if_missing_method=false sp_cleanup.make_variable_declarations_final=false +sp_cleanup.map_cloning=false +sp_cleanup.merge_conditional_blocks=false +sp_cleanup.multi_catch=false sp_cleanup.never_use_blocks=false sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.no_string_creation=true +sp_cleanup.no_super=false +sp_cleanup.number_suffix=false +sp_cleanup.objects_equals=false sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=false +sp_cleanup.operand_factorization=false sp_cleanup.organize_imports=true +sp_cleanup.overridden_assignment=false +sp_cleanup.overridden_assignment_move_decl=false +sp_cleanup.plain_replacement=false +sp_cleanup.precompile_regex=false +sp_cleanup.primitive_comparison=false +sp_cleanup.primitive_parsing=false +sp_cleanup.primitive_rather_than_wrapper=false +sp_cleanup.primitive_serialization=false +sp_cleanup.pull_out_if_from_if_else=false +sp_cleanup.pull_up_assignment=false +sp_cleanup.push_down_negation=false sp_cleanup.qualify_static_field_accesses_with_declaring_class=false sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true sp_cleanup.qualify_static_member_accesses_with_declaring_class=false sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.reduce_indentation=false +sp_cleanup.redundant_comparator=false +sp_cleanup.redundant_falling_through_block_end=false sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_modifiers=false +sp_cleanup.remove_redundant_semicolons=true sp_cleanup.remove_redundant_type_arguments=true sp_cleanup.remove_trailing_whitespaces=true sp_cleanup.remove_trailing_whitespaces_all=true sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_array_creation=true sp_cleanup.remove_unnecessary_casts=true sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unnecessary_suppress_warnings=false sp_cleanup.remove_unused_imports=false sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_method_parameters=false sp_cleanup.remove_unused_private_fields=true sp_cleanup.remove_unused_private_members=false sp_cleanup.remove_unused_private_methods=true sp_cleanup.remove_unused_private_types=true +sp_cleanup.replace_deprecated_calls=false +sp_cleanup.replace_deprecated_fields=false +sp_cleanup.return_expression=false +sp_cleanup.simplify_boolean_if_else=false +sp_cleanup.simplify_lambda_expression_and_method_ref=false +sp_cleanup.single_used_field=false sp_cleanup.sort_members=false sp_cleanup.sort_members_all=false +sp_cleanup.standard_comparison=false +sp_cleanup.static_inner_class=false +sp_cleanup.strictly_equal_or_different=false +sp_cleanup.stringbuffer_to_stringbuilder=false +sp_cleanup.stringbuilder=false +sp_cleanup.stringbuilder_for_local_vars=false +sp_cleanup.stringconcat_stringbuffer_stringbuilder=false +sp_cleanup.stringconcat_to_textblock=false +sp_cleanup.substring=false +sp_cleanup.switch=false +sp_cleanup.switch_for_instanceof_pattern=false +sp_cleanup.system_property=false +sp_cleanup.system_property_boolean=false +sp_cleanup.system_property_file_encoding=false +sp_cleanup.system_property_file_separator=false +sp_cleanup.system_property_javaspecversion=false +sp_cleanup.system_property_javaversion=false +sp_cleanup.system_property_line_separator=false +sp_cleanup.system_property_path_separator=false +sp_cleanup.ternary_operator=false +sp_cleanup.try_with_resource=false +sp_cleanup.unlooped_while=false +sp_cleanup.unreachable_block=false sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false sp_cleanup.use_blocks=false sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=false sp_cleanup.use_lambda=true sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_string_is_blank=false sp_cleanup.use_this_for_non_static_field_access=false sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true sp_cleanup.use_this_for_non_static_method_access=false sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true sp_cleanup.use_type_arguments=false +sp_cleanup.use_unboxing=false +sp_cleanup.use_var=false +sp_cleanup.useless_continue=false +sp_cleanup.useless_return=true +sp_cleanup.valueof_rather_than_instantiation=false diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java index 91a038532c8..d14a950b459 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -410,8 +410,8 @@ public void clear (int [] indices) { checkWidget (); if (indices == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); if (indices.length == 0) return; - for (int i = 0; i < indices.length; i++) { - if (!(0 <= indices [i] && indices [i] < itemsCount)) { + for (int index : indices) { + if (!(0 <= index && index < itemsCount)) { SWT.error (SWT.ERROR_INVALID_RANGE); } } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/FindListener.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/FindListener.java index a8d74e4b6a3..e5326a11f4b 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/FindListener.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/FindListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -16,6 +16,6 @@ public interface FindListener { -public boolean find(); +boolean find(); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/MyTypeTransfer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/MyTypeTransfer.java index 529af517132..21ef2ff970b 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/MyTypeTransfer.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/clipboard/MyTypeTransfer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -100,8 +100,7 @@ protected int[] getTypeIds(){ return new int[] {MYTYPEID}; } boolean checkMyType(Object object) { - if (object == null || !(object instanceof MyType[]) || ((MyType[])object).length == 0) return false; - MyType[] myTypes = (MyType[])object; + if (object == null || !(object instanceof MyType[] myTypes) || myTypes.length == 0) return false; for (MyType myType : myTypes) { if (myType == null || myType.firstName == null || diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java index d9642c80082..d60c44f2a3f 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/CoolBarTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -205,8 +205,7 @@ void createExampleWidgets () { Control control = coolItem.getControl(); Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT); Point coolSize = coolItem.computeSize(size.x, size.y); - if (control instanceof ToolBar) { - ToolBar bar = (ToolBar)control; + if (control instanceof ToolBar bar) { if (bar.getItemCount() > 0) { if (vertical) { size.y = bar.getItem(0).getBounds().height; diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashFormTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashFormTab.java index 14074899216..e3babcde27d 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashFormTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SashFormTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -81,7 +81,7 @@ void createExampleWidgets () { list2.setItems (ListData1); text = new Text (form, SWT.MULTI | SWT.BORDER); text.setText (ControlExample.getResourceString("Multi_line")); //$NON-NLS-1$ - form.setWeights(new int[] {1, 1, 1}); + form.setWeights(1, 1, 1); } /** * Creates the "Style" group. diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java index 4214eeb64a1..d6e3e480be2 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -1019,7 +1019,7 @@ String parameterInfo(String methodRoot) { if (isArray) { typeNameString += "[]"; } - return ControlExample.getResourceString("Parameter_Info", new Object[] {typeNameString, info}); + return ControlExample.getResourceString("Parameter_Info", typeNameString, info); } void getValue() { diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java index 0d4d3866a14..85705b8c0f0 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -255,7 +255,7 @@ private void createShellContents() { sashForm.setLayoutData(gridData); createTreeView(sashForm); createTableView(sashForm); - sashForm.setWeights(new int[] { 2, 5 }); + sashForm.setWeights(2, 5); numObjectsLabel = new Label(shell, SWT.BORDER); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorListener.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorListener.java index 811bee1c51d..279132e3f88 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorListener.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ColorListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -22,6 +22,6 @@ */ public interface ColorListener { - public void setColor(GraphicsBackground gb); + void setColor(GraphicsBackground gb); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicsExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicsExample.java index 6b7e32358b4..6fbe1d49b17 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicsExample.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/GraphicsExample.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -617,8 +617,7 @@ public void run() { if (canvas.isDisposed()) return; int timeout = TIMER; GraphicsTab tab = getTab(); - if (tab instanceof AnimatedGraphicsTab) { - AnimatedGraphicsTab animTab = (AnimatedGraphicsTab) tab; + if (tab instanceof AnimatedGraphicsTab animTab) { if (animate && animTab.getAnimation()) { Rectangle rect = canvas.getClientArea(); animTab.next(rect.width, rect.height); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java index 9451b18d44a..76997e404e4 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -166,12 +166,12 @@ public void createPartControl(Composite frame) { ToolBar bar = new ToolBar (frame, SWT.BORDER); for (int i=0; i<5; i++) { ToolItem item = new ToolItem (bar, SWT.PUSH); - item.setText (getResourceString("ToolItem.text", new Object[] { Integer.valueOf(i) })); + item.setText (getResourceString("ToolItem.text", Integer.valueOf(i))); item.setData ("TIP_TEXT", getResourceString("ToolItem.tooltip", - new Object[] { item.getText(), helpKey })); + item.getText(), helpKey)); item.setData ("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> { Item item1 = (Item) widget; - return getResourceString("ToolItem.help", new Object[] { item1.getText() }); + return getResourceString("ToolItem.help", item1.getText()); }); } GridData gridData = new GridData(); @@ -182,14 +182,14 @@ public void createPartControl(Composite frame) { Table table = new Table (frame, SWT.BORDER); for (int i=0; i<4; i++) { TableItem item = new TableItem (table, SWT.PUSH); - item.setText (getResourceString("Item", new Object[] { Integer.valueOf(i) })); + item.setText (getResourceString("Item", Integer.valueOf(i))); item.setData ("TIP_IMAGE", images[hhiInformation]); - item.setText (getResourceString("TableItem.text", new Object[] { Integer.valueOf(i) })); + item.setText (getResourceString("TableItem.text", Integer.valueOf(i))); item.setData ("TIP_TEXT", getResourceString("TableItem.tooltip", - new Object[] { item.getText(), helpKey })); + item.getText(), helpKey)); item.setData ("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> { Item item1 = (Item) widget; - return getResourceString("TableItem.help", new Object[] { item1.getText() }); + return getResourceString("TableItem.help", item1.getText()); }); } table.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL)); @@ -198,14 +198,14 @@ public void createPartControl(Composite frame) { Tree tree = new Tree (frame, SWT.BORDER); for (int i=0; i<4; i++) { TreeItem item = new TreeItem (tree, SWT.PUSH); - item.setText (getResourceString("Item", new Object[] { Integer.valueOf(i) })); + item.setText (getResourceString("Item", Integer.valueOf(i))); item.setData ("TIP_IMAGE", images[hhiWarning]); - item.setText (getResourceString("TreeItem.text", new Object[] { Integer.valueOf(i) })); + item.setText (getResourceString("TreeItem.text", Integer.valueOf(i))); item.setData ("TIP_TEXT", getResourceString("TreeItem.tooltip", - new Object[] { item.getText(), helpKey})); + item.getText(), helpKey)); item.setData ("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> { Item item1 = (Item) widget; - return getResourceString("TreeItem.help", new Object[] { item1.getText() }); + return getResourceString("TreeItem.help", item1.getText()); }); } tree.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL)); @@ -289,16 +289,13 @@ public void mouseExit(MouseEvent e) { public void mouseHover (MouseEvent event) { Point pt = new Point (event.x, event.y); Widget widget = event.widget; - if (widget instanceof ToolBar) { - ToolBar w = (ToolBar) widget; + if (widget instanceof ToolBar w) { widget = w.getItem (pt); } - if (widget instanceof Table) { - Table w = (Table) widget; + if (widget instanceof Table w) { widget = w.getItem (pt); } - if (widget instanceof Tree) { - Tree w = (Tree) widget; + if (widget instanceof Tree w) { widget = w.getItem (pt); } if (widget == null) { @@ -366,6 +363,6 @@ protected interface ToolTipHelpTextHandler { * @param widget the widget that is under help * @return a help text string */ - public String getHelpText(Widget widget); + String getHelpText(Widget widget); } } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java index 5daa74431ee..3285b60eb5a 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -2082,14 +2082,12 @@ void showErrorDialog(String operation, String filename, Throwable e) { String message = createMsg(bundle.getString("Error"), operation, filename); String errorMessage = ""; if (e != null) { - if (e instanceof SWTException) { - SWTException swte = (SWTException) e; + if (e instanceof SWTException swte) { errorMessage = swte.getMessage(); if (swte.throwable != null) { errorMessage += ":\n" + swte.throwable.toString(); } - } else if (e instanceof SWTError) { - SWTError swte = (SWTError) e; + } else if (e instanceof SWTError swte) { errorMessage = swte.getMessage(); if (swte.throwable != null) { errorMessage += ":\n" + swte.throwable.toString(); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java index 1da79eb9a27..48c54296698 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -143,7 +143,7 @@ void createChildWidgets () { heightText.setText(data.get(index)[HEIGHT_COL]); createTextEditor(heightText, heightEditor, HEIGHT_COL); - String[] alignValues = new String[] { "BEGINNING", "CENTER", "END", "FILL" }; + String[] alignValues = { "BEGINNING", "CENTER", "END", "FILL" }; hAlign = new CCombo(table, SWT.NONE); hAlign.setItems(alignValues); hAlign.setText(newItem.getText(HALIGN_COL)); diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSession.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSession.java index bcfda6669eb..8da410ef827 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSession.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSession.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -27,21 +27,21 @@ public interface PaintSession extends MouseListener, MouseMoveListener { * * @return the associated PaintSurface */ - public PaintSurface getPaintSurface(); + PaintSurface getPaintSurface(); /** * Activates the session. * * Note: When overriding this method, call super.beginSession() at method start. */ - public abstract void beginSession(); + void beginSession(); /** * Deactivates the session. * * Note: When overriding this method, call super.endSession() at method exit. */ - public abstract void endSession(); + void endSession(); /** * Resets the session. @@ -49,7 +49,7 @@ public interface PaintSession extends MouseListener, MouseMoveListener { * * Note: When overriding this method, call super.resetSession() at method exit. */ - public abstract void resetSession(); + void resetSession(); /** @@ -57,5 +57,5 @@ public interface PaintSession extends MouseListener, MouseMoveListener { * * @return the localized name of this tool */ - public String getDisplayName(); + String getDisplayName(); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java index 50455c66fd9..3324457cf7a 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintSurface.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -261,8 +261,8 @@ public PaintSession getPaintSession() { * might be) */ public PaintTool getPaintTool() { - return (paintSession != null && paintSession instanceof PaintTool) ? - (PaintTool)paintSession : null; + return (paintSession != null && paintSession instanceof PaintTool p) ? + p : null; } /** diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintTool.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintTool.java index 06cc1bf727e..e0239487711 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintTool.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/paint/PaintTool.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -19,5 +19,5 @@ public interface PaintTool extends PaintSession { * * @param toolSettings the new tool settings */ - public void set(ToolSettings toolSettings); + void set(ToolSettings toolSettings); } diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java index c4d5d9ab137..bc725f43cc1 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/texteditor/TextEditor.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.swt.examples.texteditor; +import static org.eclipse.swt.SWT.BOLD; +import static org.eclipse.swt.SWT.ITALIC; import static org.eclipse.swt.events.MenuListener.menuShownAdapter; import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; @@ -35,8 +37,7 @@ import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlListener; -import org.eclipse.swt.events.MenuAdapter; -import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.MenuListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.VerifyEvent; @@ -101,8 +102,6 @@ public class TextEditor { static final int BULLET_WIDTH = 40; static final int MARGIN = 5; - static final int BOLD = SWT.BOLD; - static final int ITALIC = SWT.ITALIC; static final int FONT_STYLE = BOLD | ITALIC; static final int STRIKEOUT = 1 << 3; static final int FOREGROUND = 1 << 4; @@ -257,12 +256,7 @@ void createMenuBar() { saveItem.setText(getResourceString("Save_menuitem")); //$NON-NLS-1$ saveItem.addSelectionListener(widgetSelectedAdapter(event -> saveFile())); - fileMenu.addMenuListener(new MenuAdapter() { - @Override - public void menuShown(MenuEvent event){ - saveItem.setEnabled(fileName != null); - } - }); + fileMenu.addMenuListener(MenuListener.menuShownAdapter(e -> saveItem.setEnabled(fileName != null))); MenuItem saveAsItem = new MenuItem(fileMenu, SWT.PUSH); saveAsItem.setText(getResourceString("SaveAs_menuitem")); //$NON-NLS-1$ @@ -869,8 +863,8 @@ void disposeRanges(StyleRange[] ranges) { Object data = rangeToDispose.data; if (data != null) { - if (data instanceof Image) ((Image)data).dispose(); - if (data instanceof Control) ((Control)data).dispose(); + if (data instanceof Image image) image.dispose(); + if (data instanceof Control control) control.dispose(); } } } @@ -1037,14 +1031,12 @@ void handlePaintObject(PaintObjectEvent event) { GC gc = event.gc; StyleRange style = event.style; Object data = style.data; - if (data instanceof Image) { - Image image = (Image)data; + if (data instanceof Image image) { int x = event.x; int y = event.y + event.ascent - style.metrics.ascent; gc.drawImage(image, x, y); } - if (data instanceof Control) { - Control control = (Control)data; + if (data instanceof Control control) { Point pt = control.getSize(); int x = event.x + MARGIN; int y = event.y + event.ascent - 2 * pt.y / 3; @@ -1109,8 +1101,8 @@ void installListeners() { for (StyleRange style : styles) { Object data = style.data; if (data != null) { - if (data instanceof Image) ((Image)data).dispose(); - if (data instanceof Control) ((Control)data).dispose(); + if (data instanceof Image image) image.dispose(); + if (data instanceof Control control) control.dispose(); } } });