Class file from PsiJavaFile with IntelliJ 2019.1
Answered
Hi
Before IntelliJ 2019.1, I used to fetch Java class files like this:
public static FileInfos getClassFileForJavaFile(PsiJavaFile javaFile, String packageName) throws PatchPluginException {
PsiClass[] psiClassFiles = javaFile.getClasses();
List<CompilerPathsEx.ClassFileDescriptor> classFiles = new ArrayList<>();
for (PsiClass psiClass : psiClassFiles) {
classFiles.add(CompilerPathsEx.findClassFileInOutput(psiClass));
}
if (classFiles.get(0) == null) {
throw new PatchPluginException("No class file found. Please rebuild all necessary modules and make sure to have the classes in the target folders");
}
return new FileInfos(packageName, classFiles);
}
This is no longer working with IntelliJ 2019.1s JDK.
Is there another solution?
Regards
Stefan
P.S. See also https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000656770-Class-file-from-PsiJavaFIle
Please sign in to leave a comment.
Hi Stefan,
that code was created for Bytecode Viewer plugin and was later moved into it. At the moment of change, there were no detectable usages of that code by plugins (probably yours is in-house and not published to the repository).
There is no similar method in the current API. I'd suggest to copy relevant parts from ByteCodeViewerManager#loadClassFileBytes (AFAIU, you only need the "source code" branch of it).