Kapt: Do not write references to anonymous classes to stubs & metadata (#KT-25374)
This commit is contained in:
+46
-20
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.util.isLegacyAndroidGradleVersion
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.Test
|
||||
@@ -126,29 +127,32 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testICWithAnonymousClasses() {
|
||||
val project = Project("icAnonymousTypes", directoryPrefix = "kapt2")
|
||||
setupDataBinding(project, null)
|
||||
|
||||
project.build("assembleDebug") {
|
||||
assertSuccessful()
|
||||
assertKaptSuccessful()
|
||||
}
|
||||
|
||||
val aKt = project.projectDir.getFileByName("a.kt").also { assert(it.exists()) }
|
||||
aKt.modify {
|
||||
assert(it.contains("CrashMe2(1000)"))
|
||||
it.replace("CrashMe2(1000)", "CrashMe2(2000)")
|
||||
}
|
||||
|
||||
project.build("assembleDebug") {
|
||||
assertSuccessful()
|
||||
assertKaptSuccessful()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
open fun testDatabinding() {
|
||||
val project = Project("android-databinding", directoryPrefix = "kapt2")
|
||||
|
||||
if (!isLegacyAndroidGradleVersion(androidGradlePluginVersion)) {
|
||||
project.setupWorkingDir()
|
||||
|
||||
// With new AGP, there's no need in the Databinding kapt dependency:
|
||||
project.gradleBuildScript("app").modify {
|
||||
it.lines().filterNot {
|
||||
it.contains("kapt \"com.android.databinding:compiler")
|
||||
}.joinToString("\n")
|
||||
}
|
||||
|
||||
// Workaround for KT-24915
|
||||
project.gradleBuildScript("app").appendText(
|
||||
"\n" + """
|
||||
afterEvaluate {
|
||||
kaptDebugKotlin.dependsOn dataBindingExportFeaturePackageIdsDebug
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
setupDataBinding(project, "app")
|
||||
|
||||
project.build("assembleDebug") {
|
||||
assertSuccessful()
|
||||
@@ -165,4 +169,26 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
|
||||
assertNotContains("The following options were not recognized by any processor")
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupDataBinding(project: Project, projectName: String?) {
|
||||
if (!isLegacyAndroidGradleVersion(androidGradlePluginVersion)) {
|
||||
project.setupWorkingDir()
|
||||
|
||||
// With new AGP, there's no need in the Databinding kapt dependency:
|
||||
project.gradleBuildScript(projectName).modify {
|
||||
it.lines().filterNot {
|
||||
it.contains("kapt \"com.android.databinding:compiler")
|
||||
}.joinToString("\n")
|
||||
}
|
||||
|
||||
// Workaround for KT-24915
|
||||
project.gradleBuildScript(projectName).appendText(
|
||||
"\n" + """
|
||||
afterEvaluate {
|
||||
kaptDebugKotlin.dependsOn dataBindingExportFeaturePackageIdsDebug
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven { url 'https://maven.google.com' }
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:$android_tools_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
buildToolsVersion "27.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "org.kotlinlang.test"
|
||||
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 27
|
||||
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
|
||||
dataBinding {
|
||||
enabled true
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven { url 'https://maven.google.com' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
kapt "com.android.databinding:compiler:$android_tools_version"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.databinding">
|
||||
|
||||
<application android:label="test">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class CrashMe {
|
||||
private val crashMe = object : CrashMe2(1000) {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
abstract class CrashMe2(value: Long) {
|
||||
val crashMe2 = object : Any() {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent" android:layout_height="match_parent"
|
||||
android:orientation="vertical"/>
|
||||
</layout>
|
||||
Reference in New Issue
Block a user