Implementing JvmElementProvider does not automatically add imports

I have implemented the JvmElementProvider interface and created a PsiFile using PsiFileFactory.getInstance(project).createFileFromText. The code is as follows:

PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText(
                "demo.java", 
                JavaFileType.INSTANCE, "xxx");

I have also implemented PsiShortNamesCache. While coding, code completion works fine, but during auto-import, IDEA does not automatically add import statements. Instead, it completes the class name with its fully qualified name. During debugging, I found that an exception was thrown in the following code.


My expectation was for IDEA to automatically import the necessary package.