Skip to content

Commit

Permalink
Ignore synthetic annotation classes generated in-place for instantiation
Browse files Browse the repository at this point in the history
Fixes #71
  • Loading branch information
qwwdfsad committed Nov 24, 2021
1 parent e873862 commit 0d3a78a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/kotlin/api/AsmMetadataLoading.kt
Expand Up @@ -27,18 +27,19 @@ fun isStatic(access: Int) = access and Opcodes.ACC_STATIC != 0
fun isFinal(access: Int) = access and Opcodes.ACC_FINAL != 0
fun isSynthetic(access: Int) = access and Opcodes.ACC_SYNTHETIC != 0


fun ClassNode.isEffectivelyPublic(classVisibility: ClassVisibility?) =
isPublic(access)
&& !isLocal()
&& !isWhenMappings()
&& !isSyntheticAnnotationClass()
&& (classVisibility?.isPublic(isPublishedApi()) ?: true)


val ClassNode.innerClassNode: InnerClassNode? get() = innerClasses.singleOrNull { it.name == name }
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\$")

val ClassNode.effectiveAccess: Int get() = innerClassNode?.access ?: access
val ClassNode.outerClassName: String? get() = innerClassNode?.outerName
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/cases/annotations/annotation.kt
@@ -0,0 +1,12 @@
/*
* Copyright 2016-2021 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.annotations

annotation class Foo(val i: Int)

private class Bar {
val foo: Foo = Foo(1)
}
4 changes: 4 additions & 0 deletions src/test/kotlin/cases/annotations/annotations.txt
@@ -0,0 +1,4 @@
public abstract interface annotation class cases/annotations/Foo : java/lang/annotation/Annotation {
public abstract fun i ()I
}

2 changes: 2 additions & 0 deletions src/test/kotlin/tests/CasesPublicAPITest.kt
Expand Up @@ -24,6 +24,8 @@ class CasesPublicAPITest {
@[Rule JvmField]
val testName = TestName()

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

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

@Test fun default() { snapshotAPIAndCompare(testName.methodName) }
Expand Down

0 comments on commit 0d3a78a

Please sign in to comment.