Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2020-01-02 16:28:52 +0000
committerPaul Pazderski2020-01-03 09:40:23 +0000
commita43891aa2b40babfd65b3bc67530e2f7a41fd41b (patch)
treecf4c7f668e688a36c005208ab491702321ff747d
parente5d5a40e85cdf4c3788f7ecd2139b9d7ca784702 (diff)
downloadeclipse.platform.debug-a43891aa2b40babfd65b3bc67530e2f7a41fd41b.tar.gz
eclipse.platform.debug-a43891aa2b40babfd65b3bc67530e2f7a41fd41b.tar.xz
eclipse.platform.debug-a43891aa2b40babfd65b3bc67530e2f7a41fd41b.zip
try-with-resource' Change-Id: I82ad6831d4282e6626fd38f001ea12bd15335226 Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r--org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/MidiLaunch.java19
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java35
2 files changed, 28 insertions, 26 deletions
diff --git a/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/MidiLaunch.java b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/MidiLaunch.java
index 54f1cf8d5..5ea7600b8 100644
--- a/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/MidiLaunch.java
+++ b/org.eclipse.debug.examples.core/src/org/eclipse/debug/examples/core/midi/launcher/MidiLaunch.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2018 IBM Corporation and others.
+ * Copyright (c) 2008, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -87,7 +87,7 @@ public class MidiLaunch extends Launch implements ISuspendResume {
@Override
public boolean canTerminate() {
- return getSequencer().isOpen();
+ return fSequencer.isOpen();
}
@Override
@@ -100,10 +100,11 @@ public class MidiLaunch extends Launch implements ISuspendResume {
@Override
public void terminate() throws DebugException {
- getSequencer().stop();
- getSequencer().close();
+ fSequencer.stop();
+ fSequencer.close();
fireTerminate();
- DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[]{new DebugEvent(getSequencer(), DebugEvent.TERMINATE)});
+ DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {
+ new DebugEvent(fSequencer, DebugEvent.TERMINATE) });
}
@Override
@@ -129,16 +130,16 @@ public class MidiLaunch extends Launch implements ISuspendResume {
@Override
public void resume() throws DebugException {
- getSequencer().start();
+ fSequencer.start();
fireChanged();
- fireEvent(new DebugEvent(getSequencer(), DebugEvent.RESUME, DebugEvent.CLIENT_REQUEST));
+ fireEvent(new DebugEvent(fSequencer, DebugEvent.RESUME, DebugEvent.CLIENT_REQUEST));
}
@Override
public void suspend() throws DebugException {
- getSequencer().stop();
+ fSequencer.stop();
fireChanged();
- fireEvent(new DebugEvent(getSequencer(), DebugEvent.SUSPEND, DebugEvent.CLIENT_REQUEST));
+ fireEvent(new DebugEvent(fSequencer, DebugEvent.SUSPEND, DebugEvent.CLIENT_REQUEST));
}
/**
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java
index eb0cb0aa6..88fa40207 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2019 Paul Pazderski and others.
+ * Copyright (c) 2019, 2020 Paul Pazderski and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -158,24 +158,23 @@ public class IOConsoleTests extends AbstractDebugTest {
}
c.closeOutputStream();
- if (c.getConsole().getInputStream() != null) {
- c.getConsole().getInputStream().close();
- }
- if (expectedInputLines.length > 0) {
- assertNotNull(c.getConsole().getInputStream());
- assertTrue("InputStream is empty.", c.getConsole().getInputStream().available() > 0);
+ try (InputStream consoleIn = c.getConsole().getInputStream()) {
+ if (expectedInputLines.length > 0) {
+ assertNotNull(consoleIn);
+ assertTrue("InputStream is empty.", consoleIn.available() > 0);
- final List<String> inputLines = new ArrayList<>();
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(c.getConsole().getInputStream(), c.getConsole().getCharset()))) {
- String line;
- while (reader.ready() && (line = reader.readLine()) != null) {
- inputLines.add(line);
+ final List<String> inputLines = new ArrayList<>();
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(consoleIn, c.getConsole().getCharset()))) {
+ String line;
+ while (reader.ready() && (line = reader.readLine()) != null) {
+ inputLines.add(line);
+ }
+ }
+ assertEquals("Input contains to many/few lines.", expectedInputLines.length, inputLines.size());
+ for (int i = 0; i < expectedInputLines.length; i++) {
+ assertEquals("Content of input line " + i + " not as expected.", expectedInputLines[i], inputLines.get(i));
}
- }
- assertEquals("Input contains to many/few lines.", expectedInputLines.length, inputLines.size());
- for (int i = 0; i < expectedInputLines.length; i++) {
- assertEquals("Content of input line " + i + " not as expected.", expectedInputLines[i], inputLines.get(i));
}
}
c.waitForScheduledJobs();
@@ -277,7 +276,9 @@ public class IOConsoleTests extends AbstractDebugTest {
// streams are open and to prevent premature console closing
c.getDefaultOutputStream();
try (InputStream in = new ByteArrayInputStream(new byte[0])) {
- c.getConsole().getInputStream().close();
+ try (InputStream defaultIn = c.getConsole().getInputStream()) {
+ // just close input stream
+ }
c.getConsole().setInputStream(in);
}
closeConsole(c);

Back to the top