Skip to content

Commit

Permalink
chore: fix some deprecation warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Nov 7, 2023
1 parent a43144e commit c2927be
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class LanguageServiceAccessor {

private final Project project;

public static LanguageServiceAccessor getInstance(Project project) {
return ServiceManager.getService(project, LanguageServiceAccessor.class);
public static LanguageServiceAccessor getInstance(@NotNull Project project) {
return project.getService(LanguageServiceAccessor.class);
}

private LanguageServiceAccessor(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,23 @@ private static Icon messageTypeToIcon(MessageType type) {
}

private static NotificationType messageTypeToNotificationType(MessageType type) {
NotificationType result = null;

switch (type) {
case Error:
result = NotificationType.ERROR;
break;
case Info:
case Log:
result = NotificationType.INFORMATION;
break;
case Warning:
result = NotificationType.WARNING;
}
NotificationType result = switch (type) {
case Error -> NotificationType.ERROR;
case Info, Log -> NotificationType.INFORMATION;
case Warning -> NotificationType.WARNING;
};
return result;
}


public static void showMessage(String title, MessageParams params) {
Notification notification = new Notification("Language Server Protocol", messageTypeToIcon(params.getType()), title, null, params.getMessage(), messageTypeToNotificationType(params.getType()), null);
Notification notification = new Notification("Language Server Protocol", title, params.getMessage(), messageTypeToNotificationType(params.getType()));
notification.setIcon(messageTypeToIcon(params.getType()));
Notifications.Bus.notify(notification);
}

public static CompletableFuture<MessageActionItem> showMessageRequest(LanguageServerWrapper wrapper, ShowMessageRequestParams params) {
String options[] = params.getActions().stream().map(MessageActionItem::getTitle).toArray(String[]::new);
String[] options = params.getActions().stream().map(MessageActionItem::getTitle).toArray(String[]::new);
CompletableFuture<MessageActionItem> future = new CompletableFuture<>();

ApplicationManager.getApplication().invokeLater(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package com.redhat.devtools.intellij.lsp4ij.console.explorer;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.util.text.Formats;
import com.intellij.ui.AnimatedIcon;
import com.redhat.devtools.intellij.lsp4ij.LanguageServerWrapper;
import com.redhat.devtools.intellij.lsp4ij.ServerStatus;
Expand Down Expand Up @@ -124,6 +124,6 @@ public String getDisplayName() {
public String getElapsedTime() {
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
return StringUtil.formatDuration(duration, "\u2009");
return Formats.formatDuration(duration, "\u2009");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4ij.lifecycle;

import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.intellij.lsp4ij.LanguageServerWrapper;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.messages.Message;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,8 +29,8 @@
*/
public class LanguageServerLifecycleManager {

public static LanguageServerLifecycleManager getInstance(Project project) {
return ServiceManager.getService(project, LanguageServerLifecycleManager.class);
public static LanguageServerLifecycleManager getInstance(@NotNull Project project) {
return project.getService(LanguageServerLifecycleManager.class);
}

private static final Logger LOGGER = LoggerFactory.getLogger(LanguageServerLifecycleManager.class);//$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jetbrains.annotations.NotNull;

import java.net.URI;
import java.util.concurrent.Callable;
import java.util.function.Consumer;

/**
Expand All @@ -49,7 +50,7 @@ public LSPDiagnosticHandler(LanguageServerWrapper languageServerWrapper) {
@Override
public void accept(PublishDiagnosticsParams params) {
Project project = languageServerWrapper.getProject();
if (project.isDisposed()) {
if (project == null || project.isDisposed()) {
return;
}
if (ApplicationManager.getApplication().isReadAccessAllowed()) {
Expand All @@ -58,9 +59,11 @@ public void accept(PublishDiagnosticsParams params) {
// Cancel if needed the previous "textDocument/publishDiagnostics" for a given uri.
var coalesceBy = new CoalesceByKey("textDocument/publishDiagnostics", params.getUri());
var executeInSmartMode = DumbService.getInstance(languageServerWrapper.getProject()).isDumb();
var action = ReadAction.nonBlocking(() -> updateDiagnostics(params, project))
.expireWith(languageServerWrapper)
.coalesceBy(coalesceBy);
var action = ReadAction.nonBlocking((Callable<Void>) () -> {
updateDiagnostics(params, project);
return null;
}).expireWith(languageServerWrapper)
.coalesceBy(coalesceBy);
if (executeInSmartMode) {
action.inSmartMode(project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.intellij.ProjectTopics;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
Expand All @@ -26,9 +25,8 @@
import com.intellij.psi.PsiManager;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.messages.Topic;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
Expand Down Expand Up @@ -56,8 +54,8 @@ public class ClasspathResourceChangedManager implements Disposable {
private final MessageBusConnection appConnection;
private final ClasspathResourceChangedListener listener;

public static ClasspathResourceChangedManager getInstance(Project project) {
return ServiceManager.getService(project, ClasspathResourceChangedManager.class);
public static ClasspathResourceChangedManager getInstance(@NotNull Project project) {
return project.getService(ClasspathResourceChangedManager.class);
}

public interface Listener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -190,7 +191,7 @@ protected final T getConfig() {
public void reload(PsiFile file) {
reset();
String content = file.getText();
try (InputStream input = IOUtils.toInputStream(content)) {
try (InputStream input = IOUtils.toInputStream(content, Charset.defaultCharset())) {
config = loadConfig(input);
lastModified = System.currentTimeMillis();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import com.intellij.ProjectTopics;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.ModuleListener;
Expand All @@ -37,8 +36,8 @@ public final class PsiMicroProfileProjectManager implements Disposable {

private static final String JAVA_FILE_EXTENSION = "java";

public static PsiMicroProfileProjectManager getInstance(Project project) {
return ServiceManager.getService(project, PsiMicroProfileProjectManager.class);
public static PsiMicroProfileProjectManager getInstance(@NotNull Project project) {
return project.getService(PsiMicroProfileProjectManager.class);
}

private final MessageBusConnection connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.ProcessCanceledException;
Expand Down Expand Up @@ -59,8 +58,8 @@ public class QuarkusDeploymentSupport implements ClasspathResourceChangedManager
private final MessageBusConnection connection;
private final Project project;

public static QuarkusDeploymentSupport getInstance(Project project) {
return ServiceManager.getService(project, QuarkusDeploymentSupport.class);
public static QuarkusDeploymentSupport getInstance(@NotNull Project project) {
return project.getService(QuarkusDeploymentSupport.class);
}

public QuarkusDeploymentSupport(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.intellij.json.JsonFileType;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProcessCanceledException;
Expand All @@ -32,6 +31,7 @@
import org.eclipse.lsp4mp.commons.MicroProfileProjectInfo;
import org.eclipse.lsp4mp.commons.MicroProfilePropertiesScope;
import org.eclipse.lsp4mp.utils.JSONSchemaUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -45,8 +45,8 @@ public class QuarkusProjectService implements ClasspathResourceChangedManager.Li

private final Map<Module, MutablePair<VirtualFile, Boolean>> schemas = new ConcurrentHashMap<>();

public static QuarkusProjectService getInstance(Project project) {
return ServiceManager.getService(project, QuarkusProjectService.class);
public static QuarkusProjectService getInstance(@NotNull Project project) {
return project.getService(QuarkusProjectService.class);
}

private final MessageBusConnection connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import com.intellij.facet.FacetType;
import com.intellij.framework.detection.FacetBasedFrameworkDetector;
import com.intellij.framework.detection.FileContentPattern;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.patterns.ElementPattern;
import com.intellij.util.indexing.FileContent;
import org.jetbrains.annotations.NotNull;
Expand All @@ -34,7 +34,7 @@ public FacetType<QuarkusFacet, QuarkusFacetConfiguration> getFacetType() {
@NotNull
@Override
public FileType getFileType() {
return StdFileTypes.XML;
return XmlFileType.INSTANCE;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.intellij.execution.RunManager;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.ide.util.newProjectWizard.AddModuleWizard;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings;
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId;
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType;
Expand Down Expand Up @@ -49,11 +49,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -157,7 +153,7 @@ private String getModuleDirPath(Module module) {
*/
private void collectDependencies(Module module, Path customBuildFile, Path customSettingsFile, Path outputPath, List<VirtualFile>[] result) throws IOException {
try {
final ExternalSystemFacadeManager manager = ServiceManager.getService(ExternalSystemFacadeManager.class);
final ExternalSystemFacadeManager manager = ApplicationManager.getApplication().getService(ExternalSystemFacadeManager.class);

ExternalSystemExecutionSettings settings = ExternalSystemApiUtil.getExecutionSettings(module.getProject(),
getModuleDirPath(module),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.intellij.lsp4ij.server.JavaProcessCommandBuilder;
Expand All @@ -23,6 +24,7 @@

import java.io.File;
import java.net.URI;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand All @@ -39,13 +41,17 @@ public class QuarkusServer extends ProcessStreamConnectionProvider {

public QuarkusServer(Project project) {
this.project = project;
IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus"));
File lsp4mpServerPath = new File(descriptor.getPath(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar");
File quarkusServerPath = new File(descriptor.getPath(), "lib/server/com.redhat.quarkus.ls.jar");
IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus"));
assert descriptor != null;
Path pluginPath = descriptor.getPluginPath();
assert pluginPath != null;
pluginPath = pluginPath.toAbsolutePath();
Path lsp4mpServerPath = pluginPath.resolve("lib/server/org.eclipse.lsp4mp.ls-uber.jar");
Path quarkusServerPath = pluginPath.resolve("lib/server/com.redhat.quarkus.ls.jar");

List<String> commands = new JavaProcessCommandBuilder(project, "microprofile")
.setJar(lsp4mpServerPath.getAbsolutePath())
.setCp(quarkusServerPath.getAbsolutePath())
.setJar(lsp4mpServerPath.toString())
.setCp(quarkusServerPath.toString())
.create();
commands.add("-DrunAsync=true");
super.setCommands(commands);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import com.intellij.facet.FacetType;
import com.intellij.framework.detection.FacetBasedFrameworkDetector;
import com.intellij.framework.detection.FileContentPattern;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.patterns.ElementPattern;
import com.intellij.util.indexing.FileContent;
import org.jetbrains.annotations.NotNull;
Expand All @@ -34,7 +34,7 @@ public FacetType<QuteFacet, QuteFacetConfiguration> getFacetType() {
@NotNull
@Override
public FileType getFileType() {
return StdFileTypes.XML;
return XmlFileType.INSTANCE;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.intellij.lsp4ij.server.JavaProcessCommandBuilder;
Expand All @@ -23,6 +24,7 @@

import java.io.File;
import java.net.URI;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand All @@ -39,11 +41,14 @@ public class QuteServer extends ProcessStreamConnectionProvider {

public QuteServer(Project project) {
this.project = project;
IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus"));
File quteServerPath = new File(descriptor.getPath(), "lib/server/com.redhat.qute.ls-uber.jar");
IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus"));
assert descriptor != null;
Path pluginPath = descriptor.getPluginPath();
assert pluginPath != null;
Path quteServerPath = pluginPath.toAbsolutePath().resolve("lib/server/com.redhat.qute.ls-uber.jar");

List<String> commands = new JavaProcessCommandBuilder(project, "qute")
.setJar(quteServerPath.getAbsolutePath())
.setJar(quteServerPath.toString())
.create();
commands.add("-DrunAsync=true");
super.setCommands(commands);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/lsp4ij.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
implementation="com.redhat.devtools.intellij.lsp4ij.operations.documentLink.LSPDocumentLinkGotoDeclarationHandler"/>
<highlightUsagesHandlerFactory
implementation="com.redhat.devtools.intellij.lsp4ij.operations.highlight.LSPHighlightUsagesHandlerFactory"/>
<notificationGroup id="Language Server Protocol" displayType="BALLOON" hideFromSettings="true"/>
</extensions>

<applicationListeners>
Expand Down

0 comments on commit c2927be

Please sign in to comment.