Refactor BinaryVersion and subclasses, get rid of static factories
This commit is contained in:
+3
-11
@@ -22,22 +22,14 @@ import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||
* The version of conventions used in bytecode of generated .class files, such as default method naming & signatures,
|
||||
* internal member name mangling specifics, property getter/setter names, etc.
|
||||
*/
|
||||
class JvmBytecodeBinaryVersion protected constructor(
|
||||
major: Int, minor: Int, patch: Int, rest: List<Int>
|
||||
) : BinaryVersion(major, minor, patch, rest) {
|
||||
class JvmBytecodeBinaryVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
||||
override fun isCompatible() = this.isCompatibleTo(INSTANCE)
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INSTANCE = create(1, 0, 2)
|
||||
val INSTANCE = JvmBytecodeBinaryVersion(1, 0, 2)
|
||||
|
||||
@JvmField
|
||||
val INVALID_VERSION = JvmBytecodeBinaryVersion.create(IntArray(0))
|
||||
|
||||
@JvmStatic
|
||||
fun create(version: IntArray) = create(version, ::JvmBytecodeBinaryVersion)
|
||||
|
||||
@JvmStatic
|
||||
fun create(major: Int, minor: Int, patch: Int) = create(major, minor, patch, ::JvmBytecodeBinaryVersion)
|
||||
val INVALID_VERSION = JvmBytecodeBinaryVersion()
|
||||
}
|
||||
}
|
||||
|
||||
+3
-11
@@ -22,22 +22,14 @@ import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||
* The version of the metadata serialized by the compiler and deserialized by the compiler and reflection.
|
||||
* This version includes the version of the core protobuf messages (descriptors.proto) as well as JVM extensions (jvm_descriptors.proto).
|
||||
*/
|
||||
class JvmMetadataVersion protected constructor(
|
||||
major: Int, minor: Int, patch: Int, rest: List<Int>
|
||||
) : BinaryVersion(major, minor, patch, rest) {
|
||||
class JvmMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
||||
override fun isCompatible() = this.isCompatibleTo(INSTANCE)
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INSTANCE = create(1, 0, 2)
|
||||
val INSTANCE = JvmMetadataVersion(1, 0, 2)
|
||||
|
||||
@JvmField
|
||||
val INVALID_VERSION = JvmMetadataVersion.create(IntArray(0))
|
||||
|
||||
@JvmStatic
|
||||
fun create(version: IntArray) = create(version, ::JvmMetadataVersion)
|
||||
|
||||
@JvmStatic
|
||||
fun create(major: Int, minor: Int, patch: Int) = create(major, minor, patch, ::JvmMetadataVersion)
|
||||
val INVALID_VERSION = JvmMetadataVersion()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class ModuleMapping private constructor(val packageFqName2Parts: Map<String, Pac
|
||||
}
|
||||
|
||||
val stream = DataInputStream(ByteArrayInputStream(proto))
|
||||
val version = JvmMetadataVersion.create(IntArray(stream.readInt()) { stream.readInt() })
|
||||
val version = JvmMetadataVersion(*IntArray(stream.readInt()) { stream.readInt() })
|
||||
|
||||
if (version.isCompatible()) {
|
||||
val parseFrom = JvmPackageTable.PackageTable.parseFrom(stream)
|
||||
|
||||
+4
-4
@@ -134,12 +134,12 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
}
|
||||
else if (METADATA_VERSION_FIELD_NAME.equals(string)) {
|
||||
if (value instanceof int[]) {
|
||||
metadataVersion = JvmMetadataVersion.create((int[]) value);
|
||||
metadataVersion = new JvmMetadataVersion((int[]) value);
|
||||
}
|
||||
}
|
||||
else if (BYTECODE_VERSION_FIELD_NAME.equals(string)) {
|
||||
if (value instanceof int[]) {
|
||||
bytecodeVersion = JvmBytecodeBinaryVersion.create((int[]) value);
|
||||
bytecodeVersion = new JvmBytecodeBinaryVersion((int[]) value);
|
||||
}
|
||||
}
|
||||
else if (SYNTHETIC_CLASS_KIND_FIELD_NAME.equals(string)) {
|
||||
@@ -212,11 +212,11 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
String string = name.asString();
|
||||
if (VERSION_FIELD_NAME.equals(string)) {
|
||||
if (value instanceof int[]) {
|
||||
metadataVersion = JvmMetadataVersion.create((int[]) value);
|
||||
metadataVersion = new JvmMetadataVersion((int[]) value);
|
||||
|
||||
// If there's no bytecode binary version in the class file, we assume it to be equal to the metadata version
|
||||
if (bytecodeVersion == null) {
|
||||
bytecodeVersion = JvmBytecodeBinaryVersion.create((int[]) value);
|
||||
bytecodeVersion = new JvmBytecodeBinaryVersion((int[]) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user