"Custom" Find Usages

Hi guys,

I have the following code:

public class Test1 {

    @Foo(order = FIRST)

    public void run(Bar bar) {

    }

}

public class Test2 {

    @Foo(order = SECOND)

    public void run(Bar bar) {

    }

}



I want to write an intention plugin where user can highlight Bar, then choose intention "Generate flow" (my plugin), then something like this would show up in console:

Bar:

  Test1.run()

  Test2.run()

Essentialy, "list all class.method() where it has @Foo and Bar as param, order by @Foo(order)". So my questions:

1. How do I list all method matching "has X as param and Y as annotation"?
2. How do I output to console?
3. Is there any recipe wiki for IntelliJ plugin development?
4. Where can I get the Javadoc?

2 comments
Comment actions Permalink

Anyway here's what I've come up so far:

    public void invoke( @NotNull Project project, Editor editor, @NotNull PsiElement file ) throws IncorrectOperationException
    {
        PsiElement element = file.findElementAt( editor.getCaretModel().getOffset() );

        if( element != null )
        {
            Query<PsiReference> usages = search( element , projectScope( project ) );

            for( PsiReference ref : usages.findAll() )
            {
                System.out.println( ref ); // not going here, usages.findAll() is empty
            }

    }


But usages.findAll() is empty, what do I miss?
0
Comment actions Permalink

1. You need to find the classes for your annotation and parameter type using JavaPsiFacade.findClass() and then look for their usages using the ReferencesSearch class. Then you need to walk the PSI tree up from the found element to make sure it was found in the context that you expect (inside an annotation or as a parameter type).
2. I'm not sure which console you mean. If you want to print some debugging output, you can simply use System.out.println. If you want to show this to your users, you'll be better off using a message box or a dialog. As you can probably see when using IntellIJ IDEA, it does not have any general purpose console toolwindow that plugins can use.
3. All the available plugin development documentation is linked from http://confluence.jetbrains.net/display/IDEADEV/PluginDevelopment
4. All the existing javadocs are included in the IntelliJ IDEA Community Edition source code.

0

Please sign in to leave a comment.