Skip to content

Commit e8a617b

Browse files
committed
Empty implementation for Done callback to stop accepting null
Currently `null` is tolerated as a callback for a number of terminal-related operations. The introduced empty implementation `NOOP` allows to prohibit `null` as a callback argument.
1 parent cbe2947 commit e8a617b

File tree

12 files changed

+49
-22
lines changed

12 files changed

+49
-22
lines changed

terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
7777
@Override
7878
public void execute(Map<String, Object> properties, ITerminalService.Done done) {
7979
Assert.isNotNull(properties);
80+
Assert.isNotNull(done);
8081

8182
// Set the terminal tab title
8283
String terminalTitle = getTerminalTitle(properties);

terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.eclipse.jface.viewers.IStructuredSelection;
2424
import org.eclipse.jface.viewers.StructuredSelection;
2525
import org.eclipse.terminal.connector.local.activator.UIPlugin;
26+
import org.eclipse.terminal.view.core.ITerminalService;
2627
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
2728
import org.eclipse.terminal.view.ui.launcher.ILauncherDelegate;
2829
import org.eclipse.ui.IEditorInput;
@@ -68,7 +69,7 @@ private void executeDelegate(ISelection selection, ILauncherDelegate delegate) {
6869
Map<String, Object> properties = new HashMap<>();
6970
properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegate.getId());
7071
properties.put(ITerminalsConnectorConstants.PROP_SELECTION, selection);
71-
delegate.execute(properties, null);
72+
delegate.execute(properties, ITerminalService.NOOP);
7273
}
7374

7475
}

terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/internal/ProcessLauncherDelegate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
4747
@Override
4848
public void execute(Map<String, Object> properties, ITerminalService.Done done) {
4949
Assert.isNotNull(properties);
50+
Assert.isNotNull(done);
5051

5152
// Get the terminal service
5253
ITerminalService terminal = getTerminalService();

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshLauncherDelegate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
5555
@Override
5656
public void execute(Map<String, Object> properties, ITerminalService.Done done) {
5757
Assert.isNotNull(properties);
58+
Assert.isNotNull(done);
5859

5960
// Set the terminal tab title
6061
String terminalTitle = getTerminalTitle(properties);

terminal/bundles/org.eclipse.terminal.connector.telnet/src/org/eclipse/terminal/connector/telnet/launcher/TelnetLauncherDelegate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
5454
@Override
5555
public void execute(Map<String, Object> properties, ITerminalService.Done done) {
5656
Assert.isNotNull(properties);
57+
Assert.isNotNull(done);
5758

5859
// Set the terminal tab title
5960
String terminalTitle = getTerminalTitle(properties);

terminal/bundles/org.eclipse.terminal.view.core/src/org/eclipse/terminal/view/core/ITerminalService.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 - 2018 Wind River Systems, Inc. and others. All rights reserved.
2+
* Copyright (c) 2011 - 2025 Wind River Systems, Inc. and others. All rights reserved.
33
* This program and the accompanying materials are made available under the terms
44
* of the Eclipse Public License 2.0 which accompanies this distribution, and is
55
* available at https://www.eclipse.org/legal/epl-2.0/
@@ -8,6 +8,7 @@
88
*
99
* Contributors:
1010
* Wind River Systems - initial API and implementation
11+
* Alexander Fedorov (ArSysOp) - further evolution
1112
*******************************************************************************/
1213
package org.eclipse.terminal.view.core;
1314

@@ -32,34 +33,48 @@ public interface Done {
3233
public void done(IStatus status);
3334
}
3435

36+
/**
37+
* Empty callback if no action is needed
38+
*/
39+
Done NOOP = new Done() {
40+
41+
@Override
42+
public void done(IStatus status) {
43+
//no-op
44+
}
45+
};
46+
3547
/**
3648
* Opens a terminal asynchronously and invokes the given callback if done.
3749
*
3850
* @param properties The terminal properties. Must not be <code>null</code>.
39-
* @param done The callback to invoke if finished or <code>null</code>.
51+
* @param done The callback to invoke if finished. Must not be <code>null</code>.
52+
* @see ITerminalService#NOOP
4053
*/
4154
public void openConsole(Map<String, Object> properties, Done done);
4255

4356
/**
4457
* Close the terminal asynchronously and invokes the given callback if done.
4558
*
4659
* @param properties The terminal properties. Must not be <code>null</code>.
47-
* @param done The callback to invoke if finished or <code>null</code>.
60+
* @param done The callback to invoke if finished. Must not be <code>null</code>.
61+
* @see ITerminalService#NOOP
4862
*/
4963
public void closeConsole(Map<String, Object> properties, Done done);
5064

5165
/**
5266
* Terminate (disconnect) the terminal asynchronously and invokes the given callback if done.
5367
*
5468
* @param properties The terminal properties. Must not be <code>null</code>.
55-
* @param done The callback to invoke if finished or <code>null</code>.
69+
* @param done The callback to invoke if finished. Must not be <code>null</code>.
70+
* @see ITerminalService#NOOP
5671
*/
5772
public void terminateConsole(Map<String, Object> properties, Done done);
5873

5974
/**
6075
* Register the given listener to receive notifications about terminal events.
6176
* Calling this method multiple times with the same listener has no effect.
62-
77+
6378
* @param listener The terminal tab listener. Must not be <code>null</code>.
6479
*/
6580
public void addTerminalTabListener(ITerminalTabListener listener);

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ protected static abstract class TerminalServiceRunnable {
7777
* @param title The terminal tab title. Must not be <code>null</code>.
7878
* @param connector The terminal connector. Must not be <code>null</code>.
7979
* @param data The custom terminal data node or <code>null</code>.
80-
* @param done The callback to invoke if the operation finished or <code>null</code>.
80+
* @param done The callback to invoke if finished. Must not be <code>null</code>.
81+
* @see ITerminalService#NOOP
8182
*/
8283
public abstract void run(TerminalViewId tvid, String title, ITerminalConnector connector, Object data,
8384
Done done);
@@ -165,6 +166,7 @@ protected final void executeServiceOperation(final Map<String, Object> propertie
165166
final TerminalServiceRunnable runnable, final Done done) {
166167
Assert.isNotNull(properties);
167168
Assert.isNotNull(runnable);
169+
Assert.isNotNull(done);
168170

169171
// Extract the properties
170172
String id = (String) properties.get(ITerminalsConnectorConstants.PROP_ID);
@@ -186,9 +188,7 @@ protected final void executeServiceOperation(final Map<String, Object> propertie
186188
connector = createTerminalConnector(properties);
187189
} catch (CoreException e) {
188190
// Properties contain invalid connector arguments
189-
if (done != null) {
190-
done.done(e.getStatus());
191-
}
191+
done.done(e.getStatus());
192192
return;
193193
}
194194
executeServiceOperation(runnable, new TerminalViewId(id, secondaryId), title, connector, data, done);
@@ -260,6 +260,7 @@ protected ITerminalConnector createTerminalConnector(Map<String, Object> propert
260260
@Override
261261
public void openConsole(final Map<String, Object> properties, final Done done) {
262262
Assert.isNotNull(properties);
263+
Assert.isNotNull(done);
263264
final boolean restoringView = fRestoringView;
264265

265266
executeServiceOperation(properties, new TerminalServiceRunnable() {
@@ -317,13 +318,9 @@ public void doRun(TerminalViewId tvid, String title, ITerminalConnector connecto
317318
console.setData("properties", properties); //$NON-NLS-1$
318319
}
319320
// Invoke the callback
320-
if (done != null) {
321-
done.done(Status.OK_STATUS);
322-
}
321+
done.done(Status.OK_STATUS);
323322
} catch (CoreException e) {
324-
if (done != null) {
325-
done.done(e.getStatus());
326-
}
323+
done.done(e.getStatus());
327324
}
328325
}
329326
}, done);
@@ -332,6 +329,7 @@ public void doRun(TerminalViewId tvid, String title, ITerminalConnector connecto
332329
@Override
333330
public void closeConsole(final Map<String, Object> properties, final Done done) {
334331
Assert.isNotNull(properties);
332+
Assert.isNotNull(done);
335333

336334
executeServiceOperation(properties, new TerminalServiceRunnable() {
337335
@Override
@@ -349,6 +347,7 @@ public void run(TerminalViewId tvid, String title, ITerminalConnector connector,
349347
@Override
350348
public void terminateConsole(Map<String, Object> properties, Done done) {
351349
Assert.isNotNull(properties);
350+
Assert.isNotNull(done);
352351

353352
executeServiceOperation(properties, new TerminalServiceRunnable() {
354353
@Override

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.eclipse.terminal.connector.ITerminalConnector;
3131
import org.eclipse.terminal.view.core.IContextPropertiesConstants;
3232
import org.eclipse.terminal.view.core.ITerminalContextPropertiesProvider;
33+
import org.eclipse.terminal.view.core.ITerminalService;
3334
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
3435
import org.eclipse.terminal.view.core.TerminalContextPropertiesProviderFactory;
3536
import org.eclipse.terminal.view.ui.internal.ITraceIds;
@@ -84,7 +85,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
8485
dialog.setSelection(selection);
8586
}
8687
if (dialog.open() == Window.OK) {
87-
findDelegate(dialog).ifPresent(delegate -> delegate.execute(dialog.getSettings(), null));
88+
findDelegate(dialog)
89+
.ifPresent(delegate -> delegate.execute(dialog.getSettings(), ITerminalService.NOOP));
8890
}
8991
} else {
9092
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
@@ -116,7 +118,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
116118
dialog.setSelection(selection);
117119
}
118120
if (dialog.open() == Window.OK) {
119-
findDelegate(dialog).ifPresent(delegate -> delegate.execute(dialog.getSettings(), null));
121+
findDelegate(dialog)
122+
.ifPresent(delegate -> delegate.execute(dialog.getSettings(), ITerminalService.NOOP));
120123
}
121124
} else if (delegates.size() == 1) {
122125
ILauncherDelegate delegate = delegates.get(0);

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/local/showin/DynamicContributionItems.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.jface.resource.ImageDescriptor;
2626
import org.eclipse.jface.viewers.ISelection;
2727
import org.eclipse.swt.graphics.ImageData;
28+
import org.eclipse.terminal.view.core.ITerminalService;
2829
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
2930
import org.eclipse.terminal.view.ui.IExternalExecutablesProperties;
3031
import org.eclipse.terminal.view.ui.internal.UIPlugin;
@@ -128,7 +129,7 @@ public void run() {
128129
properties.put(ITerminalsConnectorConstants.PROP_TRANSLATE_BACKSLASHES_ON_PASTE,
129130
Boolean.valueOf(translate));
130131

131-
delegate.execute(properties, null);
132+
delegate.execute(properties, ITerminalService.NOOP);
132133
}
133134
};
134135

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/view/TerminalsViewMementoHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.eclipse.core.runtime.Assert;
2222
import org.eclipse.swt.custom.CTabItem;
2323
import org.eclipse.terminal.control.ITerminalViewControl;
24+
import org.eclipse.terminal.view.core.ITerminalService;
2425
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
2526
import org.eclipse.terminal.view.ui.IMementoHandler;
2627
import org.eclipse.terminal.view.ui.internal.UIPlugin;
@@ -186,7 +187,7 @@ protected void restoreState(final TerminalsView view, IMemento memento) {
186187
delegate.map(d -> d.getAdapter(IMementoHandler.class))
187188
.ifPresent(mh -> mh.restoreState(connection, properties));
188189
// Restore the terminal connection
189-
delegate.ifPresent(d -> d.execute(properties, null));
190+
delegate.ifPresent(d -> d.execute(properties, ITerminalService.NOOP));
190191
}
191192
}
192193
}

0 commit comments

Comments
 (0)