square / dagger

A fast dependency injector for Android and Java.
https://square.github.io/dagger/
Apache License 2.0
7.3k stars 3.07k forks source link

Documentation Tip: Search Structurally @Provides #521

Open jmfayard opened 8 years ago

jmfayard commented 8 years ago

Hello, thanks for dagger, which is great.

A co-worker of mine who was unfamiliar with it was confused all the time from where those @Inject fields come from.

To make his life easier, here is a structural search pattern that people can use, it's quite useful


Action Search Structurally (or Edit > Find > Search Structurally)

Enter the following template

class $Class$ {
  @Provides( )
  $MethodType$ $MethodName$($ParameterType$ $ParameterName$);
}

In Edit variables, edit $MethodName$ like this image

Also edit $ParameterName$ image

Now when you serach Search Structurally, you get

image

Save it as template named Dagger @Provides so you can use it next time from (Copy from existing template)

Hope that helps!

JakeWharton commented 8 years ago

This is amazing!

We actually have an IntelliJ plugin which is supposed to provide this functionality as well: https://github.com/square/dagger-intellij-plugin. Sadly it's fallen a bit out of favor with regard to upkeep, but we have plans to revive it and restore it to its former glory.