I'm trying to add the @Entity javax persistence annotation to a class. My code is as follows:
PsiJavaFile psiJavaFile = (PsiJavaFile) psiClass.getContainingFile();
PsiImportList psiImportList = psiJavaFile.getImportList();
PsiAnnotation entityAnnotation = elementFactory.createAnnotationFromText("@javax.persistence.Entity", null);
// shortenClassReferences takes the fully qualified class name used in the annotation and shortens it, adding the import
The annotation appears in the class, after the import list, but it is still fully qualified, no import has been added for it. Any ideas what I have got wrong here? In addition, there is one line of white space between it and the start of the class identifier, what is the correct way to position it so I don't get this extra line gap?
Thanks for any help.