views:

40

answers:

2

How would I go about writing my own Intelli-J inspection? I'm looking for some general guides or resources.

I want to bring up an inspection hint every time a collection class is instantiated manually, rather than through the Guava (List.newArrayList()/Maps.newHashMap()) etc. as per a team-wide standard.

I'd appreciate any direction.

+1  A: 

I'll have to disappoint you but there are no written guidelines nor resources nor documentation for almost everything related to plug-ins and IntelliJ :(. (this is the main reason many IntelliJ fans haven't worked on plug-ins for their favorite tool).

That company makes fantastic products, but when it comes to documentation, books, and guidelines for developers (not users) - well, they're practically non-existing :(.

Your only bet is to take a look the source of actual IntelliJ plug-ins (some of them are here: http://git.jetbrains.org/) and ask very concrete questions on the IntelliJ plug-in list since the development team will gladly answer you usually in a matter of minutes.

A. Ionescu
This is the saddest response I've ever had. I don't know if I'm that willing to jump down the rabbit hole.
Stefan Kendall
It's not that it's impossible. There are already incredibly good plug-ins for IntelliJ. Just that those developers are very very skilled (compared to me) and are able to code without docs (I'm not :( ). Maybe they also like coding puzzles - and this quite close to it. It's also not that I'm so bad (I hope so :) ), since I was able to code plug-ins for Netbeans and Eclipse very easily, but there was good documentation available.
A. Ionescu
+1  A: 

For such an inspection you don't need to write a plug-in, instead use the Structural Search and Replace (SSR) feature which allows to create custom inspections with quick fixes.

See also the Creating your own inspections section and documentation for this feature.

Note that it's available in the Ultimate version only.

CrazyCoder
I've got the ultimate edition. Thanks!
Stefan Kendall
Is there an easy way to capture types? I can't seem to do basic things like use variable expressions side by side, such as $mapType$$mapEnd$ to do a simple replacement. Is there any reason this might be?That is, if I have a single expression, say .*\s*.*abc, and I break it into two variables, .*\s* and .*abc, the expression does not match any text. What could be going wrong?
Stefan Kendall
SSR matches one or many language constructions per variable, it will NOT capture several variables ($mapType$$mapEnd$) into type reference.If I understand you correctly you need to matchList<$Type$> $variable$ = new $ListType$<$Type$>()and replace it accordingly.
nicity
This topic has more detailed information on the subject http://stackoverflow.com/questions/3302233/intelli-j-structural-search-and-replace-problems
nicity

related questions