Skip to content

Commit

Permalink
fix: Read access problem with Qute getJavadoc (redhat-developer#932)
Browse files Browse the repository at this point in the history
Fixes redhat-developer#932

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr authored and fbricon committed Jun 9, 2023
1 parent ccc625c commit ef75697
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
*******************************************************************************/
package com.redhat.devtools.intellij.qute.psi;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.JavaModuleType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils;
Expand Down Expand Up @@ -51,7 +53,7 @@

/**
* Qute support for Template file.
*
*
* @author Angelo ZERR
*
*/
Expand All @@ -69,11 +71,11 @@ public static QuteSupportForTemplate getInstance() {

/**
* Returns the project information for the given project Uri.
*
*
* @param params the project information parameters.
* @param utils the JDT LS utility.
* @param monitor the progress monitor.
*
*
* @return the project information for the given project Uri and null otherwise.
*/
public ProjectInfo getProjectInfo(QuteProjectParams params, IPsiUtils utils, ProgressIndicator monitor) {
Expand All @@ -90,7 +92,7 @@ public ProjectInfo getProjectInfo(QuteProjectParams params, IPsiUtils utils, Pro
/**
* Collect data model templates from the given project Uri. A data model
* template can be declared with:
*
*
* <ul>
* <li>@CheckedTemplate support: collect parameters for Qute Template by
* searching @CheckedTemplate annotation.</li>
Expand All @@ -99,11 +101,11 @@ public ProjectInfo getProjectInfo(QuteProjectParams params, IPsiUtils utils, Pro
* <li>Template extension support: see
* https://quarkus.io/guides/qute-reference#template_extension_methods</li>
* </ul>
*
*
* @param params the project uri.
* @param utils JDT LS utilities
* @param monitor the progress monitor
*
*
* @return data model templates from the given project Uri.
*/
public DataModelProject<DataModelTemplate<DataModelParameter>> getDataModelProject(
Expand All @@ -121,11 +123,11 @@ public DataModelProject<DataModelTemplate<DataModelParameter>> getDataModelProje

/**
* Collect user tags from the given project Uri.
*
*
* @param params the project uri.
* @param utils JDT LS utilities
* @param monitor the progress monitor
*
*
* @return user tags from the given project Uri.
*/
public List<UserTagInfo> getUserTags(QuteUserTagParams params, IPsiUtils utils, ProgressIndicator monitor)
Expand All @@ -141,11 +143,11 @@ public List<UserTagInfo> getUserTags(QuteUserTagParams params, IPsiUtils utils,
/**
* Returns Java types for the given pattern which belong to the given project
* Uri.
*
*
* @param params the java types parameters.
* @param utils the JDT LS utility.
* @param monitor the progress monitor.
*
*
* @return list of Java types.
*/
public List<JavaTypeInfo> getJavaTypes(QuteJavaTypesParams params, IPsiUtils utils, ProgressIndicator monitor) {
Expand All @@ -163,11 +165,11 @@ public List<JavaTypeInfo> getJavaTypes(QuteJavaTypesParams params, IPsiUtils uti
/**
* Returns the Java definition of the given Java type, method, field, method
* parameter, method invocation parameter and null otherwise.
*
*
* @param params the Java element information.
* @param utils the JDT LS utility.
* @param monitor the progress monitor.
*
*
* @return the Java definition of the given Java type, method, field, method
* parameter, method invocation parameter and null otherwise.
*/
Expand Down Expand Up @@ -249,11 +251,11 @@ private PsiMethod findMethod(PsiClass type, String sourceMethod) {

/**
* Returns the resolved type (fields and methods) for the given Java type.
*
*
* @param params the Java type to resolve.
* @param utils the JDT LS utility.
* @param monitor the progress monitor.
*
*
* @return the resolved type (fields and methods) for the given Java type.
*/
public ResolvedJavaTypeInfo getResolvedJavaType(QuteResolvedJavaTypeParams params, IPsiUtils utils,
Expand Down Expand Up @@ -370,8 +372,10 @@ public String getJavadoc(QuteJavadocParams params, IPsiUtils utils, ProgressIndi
if (type == null) {
return null;
}
return getJavadoc(type, params.getDocumentFormat(), params.getMemberName(), params.getSignature(), utils,
monitor, new HashSet<>());
final var finalUtils = utils;
return ApplicationManager.getApplication()
.runReadAction((Computable<String>) () -> getJavadoc(type, params.getDocumentFormat(), params.getMemberName(), params.getSignature(), finalUtils,
monitor, new HashSet<>()));
} catch (Exception e) {
LOGGER.log(Level.WARNING,
"Error while collecting Javadoc for " + params.getSourceType() + "#" + params.getMemberName(), e);
Expand Down

0 comments on commit ef75697

Please sign in to comment.