Skip to content

Commit 7a2ff74

Browse files
committed
refactor: Get rid of some deprecated APIs
+ Use `setComparator` instead of `setSorter` + Don't use deprecated URL constructor when opening a Browser + Refactor `DSPImages` to be more similar to `LSPImages`, to get rid of URL usage
1 parent 7abcc39 commit 7a2ff74

File tree

5 files changed

+36
-48
lines changed

5 files changed

+36
-48
lines changed

org.eclipse.lsp4e.debug/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: Debug Adapter client for Eclipse IDE (Incubation)
44
Bundle-SymbolicName: org.eclipse.lsp4e.debug;singleton:=true
55
Bundle-Vendor: Eclipse LSP4E
6-
Bundle-Version: 0.16.3.qualifier
6+
Bundle-Version: 0.17.0.qualifier
77
Bundle-Activator: org.eclipse.lsp4e.debug.DSPPlugin
88
Require-Bundle: org.eclipse.ui,
99
org.eclipse.core.runtime,

org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/DSPImages.java

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,74 +13,58 @@
1313
*******************************************************************************/
1414
package org.eclipse.lsp4e.debug;
1515

16-
import java.net.MalformedURLException;
1716
import java.net.URL;
1817

18+
import org.eclipse.core.runtime.FileLocator;
19+
import org.eclipse.core.runtime.Path;
1920
import org.eclipse.core.runtime.Platform;
2021
import org.eclipse.jdt.annotation.Nullable;
2122
import org.eclipse.jface.resource.ImageDescriptor;
2223
import org.eclipse.jface.resource.ImageRegistry;
2324
import org.eclipse.swt.graphics.Image;
25+
import org.osgi.framework.Bundle;
2426

2527
public final class DSPImages {
2628
private DSPImages() {
2729
// private constructor to avoid instances, requested by sonar
2830
}
2931

30-
private static final String NAME_PREFIX = DSPPlugin.PLUGIN_ID + '.';
31-
private static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
32+
private static @Nullable ImageRegistry imageRegistry;
33+
private static final String ICONS_PATH = "$nl$/icons/"; //$NON-NLS-1$
34+
private static final String VIEWS = ICONS_PATH + "view16/";
3235

33-
// The plugin registry
34-
private static ImageRegistry imageRegistry = new ImageRegistry();
36+
public static final String IMG_VIEW_DEBUGGER_TAB = "IMG_DEBUGGER_TAB"; //$NON-NLS-1$
3537

36-
// Subdirectory (under the package containing this class) where 16 color images
37-
// are
38-
private static URL fgIconBaseURL;
39-
static {
40-
fgIconBaseURL = Platform.getBundle(DSPPlugin.PLUGIN_ID).getEntry("/icons/"); //$NON-NLS-1$
38+
public static void initialize(ImageRegistry registry) {
39+
imageRegistry = registry;
40+
declareRegistryImage(IMG_VIEW_DEBUGGER_TAB, VIEWS + "debugger_tab.svg");
4141
}
4242

43-
private static final String T_TABS = "view16/"; //$NON-NLS-1$
44-
@SuppressWarnings("unused") // none yet, leave for the future
45-
private static final String T_OBJS = "obj16/"; //$NON-NLS-1$
46-
47-
public static final String IMG_VIEW_DEBUGGER_TAB = NAME_PREFIX + "debugger_tab.svg"; //$NON-NLS-1$
48-
49-
public static final ImageDescriptor DESC_TAB_DEBUGGER = createManaged(T_TABS, IMG_VIEW_DEBUGGER_TAB);
50-
51-
public static void initialize() {
52-
}
53-
54-
private static ImageDescriptor createManaged(String prefix, String name) {
55-
return createManaged(imageRegistry, prefix, name);
56-
}
57-
58-
private static ImageDescriptor createManaged(ImageRegistry registry, String prefix, String name) {
59-
ImageDescriptor result = ImageDescriptor
60-
.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
61-
registry.put(name, result);
62-
return result;
43+
private static void declareRegistryImage(String key, String path) {
44+
ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
45+
Bundle bundle = Platform.getBundle(DSPPlugin.PLUGIN_ID);
46+
URL url = null;
47+
if (bundle != null) {
48+
url = FileLocator.find(bundle, new Path(path), null);
49+
if (url != null) {
50+
desc = ImageDescriptor.createFromURL(url);
51+
}
52+
}
53+
getImageRegistry().put(key, desc);
6354
}
6455

6556
public static @Nullable Image get(String key) {
66-
return imageRegistry.get(key);
67-
}
68-
69-
private static @Nullable URL makeIconFileURL(String prefix, String name) {
70-
final var buffer = new StringBuilder(prefix);
71-
buffer.append(name);
72-
try {
73-
return new URL(fgIconBaseURL, buffer.toString());
74-
} catch (MalformedURLException e) {
75-
DSPPlugin.logError(e);
76-
return null;
77-
}
57+
return getImageRegistry().get(key);
7858
}
7959

8060
/**
8161
* Helper method to access the image registry from the JavaPlugin class.
8262
*/
8363
static ImageRegistry getImageRegistry() {
64+
ImageRegistry imageRegistry = DSPImages.imageRegistry;
65+
if (imageRegistry == null) {
66+
imageRegistry = DSPImages.imageRegistry = DSPPlugin.getDefault().getImageRegistry();
67+
}
8468
return imageRegistry;
8569
}
8670
}

org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/DSPPlugin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.eclipse.core.runtime.Platform;
1414
import org.eclipse.core.runtime.Status;
1515
import org.eclipse.jdt.annotation.Nullable;
16+
import org.eclipse.jface.resource.ImageRegistry;
1617
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
1718
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
1819
import org.eclipse.ui.plugin.AbstractUIPlugin;
@@ -135,4 +136,9 @@ private static void log(final int severity, @Nullable String message, final @Nul
135136
getDefault().getLog().log(new Status(severity, PLUGIN_ID, 0, message, thr));
136137
}
137138

139+
@Override
140+
protected void initializeImageRegistry(ImageRegistry registry) {
141+
DSPImages.initialize(registry);
142+
}
143+
138144
}

org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.lang.reflect.Method;
3333
import java.net.URI;
3434
import java.net.URISyntaxException;
35-
import java.net.URL;
3635
import java.nio.file.Paths;
3736
import java.util.ArrayList;
3837
import java.util.Arrays;
@@ -813,7 +812,7 @@ protected static void openIntroURL(final String uri) {
813812
protected static void openHttpLocationInBrowser(final String uri, IWorkbenchPage page) {
814813
page.getWorkbenchWindow().getShell().getDisplay().asyncExec(() -> {
815814
try {
816-
final var url = new URL(uri);
815+
final var parsed = new URI(uri);
817816

818817
IWorkbenchBrowserSupport browserSupport = page.getWorkbenchWindow().getWorkbench()
819818
.getBrowserSupport();
@@ -826,8 +825,7 @@ protected static void openHttpLocationInBrowser(final String uri, IWorkbenchPage
826825
browserSupport
827826
.createBrowser(IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR
828827
| IWorkbenchBrowserSupport.NAVIGATION_BAR, "lsp4e-symbols", browserName, uri) //$NON-NLS-1$
829-
.openURL(url);
830-
828+
.openURL(parsed.toURL());
831829
} catch (Exception e) {
832830
LanguageServerPlugin.logError(e);
833831
}

org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/CNFOutlinePage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void createControl(final Composite parent) {
8989
if (document != null) {
9090
outlineViewer.setInput(new OutlineViewerInput(document, wrapper, textEditor));
9191
}
92-
outlineViewer.setSorter(new CommonViewerSorter());
92+
outlineViewer.setComparator(new CommonViewerSorter());
9393
outlineViewer.getLabelProvider().addListener(this);
9494
final var textEditor = this.textEditor;
9595
if (textEditor != null) {

0 commit comments

Comments
 (0)