PsiReference

Hi,

try to develop a code completion plug-in for a xml-configuration for a
Bean-Mapper (Dozer):



Code completion for Tag class-a and class-b is ok.
Now I try to manage the completion for the methods of the java-beans (f.e?

In my ProjectComponent-Implementation i register XmlTag.class wiht my
PsiReferenceProvicer:

        • DozerProjectComponent*******

I am not shure: How can I register only the Tags and to the
ReferenceProvider?

public void initComponent() {
         DozerPsiReferenceProvider dozerPsiReferenceProvider = new
DozerPsiReferenceProvider();

ReferenceProvidersRegistry.getInstance(project).registerReferenceProvider(XmlTag.class,
dozerPsiReferenceProvider);
     }

        • DozerPsiReferenceProvider*****

Ok?
public PsiReference[] getReferencesByElement(@NotNull PsiElement
element, @NotNull ProcessingContext context) {
         return new DozerPsiReference[0];
     }

        • DozerPsiReference

How can I obtain all methods of the Java-Beans in my Project?
  @NotNull
     public Object[] getVariants() {
         LookupValueFactory.? (?????)
         return psiClass.getMethods();
     }

Thanks in advance for your help!
BTW: Is there any short how-to / tutorial / sample available?

best regards,
Matthias

2 comments
Comment actions Permalink

Check the com.intellij.xml.util.XmlUtil class.  You'll need the idea.jar in your SDK classpath.  This class has for registerXml* methods.  You want the registerXmlTagReferenceProvider method.

0
Comment actions Permalink

ReferenceProvidersRegistry.getInstance(project).registerReferenceProvider(XmlTag.class,
dozerPsiReferenceProvider);

You'll also need to provide a meaningful ElementPattern here, otherwise
your references will appear in just any XML. You may also consider using
DOM (http://www.jetbrains.com/idea/documentation/dom-rp.html) for your
purposes.

        • DozerPsiReference

How can I obtain all methods of the Java-Beans in my Project?
@NotNull
public Object[] getVariants() {
LookupValueFactory.? (?????)
return psiClass.getMethods();
}

Yes, you have to get a PsiClass from the other tag's value and get its
methods. If you want to get its superclasses' methods without
duplicates, invoking PsiClass#processDeclarations seems to be the best
way. As for creating LookupElements, consider using LookupElementBuilder.

0

Please sign in to leave a comment.