Skip to content

Commit de16eb0

Browse files
committed
Continue #2027: use List instead of array for ILaunchDelegateManager
* see #2027 (comment) * see #2027 (comment)
1 parent d2f0d7d commit de16eb0

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2014, 2018 Wind River Systems, Inc. and others. All rights reserved.
2+
* Copyright (c) 2014, 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,10 +8,12 @@
88
*
99
* Contributors:
1010
* Wind River Systems - initial API and implementation
11+
* Alexander Fedorov (ArSysOp) - further evolution
1112
*******************************************************************************/
1213
package org.eclipse.terminal.connector.local.launcher;
1314

1415
import java.util.HashMap;
16+
import java.util.List;
1517
import java.util.Map;
1618

1719
import org.eclipse.core.commands.AbstractHandler;
@@ -56,7 +58,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
5658
}
5759

5860
// Get all applicable launcher delegates for the current selection
59-
ILauncherDelegate[] delegates = UIPlugin.getLaunchDelegateManager().getApplicableLauncherDelegates(selection);
61+
List<ILauncherDelegate> delegates = UIPlugin.getLaunchDelegateManager()
62+
.getApplicableLauncherDelegates(selection);
6063
// Find the local terminal launcher delegate
6164
ILauncherDelegate delegate = null;
6265
for (ILauncherDelegate candidate : delegates) {

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

Lines changed: 8 additions & 8 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.ui.internal;
1314

@@ -227,19 +228,18 @@ public int compare(IExtension o1, IExtension o2) {
227228
* @param unique If <code>true</code>, the method returns new instances for each
228229
* contributed terminal launcher delegate.
229230
*
230-
* @return The list of contributed terminal launcher delegates, or an empty array.
231+
* @return The list of contributed terminal launcher delegates, or an empty list.
231232
*/
232233
@Override
233-
public ILauncherDelegate[] getLauncherDelegates(boolean unique) {
234+
public List<ILauncherDelegate> getLauncherDelegates(boolean unique) {
234235
List<ILauncherDelegate> contributions = new ArrayList<>();
235236
for (Proxy launcherDelegate : getExtensions().values()) {
236237
ILauncherDelegate instance = unique ? launcherDelegate.newInstance() : launcherDelegate.getInstance();
237238
if (instance != null && !contributions.contains(instance)) {
238239
contributions.add(instance);
239240
}
240241
}
241-
242-
return contributions.toArray(new ILauncherDelegate[contributions.size()]);
242+
return contributions;
243243
}
244244

245245
/**
@@ -268,10 +268,10 @@ public ILauncherDelegate getLauncherDelegate(String id, boolean unique) {
268268
* Returns the applicable terminal launcher delegates for the given selection.
269269
*
270270
* @param selection The selection or <code>null</code>.
271-
* @return The list of applicable terminal launcher delegates or an empty array.
271+
* @return The list of applicable terminal launcher delegates or an empty list.
272272
*/
273273
@Override
274-
public ILauncherDelegate[] getApplicableLauncherDelegates(ISelection selection) {
274+
public List<ILauncherDelegate> getApplicableLauncherDelegates(ISelection selection) {
275275
List<ILauncherDelegate> applicable = new ArrayList<>();
276276

277277
for (ILauncherDelegate delegate : getLauncherDelegates(false)) {
@@ -312,7 +312,7 @@ public ILauncherDelegate[] getApplicableLauncherDelegates(ISelection selection)
312312
}
313313
}
314314

315-
return applicable.toArray(new ILauncherDelegate[applicable.size()]);
315+
return applicable;
316316
}
317317

318318
/**

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

Lines changed: 3 additions & 2 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.ui.internal;
1314

@@ -30,7 +31,7 @@ public boolean test(Object receiver, String property, Object[] args, Object expe
3031
if ("hasApplicableLauncherDelegates".equals(property)) { //$NON-NLS-1$
3132
ISelection selection = receiver instanceof ISelection i ? i : new StructuredSelection(receiver);
3233
return expectedValue.equals(Boolean
33-
.valueOf(UIPlugin.getLaunchDelegateManager().getApplicableLauncherDelegates(selection).length > 0));
34+
.valueOf(!UIPlugin.getLaunchDelegateManager().getApplicableLauncherDelegates(selection).isEmpty()));
3435
}
3536

3637
if ("canDisconnect".equals(property) && receiver instanceof ITerminalsView) { //$NON-NLS-1$

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/dialogs/LaunchTerminalSettingsDialog.java

Lines changed: 4 additions & 3 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/
@@ -10,6 +10,7 @@
1010
* Wind River Systems - initial API and implementation
1111
* Max Weninger (Wind River) - [361352] [TERMINALS][SSH] Add SSH terminal support
1212
* Dirk Fauth <[email protected]> - Bug 460496
13+
* Alexander Fedorov (ArSysOp) - further evolution
1314
*******************************************************************************/
1415
package org.eclipse.terminal.view.ui.internal.dialogs;
1516

@@ -420,7 +421,7 @@ protected List<String> getTerminals() {
420421
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
421422
}
422423

423-
ILauncherDelegate[] delegates = UIPlugin.getLaunchDelegateManager().getLauncherDelegates(false);
424+
List<ILauncherDelegate> delegates = UIPlugin.getLaunchDelegateManager().getLauncherDelegates(false);
424425

425426
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
426427
UIPlugin.getTraceHandler().trace(
@@ -450,7 +451,7 @@ protected List<String> getTerminals() {
450451
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
451452
}
452453

453-
ILauncherDelegate[] delegates = UIPlugin.getLaunchDelegateManager()
454+
List<ILauncherDelegate> delegates = UIPlugin.getLaunchDelegateManager()
454455
.getApplicableLauncherDelegates(selection);
455456

456457
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {

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

Lines changed: 7 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,12 +8,14 @@
88
*
99
* Contributors:
1010
* Wind River Systems - initial API and implementation
11+
* Alexander Fedorov (ArSysOp) - further evolution
1112
*******************************************************************************/
1213
package org.eclipse.terminal.view.ui.internal.handler;
1314

1415
import java.text.DateFormat;
1516
import java.util.Date;
1617
import java.util.HashMap;
18+
import java.util.List;
1719
import java.util.Map;
1820

1921
import org.eclipse.core.commands.AbstractHandler;
@@ -104,7 +106,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
104106
}
105107

106108
// Check if the dialog needs to be shown at all
107-
ILauncherDelegate[] delegates = UIPlugin.getLaunchDelegateManager()
109+
List<ILauncherDelegate> delegates = UIPlugin.getLaunchDelegateManager()
108110
.getApplicableLauncherDelegates(selection);
109111

110112
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
@@ -113,7 +115,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
113115
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalCommandHandler.this);
114116
}
115117

116-
if (delegates.length > 1 || (delegates.length == 1 && delegates[0].needsUserConfiguration())) {
118+
if (delegates.size() > 1 || (delegates.size() == 1 && delegates.get(0).needsUserConfiguration())) {
117119
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
118120
UIPlugin.getTraceHandler().trace("(b) Attempt to open launch terminal settings dialog after " //$NON-NLS-1$
119121
+ (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$
@@ -137,8 +139,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
137139
delegate.execute(properties, null);
138140
}
139141
}
140-
} else if (delegates.length == 1) {
141-
ILauncherDelegate delegate = delegates[0];
142+
} else if (delegates.size() == 1) {
143+
ILauncherDelegate delegate = delegates.get(0);
142144
Map<String, Object> properties = new HashMap<>();
143145

144146
// Store the id of the selected delegate

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/ILaunchDelegateManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
* Contributors:
1010
* Wind River Systems - initial API and implementation
1111
* Christoph Läubrich - extract to interface
12+
* Alexander Fedorov (ArSysOp) - further evolution
1213
*******************************************************************************/
1314
package org.eclipse.terminal.view.ui.launcher;
1415

16+
import java.util.List;
17+
1518
import org.eclipse.jface.viewers.ISelection;
1619

1720
public interface ILaunchDelegateManager {
@@ -22,9 +25,9 @@ public interface ILaunchDelegateManager {
2225
* @param unique If <code>true</code>, the method returns new instances for each
2326
* contributed terminal launcher delegate.
2427
*
25-
* @return The list of contributed terminal launcher delegates, or an empty array.
28+
* @return The list of contributed terminal launcher delegates, or an empty list.
2629
*/
27-
ILauncherDelegate[] getLauncherDelegates(boolean unique);
30+
List<ILauncherDelegate> getLauncherDelegates(boolean unique);
2831

2932
/**
3033
* Returns the terminal launcher delegate identified by its unique id. If no terminal
@@ -41,8 +44,8 @@ public interface ILaunchDelegateManager {
4144
* Returns the applicable terminal launcher delegates for the given selection.
4245
*
4346
* @param selection The selection or <code>null</code>.
44-
* @return The list of applicable terminal launcher delegates or an empty array.
47+
* @return The list of applicable terminal launcher delegates or an empty list.
4548
*/
46-
ILauncherDelegate[] getApplicableLauncherDelegates(ISelection selection);
49+
List<ILauncherDelegate> getApplicableLauncherDelegates(ISelection selection);
4750

4851
}

0 commit comments

Comments
 (0)