Use JvmMetadataVersion where appropriate instead of bytecode version

This commit is contained in:
Alexander Udalov
2016-01-13 21:24:20 +03:00
parent bd47e9d47b
commit b587d3a78d
19 changed files with 65 additions and 56 deletions
@@ -71,7 +71,7 @@ fun LazyJavaResolverContext.resolveKotlinBinaryClass(kotlinClass: KotlinJvmBinar
val header = kotlinClass.classHeader
return when {
!header.metadataVersion.isCompatible() -> {
components.errorReporter.reportIncompatibleAbiVersion(kotlinClass.classId, kotlinClass.location, header.metadataVersion)
components.errorReporter.reportIncompatibleMetadataVersion(kotlinClass.classId, kotlinClass.location, header.metadataVersion)
KotlinClassLookupResult.NotFound
}
header.kind == KotlinClassHeader.Kind.CLASS -> {
@@ -116,7 +116,7 @@ public final class DeserializedDescriptorResolver {
public String[] readData(@NotNull KotlinJvmBinaryClass kotlinClass, @NotNull Set<KotlinClassHeader.Kind> expectedKinds) {
KotlinClassHeader header = kotlinClass.getClassHeader();
if (!header.getMetadataVersion().isCompatible()) {
errorReporter.reportIncompatibleAbiVersion(kotlinClass.getClassId(), kotlinClass.getLocation(), header.getMetadataVersion());
errorReporter.reportIncompatibleMetadataVersion(kotlinClass.getClassId(), kotlinClass.getLocation(), header.getMetadataVersion());
}
else if (expectedKinds.contains(header.getKind())) {
return header.getAnnotationData();
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion
import org.jetbrains.kotlin.serialization.jvm.JvmPackageTable
import java.io.ByteArrayInputStream
import java.io.DataInputStream
@@ -28,22 +27,22 @@ class ModuleMapping private constructor(val packageFqName2Parts: Map<String, Pac
}
companion object {
@JvmField val MAPPING_FILE_EXT: String = "kotlin_module"
@JvmField
val MAPPING_FILE_EXT: String = "kotlin_module"
@JvmField val EMPTY: ModuleMapping = ModuleMapping(emptyMap())
@JvmField
val EMPTY: ModuleMapping = ModuleMapping(emptyMap())
fun create(proto: ByteArray? = null): ModuleMapping {
if (proto == null) {
return EMPTY
}
val inputStream = DataInputStream(ByteArrayInputStream(proto))
val size = inputStream.readInt()
val version = JvmBytecodeBinaryVersion.create((0..size - 1).map { inputStream.readInt() }.toIntArray())
val stream = DataInputStream(ByteArrayInputStream(proto))
val version = JvmMetadataVersion.create(IntArray(stream.readInt()) { stream.readInt() })
if (version.isCompatible()) {
val parseFrom = JvmPackageTable.PackageTable.parseFrom(inputStream)
val parseFrom = JvmPackageTable.PackageTable.parseFrom(stream)
if (parseFrom != null) {
val packageFqNameParts = hashMapOf<String, PackageParts>()
parseFrom.packagePartsList.forEach {
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.load.java.components
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
@@ -29,14 +29,14 @@ object RuntimeErrorReporter : ErrorReporter {
throw IllegalStateException("Incomplete hierarchy for class ${descriptor.name}, unresolved classes $unresolvedSuperClasses")
}
override fun reportIncompatibleAbiVersion(classId: ClassId, filePath: String, actualVersion: BinaryVersion) {
throw IllegalStateException("Incompatible ABI version of $classId: $actualVersion " +
"(expected version is ${JvmBytecodeBinaryVersion.INSTANCE})")
override fun reportIncompatibleMetadataVersion(classId: ClassId, filePath: String, actualVersion: BinaryVersion) {
throw IllegalStateException("Incompatible binary version of $classId: $actualVersion " +
"(expected version is ${JvmMetadataVersion.INSTANCE})")
}
override fun reportCannotInferVisibility(descriptor: CallableMemberDescriptor) {
// TODO: use DescriptorRenderer
throw IllegalStateException("Cannot infer visibility for class ${descriptor.name}")
throw IllegalStateException("Cannot infer visibility for $descriptor")
}
override fun reportLoadingError(message: String, exception: Exception?) {
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.ClassId;
import java.util.List;
public interface ErrorReporter {
void reportIncompatibleAbiVersion(@NotNull ClassId classId, @NotNull String filePath, @NotNull BinaryVersion actualVersion);
void reportIncompatibleMetadataVersion(@NotNull ClassId classId, @NotNull String filePath, @NotNull BinaryVersion actualVersion);
void reportIncompleteHierarchy(@NotNull ClassDescriptor descriptor, @NotNull List<String> unresolvedSuperClasses);
@@ -35,7 +35,7 @@ public interface ErrorReporter {
ErrorReporter DO_NOTHING = new ErrorReporter() {
@Override
public void reportIncompatibleAbiVersion(
public void reportIncompatibleMetadataVersion(
@NotNull ClassId classId, @NotNull String filePath, @NotNull BinaryVersion actualVersion
) {
}