Class file from PsiJavaFIle
Hi
Is it possible to create or get the corresponding, compiled class file out of an existing PsiJavaFile from the project view?
I need it for a Java patch plugin in IntelliJ, where we directly patch classes.
Regards
Stefan
Please sign in to leave a comment.
Hi Stefan,
BytecodeViewer plugin does similar thing. Please check ByteCodeViewerManager.getByteCode(PsiElement element)
@Nullable
public static String getByteCode(@NotNull PsiElement psiElement) {
PsiClass containingClass = getContainingClass(psiElement);
if (containingClass == null) return null;
CompilerPathsEx.ClassFileDescriptor file = CompilerPathsEx.findClassFileInOutput(containingClass);
if (file != null) {
try {
return processClassFile(file.loadFileBytes());
}
catch (IOException e) {
LOG.error(e);
}
}
return null;
}
This perfectly works, thank you!