Questions about class creation

Hello all,
I'm trying to create a new class (Manager) using Annotations from an other
class (POJO).

Now I've successfully created a new PsiJavaFile in the same directory of the
POJO and I'm
trying to create or recreate the PsiPackageStatement, PsiClass (thanks to
the PsiViewer)...

So the first thing I do is trying to delete/remove every PsiElement of the
PsiJavaFile:

for (PsiElement e : managerFile.getChildren()) {
e.delete();
}

But I get a NullPointerException with a strange message: "Repository caches
are corrupted and will be rebuilt on next startup"
Last Action: $Delete

java.lang.NullPointerException
at
com.intellij.psi.impl.cache.impl.repositoryCache.JavaFileRecord.write(JavaFi
leRecord.java:57)
at
com.intellij.psi.impl.cache.impl.repositoryCache.RecordManager.a(RecordManag
er.java:125)
at
com.intellij.psi.impl.cache.impl.repositoryCache.RecordManager.createFile(Re
cordManager.java:37)
at
com.intellij.psi.impl.cache.impl.repositoryCache.RepositoryCache$5.run(Repos
itoryCache.java:9)
at
com.intellij.psi.impl.cache.impl.repositoryCache.RepositoryCache.a(Repositor
yCache.java:9)
at
com.intellij.psi.impl.cache.impl.repositoryCache.RepositoryCache.fileCreated
(RepositoryCache.java:282)
at
com.intellij.psi.impl.cache.impl.RepositoryManagerImpl.a(RepositoryManagerIm
pl.java:106)
at
com.intellij.psi.impl.cache.impl.RepositoryManagerImpl.updateAll(RepositoryM
anagerImpl.java:27)
at
com.intellij.psi.impl.cache.impl.RepositoryManagerImpl.updateAll(RepositoryM
anagerImpl.java:77)
at
com.intellij.psi.impl.cache.impl.RepositoryIndexImpl.getNameOccurrencesInExt
endsLists(RepositoryIndexImpl.java:85)
at
com.intellij.psi.impl.search.PsiSearchHelperImpl.a(PsiSearchHelperImpl.java:
546)
at
com.intellij.psi.impl.search.PsiSearchHelperImpl.processInheritors(PsiSearch
HelperImpl.java:663)
at
com.intellij.psi.impl.search.PsiSearchHelperImpl.processInheritors(PsiSearch
HelperImpl.java:58)
at
com.intellij.codeInsight.daemon.impl.OverridenMarkersPass.b(OverridenMarkers
Pass.java:50)
at
com.intellij.codeInsight.daemon.impl.OverridenMarkersPass.a(OverridenMarkers
Pass.java:86)
at
com.intellij.codeInsight.daemon.impl.OverridenMarkersPass.a(OverridenMarkers
Pass.java:0)
at
com.intellij.codeInsight.daemon.impl.OverridenMarkersPass.doCollectInformati
on(OverridenMarkersPass.java:54)
at
com.intellij.codeInsight.daemon.impl.TextEditorHighlightingPass.collectInfor
mation(TextEditorHighlightingPass.java:6)
at
com.intellij.codeInsight.daemon.impl.UpdateThread$2.run(UpdateThread.java:1)
at
com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(Applicat
ionImpl.java:357)
at com.intellij.codeInsight.daemon.impl.UpdateThread.a(UpdateThread.java:1)
at
com.intellij.codeInsight.daemon.impl.UpdateThread.access$100(UpdateThread.ja
va:5)
at
com.intellij.codeInsight.daemon.impl.UpdateThread$1.run(UpdateThread.java:2)
at
com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressMa
nagerImpl.java:24)
at
com.intellij.codeInsight.daemon.impl.UpdateThread.run(UpdateThread.java:10)

Did I forgot to do something?

Thanks in advance for your comments.
Loïc Lefèvre


1 comment
Comment actions Permalink

Hello Loïc,

LL> I'm trying to create a new class (Manager) using Annotations from an
other
LL> class (POJO).
LL> Now I've successfully created a new PsiJavaFile in the same
LL> directory of the
LL> POJO and I'm
LL> trying to create or recreate the PsiPackageStatement, PsiClass
LL> (thanks to
LL> the PsiViewer)...
LL> So the first thing I do is trying to delete/remove every PsiElement
LL> of the PsiJavaFile:
LL>
LL> for (PsiElement e : managerFile.getChildren()) {
LL> e.delete();
LL> }

Don't do that. A much easier way to create a Java file with required contents
is to use PsiElementFactory.createFileFromText(). It will create all the
necessary PSI structures for you.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.