Custom Reference containing other references ?

Hello
Sorry for ambigous thread naming but the question is following
I wanna implement some references in string literals having similar behaviour like Java classes references in JSP. Im using ReferenceProviderRegistry.
registry.registerReferenceProvider(new MyFilter(), PsiLiteralExpression.class, new PsiReferenceProviderBase() {
@NotNull
public PsiReference[] getReferencesByElement(PsiElement psiElement) {
return .......;
}
});

For example if we have string declaration

String s = "qwe.asd.zxc";

I want all parts ("qwe", "asd", "zxc") to be resolved to different elements. Like if one puts smth like com.intellij.psi. - each part resolves to own package/subpackage/class.

As i see i should do some trick on my ReferenceProvider/PsiReference implementation. But can't understand by myself what kind of tricks i should do.

4 comments
Comment actions Permalink

StringTokenizer?

0
Comment actions Permalink

StringTokenizer?

If you can do me a favor and explain how this can help ?

0
Comment actions Permalink

Hello Evgeny,

you need to create an array of several PsiReferences in your implementation of com.intellij.psi.PsiReferenceProvider that resolve to the different packages/classes that are represented by the dot-separated parts of the String literal. The references need to be put on the correct place in the literal, see com.intellij.psi.PsiReference#getRangeInElement.

To resolve the names of the parts in the String, use com.intellij.psi.JavaPsiFacade#findPackage and #findClass to return the PSI objects for the fully qualified names.

There are also a couple of examples available how to implement PsiReferences in the open-source plugins (e.g. JavaScript). If this doesn't help you, please try to describe your actual problem in more detail.

Sascha

0
Comment actions Permalink

Hello
Very appreciate for showing the algorithm of solving such problems :)
Will try to implement my task basing on your ideas.

0

Please sign in to leave a comment.