Simple (?) reference resolution question
I want to resolve PsiClasses from my custom language PsiReference elements. I
don't know where to start because PsiSearchHelper, PsiResolveHelper, etc. are
not documented. I want to search for a class with a specific name, which extends
a specific type, using the same scope rules that some class in a specific source
root would be use to resolve (unqualified) classname.
I try to use PsiResolveHelper but when I call
PsiResolveHelper("SomeClassInClasspath", getContext()) from a PsiElement of my
custom language, it returns null, even though the class is definitely there.
Can someone help?
Please sign in to leave a comment.
Keith,
sorry for a long delay, it was really release party that made us silent.
You can get all classes with a certain name from a certain scope with
PsiManager.getShortNamesCache().getClassesByName(). Then you can filter the
results as you need.
Eugene.
"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:dcr9b9$4jf$1@is.intellij.net...
elements. I
are
extends
source
>
of my
there.
>
Eugene Vigdorchik (JetBrains) wrote:
It's cool, I feel good that you guys had a fun time. My PSI questions are not as
important as you guys having fun and celebrating a release.
Cool, maybe you could add a single line of Javadoc to getShortNamesCache()
saying "This can be used to find a class by short name" with a link to
getClassesByName, until more complete docs are ready.
There is one more point about your references:
since you are resolving based on short class name, chances are that there
might be multiple resolve targets.
To handle this case we've introduced PsiPolyvariantReference that you
probably should implement. Doing this will automatically show a popup with
possible targets in case ctrl-B is ambigous.
Since this class is a recent addition (and also since I still remember
writing javadocs for it:), it is fairly well documented.
Eugene.
"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:dcr9b9$4jf$1@is.intellij.net...
elements. I
are
extends
source
>
of my
there.
>
I was just thinking there should be a way to resolve to multiple references.
While we're talking, I'll ask you something else. I was going to try to figure
this thing out myself, but how would I get IDEA to perform import popup for me?
I'm resolving based on short class name in the same way that IDEA does - I will
add an import once the user chooses which one.
Eugene Vigdorchik (JetBrains) wrote:
>>I want to resolve PsiClasses from my custom language PsiReference
>>don't know where to start because PsiSearchHelper, PsiResolveHelper, etc.
>>not documented. I want to search for a class with a specific name, which
>>a specific type, using the same scope rules that some class in a specific
>>root would be use to resolve (unqualified) classname.
>>
>>I try to use PsiResolveHelper but when I call
>>PsiResolveHelper("SomeClassInClasspath", getContext()) from a PsiElement
>>custom language, it returns null, even though the class is definitely
>>Can someone help?
No, IDEA does not resolve based on short name. Instead it shows the import
hint for unresolved references.
What's the use in offering to import if the reference is already
resolved,even if it is resolved with some problems?
Back to showing import hints, currently this code is not available through
openapi, this sounds like a further direction
for language API development.
Eugene.
"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:dd07o5$hih$1@is.intellij.net...
references.
>
figure
for me?
will
>
there
with
etc.
specific
The reference is not resolved until an import is present, as in Java. I only
plan to resolve it once I know FQN, after I add import. Is there a class to at
least show import popup with custom contents & select action?
I've filed http://jetbrains.net/jira/browse/IDEA-4374 about import popup issue.
By the way if it's possible will you look at my issues & questions from earlier
this week which have not been answered:
- Formatting problem.
http://intellij.net/forums/thread.jsp?forum=23&thread=155298
- Providing context to embedded Java code.
http://intellij.net/forums/thread.jsp?forum=23&thread=155262
- Showing standard Java syntax highlighting inside embedded Java code. (Also, I
have a new related question - how to get standard Java formatting for embedded
code?)
http://intellij.net/forums/thread.jsp?forum=23&thread=155262#4898776
Thanks!
Eugene Vigdorchik (JetBrains) wrote:
>>I was just thinking there should be a way to resolve to multiple
>>While we're talking, I'll ask you something else. I was going to try to
>>this thing out myself, but how would I get IDEA to perform import popup
>>I'm resolving based on short class name in the same way that IDEA does - I
>>add an import once the user chooses which one.
>>
>>Eugene Vigdorchik (JetBrains) wrote:
>>
>>>There is one more point about your references:
>>>since you are resolving based on short class name, chances are that
>>>might be multiple resolve targets.
>>>To handle this case we've introduced PsiPolyvariantReference that you
>>>probably should implement. Doing this will automatically show a popup
>>>possible targets in case ctrl-B is ambigous.
>>>
>>>Since this class is a recent addition (and also since I still remember
>>>writing javadocs for it:), it is fairly well documented.
>>>
>>>Eugene.
>>>"Keith Lea" <keith@cs.oswego.edu> wrote in message
>>>news:dcr9b9$4jf$1@is.intellij.net...
>>>
>>>
>>>>I want to resolve PsiClasses from my custom language PsiReference
>>>
>>>elements. I
>>>
>>>
>>>>don't know where to start because PsiSearchHelper, PsiResolveHelper,
>>>are
>>>
>>>
>>>>not documented. I want to search for a class with a specific name, which
>>>
>>>extends
>>>
>>>
>>>>a specific type, using the same scope rules that some class in a
>>>source
>>>
>>>
>>>>root would be use to resolve (unqualified) classname.
>>>>
>>>>I try to use PsiResolveHelper but when I call
>>>>PsiResolveHelper("SomeClassInClasspath", getContext()) from a PsiElement
>>>
>>>of my
>>>
>>>
>>>>custom language, it returns null, even though the class is definitely
>>>
>>>there.
>>>
>>>
>>>>Can someone help?
>>>
>>>
>>>