Skip to content

Commit

Permalink
Make all Kotlin warnings errors and fix existing warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
vRallev committed Nov 20, 2020
1 parent 62cf669 commit d43474c
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 31 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ subprojects {

//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
kotlinOptions.useIR = rootProject.ext.kotlinUseIR
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
useIR = rootProject.ext.kotlinUseIR
allWarningsAsErrors = true
}
}

// TODO: fix obscure dependency substitution error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ import java.lang.reflect.Modifier

val Member.isStatic: Boolean get() = Modifier.isStatic(modifiers)
val Member.isAbstract: Boolean get() = Modifier.isAbstract(modifiers)

fun <T : Any> Class<T>.newInstanceNoArgs(): T = getDeclaredConstructor().newInstance()
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ class ComponentDetectorCheckTest {
}
}

@Suppress("CHANGING_ARGUMENTS_EXECUTION_ORDER_FOR_NAMED_VARARGS")
private fun compile(
vararg sources: String,
block: Result.() -> Unit = { }
): Result = com.squareup.anvil.compiler.compile(
sources = *sources,
sources = sources,
generateDaggerFactories = true,
block = block
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1303,11 +1303,12 @@ public final class InjectClass_Factory<T extends CharSequence> implements Factor
}
}

@Suppress("CHANGING_ARGUMENTS_EXECUTION_ORDER_FOR_NAMED_VARARGS")
private fun compile(
vararg sources: String,
block: Result.() -> Unit = { }
): Result = com.squareup.anvil.compiler.compile(
sources = *sources,
sources = sources,
enableDaggerAnnotationProcessor = useDagger,
generateDaggerFactories = !useDagger,
block = block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.common.truth.Truth.assertThat
import com.squareup.anvil.compiler.injectClass
import com.squareup.anvil.compiler.isStatic
import com.squareup.anvil.compiler.membersInjector
import com.squareup.anvil.compiler.newInstanceNoArgs
import com.tschuchort.compiletesting.KotlinCompilation.Result
import dagger.Lazy
import dagger.MembersInjector
Expand Down Expand Up @@ -175,10 +176,10 @@ public final class InjectClass_MembersInjector implements MembersInjector<Inject
)
as MembersInjector<Any>

val injectInstanceConstructor = injectClass.newInstance()
val injectInstanceConstructor = injectClass.newInstanceNoArgs()
membersInjectorInstance.injectMembers(injectInstanceConstructor)

val injectInstanceStatic = injectClass.newInstance()
val injectInstanceStatic = injectClass.newInstanceNoArgs()

membersInjector.staticInjectMethod("string")
.invoke(null, injectInstanceStatic, "a")
Expand Down Expand Up @@ -309,10 +310,10 @@ public final class InjectClass_MembersInjector implements MembersInjector<Inject
)
as MembersInjector<Any>

val injectInstanceConstructor = injectClass.newInstance()
val injectInstanceConstructor = injectClass.newInstanceNoArgs()
membersInjectorInstance.injectMembers(injectInstanceConstructor)

val injectInstanceStatic = injectClass.newInstance()
val injectInstanceStatic = injectClass.newInstanceNoArgs()

membersInjector.staticInjectMethod("string")
.invoke(null, injectInstanceStatic, "a")
Expand Down Expand Up @@ -421,10 +422,10 @@ public final class InjectClass_MembersInjector implements MembersInjector<Inject
.newInstance(Provider { File("") }, Provider { File("").toPath() })
as MembersInjector<Any>

val injectInstanceConstructor = injectClass.newInstance()
val injectInstanceConstructor = injectClass.newInstanceNoArgs()
membersInjectorInstance.injectMembers(injectInstanceConstructor)

val injectInstanceStatic = injectClass.newInstance()
val injectInstanceStatic = injectClass.newInstanceNoArgs()

membersInjector.staticInjectMethod("file")
.invoke(null, injectInstanceStatic, File(""))
Expand Down Expand Up @@ -543,10 +544,10 @@ public final class OuterClass_InjectClass_MembersInjector implements MembersInje
.newInstance(Provider { "a" }, Provider<CharSequence> { "b" }, Provider { listOf("c") })
as MembersInjector<Any>

val injectInstanceConstructor = injectClass.newInstance()
val injectInstanceConstructor = injectClass.newInstanceNoArgs()
membersInjectorInstance.injectMembers(injectInstanceConstructor)

val injectInstanceStatic = injectClass.newInstance()
val injectInstanceStatic = injectClass.newInstanceNoArgs()

membersInjector.staticInjectMethod("string")
.invoke(null, injectInstanceStatic, "a")
Expand Down Expand Up @@ -684,11 +685,12 @@ public final class InjectClass_MembersInjector<T, U, V> implements MembersInject
.single { it.name == "inject${memberName.capitalize(US)}" }
}

@Suppress("CHANGING_ARGUMENTS_EXECUTION_ORDER_FOR_NAMED_VARARGS")
private fun compile(
vararg sources: String,
block: Result.() -> Unit = { }
): Result = com.squareup.anvil.compiler.compile(
sources = *sources,
sources = sources,
enableDaggerAnnotationProcessor = useDagger,
generateDaggerFactories = !useDagger,
block = block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.squareup.anvil.compiler.daggerModule1
import com.squareup.anvil.compiler.innerModule
import com.squareup.anvil.compiler.isStatic
import com.squareup.anvil.compiler.moduleFactoryClass
import com.squareup.anvil.compiler.newInstanceNoArgs
import com.tschuchort.compiletesting.KotlinCompilation.ExitCode.COMPILATION_ERROR
import com.tschuchort.compiletesting.KotlinCompilation.Result
import dagger.Lazy
Expand Down Expand Up @@ -91,7 +92,7 @@ public final class DaggerModule1_ProvideStringFactory implements Factory<String>
val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }
assertThat(staticMethods).hasSize(2)

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -162,7 +163,7 @@ public final class DaggerModule1_ProvideFactoryFactory implements Factory<com.sq
val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }
assertThat(staticMethods).hasSize(2)

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -234,7 +235,7 @@ public final class DaggerModule1_ProvideStringFactory implements Factory<String>
val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }
assertThat(staticMethods).hasSize(2)

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -309,7 +310,7 @@ public final class DaggerModule1_ProvideFileFactory implements Factory<File> {
val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }
assertThat(staticMethods).hasSize(2)

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -383,7 +384,7 @@ public final class DaggerModule1_ProvideFileFactory implements Factory<File> {
val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }
assertThat(staticMethods).hasSize(2)

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -454,7 +455,7 @@ public final class DaggerModule1_ProvideStringListFactory implements Factory<Lis
val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }
assertThat(staticMethods).hasSize(2)

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -527,7 +528,7 @@ public final class DaggerModule1_ProvidePairFactory implements Factory<Pair<Pair

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -639,7 +640,7 @@ public final class DaggerModule1_ProvideIntFactory implements Factory<Integer> {
val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }
assertThat(staticMethods).hasSize(2)

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -795,7 +796,7 @@ public final class DaggerModule1_ProvideStringFactory implements Factory<String>

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module, Provider { "a" }, Provider<CharSequence> { "b" })
Expand Down Expand Up @@ -892,7 +893,7 @@ public final class DaggerModule1_ProvideStringFactory implements Factory<String>

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module, Provider { "a" }, Provider { "b" }, Provider { listOf("c") })
Expand Down Expand Up @@ -992,7 +993,7 @@ public final class DaggerModule1_ProvideStringFactory implements Factory<String>

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module, Provider { "a" }, Provider { "b" }, Provider { listOf("c") })
Expand Down Expand Up @@ -1086,7 +1087,7 @@ public final class DaggerModule1_ProvideStringFactory implements Factory<String>

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module, Provider { listOf("a") },
Expand Down Expand Up @@ -1332,7 +1333,7 @@ public final class DaggerModule1_ProvideStringFactory implements Factory<String>

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -1497,7 +1498,7 @@ public final class DaggerModule1_ProvideStringFactory implements Factory<String>

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module, Provider { null }, Provider { null })
Expand Down Expand Up @@ -2497,7 +2498,7 @@ public final class DaggerModule1_GetStringFactory implements Factory<String> {

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -2709,7 +2710,7 @@ public final class DaggerModule1_GetStringFactory implements Factory<String> {

val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }

val module = daggerModule1.newInstance()
val module = daggerModule1.newInstanceNoArgs()

val factoryInstance = staticMethods.single { it.name == "create" }
.invoke(null, module)
Expand Down Expand Up @@ -2792,11 +2793,12 @@ public final class DaggerModule1_GetStringFactory implements Factory<String> {
}
}

@Suppress("CHANGING_ARGUMENTS_EXECUTION_ORDER_FOR_NAMED_VARARGS")
private fun compile(
vararg sources: String,
block: Result.() -> Unit = { }
): Result = com.squareup.anvil.compiler.compile(
sources = *sources,
sources = sources,
enableDaggerAnnotationProcessor = useDagger,
generateDaggerFactories = !useDagger,
block = block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ object Factory

object Date

abstract class OuterClass constructor(innerClass: InnerClass) {
abstract class OuterClass constructor(
@Suppress("UNUSED_PARAMETER") innerClass: InnerClass
) {
class InnerClass
}
4 changes: 4 additions & 0 deletions gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ tasks.withType(JavaCompile).configureEach {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8

// TODO: enable when this module is migrated to Kotlin 1.4.
// allWarningsAsErrors = true

freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}
Expand Down

0 comments on commit d43474c

Please sign in to comment.