Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Jump to inner Java class from property doesn't work. #1257

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +25,7 @@
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;
Expand Down Expand Up @@ -89,8 +90,8 @@ 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 ClassUtil.findPsiClass(PsiManager.getInstance(module.getProject()), className, null, false,
GlobalSearchScope.allScope(module.getProject()));
}

@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
Loading