Exclude synthetic classes from ABI classes
This commit is contained in:
+14
-8
@@ -79,20 +79,26 @@ class JvmAbiAnalysisHandlerExtension(
|
||||
*/
|
||||
private fun removeUnneededClasses(outputs: Iterable<AbiOutput>) {
|
||||
val removedClasses = HashSet<String>()
|
||||
|
||||
for (output in outputs) {
|
||||
if (!output.file.isClassFile()) continue
|
||||
|
||||
val classData = output.classData() ?: continue
|
||||
val header = classData.classHeader
|
||||
if (header.kind == KotlinClassHeader.Kind.CLASS) {
|
||||
val (_, classProto) = JvmProtoBufUtil.readClassDataFrom(header.data!!, header.strings!!)
|
||||
|
||||
val visibility = Flags.VISIBILITY.get(classProto.flags)
|
||||
if (visibility == ProtoBuf.Visibility.PRIVATE || visibility == ProtoBuf.Visibility.LOCAL) {
|
||||
output.delete()
|
||||
val jvmClassName = JvmClassName.byClassId(classData.classId)
|
||||
removedClasses.add(jvmClassName.internalName)
|
||||
val isNeededForAbi = when (header.kind) {
|
||||
KotlinClassHeader.Kind.CLASS -> {
|
||||
val (_, classProto) = JvmProtoBufUtil.readClassDataFrom(header.data!!, header.strings!!)
|
||||
val visibility = Flags.VISIBILITY.get(classProto.flags)
|
||||
visibility != ProtoBuf.Visibility.PRIVATE && visibility != ProtoBuf.Visibility.LOCAL
|
||||
}
|
||||
KotlinClassHeader.Kind.SYNTHETIC_CLASS -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
if (!isNeededForAbi) {
|
||||
output.delete()
|
||||
val jvmClassName = JvmClassName.byClassId(classData.classId)
|
||||
removedClasses.add(jvmClassName.internalName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.jvm.abi
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.incremental.AbstractIncrementalCompilerRunnerTestBase
|
||||
import org.jetbrains.kotlin.incremental.utils.TestMessageCollector
|
||||
import java.io.File
|
||||
|
||||
@@ -52,6 +54,7 @@ abstract class BaseJvmAbiTest : TestCase() {
|
||||
val compiler = K2JVMCompiler()
|
||||
val args = compiler.createArguments().apply {
|
||||
freeArgs = listOf(compilation.srcDir.canonicalPath)
|
||||
classpath = kotlinJvmStdlib.canonicalPath
|
||||
pluginClasspaths = arrayOf(abiPluginJar.canonicalPath)
|
||||
pluginOptions = arrayOf(abiOption("outputDir", compilation.abiDir.canonicalPath))
|
||||
destination = compilation.destinationDir.canonicalPath
|
||||
@@ -62,4 +65,8 @@ abstract class BaseJvmAbiTest : TestCase() {
|
||||
error(errorLines.joinToString("\n"))
|
||||
}
|
||||
}
|
||||
|
||||
private val kotlinJvmStdlib = File("dist/kotlinc/lib/kotlin-stdlib.jar").also {
|
||||
UsefulTestCase.assertExists(it)
|
||||
}
|
||||
}
|
||||
+15
@@ -29,6 +29,11 @@ public class CompareJvmAbiTestGenerated extends AbstractCompareJvmAbiTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/jvm-abi-gen/testData/compare"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
|
||||
}
|
||||
|
||||
@TestMetadata("anonymousClass")
|
||||
public void testAnonymousClass() throws Exception {
|
||||
runTest("plugins/jvm-abi-gen/testData/compare/anonymousClass/");
|
||||
}
|
||||
|
||||
@TestMetadata("classPrivateMemebers")
|
||||
public void testClassPrivateMemebers() throws Exception {
|
||||
runTest("plugins/jvm-abi-gen/testData/compare/classPrivateMemebers/");
|
||||
@@ -44,6 +49,11 @@ public class CompareJvmAbiTestGenerated extends AbstractCompareJvmAbiTest {
|
||||
runTest("plugins/jvm-abi-gen/testData/compare/inlineFunctionBody/");
|
||||
}
|
||||
|
||||
@TestMetadata("lambda")
|
||||
public void testLambda() throws Exception {
|
||||
runTest("plugins/jvm-abi-gen/testData/compare/lambda/");
|
||||
}
|
||||
|
||||
@TestMetadata("localClass")
|
||||
public void testLocalClass() throws Exception {
|
||||
runTest("plugins/jvm-abi-gen/testData/compare/localClass/");
|
||||
@@ -59,6 +69,11 @@ public class CompareJvmAbiTestGenerated extends AbstractCompareJvmAbiTest {
|
||||
runTest("plugins/jvm-abi-gen/testData/compare/privateTypealias/");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyReference")
|
||||
public void testPropertyReference() throws Exception {
|
||||
runTest("plugins/jvm-abi-gen/testData/compare/propertyReference/");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPrivateMembers")
|
||||
public void testTopLevelPrivateMembers() throws Exception {
|
||||
runTest("plugins/jvm-abi-gen/testData/compare/topLevelPrivateMembers/");
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package test
|
||||
|
||||
interface Interface {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
class InterfaceImpl : Interface {
|
||||
override fun foo(): Int = 0
|
||||
}
|
||||
|
||||
fun getInterface(): Interface =
|
||||
object : Interface {
|
||||
override fun foo(): Int = 0
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package test
|
||||
|
||||
interface Interface {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
class InterfaceImpl : Interface {
|
||||
override fun foo(): Int = 0
|
||||
}
|
||||
|
||||
fun getInterface(): Interface =
|
||||
InterfaceImpl()
|
||||
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
class Class {
|
||||
fun method(): Int {
|
||||
val square: (Int) -> Int = { it * it }
|
||||
return square(2)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
fun function(): Int {
|
||||
val square: (Int) -> Int = { it * it }
|
||||
return square(2)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class Class {
|
||||
fun method(): Int {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun function(): Int {
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class Class {
|
||||
val property: Int = 0
|
||||
}
|
||||
|
||||
fun getProp(c: Class) = Class::property.get(c)
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class Class {
|
||||
val property: Int = 0
|
||||
}
|
||||
|
||||
fun getProp(c: Class) = c.property
|
||||
Reference in New Issue
Block a user