When constructor injecting class with Dagger, the Dagger compiler will generate <Type>_Factory.java
classes. This gist demonstrates the generated Java code and Kotlin equivalent code used in the blog post for Kotlin build performance measurements.
-
-
Save ZacSweers/61b83d7333fc5425084e712fb3c665ba to your computer and use it in GitHub Desktop.
Dagger Factory Generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.uber.model.core.generated.example; | |
import com.google.errorprone.annotations.RestrictedApi; | |
import com.uber.presidio.realtime.core.Data; | |
import com.uber.presidio.realtime.core.RealtimeClient; | |
import dagger.internal.Factory; | |
import javax.annotation.Generated; | |
import javax.inject.Provider; | |
@Generated( | |
value = "com.uber.realtime.android.servicebuilder.RealtimeJavaServiceBuilder", | |
comments = "This code was generated by the Uber Jenga Compiler for use with Dagger." | |
) | |
public final class SampleServiceClient_Factory<D extends Data> | |
implements Factory<SampleServiceClient<D>> { | |
private final Provider<RealtimeClient<D>> clientProvider; | |
@RestrictedApi( | |
explanation = "This should only be accessed from Dagger code", | |
link = "", | |
whitelistAnnotations = Generated.class | |
) | |
public SampleServiceClient_Factory(Provider<RealtimeClient<D>> clientProvider) { | |
this.clientProvider = clientProvider; | |
} | |
@Override | |
@RestrictedApi( | |
explanation = "This should only be accessed from Dagger code", | |
link = "", | |
whitelistAnnotations = Generated.class | |
) | |
public SampleServiceClient<D> get() { | |
return provideInstance(clientProvider); | |
} | |
@SuppressWarnings("CallingProviderGetDuringInit") | |
@RestrictedApi( | |
explanation = "This should only be accessed from Dagger code", | |
link = "", | |
whitelistAnnotations = Generated.class | |
) | |
public static <D extends Data> SampleServiceClient<D> provideInstance( | |
Provider<RealtimeClient<D>> clientProvider) { | |
return new SampleServiceClient<D>(clientProvider.get()); | |
} | |
@RestrictedApi( | |
explanation = "This should only be accessed from Dagger code", | |
link = "", | |
whitelistAnnotations = Generated.class | |
) | |
public static <D extends Data> SampleServiceClient_Factory<D> create( | |
Provider<RealtimeClient<D>> clientProvider) { | |
return new SampleServiceClient_Factory<D>(clientProvider); | |
} | |
@RestrictedApi( | |
explanation = "This should only be accessed from Dagger code", | |
link = "", | |
whitelistAnnotations = Generated.class | |
) | |
public static <D extends Data> SampleServiceClient<D> newSampleServiceClient( | |
RealtimeClient<D> client) { | |
return new SampleServiceClient<D>(client); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.uber.model.core.generated.example | |
import com.google.errorprone.annotations.RestrictedApi | |
import com.uber.presidio.realtime.core.Data | |
import com.uber.presidio.realtime.core.RealtimeClient | |
import dagger.internal.Factory | |
import javax.annotation.Generated | |
import javax.inject.Provider | |
import kotlin.jvm.JvmStatic | |
@Generated( | |
"com.uber.realtime.android.servicebuilder.kotlin.RealtimeKotlinServiceBuilder", | |
comments = "This code was generated by the Uber Jenga Compiler for use with Dagger." | |
) | |
class SampleServiceClient_Factory<D : Data>(private val clientProvider: Provider<RealtimeClient<D>>) | |
: Factory<SampleServiceClient<D>> { | |
override fun get(): SampleServiceClient<D> = provideInstance<D>(clientProvider) | |
companion object { | |
@RestrictedApi( | |
explanation = "This should only be accessed from Dagger code", | |
link = "", | |
whitelistAnnotations = [Generated::class] | |
) | |
@JvmStatic | |
fun <D : Data> provideInstance(clientProvider: Provider<RealtimeClient<D>>): | |
SampleServiceClient<D> = SampleServiceClient<D>(clientProvider.get()) | |
@RestrictedApi( | |
explanation = "This should only be accessed from Dagger code", | |
link = "", | |
whitelistAnnotations = [Generated::class] | |
) | |
@JvmStatic | |
fun <D : Data> create(clientProvider: Provider<RealtimeClient<D>>): | |
SampleServiceClient_Factory<D> = SampleServiceClient_Factory<D>(clientProvider) | |
@RestrictedApi( | |
explanation = "This should only be accessed from Dagger code", | |
link = "", | |
whitelistAnnotations = [Generated::class] | |
) | |
@JvmStatic | |
fun <D : Data> newSampleServiceClient(client: RealtimeClient<D>): SampleServiceClient<D> = | |
SampleServiceClient<D>(client) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment