create hyperlinks when the user presses ctrl and hovers the mouse over custom text in javadoc

Hi I would like to get a functionality like the hyperlinks in eclipse, now I think these are called highlighters in IntelliJ, and I would like to know how to register them in java editors.

For example, i want that this:



    /**
     * @should do my thing
     */
    void doIt(){


    }



when the user hover the mouse (with ctrl) over  the 'do my thing' string get underlined, like this:

    /**
     * @should do my thing
     */
    void doIt(){


    }



and allow me to jump somewhere in the project after clicking on the created link.

Which is the right place to extend the editor in this way?
7 comments
Comment actions Permalink

The most non-obtrusive way would be to register a GotoDeclarationHandler. In your plugin.xml, use the extension point com.intellij.gotoDeclarationHandler that points to your class that implements com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler.

Another way would be to create PSI references by registering a PsiReferenceProvider. The advantage with PSI references is that you can get additional featureas for (almost) free, such as "Find Usages", "Refactor/Rename"...

0
Comment actions Permalink

Thanks, it made the work

0
Comment actions Permalink

I got it working with com.intellij.gotoDeclarationHandler but it add only the basic ctrl+ click functionality, now I think I need the second approach you mentioned to get more advanced functionality for my custom javadoc tags

0
Comment actions Permalink

Now I´m realizing that PsiReferenceProvider only works for String literals, this is:

String zas = "psiReferenceProviderworkshere";

But I want to be able to create references from the value of a custom tag in the javadoc for a method:

  /**
     * @should need to provider references from here
     */
    void doIt(){


    }

How could I extend the provider for references for places as that, this is custom javadoc tags.

Thanks

0
Comment actions Permalink

Hi Jaime,



it's not supported at the moment. You may file a request.

Update: it's not supported for arbitrary text in a comment but works for tags. Sorry for misinformation.

0
Comment actions Permalink

Actually it's possible to use the PsiReferenceProvider API to inject references into a PsiDocTag. This should do what you need.

0
Comment actions Permalink

I just registered my own com.intellij.psi.PsiReferenceProvider and to inject com.intellij.psi.PsiReference from PsiDocTag's, and it works quite well for navigating to the target element, like this:

References are injected to PsiDocTag (@should need to provider references from here)

  /**
     * @should need to provider references from here
     */
    void doIt(){


    }


When control click over the reference I get to the target test method.

    /**
     * @verifies need to provider references from here
     * @see A#doIt()
     */
    @Test
    public void doIt_shouldNeedToProviderReferencesFromHere() throws Exception { <--- references to this
        //TODO auto-generated
        Assert.fail("Not yet implemented");
    }

But as Ronnie Kolehmainen PsiReferences can help to add renaming support so I want to add renaming support for the test method FROM THE REFERENCE ELEMENT. It is, when the user fires rename action over the PsiDocTag (@should need to provider references from here), only the text (need to provider references from here) should appear in the rename dialog, and when the user accepts the refactor I want to be able to regenerate the test method name. Is there a standard way to get this done? Because I have see that maybe I could do something like extend renamePsiElementProcessor to create my custom processing.

Another approach that I could take is to register a nameSuggestionProvider to provide the name(need to provider references from here) in the dialog but then the name isn't a correct identifier for a method in the RenameDialog 

0

Please sign in to leave a comment.