Skip to content

Commit 162cbb4

Browse files
Copilotlaeubi
andcommitted
Store beep property evaluation in static boolean field and remove test cases
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
1 parent fdfc8e5 commit 162cbb4

4 files changed

Lines changed: 6 additions & 50 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ enum APPEARANCE {
117117
/* System property to be set for SWT application to use the system's theme */
118118
static final String USE_SYSTEM_THEME = "org.eclipse.swt.display.useSystemTheme";
119119
/* System property to control beep sounds */
120-
static final String BEEP_ENABLED = "swt.beep";
120+
public static final boolean BEEP_ENABLED = !"off".equalsIgnoreCase(System.getProperty("swt.beep"));
121121

122122
/* Windows and Events */
123123
Event [] eventQueue;
@@ -673,7 +673,7 @@ public void execute(Runnable runnable) {
673673
*/
674674
public void beep () {
675675
checkDevice ();
676-
if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) {
676+
if (BEEP_ENABLED) {
677677
OS.NSBeep ();
678678
}
679679
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ public void stop() {
510510
/* Package name */
511511
static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$
512512
/* System property to control beep sounds */
513-
static final String BEEP_ENABLED = "swt.beep";
513+
public static final boolean BEEP_ENABLED = !"off".equalsIgnoreCase(System.getProperty("swt.beep"));
514514
/* This code is intentionally commented.
515515
* ".class" can not be used on CLDC.
516516
*/
@@ -990,7 +990,7 @@ public void execute(Runnable runnable) {
990990
*/
991991
public void beep () {
992992
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
993-
if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) {
993+
if (BEEP_ENABLED) {
994994
GDK.gdk_display_beep(GDK.gdk_display_get_default());
995995
}
996996
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public class Display extends Device implements Executor {
225225
static final String USE_WS_BORDER_TEXT_KEY = "org.eclipse.swt.internal.win32.Text.use_WS_BORDER"; //$NON-NLS-1$
226226
boolean useWsBorderText = false;
227227
/* System property to control beep sounds */
228-
static final String BEEP_ENABLED = "swt.beep";
228+
public static final boolean BEEP_ENABLED = !"off".equalsIgnoreCase(System.getProperty("swt.beep"));
229229
/**
230230
* Changes the color of Table header's column delimiters.
231231
* Only affects custom-drawn header, that is when background/foreground header color is set.
@@ -854,7 +854,7 @@ public void execute(Runnable runnable) {
854854
*/
855855
public void beep () {
856856
checkDevice ();
857-
if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) {
857+
if (BEEP_ENABLED) {
858858
OS.MessageBeep (OS.MB_OK);
859859
}
860860
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -229,50 +229,6 @@ public void test_beep() {
229229
}
230230
}
231231

232-
@Test
233-
public void test_beep_disabled() {
234-
String originalValue = System.getProperty("swt.beep");
235-
try {
236-
System.setProperty("swt.beep", "off");
237-
Display display = new Display();
238-
try {
239-
// Should not beep when property is "off"
240-
display.beep();
241-
} finally {
242-
display.dispose();
243-
}
244-
} finally {
245-
// Restore original value
246-
if (originalValue != null) {
247-
System.setProperty("swt.beep", originalValue);
248-
} else {
249-
System.clearProperty("swt.beep");
250-
}
251-
}
252-
}
253-
254-
@Test
255-
public void test_beep_enabled() {
256-
String originalValue = System.getProperty("swt.beep");
257-
try {
258-
System.setProperty("swt.beep", "on");
259-
Display display = new Display();
260-
try {
261-
// Should beep when property is "on"
262-
display.beep();
263-
} finally {
264-
display.dispose();
265-
}
266-
} finally {
267-
// Restore original value
268-
if (originalValue != null) {
269-
System.setProperty("swt.beep", originalValue);
270-
} else {
271-
System.clearProperty("swt.beep");
272-
}
273-
}
274-
}
275-
276232
@Test
277233
public void test_close() {
278234
Display display = new Display();

0 commit comments

Comments
 (0)