Fix "@JvmStatic used for @Provides function in an object class" Lint warning.

See https://github.com/google/dagger/releases/tag/dagger-2.25.2 point 2.ii. : @Module object classes no longer need @JvmStatic on the provides methods.
Ensure this warning does not appear again.
This commit is contained in:
Benoit Marty 2021-11-19 15:29:11 +01:00
parent 289339f2db
commit d80a25feac
7 changed files with 12 additions and 32 deletions

View File

@ -84,4 +84,7 @@
<!-- Bug in lint agp 4.1 incorrectly thinks kotlin forEach is using java 8 API's. --> <!-- Bug in lint agp 4.1 incorrectly thinks kotlin forEach is using java 8 API's. -->
<!-- FIXME this workaround should be removed in a near future --> <!-- FIXME this workaround should be removed in a near future -->
<issue id="NewApi" severity="warning" /> <issue id="NewApi" severity="warning" />
<!-- DI -->
<issue id="JvmStaticProvidesInObjectDetector" severity="error" />
</lint> </lint>

View File

@ -25,16 +25,12 @@ import im.vector.app.core.services.GuardServiceStarter
import im.vector.app.fdroid.service.FDroidGuardServiceStarter import im.vector.app.fdroid.service.FDroidGuardServiceStarter
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
@Module
@InstallIn(SingletonComponent::class) @InstallIn(SingletonComponent::class)
abstract class FlavorModule { @Module
object FlavorModule {
companion object { @Provides
fun provideGuardServiceStarter(preferences: VectorPreferences, appContext: Context): GuardServiceStarter {
@Provides return FDroidGuardServiceStarter(preferences, appContext)
@JvmStatic
fun provideGuardServiceStarter(preferences: VectorPreferences, appContext: Context): GuardServiceStarter {
return FDroidGuardServiceStarter(preferences, appContext)
}
} }
} }

View File

@ -24,14 +24,10 @@ import im.vector.app.core.services.GuardServiceStarter
@InstallIn(SingletonComponent::class) @InstallIn(SingletonComponent::class)
@Module @Module
abstract class FlavorModule { object FlavorModule {
companion object { @Provides
fun provideGuardServiceStarter(): GuardServiceStarter {
@Provides return object : GuardServiceStarter {}
@JvmStatic
fun provideGuardServiceStarter(): GuardServiceStarter {
return object : GuardServiceStarter {}
}
} }
} }

View File

@ -28,7 +28,6 @@ import im.vector.app.features.home.room.detail.timeline.helper.TimelineAsyncHelp
@InstallIn(ActivityComponent::class) @InstallIn(ActivityComponent::class)
object HomeModule { object HomeModule {
@Provides @Provides
@JvmStatic
@TimelineEventControllerHandler @TimelineEventControllerHandler
fun providesTimelineBackgroundHandler(): Handler { fun providesTimelineBackgroundHandler(): Handler {
return TimelineAsyncHelper.getBackgroundHandler() return TimelineAsyncHelper.getBackgroundHandler()

View File

@ -30,11 +30,9 @@ import im.vector.app.core.glide.GlideApp
object ScreenModule { object ScreenModule {
@Provides @Provides
@JvmStatic
fun providesGlideRequests(context: AppCompatActivity) = GlideApp.with(context) fun providesGlideRequests(context: AppCompatActivity) = GlideApp.with(context)
@Provides @Provides
@JvmStatic
@ActivityScoped @ActivityScoped
fun providesSharedViewPool() = RecyclerView.RecycledViewPool() fun providesSharedViewPool() = RecyclerView.RecycledViewPool()
} }

View File

@ -73,69 +73,58 @@ abstract class VectorBindModule {
object VectorStaticModule { object VectorStaticModule {
@Provides @Provides
@JvmStatic
fun providesContext(application: Application): Context { fun providesContext(application: Application): Context {
return application.applicationContext return application.applicationContext
} }
@Provides @Provides
@JvmStatic
fun providesResources(context: Context): Resources { fun providesResources(context: Context): Resources {
return context.resources return context.resources
} }
@Provides @Provides
@JvmStatic
fun providesSharedPreferences(context: Context): SharedPreferences { fun providesSharedPreferences(context: Context): SharedPreferences {
return context.getSharedPreferences("im.vector.riot", MODE_PRIVATE) return context.getSharedPreferences("im.vector.riot", MODE_PRIVATE)
} }
@Provides @Provides
@JvmStatic
fun providesMatrix(context: Context): Matrix { fun providesMatrix(context: Context): Matrix {
return Matrix.getInstance(context) return Matrix.getInstance(context)
} }
@Provides @Provides
@JvmStatic
fun providesCurrentSession(activeSessionHolder: ActiveSessionHolder): Session { fun providesCurrentSession(activeSessionHolder: ActiveSessionHolder): Session {
// TODO: handle session injection better // TODO: handle session injection better
return activeSessionHolder.getActiveSession() return activeSessionHolder.getActiveSession()
} }
@Provides @Provides
@JvmStatic
fun providesLegacySessionImporter(matrix: Matrix): LegacySessionImporter { fun providesLegacySessionImporter(matrix: Matrix): LegacySessionImporter {
return matrix.legacySessionImporter() return matrix.legacySessionImporter()
} }
@Provides @Provides
@JvmStatic
fun providesAuthenticationService(matrix: Matrix): AuthenticationService { fun providesAuthenticationService(matrix: Matrix): AuthenticationService {
return matrix.authenticationService() return matrix.authenticationService()
} }
@Provides @Provides
@JvmStatic
fun providesRawService(matrix: Matrix): RawService { fun providesRawService(matrix: Matrix): RawService {
return matrix.rawService() return matrix.rawService()
} }
@Provides @Provides
@JvmStatic
fun providesHomeServerHistoryService(matrix: Matrix): HomeServerHistoryService { fun providesHomeServerHistoryService(matrix: Matrix): HomeServerHistoryService {
return matrix.homeServerHistoryService() return matrix.homeServerHistoryService()
} }
@Provides @Provides
@JvmStatic
@Singleton @Singleton
fun providesApplicationCoroutineScope(): CoroutineScope { fun providesApplicationCoroutineScope(): CoroutineScope {
return CoroutineScope(SupervisorJob() + Dispatchers.Main) return CoroutineScope(SupervisorJob() + Dispatchers.Main)
} }
@Provides @Provides
@JvmStatic
fun providesCoroutineDispatchers(): CoroutineDispatchers { fun providesCoroutineDispatchers(): CoroutineDispatchers {
return CoroutineDispatchers(io = Dispatchers.IO, computation = Dispatchers.Default) return CoroutineDispatchers(io = Dispatchers.IO, computation = Dispatchers.Default)
} }

View File

@ -28,7 +28,6 @@ import im.vector.app.features.home.room.detail.timeline.helper.TimelineAsyncHelp
object HomeModule { object HomeModule {
@Provides @Provides
@JvmStatic
@TimelineEventControllerHandler @TimelineEventControllerHandler
fun providesTimelineBackgroundHandler(): Handler { fun providesTimelineBackgroundHandler(): Handler {
return TimelineAsyncHelper.getBackgroundHandler() return TimelineAsyncHelper.getBackgroundHandler()