Getting full class name from PsiType and finding resource dir in the current project
Hi!
I'm developing the plugin for IDEA, and I've faced the following problem. I want to get fully-qualified class names of the method parameters and method return types. Currently I;m doing it like this:
for (PsiParameter param : method.getParameterList().getParameters()) {
parameters.add(new ManifestParameter(param.getType().getCanonicalText());
}
It works for custom classes, but returns only class name without package name for the JVM standard classes like `String` or `List`.
Is it possible to get fully qualified name for all types?
And the second question - is there any method to get all the directories marked as `resource` for current project?
请先登录再写评论。
com.intellij.psi.util.PsiTypesUtil#getPsiClass
-> if not null, com.intellij.psi.PsiClass#getQualifiedName
Resource roots (IJ 13 only)
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
List<VirtualFile> sourceRoots = rootManager.getSourceRoots(JavaModuleSourceRootTypes.RESOURCES);
I've tried it
PsiClass parameterClass = PsiTypesUtil.getPsiClass(method.getReturnType());
if (parameterClass != null) {
System.out.println("->" + parameterClass.getQualifiedName());
} else {
System.out.println("Not class ->" + method.getReturnType());
}
But for String, List etc variable `parameterClass` is null. What's wrong?
In what context did you try this, open new IJ instance with test project or unit test? If test project, is JDK correctly attached? Index corrupted? If unit test, did you attach test JDK?
Yep, I had to reset JDK for the test instance, it became invalid somehow. Thanks!