Access methods of PsiVariable object representation
Answered
Hi folks,
I made a plugin that works with groovy language. Let's say this code (from a test, failing at this point)
List<GenericValue> rings = from('Mordor')//...
rings.forEach{GenericValue it ->
it.<caret>
}
The plugin now manages to see that the it element is of a type GenericValue.
But i know that the GenericValue class has a method which is getEntityName.
What i'd like to know is this :
Is there a way to access the getEntityName method ( and result ) from the PsiVariable element representing the it element ?
Something like :
PsiVariable myVar.computeInnerMethodWithName('getEntityName')
Please sign in to leave a comment.
Hi Gaëtan,
If you see the "it" type, then check what is the class of type and what it contains. If it is PsiClassType, you can get PsiClass and get methods from it.
Hi Karol, thanks a lot for your answer.
I don't think i understand it, how would a PsiMethod from the class would give the result from the it instance
that i'm trying to emulate ?
Maybe my problem isn't clear ?
Hi Gaëtan,
I think I understand your problem and maybe I was unclear with my answer.
My understanding:
If I'm wrong at any point, please provide more information that will fill the gap.
=> Yes, that's done in a pattern (from an other topic : https://intellij-support.jetbrains.com/hc/en-us/community/posts/4417764322578-How-to-get-the-type-of-a-variable-in-a-pattern?page=1#community_comment_4418809943570 )
=> I have the definition :
Currently, i use a regexp to extract (from the definition text) the information i'm looking for, which is the entity name. This one works.
But now i have the case of a loop inside a list, like in the intro of the thread.
=> yes, i have that now, but is there a way to compute and get the result of such a method for the it object?
Again, thanks a lot for your answers
Hi Gaëtan,
Sorry, I misunderstood you then.
I'm not sure it is a good idea to evaluate scripts in the completion, which should be fast, but you can take a look at:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000149284-Running-a-script-in-a-plugin
Thanks. I'll look into this. I started to figure that there would be no easy way to do this.
I'll come back and post my solution if i manage one :)