Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out $EntriesMappings class for Kotlin's 1.9 feature 'Enum entries' #144

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ val createClasspathManifest = tasks.register("createClasspathManifest") {
val kotlinVersion: String by project
val androidGradlePluginVersion: String = "7.2.2"

configurations.implementation {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
}

dependencies {
implementation(gradleApi())
implementation("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.2")
Expand Down Expand Up @@ -116,7 +110,8 @@ java {
tasks {
compileTestKotlin {
kotlinOptions {
languageVersion = "1.6"
languageVersion = "1.9"
freeCompilerArgs += "-Xsuppress-version-warnings"
}
}
test {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version=0.13.2-SNAPSHOT
group=org.jetbrains.kotlinx

kotlinVersion=1.8.10
kotlinVersion=1.8.20
pluginPublishVersion=0.10.1

kotlin.stdlib.default.dependency=false
2 changes: 2 additions & 0 deletions src/main/kotlin/api/AsmMetadataLoading.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fun ClassNode.isEffectivelyPublic(classVisibility: ClassVisibility?) =
&& !isLocal()
&& !isWhenMappings()
&& !isSyntheticAnnotationClass()
&& !isEnumEntriesMappings()
&& (classVisibility?.isPublic(isPublishedApi()) ?: true)


Expand All @@ -40,6 +41,7 @@ fun ClassNode.isLocal() = outerMethod != null
fun ClassNode.isInner() = innerClassNode != null
fun ClassNode.isWhenMappings() = isSynthetic(access) && name.endsWith("\$WhenMappings")
fun ClassNode.isSyntheticAnnotationClass() = isSynthetic(access) && name.contains("\$annotationImpl\$")
fun ClassNode.isEnumEntriesMappings() = isSynthetic(access) && name.endsWith("\$EntriesMappings")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are currently no tests that check this behaviour.

You'll need when over old Kotlin enum (unlikely it's easy to get one in the robust manner) or any Java one in the code to force $EntriesMapping appearance

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing to this! Seems like IDE cached something wrong, so when I validated the test without ClassNode.isEnumEntriesMappings EntriesMapping was there despite the fact that Enum is a "new" enum.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries.

There is something suspicious happening:

  1. IDE highlights EnumClass.entries as available only since API version 1.8 (red code, [UNSUPPORTED_FEATURE]) even though you clearly set it up
  2. For clean builds, everything works as expected
  3. For incremental builds (run all tests, change something in entries.kt), mappings start being generated even though entries member is present

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll proceed with the issue further


val ClassNode.effectiveAccess: Int get() = innerClassNode?.access ?: access
val ClassNode.outerClassName: String? get() = innerClassNode?.outerName
Expand Down
8 changes: 8 additions & 0 deletions src/test/kotlin/cases/enums/EnumClass.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright 2016-2023 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

package cases.enums

enum class EnumClass { A, B, C }
10 changes: 10 additions & 0 deletions src/test/kotlin/cases/enums/JavaEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright 2016-2023 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

package cases.enums;

public enum JavaEnum {
JA, JB, JC
}
13 changes: 13 additions & 0 deletions src/test/kotlin/cases/enums/entries.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cases.enums

@OptIn(ExperimentalStdlibApi::class)
fun test() {
EnumClass.entries.forEach {
println(it)
}

JavaEnum.entries.forEach {
println(it)
}
}

21 changes: 21 additions & 0 deletions src/test/kotlin/cases/enums/enums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public final class cases/enums/EntriesKt {
public static final fun test ()V
}

public final class cases/enums/EnumClass : java/lang/Enum {
public static final field A Lcases/enums/EnumClass;
public static final field B Lcases/enums/EnumClass;
public static final field C Lcases/enums/EnumClass;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcases/enums/EnumClass;
public static fun values ()[Lcases/enums/EnumClass;
}

public final class cases/enums/JavaEnum : java/lang/Enum {
public static final field JA Lcases/enums/JavaEnum;
public static final field JB Lcases/enums/JavaEnum;
public static final field JC Lcases/enums/JavaEnum;
public static fun valueOf (Ljava/lang/String;)Lcases/enums/JavaEnum;
public static fun values ()[Lcases/enums/JavaEnum;
}

1 change: 1 addition & 0 deletions src/test/kotlin/cases/whenMappings/whenMappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public final class cases/whenMappings/SampleEnum : java/lang/Enum {
public static final field A Lcases/whenMappings/SampleEnum;
public static final field B Lcases/whenMappings/SampleEnum;
public static final field C Lcases/whenMappings/SampleEnum;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcases/whenMappings/SampleEnum;
public static fun values ()[Lcases/whenMappings/SampleEnum;
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/kotlin/tests/CasesPublicAPITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class CasesPublicAPITest {

@Test fun whenMappings() { snapshotAPIAndCompare(testName.methodName) }

@Test fun enums() { snapshotAPIAndCompare(testName.methodName) }

private fun snapshotAPIAndCompare(testClassRelativePath: String, nonPublicMarkers: Set<String> = emptySet()) {
val testClassPaths = baseClassPaths.map { it.resolve(testClassRelativePath) }
val testClasses = testClassPaths.flatMap { it.listFiles().orEmpty().asIterable() }
Expand Down