Skip to content

Commit

Permalink
Merge pull request #1207 from dessina-devasia/1176-replace-deprecated…
Browse files Browse the repository at this point in the history
…-runReadActionInSmartMode

Replaced the usage of deprecated method DumbService.runReadActionInSmartMode(Computable)
  • Loading branch information
dessina-devasia authored Jan 13, 2025
2 parents 672fbcb + 7bdc95f commit 091d9cf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2020 Red Hat Inc. and others.
* Copyright (c) 2019-2025 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
Expand All @@ -11,13 +11,10 @@
*******************************************************************************/
package io.openliberty.tools.intellij.lsp4mp4ij.psi.core;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils;
import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl;
Expand Down Expand Up @@ -97,7 +94,7 @@ public ProjectLabelInfoEntry getProjectLabelInfo(MicroProfileJavaProjectLabelsPa
if (module == null) {
return ProjectLabelInfoEntry.EMPTY_PROJECT_INFO;
}
return DumbService.getInstance(module.getProject()).runReadActionInSmartMode(() -> getProjectLabelInfo(module, params.getTypes(), utils));
return getProjectLabelInfo(module, params.getTypes(), utils);
} catch (IOException e) {
return ProjectLabelInfoEntry.EMPTY_PROJECT_INFO;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat, Inc.
* Copyright (c) 2019, 2025 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
Expand All @@ -12,7 +12,6 @@

import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -219,20 +218,18 @@ public Location findPropertyLocation(VirtualFile file, String sourceType, String
}

public Location findPropertyLocation(Module module, String sourceType, String sourceField, String sourceMethod, IPsiUtils utils) {
return DumbService.getInstance(module.getProject()).runReadActionInSmartMode(() -> {
PsiMember fieldOrMethod = findDeclaredProperty(module, sourceType, sourceField, sourceMethod, utils);
if (fieldOrMethod != null) {
PsiFile classFile = fieldOrMethod.getContainingFile();
if (classFile != null) {
// Try to download source if required
if (utils != null) {
utils.discoverSource(classFile);
}
PsiMember fieldOrMethod = findDeclaredProperty(module, sourceType, sourceField, sourceMethod, utils);
if (fieldOrMethod != null) {
PsiFile classFile = fieldOrMethod.getContainingFile();
if (classFile != null) {
// Try to download source if required
if (utils != null) {
utils.discoverSource(classFile);
}
return utils.toLocation(fieldOrMethod);
}
return null;
});
return utils.toLocation(fieldOrMethod);
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2024 Red Hat Inc. and others.
* Copyright (c) 2020, 2025 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
Expand All @@ -14,7 +14,6 @@

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.psi.PsiFile;
Expand All @@ -32,7 +31,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public final class DiagnosticsHandler {

Expand Down Expand Up @@ -69,28 +67,23 @@ private void collectDiagnostics(String uri, IPsiUtils utils, DocumentFormat docu

try {
Module module = ApplicationManager.getApplication().runReadAction((ThrowableComputable<Module, IOException>) () -> utils.getModule(uri));
DumbService.getInstance(module.getProject()).runReadActionInSmartMode(() -> {
// Collect all adapted diagnostic definitions
JavaDiagnosticsContext context = new JavaDiagnosticsContext(uri, typeRoot, utils, module, documentFormat, settings);
List<JavaDiagnosticsDefinition> definitions = JavaDiagnosticsDefinition.EP_NAME.getExtensionList()
.stream()
.filter(definition -> group.equals(definition.getGroup()))
.filter(definition -> definition.isAdaptedForDiagnostics(context))
.toList();
if (definitions.isEmpty()) {
return;
}
// Collect all adapted diagnostic definitions
JavaDiagnosticsContext context = new JavaDiagnosticsContext(uri, typeRoot, utils, module, documentFormat, settings);
List<JavaDiagnosticsDefinition> definitions = JavaDiagnosticsDefinition.EP_NAME.getExtensionList()
.stream()
.filter(definition -> group.equals(definition.getGroup()))
.filter(definition -> definition.isAdaptedForDiagnostics(context))
.toList();

// Begin, collect, end participants
definitions.forEach(definition -> definition.beginDiagnostics(context));
definitions.forEach(definition -> {
List<Diagnostic> collectedDiagnostics = definition.collectDiagnostics(context);
if (collectedDiagnostics != null && !collectedDiagnostics.isEmpty()) {
diagnostics.addAll(collectedDiagnostics);
}
});
definitions.forEach(definition -> definition.endDiagnostics(context));
// Begin, collect, end participants
definitions.forEach(definition -> definition.beginDiagnostics(context));
definitions.forEach(definition -> {
List<Diagnostic> collectedDiagnostics = definition.collectDiagnostics(context);
if (collectedDiagnostics != null && !collectedDiagnostics.isEmpty()) {
diagnostics.addAll(collectedDiagnostics);
}
});
definitions.forEach(definition -> definition.endDiagnostics(context));
} catch (IOException e) {
LOGGER.warn(e.getLocalizedMessage(), e);
}
Expand Down

0 comments on commit 091d9cf

Please sign in to comment.