From 9748903772e7771dfc5eaf044f2b542e78193844 Mon Sep 17 00:00:00 2001 From: dessina-devasia <143582034+dessina-devasia@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:53:03 +0530 Subject: [PATCH 1/2] [#1420]: Modification to replace the usage of deprecated method DumbService.runReadActionInSmartMode(Computable) --- .../lsp4mp4ij/psi/core/ProjectLabelManager.java | 7 ++----- .../lsp4mp4ij/psi/core/PropertiesManager.java | 13 ++++++------- .../psi/core/PropertiesManagerForJava.java | 6 +----- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/ProjectLabelManager.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/ProjectLabelManager.java index 83f0be3cd..8cc03da0a 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/ProjectLabelManager.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/ProjectLabelManager.java @@ -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 @@ -11,13 +11,10 @@ *******************************************************************************/ package com.redhat.devtools.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 com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; @@ -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; } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java index 244f76865..b104f2f28 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java @@ -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, @@ -10,12 +10,10 @@ ******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.module.Module; -import com.intellij.openapi.progress.EmptyProgressIndicator; import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.util.Computable; +import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiFile; @@ -222,7 +220,8 @@ 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(() -> { + Project project = module.getProject(); + return ReadAction.nonBlocking(() -> { PsiMember fieldOrMethod = findDeclaredProperty(module, sourceType, sourceField, sourceMethod, utils); if (fieldOrMethod != null) { PsiFile classFile = fieldOrMethod.getContainingFile(); @@ -235,7 +234,7 @@ public Location findPropertyLocation(Module module, String sourceType, String so return utils.toLocation(fieldOrMethod); } return null; - }); + }).inSmartMode(project).executeSynchronously(); } /** diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java index cc55cf694..9fdc8b172 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerForJava.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 Red Hat, Inc. + * Copyright (c) 2020-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, @@ -11,14 +11,10 @@ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core; import com.intellij.lang.jvm.JvmParameter; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; From c169400c0c8b615d67c21cd1929edff1d770bd1a Mon Sep 17 00:00:00 2001 From: dessina-devasia <143582034+dessina-devasia@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:19:18 +0530 Subject: [PATCH 2/2] Removed the ReadAction.nonBlocking() as findPropertyLocation() is already executed in a NonBlocking ReadAction --- .../lsp4mp4ij/psi/core/PropertiesManager.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java index b104f2f28..27c7367df 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManager.java @@ -10,10 +10,8 @@ ******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core; -import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiFile; @@ -220,21 +218,18 @@ public Location findPropertyLocation(VirtualFile file, String sourceType, String } public Location findPropertyLocation(Module module, String sourceType, String sourceField, String sourceMethod, IPsiUtils utils) { - Project project = module.getProject(); - return ReadAction.nonBlocking(() -> { - 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; - }).inSmartMode(project).executeSynchronously(); + return utils.toLocation(fieldOrMethod); + } + return null; } /**