Skip to content

Commit

Permalink
fix: Jump to inner Java class from property doesn't work.
Browse files Browse the repository at this point in the history
Fixes #1256

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Nov 7, 2023
1 parent a43144e commit 2852c19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
* PSI Type utilities.
*
* @see <a href="https://github.com/redhat-developer/quarkus-ls/blob/master/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/core/utils/JDTTypeUtils.java">https://github.com/redhat-developer/quarkus-ls/blob/master/microprofile.jdt/com.redhat.microprofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/core/utils/JDTTypeUtils.java</a>
*
*/

public class PsiTypeUtils {
Expand All @@ -71,7 +70,7 @@ public static String getResolvedTypeName(PsiType type) {
return null;
}
while (type instanceof PsiArrayType) {
type = ((PsiArrayType)type).getComponentType();
type = ((PsiArrayType) type).getComponentType();
}
return type.getCanonicalText();
}
Expand Down Expand Up @@ -102,24 +101,24 @@ public static String getResolvedTypeName(PsiElement element) {
public static String getDefaultValue(PsiMethod method) {
String value = null;
if (method instanceof PsiAnnotationMethod) {
PsiAnnotationMemberValue defaultValue = ((PsiAnnotationMethod)method).getDefaultValue();
PsiAnnotationMemberValue defaultValue = ((PsiAnnotationMethod) method).getDefaultValue();
if (defaultValue instanceof PsiAnnotation) {
value = ((PsiAnnotation)defaultValue).getQualifiedName();
value = ((PsiAnnotation) defaultValue).getQualifiedName();
int index = value.lastIndexOf('.');
if (index != (-1)) {
value = value.substring(index + 1, value.length());
}
} else if (defaultValue instanceof PsiLiteral) {
value = ((PsiLiteral)defaultValue).getValue().toString();
value = ((PsiLiteral) defaultValue).getValue().toString();
} else if (defaultValue instanceof PsiReference) {
value = ((PsiReference)defaultValue).getCanonicalText();
value = ((PsiReference) defaultValue).getCanonicalText();
int index = value.lastIndexOf('.');
if (index != (-1)) {
value = value.substring(index + 1, value.length());
}
}
}
return value == null || value.isEmpty()? null : value;
return value == null || value.isEmpty() ? null : value;
}


Expand All @@ -129,10 +128,11 @@ public static String getPropertyType(PsiClass psiClass, String typeName) {

public static String getSourceType(PsiModifierListOwner psiElement) {
if (psiElement instanceof PsiField || psiElement instanceof PsiMethod) {
return ClassUtil.getJVMClassName(((PsiMember)psiElement).getContainingClass());
return ClassUtil.getJVMClassName(((PsiMember) psiElement).getContainingClass());
} else if (psiElement instanceof PsiParameter) {
return ClassUtil.getJVMClassName(((PsiMethod)((PsiParameter)psiElement).getDeclarationScope()).getContainingClass());
} if (psiElement instanceof PsiClass) {
return ClassUtil.getJVMClassName(((PsiMethod) ((PsiParameter) psiElement).getDeclarationScope()).getContainingClass());
}
if (psiElement instanceof PsiClass) {
return getPropertyType((PsiClass) psiElement, null);
}
return null;
Expand All @@ -146,13 +146,12 @@ public static String getSourceMethod(PsiMethod method) {

@Nullable
public static PsiClass findType(PsiManager manager, String name) {
JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
return facade.findClass(name, GlobalSearchScope.allScope(manager.getProject()));
return ClassUtil.findPsiClass(manager, name);
}

public static PsiClass findType(Module module, String name) {
JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
return facade.findClass(name, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
return ClassUtil.findPsiClass(PsiManager.getInstance(module.getProject()), name, null, false,
GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
}

public static String getSourceField(PsiMember psiMember) {
Expand Down Expand Up @@ -191,7 +190,7 @@ public static String getOptionalTypeParameter(String typeName) {
/**
* Returns the first (generic) type parameter for the given <code>psiType</code>.
* Returns <code>null</code> if the given psiType has no generic type parameter.
*
* <p>
* Examples:
* <ul>.
* <li>returns {@code String} for {@code List<String>}</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import com.intellij.psi.PsiMember;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.ClassUtil;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.JsonRpcHelpers;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PsiUtils;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils;
import com.redhat.devtools.intellij.quarkus.javadoc.JavadocContentAccess;
import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils;
import org.eclipse.lsp4j.Location;
Expand Down Expand Up @@ -89,8 +91,7 @@ public Module getModule(String uri) throws IOException {

@Override
public PsiClass findClass(Module module, String className) {
JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
return facade.findClass(className, GlobalSearchScope.allScope(module.getProject()));
return PsiTypeUtils.findType(module, className);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static String getSimpleClassName(String className) {
return className;
}

public static PsiClass findType(Module project, String name) {
JavaPsiFacade facade = JavaPsiFacade.getInstance(project.getProject());
return facade.findClass(name, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(project));
public static PsiClass findType(Module module, String name) {
return ClassUtil.findPsiClass(PsiManager.getInstance(module.getProject()), name, null, false,
GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
}

/**
Expand Down

0 comments on commit 2852c19

Please sign in to comment.