OpenAPI PSI questions

Does JavaElementVisitor visit expressions and statements in order of operation
(that is, the order that they would be executed / evaluated)?

Is there a simple way to resolve a reference expression to the element being
referenced? What should be passed to a PsiResolveHelper for "context"?

Is there a page with recommended methods of doing certain things with PSI?
For example, I want to synthesize expressions, such as "A == B", but where
A and B are specific PsiElement instances. (It will not be added to the PSI
tree, it's only for internal use.) Is there documentation for how something
like this should be done?

Thanks,
-Keith


3 comments
Comment actions Permalink

Keith Lea wrote:

Does JavaElementVisitor visit expressions and statements in order of operation
(that is, the order that they would be executed / evaluated)?


As far as I know, order of declaration in the source/class file.

Is there a simple way to resolve a reference expression to the element being
referenced? What should be passed to a PsiResolveHelper for "context"?


A reference expression has a resolve() method which returns the element
referenced.

Is there a page with recommended methods of doing certain things with PSI?
For example, I want to synthesize expressions, such as "A == B", but where
A and B are specific PsiElement instances. (It will not be added to the PSI
tree, it's only for internal use.) Is there documentation for how something
like this should be done?


I don't know of any documentation except the source provided with the
default plugins. You could try something like this:


Bas

0
Comment actions Permalink

>> Is there a page with recommended methods of doing certain things with
>> PSI? For example, I want to synthesize expressions, such as "A == B",
>> but where A and B are specific PsiElement instances. (It will not be
>> added to the PSI tree, it's only for internal use.) Is there
>> documentation for how something like this should be done?
>>

I don't know of any documentation except the source provided with the
default plugins. You could try something like this:

 String stringA = A.getText();
> String StringB = B.getText();
> PsiExpression element =
> elementFactory.createExpressionFromText(stringA
> + "==" + stringB, null);
> ]]>

Bas


The problem is, the elements in the expression must be the specific PsiElement
instances, not copies of those objects. I'm trying to build expressions which
define assertions which can be made about the code at certain points, and
it's necessary for me to reference specific PsiElements for use later when
working with the assertions.



0
Comment actions Permalink


"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:157174632437188697063856@news.jetbrains.com...

>> Is there a page with recommended methods of doing certain things with
>> PSI? For example, I want to synthesize expressions, such as "A == B",
>> but where A and B are specific PsiElement instances. (It will not be
>> added to the PSI tree, it's only for internal use.) Is there
>> documentation for how something like this should be done?
>>

I don't know of any documentation except the source provided with the
default plugins. You could try something like this:

 > String stringA = A.getText();
> > String StringB = B.getText();
> > PsiExpression element =
> > elementFactory.createExpressionFromText(stringA
> > + "==" + stringB, null);
> > ]]>

Bas

>

The problem is, the elements in the expression must be the specific

PsiElement

instances, not copies of those objects. I'm trying to build expressions

which

define assertions which can be made about the code at certain points, and
it's necessary for me to reference specific PsiElements for use later when
working with the assertions.


You are not allowed to do that in PSI: the internals of the implementation
may freely change the specific instance of any PsiElement
in the tree. A legal way to associate information with specific PsiElement
is to call putUserData (or even putCopiableUserData()) on it and retrieve it
later.

BTW, a better way to create a relation expression is:
PsiBinaryExpression expr =
(PsiBinaryExpression)elementFactory.createExpressionFromText( "a ==b ",
context);
expr.getLOperand().replace(A);
expr.getROperand().replace(B);

The context parameter is needed if you are going to resolve references in
expr, and the contract for resolve is such, that expr is a direct child of
context.

Please feel free to ask more questions, I realize that there are currently
no docs on PSI, so probably you will guide us on what should be covered.
Eugene.


0

Please sign in to leave a comment.