Skip to content

Commit

Permalink
Merge pull request #59 from square/ralf/kotlin-1-4
Browse files Browse the repository at this point in the history
Kotlin 1.4 - First steps
  • Loading branch information
vRallev authored Nov 20, 2020
2 parents 5505384 + 450c37c commit 23b131e
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# solution.
fail-fast: false
matrix:
kotlin-version: [1.3.72, 1.4.10, 1.4.20-RC]
kotlin-version: [1.4.10, 1.4.20-RC]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
# solution.
fail-fast: false
matrix:
kotlin-version: [1.3.72, 1.4.10]
kotlin-version: [1.4.10]

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 1 addition & 5 deletions annotations/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'com.vanniktech.maven.publish'

dependencies {
implementation deps.kotlin.stdlib
}
apply plugin: 'com.vanniktech.maven.publish'
13 changes: 4 additions & 9 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dependencies {
implementation project(':annotations')
implementation deps.dagger2.dagger
implementation deps.jsr250
implementation deps.kotlin.stdlib
implementation deps.kotlinpoet

compileOnly deps.auto.service.annotations
Expand All @@ -31,13 +30,9 @@ if (rootProject.ext.kotlinIrSupported) {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"

// TODO: remove the if-check when upgrading to Kotlin 1.4.
if (rootProject.ext.kotlinVersion.startsWith('1.4')) {
// The flag is needed because we extend an interface that uses @JvmDefault and the Kotlin
// compiler requires this flag when doing so.
freeCompilerArgs += "-Xjvm-default=enable"
}

// The flag is needed because we extend an interface that uses @JvmDefault and the Kotlin
// compiler requires this flag when doing so.
freeCompilerArgs += "-Xjvm-default=enable"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ internal class BindingModuleGenerator(
.toList()
}

@OptIn(ExperimentalStdlibApi::class)
override fun flush(
codeGenDir: File,
module: ModuleDescriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,11 @@ internal fun <T : KtCallableDeclaration> TypeName.withJvmSuppressWildcardsIfNeed

return when {
hasJvmSuppressWildcards || isGenericType -> this.jvmSuppressWildcards()
isFunctionType -> this.jvmSuppressWildcardsKt31734()
isFunctionType -> this.jvmSuppressWildcards()
else -> this
}
}

// TODO: remove with Kotlin 1.4.
// Notice the empty member. Instead of generating `@JvmSuppressWildcards Type` it generates
// `@JvmSuppressWildcards() Type`. This is necessary to avoid KT-31734 where the type is a function.
private fun TypeName.jvmSuppressWildcardsKt31734() =
copy(
annotations = this.annotations + AnnotationSpec.builder(JvmSuppressWildcards::class)
.addMember("")
.build()
)

internal fun List<Parameter>.asArgumentList(
asProvider: Boolean,
includeModule: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ internal class InjectConstructorFactoryGenerator : PrivateCodeGenerator() {
}
}

@OptIn(ExperimentalStdlibApi::class)
private fun generateFactoryClass(
codeGenDir: File,
module: ModuleDescriptor,
Expand All @@ -60,7 +59,7 @@ internal class InjectConstructorFactoryGenerator : PrivateCodeGenerator() {
val packageName = clazz.containingKtFile.packageFqName.asString()
val className = "${clazz.generateClassName()}_Factory"

val parameters = constructor.getValueParameters().mapToParameter(module)
val parameters = constructor.valueParameters.mapToParameter(module)

val typeParameters = clazz.typeParameterList
?.parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ internal class MembersInjectorGenerator : PrivateCodeGenerator() {
}
}

@OptIn(ExperimentalStdlibApi::class)
private fun generateMembersInjectorClass(
codeGenDir: File,
module: ModuleDescriptor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ internal class ProvidesMethodFactoryGenerator : PrivateCodeGenerator() {
}
}

@OptIn(ExperimentalStdlibApi::class)
private fun generateFactoryClass(
codeGenDir: File,
module: ModuleDescriptor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,37 +116,32 @@ internal val Result.innerModule: Class<*>
internal val Result.injectClass: Class<*>
get() = classLoader.loadClass("com.squareup.test.InjectClass")

@OptIn(ExperimentalStdlibApi::class)
internal val Class<*>.hintContributes: KClass<*>?
get() = contributedProperties(HINT_CONTRIBUTES_PACKAGE_PREFIX)
?.filter { it.java == this }
?.also { assertThat(it.size).isEqualTo(1) }
?.first()

@OptIn(ExperimentalStdlibApi::class)
internal val Class<*>.hintContributesScope: KClass<*>?
get() = contributedProperties(HINT_CONTRIBUTES_PACKAGE_PREFIX)
?.also { assertThat(it.size).isEqualTo(2) }
?.filter { it.java != this }
?.also { assertThat(it.size).isEqualTo(1) }
?.first()

@OptIn(ExperimentalStdlibApi::class)
internal val Class<*>.hintBinding: KClass<*>?
get() = contributedProperties(HINT_BINDING_PACKAGE_PREFIX)
?.filter { it.java == this }
?.also { assertThat(it.size).isEqualTo(1) }
?.first()

@OptIn(ExperimentalStdlibApi::class)
internal val Class<*>.hintBindingScope: KClass<*>?
get() = contributedProperties(HINT_BINDING_PACKAGE_PREFIX)
?.also { assertThat(it.size).isEqualTo(2) }
?.filter { it.java != this }
?.also { assertThat(it.size).isEqualTo(1) }
?.first()

@OptIn(ExperimentalStdlibApi::class)
internal fun Class<*>.moduleFactoryClass(
providerMethodName: String,
companion: Boolean = false
Expand All @@ -160,22 +155,19 @@ internal fun Class<*>.moduleFactoryClass(
)
}

@OptIn(ExperimentalStdlibApi::class)
internal fun Class<*>.factoryClass(): Class<*> {
val enclosingClassString = enclosingClass?.let { "${it.simpleName}_" } ?: ""

return classLoader.loadClass("${`package`.name}.$enclosingClassString${simpleName}_Factory")
}

@OptIn(ExperimentalStdlibApi::class)
internal fun Class<*>.membersInjector(): Class<*> {
val enclosingClassString = enclosingClass?.let { "${it.simpleName}_" } ?: ""

return classLoader.loadClass("${`package`.name}." +
"$enclosingClassString${simpleName}_MembersInjector")
}

@OptIn(ExperimentalStdlibApi::class)
private fun Class<*>.contributedProperties(packagePrefix: String): List<KClass<*>>? {
// The capitalize() doesn't make sense, I don't know where this is coming from. Maybe it's a
// bug in the compile testing library?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public final class InjectClass_MembersInjector implements MembersInjector<Inject
Provider::class.java, Provider::class.java
)

@Suppress("RedundantLambdaArrow")
val membersInjectorInstance = constructor
.newInstance(
Provider { "a" }, Provider<CharSequence> { "b" }, Provider { listOf("c") },
Expand Down Expand Up @@ -675,7 +676,6 @@ public final class InjectClass_MembersInjector<T, U, V> implements MembersInject
}
}

@OptIn(ExperimentalStdlibApi::class)
private fun Class<*>.staticInjectMethod(memberName: String): Method {
// We can't check the @InjectedFieldSignature annotation unfortunately, because it has class
// retention.
Expand Down
9 changes: 8 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
daggerVersion = '2.28'
espressoVersion = '3.2.0'
kotlinVersion = project.hasProperty('square.kotlinVersion') ?
project.getProperty('square.kotlinVersion') : '1.3.72'
project.getProperty('square.kotlinVersion') : '1.4.10'

kotlinUseIR = (project.hasProperty('square.useIR') ?
project.getProperty('square.useIR') : 'false').toBoolean()
Expand Down Expand Up @@ -70,6 +70,13 @@ ext {
stdlib: "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion",
],

// Required until Gradle uses Kotlin 1.4.
kotlin_gradle: [
gradle_plugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72",
gradle_plugin_api: "org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.3.72",
stdlib: "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72",
],

kotlinpoet: "com.squareup:kotlinpoet:1.7.2",

truth: "com.google.truth:truth:1.0.1",
Expand Down
8 changes: 4 additions & 4 deletions gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
}

dependencies {
classpath deps.kotlin.gradle_plugin
classpath deps.kotlin_gradle.gradle_plugin
classpath deps.maven_publishing_plugin
classpath deps.gradle_publishing_plugin
classpath deps.ktlint_plugin
Expand Down Expand Up @@ -76,9 +76,9 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
}

dependencies {
implementation deps.kotlin.gradle_plugin
implementation deps.kotlin.gradle_plugin_api
implementation deps.kotlin.stdlib
implementation deps.kotlin_gradle.gradle_plugin
implementation deps.kotlin_gradle.gradle_plugin_api
implementation deps.kotlin_gradle.stdlib

// Compile only so that Java / Kotlin modules don't download it unnecessarily.
compileOnly deps.android_gradle_plugin
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 0 additions & 1 deletion integration-tests/library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ if (rootProject.ext.generateDaggerFactoriesWithAnvil) {

dependencies {
api deps.dagger2.dagger
api deps.kotlin.stdlib
}

//noinspection UnnecessaryQualifiedReference
Expand Down
1 change: 0 additions & 1 deletion integration-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dependencies {
testImplementation project(':integration-tests:library')
testImplementation deps.dagger2.dagger
testImplementation deps.junit
testImplementation deps.kotlin.stdlib
testImplementation deps.truth

kaptTest deps.dagger2.compiler
Expand Down
1 change: 0 additions & 1 deletion sample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dependencies {
implementation project(':sample:library')
implementation project(':sample:scopes')

implementation deps.kotlin.stdlib
implementation deps.androidx.appcompat
implementation deps.androidx.core
implementation deps.androidx.material
Expand Down
8 changes: 0 additions & 8 deletions sample/library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,4 @@ if (rootProject.ext.generateDaggerFactoriesWithAnvil) {
dependencies {
api project(':sample:scopes')
api deps.dagger2.dagger
api deps.kotlin.stdlib
}

//noinspection UnnecessaryQualifiedReference
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.squareup.scopes.ComponentHolder
import java.util.Locale

object Description {
@OptIn(ExperimentalStdlibApi::class)
fun of(god: God): String {
val name = god.name.toLowerCase(Locale.US)
.capitalize(Locale.US)
Expand All @@ -16,12 +15,8 @@ object Description {
MOTHER -> "daughter"
}

return "$name, $child of ${
ComponentHolder.component<DescriptionComponent>()
.fatherProvider()
.father(god)} and ${
ComponentHolder.component<DescriptionComponent>()
.motherProvider()
.mother(god)}"
return "$name, $child of " +
"${ComponentHolder.component<DescriptionComponent>().fatherProvider().father(god)} and " +
ComponentHolder.component<DescriptionComponent>().motherProvider().mother(god)
}
}
1 change: 0 additions & 1 deletion sample/scopes/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'org.jetbrains.kotlin.jvm'

dependencies {
api deps.kotlin.stdlib
api deps.inject
}

0 comments on commit 23b131e

Please sign in to comment.