JVM_IR: implement isCompiledToJvm8OrHigher on IrClass
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.codegen
|
package org.jetbrains.kotlin.codegen
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass
|
import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass
|
||||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
||||||
@@ -99,8 +100,10 @@ abstract class TypeAnnotationCollector<T>(val context: TypeSystemCommonBackendCo
|
|||||||
abstract fun KotlinTypeMarker.extractAnnotations(): List<T>
|
abstract fun KotlinTypeMarker.extractAnnotations(): List<T>
|
||||||
|
|
||||||
fun isCompiledToJvm8OrHigher(descriptor: ClassDescriptor?): Boolean =
|
fun isCompiledToJvm8OrHigher(descriptor: ClassDescriptor?): Boolean =
|
||||||
(descriptor as? DeserializedClassDescriptor)?.let { classDescriptor ->
|
(descriptor as? DeserializedClassDescriptor)?.let { classDescriptor -> isCompiledToJvm8OrHigher(classDescriptor.source) }
|
||||||
((classDescriptor.source as? KotlinJvmBinarySourceElement)?.binaryClass as? FileBasedKotlinClass)?.classVersion ?: 0 >= Opcodes.V1_8
|
?: true
|
||||||
} ?: true
|
|
||||||
|
|
||||||
|
fun isCompiledToJvm8OrHigher(source: SourceElement): Boolean =
|
||||||
|
(source !is KotlinJvmBinarySourceElement ||
|
||||||
|
(source.binaryClass as? FileBasedKotlinClass)?.classVersion ?: 0 >= Opcodes.V1_8)
|
||||||
}
|
}
|
||||||
+7
-2
@@ -341,13 +341,18 @@ abstract class AnnotationCodegen(
|
|||||||
override fun KotlinTypeMarker.extractAnnotations(): List<IrConstructorCall> {
|
override fun KotlinTypeMarker.extractAnnotations(): List<IrConstructorCall> {
|
||||||
require(this is IrType)
|
require(this is IrType)
|
||||||
return annotations.filter {
|
return annotations.filter {
|
||||||
//We only generate annotations which have the TYPE_USE Java target.
|
// We only generate annotations which have the TYPE_USE Java target.
|
||||||
// Those are type annotations which were compiled with JVM target bytecode version 1.8 or greater
|
// Those are type annotations which were compiled with JVM target bytecode version 1.8 or greater
|
||||||
(it.annotationClass.origin != IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB &&
|
(it.annotationClass.origin != IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB &&
|
||||||
it.annotationClass.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB) ||
|
it.annotationClass.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB) ||
|
||||||
isCompiledToJvm8OrHigher(it.annotationClass.descriptor)
|
it.annotationClass.isCompiledToJvm8OrHigher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val IrClass.isCompiledToJvm8OrHigher: Boolean
|
||||||
|
get() =
|
||||||
|
(origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB || origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB) &&
|
||||||
|
isCompiledToJvm8OrHigher(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user