About PSI element creation!

hi, i am doing a testing for the PSI api and want to ask some questions.


1) how to create psiClass using
public abstract PsiClass createClassFromText(String s, PsiElement psielement) in the ElementFactory. What is the purpose for the "psielement" parameter?

2) Such as PSIclass, if i want to add a new super class to it, then what can i do? I cannot find superClass element can be created in PSIElementFactory.
And i want to make sure that if i want to set modifier, super class, interface and etc to PSIClass, is that every thing can be done by "PSIClass.add(element)"? I cann find any other set or add method to do these.

thx

5 comments
Comment actions Permalink

andyfai wrote:

hi, i am doing a testing for the PSI api and want to ask some questions.


1) how to create psiClass using
public abstract PsiClass createClassFromText(String s, PsiElement
psielement) in the ElementFactory. What is the purpose for the
"psielement" parameter?


This is a context, that is place where all references in your class text
will be resolved. Can be null.


2) Such as PSIclass, if i want to add a new super class to it, then what
can i do? I cannot find superClass element can be created in
PSIElementFactory.
And i want to make sure that if i want to set modifier, super class,
interface and etc to PSIClass, is that every thing can be done by
"PSIClass.add(element)"? I cann find any other set or add method to do
these.


getModifierList() to add/change modifeiers
getExtendsList() and getImplementsList() to add supre classes
add(...) to add methods and fields.

I guess it will be a good idea for you to get one of existing plugins and
read its code.

Friendly,
Dmitry

--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

-1
Comment actions Permalink

Dmitry Lomov (JetBrains) wrote:

>I guess it will be a good idea for you to get one of existing plugins and
>read its code.

>

As all intellectual challenges, Reverse Engineering the openapi can be
fun, but sometimes I wish I could skip the "Indiana Jones" part, and
read some javadoc info, and a basic design document, to patch the holes
in my understanding of the PSI.

I wish a compassionate JetBrains developer would pity us, PSI newbies,
and spend an hour or two writing a few paragraphs about VirtualFile,
Presentation, etc...

I don't need the full IDEA design, but just what's useful to plugin
developers.
The Wiki would be the right place to store this info.

Alain

1
Comment actions Permalink

I would be just as happy if one of the JetBrains developers would take pity on us and simply spin their source code through JavaDoc so we could at least find out what the names of the parameters are. That would answer 99% of these questions, I think and would take JetBrains a grand total of a few minutes of unmonitored computer time.

1
Comment actions Permalink

I loved the reference to indiana jones, that is so true. I think writing more documentation and spending time on adding context to the javadocs would be a big win.

In my opinion, writing docs takes little effort and produces huge wins for developers down stream.
I've created my own psi cookbook to add a little context and so I don't have to remember every api > https://code.google.com/p/ide-examples/wiki/IntelliJIdeaPsiCookbook

0
Comment actions Permalink

One of the great parts of developing IntelliJ Plugins, is that you have IntelliJ itself to help answer your questions on how certain api are used. During your exploration you begin to realize just how powerful a tool it actually is.

JavaDocs are nice, but they almost never include examples. Source code is so much bettter in that respect.

There is a learning curve, I think everyone struggles with it at first - but as a developer often times working source is the best documentation.

Your docs are exceptional in htat they provide mostly source - they are really more like snippets. Why not package them up as such? Make them into templates or live-templates.

0

Please sign in to leave a comment.