Listening to new class events

I was hoping to use the PsiManager.addPsiTreeChangeListener to listen to class creation(or any other PsiFile) events.

The problem is that the childAdded method in the listeners are getting called before i can access it's contents. What this means is that i just can't get any basic information about the created class like it's package.

((PsiJavaFile) event.getChild()).getPackageName() always returns null.

Am i doing something wrong ? Is there any other type of listener i can use to get this done ?

Thanks.

6 comments

Correction, ((PsiJavaFile) event.getChild()).getPackageName() return empty string.

0

Hello Hugo,

Correction, ((PsiJavaFile) event.getChild()).getPackageName() return
empty string.


Is that the first file in the package?

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

No, there's more files in the same package.

0

Should it make a difference ?

0

I've searched and searched and can't find a solution for this.

Can anyone please help me ? There's got to be someone out there that has a similar use case working.

0

Sorry to bump this again but's it's just that this should be simple and i just can't a find a way to do it....

All i want is to listen to new file events and be able to access the file contents when it happens.

0

Please sign in to leave a comment.