Psi: creating an inner PsiClass and importing it
I am trying to do the following via Psi:
Create an inner class inner in class a
Add an import to inner in file f
The code I have is (embedded in a Command)
-
PsiClass inner = psiManager.getElementFactory().createInterface("inner");
a.add(inner);
PsiImportStatement importStatement = psiManager.getElementFactory().createImportStatement(inner);
f.getImportList().add(importStatement);
---
The resulting import is import I;, rather than import org.B.I;
If inner already exists then the import is done correctly, so I suspect I need to do something to get it resolved correctly after creation.
Any hints?
Please sign in to leave a comment.
I found a workaround.
I create the import statement as before and then replace the PsiJavaCodeReferenceElement child of the importStatement with a new PsiJavaCodeReferenceElement, created via psiManager.getElementFactory().createFQClassNameReferenceElement.
edwin hautus wrote:
Sorry for not answering quickly
--
Maxim Shafirov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"