Support version kind for RequireKotlin

#KT-20584 Fixed
This commit is contained in:
Alexander Udalov
2017-10-09 19:25:27 +02:00
parent 4532f7556c
commit a96861c353
13 changed files with 538 additions and 33 deletions
@@ -855,6 +855,11 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
if (!checkStringEquals(old.message, new.message)) return false
}
if (old.hasVersionKind() != new.hasVersionKind()) return false
if (old.hasVersionKind()) {
if (old.versionKind != new.versionKind) return false
}
return true
}
@@ -1797,6 +1802,10 @@ fun ProtoBuf.VersionRequirement.hashCode(stringIndexes: (Int) -> Int, fqNameInde
hashCode = 31 * hashCode + stringIndexes(message)
}
if (hasVersionKind()) {
hashCode = 31 * hashCode + versionKind.hashCode()
}
return hashCode
}
@@ -25767,6 +25767,25 @@ public final class DebugProtoBuf {
* </pre>
*/
int getMessage();
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
boolean hasVersionKind();
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind getVersionKind();
}
/**
* Protobuf type {@code org.jetbrains.kotlin.serialization.VersionRequirement}
@@ -25851,6 +25870,17 @@ public final class DebugProtoBuf {
message_ = input.readInt32();
break;
}
case 48: {
int rawValue = input.readEnum();
org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind value = org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind.valueOf(rawValue);
if (value == null) {
unknownFields.mergeVarintField(6, rawValue);
} else {
bitField0_ |= 0x00000020;
versionKind_ = value;
}
break;
}
}
}
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
@@ -25981,6 +26011,97 @@ public final class DebugProtoBuf {
// @@protoc_insertion_point(enum_scope:org.jetbrains.kotlin.serialization.VersionRequirement.Level)
}
/**
* Protobuf enum {@code org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind}
*/
public enum VersionKind
implements org.jetbrains.kotlin.protobuf.ProtocolMessageEnum {
/**
* <code>LANGUAGE_VERSION = 0;</code>
*/
LANGUAGE_VERSION(0, 0),
/**
* <code>COMPILER_VERSION = 1;</code>
*/
COMPILER_VERSION(1, 1),
/**
* <code>API_VERSION = 2;</code>
*/
API_VERSION(2, 2),
;
/**
* <code>LANGUAGE_VERSION = 0;</code>
*/
public static final int LANGUAGE_VERSION_VALUE = 0;
/**
* <code>COMPILER_VERSION = 1;</code>
*/
public static final int COMPILER_VERSION_VALUE = 1;
/**
* <code>API_VERSION = 2;</code>
*/
public static final int API_VERSION_VALUE = 2;
public final int getNumber() { return value; }
public static VersionKind valueOf(int value) {
switch (value) {
case 0: return LANGUAGE_VERSION;
case 1: return COMPILER_VERSION;
case 2: return API_VERSION;
default: return null;
}
}
public static org.jetbrains.kotlin.protobuf.Internal.EnumLiteMap<VersionKind>
internalGetValueMap() {
return internalValueMap;
}
private static org.jetbrains.kotlin.protobuf.Internal.EnumLiteMap<VersionKind>
internalValueMap =
new org.jetbrains.kotlin.protobuf.Internal.EnumLiteMap<VersionKind>() {
public VersionKind findValueByNumber(int number) {
return VersionKind.valueOf(number);
}
};
public final org.jetbrains.kotlin.protobuf.Descriptors.EnumValueDescriptor
getValueDescriptor() {
return getDescriptor().getValues().get(index);
}
public final org.jetbrains.kotlin.protobuf.Descriptors.EnumDescriptor
getDescriptorForType() {
return getDescriptor();
}
public static final org.jetbrains.kotlin.protobuf.Descriptors.EnumDescriptor
getDescriptor() {
return org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.getDescriptor().getEnumTypes().get(1);
}
private static final VersionKind[] VALUES = values();
public static VersionKind valueOf(
org.jetbrains.kotlin.protobuf.Descriptors.EnumValueDescriptor desc) {
if (desc.getType() != getDescriptor()) {
throw new java.lang.IllegalArgumentException(
"EnumValueDescriptor is not for this type.");
}
return VALUES[desc.getIndex()];
}
private final int index;
private final int value;
private VersionKind(int index, int value) {
this.index = index;
this.value = value;
}
// @@protoc_insertion_point(enum_scope:org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind)
}
private int bitField0_;
public static final int VERSION_FIELD_NUMBER = 1;
private int version_;
@@ -26103,12 +26224,38 @@ public final class DebugProtoBuf {
return message_;
}
public static final int VERSION_KIND_FIELD_NUMBER = 6;
private org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind versionKind_;
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public boolean hasVersionKind() {
return ((bitField0_ & 0x00000020) == 0x00000020);
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind getVersionKind() {
return versionKind_;
}
private void initFields() {
version_ = 0;
versionFull_ = 0;
level_ = org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.Level.ERROR;
errorCode_ = 0;
message_ = 0;
versionKind_ = org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -26138,6 +26285,9 @@ public final class DebugProtoBuf {
if (((bitField0_ & 0x00000010) == 0x00000010)) {
output.writeInt32(5, message_);
}
if (((bitField0_ & 0x00000020) == 0x00000020)) {
output.writeEnum(6, versionKind_.getNumber());
}
getUnknownFields().writeTo(output);
}
@@ -26167,6 +26317,10 @@ public final class DebugProtoBuf {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32Size(5, message_);
}
if (((bitField0_ & 0x00000020) == 0x00000020)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeEnumSize(6, versionKind_.getNumber());
}
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
return size;
@@ -26294,6 +26448,8 @@ public final class DebugProtoBuf {
bitField0_ = (bitField0_ & ~0x00000008);
message_ = 0;
bitField0_ = (bitField0_ & ~0x00000010);
versionKind_ = org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION;
bitField0_ = (bitField0_ & ~0x00000020);
return this;
}
@@ -26342,6 +26498,10 @@ public final class DebugProtoBuf {
to_bitField0_ |= 0x00000010;
}
result.message_ = message_;
if (((from_bitField0_ & 0x00000020) == 0x00000020)) {
to_bitField0_ |= 0x00000020;
}
result.versionKind_ = versionKind_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -26373,6 +26533,9 @@ public final class DebugProtoBuf {
if (other.hasMessage()) {
setMessage(other.getMessage());
}
if (other.hasVersionKind()) {
setVersionKind(other.getVersionKind());
}
this.mergeUnknownFields(other.getUnknownFields());
return this;
}
@@ -26655,6 +26818,61 @@ public final class DebugProtoBuf {
return this;
}
private org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind versionKind_ = org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION;
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public boolean hasVersionKind() {
return ((bitField0_ & 0x00000020) == 0x00000020);
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind getVersionKind() {
return versionKind_;
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public Builder setVersionKind(org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind value) {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000020;
versionKind_ = value;
onChanged();
return this;
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public Builder clearVersionKind() {
bitField0_ = (bitField0_ & ~0x00000020);
versionKind_ = org.jetbrains.kotlin.serialization.DebugProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION;
onChanged();
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.VersionRequirement)
}
@@ -28906,29 +29124,34 @@ public final class DebugProtoBuf {
"\003(\0132..org.jetbrains.kotlin.serialization" +
".Annotation\022\033\n\023version_requirement\030\037 \001(\005",
"*\005\010d\020\310\001\"&\n\tEnumEntry\022\022\n\004name\030\001 \001(\005B\004\210\265\030\001" +
"*\005\010d\020\310\001\"\347\001\n\022VersionRequirement\022\017\n\007versio" +
"*\005\010d\020\310\001\"\237\003\n\022VersionRequirement\022\017\n\007versio" +
"n\030\001 \001(\005\022\024\n\014version_full\030\002 \001(\005\022R\n\005level\030\003" +
" \001(\0162<.org.jetbrains.kotlin.serializatio" +
"n.VersionRequirement.Level:\005ERROR\022\022\n\nerr" +
"or_code\030\004 \001(\005\022\025\n\007message\030\005 \001(\005B\004\230\265\030\001\"+\n\005" +
"Level\022\013\n\007WARNING\020\000\022\t\n\005ERROR\020\001\022\n\n\006HIDDEN\020" +
"\002\"f\n\027VersionRequirementTable\022K\n\013requirem" +
"ent\030\001 \003(\01326.org.jetbrains.kotlin.seriali" +
"zation.VersionRequirement\"\243\002\n\017PackageFra",
"gment\022@\n\007strings\030\001 \001(\0132/.org.jetbrains.k" +
"otlin.serialization.StringTable\022O\n\017quali" +
"fied_names\030\002 \001(\01326.org.jetbrains.kotlin." +
"serialization.QualifiedNameTable\022<\n\007pack" +
"age\030\003 \001(\0132+.org.jetbrains.kotlin.seriali" +
"zation.Package\0228\n\005class\030\004 \003(\0132).org.jetb" +
"rains.kotlin.serialization.Class*\005\010d\020\310\001*" +
"9\n\010Modality\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABST" +
"RACT\020\002\022\n\n\006SEALED\020\003*b\n\nVisibility\022\014\n\010INTE" +
"RNAL\020\000\022\013\n\007PRIVATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PU",
"BLIC\020\003\022\023\n\017PRIVATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005*Q" +
"\n\nMemberKind\022\017\n\013DECLARATION\020\000\022\021\n\rFAKE_OV" +
"ERRIDE\020\001\022\016\n\nDELEGATION\020\002\022\017\n\013SYNTHESIZED\020" +
"\003B\017B\rDebugProtoBuf"
"or_code\030\004 \001(\005\022\025\n\007message\030\005 \001(\005B\004\230\265\030\001\022j\n\014" +
"version_kind\030\006 \001(\0162B.org.jetbrains.kotli" +
"n.serialization.VersionRequirement.Versi" +
"onKind:\020LANGUAGE_VERSION\"+\n\005Level\022\013\n\007WAR" +
"NING\020\000\022\t\n\005ERROR\020\001\022\n\n\006HIDDEN\020\002\"J\n\013Version",
"Kind\022\024\n\020LANGUAGE_VERSION\020\000\022\024\n\020COMPILER_V" +
"ERSION\020\001\022\017\n\013API_VERSION\020\002\"f\n\027VersionRequ" +
"irementTable\022K\n\013requirement\030\001 \003(\01326.org." +
"jetbrains.kotlin.serialization.VersionRe" +
"quirement\"\243\002\n\017PackageFragment\022@\n\007strings" +
"\030\001 \001(\0132/.org.jetbrains.kotlin.serializat" +
"ion.StringTable\022O\n\017qualified_names\030\002 \001(\013" +
"26.org.jetbrains.kotlin.serialization.Qu" +
"alifiedNameTable\022<\n\007package\030\003 \001(\0132+.org." +
"jetbrains.kotlin.serialization.Package\0228",
"\n\005class\030\004 \003(\0132).org.jetbrains.kotlin.ser" +
"ialization.Class*\005\010d\020\310\001*9\n\010Modality\022\t\n\005F" +
"INAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABSTRACT\020\002\022\n\n\006SEALED" +
"\020\003*b\n\nVisibility\022\014\n\010INTERNAL\020\000\022\013\n\007PRIVAT" +
"E\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PUBLIC\020\003\022\023\n\017PRIVAT" +
"E_TO_THIS\020\004\022\t\n\005LOCAL\020\005*Q\n\nMemberKind\022\017\n\013" +
"DECLARATION\020\000\022\021\n\rFAKE_OVERRIDE\020\001\022\016\n\nDELE" +
"GATION\020\002\022\017\n\013SYNTHESIZED\020\003B\017B\rDebugProtoB" +
"uf"
};
org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -29056,7 +29279,7 @@ public final class DebugProtoBuf {
internal_static_org_jetbrains_kotlin_serialization_VersionRequirement_fieldAccessorTable = new
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_org_jetbrains_kotlin_serialization_VersionRequirement_descriptor,
new java.lang.String[] { "Version", "VersionFull", "Level", "ErrorCode", "Message", });
new java.lang.String[] { "Version", "VersionFull", "Level", "ErrorCode", "Message", "VersionKind", });
internal_static_org_jetbrains_kotlin_serialization_VersionRequirementTable_descriptor =
getDescriptor().getMessageTypes().get(15);
internal_static_org_jetbrains_kotlin_serialization_VersionRequirementTable_fieldAccessorTable = new
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.annotations.argumentValue
import org.jetbrains.kotlin.resolve.calls.checkers.isOperatorMod
import org.jetbrains.kotlin.resolve.calls.checkers.shouldWarnAboutDeprecatedModFromBuiltIns
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberDescriptor
import org.jetbrains.kotlin.serialization.deserialization.descriptors.VersionRequirement
@@ -292,8 +293,17 @@ class DeprecationResolver(
if (versionRequirement != null) {
// We're using ApiVersion because it's convenient to compare versions, "-api-version" is not involved in any way
// TODO: usage of ApiVersion is confusing here, refactor
if (ApiVersion.createByVersionRequirement(versionRequirement) >
ApiVersion.createByLanguageVersion(languageVersionSettings.languageVersion)) {
val requiredVersion = ApiVersion.createByVersionRequirement(versionRequirement)
val currentVersion = when (versionRequirement.kind) {
ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION ->
ApiVersion.createByLanguageVersion(languageVersionSettings.languageVersion)
ProtoBuf.VersionRequirement.VersionKind.API_VERSION ->
languageVersionSettings.apiVersion
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION ->
ApiVersion.LATEST_STABLE
else -> null
}
if (currentVersion != null && currentVersion < requiredVersion) {
result.add(DeprecatedByVersionRequirement(versionRequirement, target))
}
}
@@ -633,6 +633,15 @@ class DescriptorSerializer private constructor(
DeprecationLevel.HIDDEN.toString() -> proto.level = ProtoBuf.VersionRequirement.Level.HIDDEN
}
val versionKind = (args[RequireKotlinNames.VERSION_KIND] as? EnumValue)?.value?.name?.asString()
when (versionKind) {
ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION.toString() -> { /* LANGUAGE_VERSION is the default kind */ }
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION.toString() ->
proto.versionKind = ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION
ProtoBuf.VersionRequirement.VersionKind.API_VERSION.toString() ->
proto.versionKind = ProtoBuf.VersionRequirement.VersionKind.API_VERSION
}
val errorCode = (args[RequireKotlinNames.ERROR_CODE] as? IntValue)?.value
if (errorCode != null && errorCode != -1) {
proto.errorCode = errorCode
@@ -656,6 +665,7 @@ class DescriptorSerializer private constructor(
val VERSION = Name.identifier("version")
val MESSAGE = Name.identifier("message")
val LEVEL = Name.identifier("level")
val VERSION_KIND = Name.identifier("versionKind")
val ERROR_CODE = Name.identifier("errorCode")
val VERSION_REGEX: Regex = "(0|[1-9][0-9]*)".let { number -> Regex("$number\\.$number(\\.$number)?") }
@@ -0,0 +1,19 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package test
import kotlin.internal.RequireKotlin
import kotlin.internal.RequireKotlinVersionKind
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, RequireKotlinVersionKind.API_VERSION, 42)
class Klass
class Konstructor @RequireKotlin("1.1", "message", DeprecationLevel.WARNING, RequireKotlinVersionKind.API_VERSION, 42) constructor()
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, RequireKotlinVersionKind.API_VERSION, 42)
typealias Typealias = String
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, RequireKotlinVersionKind.API_VERSION, 42)
fun function() {}
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, RequireKotlinVersionKind.API_VERSION, 42)
val property = ""
@@ -3,16 +3,16 @@ package test
import kotlin.internal.RequireKotlin
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, 42)
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, errorCode = 42)
class Klass
class Konstructor @RequireKotlin("1.1", "message", DeprecationLevel.WARNING, 42) constructor()
class Konstructor @RequireKotlin("1.1", "message", DeprecationLevel.WARNING, errorCode = 42) constructor()
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, 42)
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, errorCode = 42)
typealias Typealias = String
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, 42)
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, errorCode = 42)
fun function() {}
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, 42)
@RequireKotlin("1.1", "message", DeprecationLevel.WARNING, errorCode = 42)
val property = ""
@@ -40,6 +40,7 @@ class VersionRequirementTest : TestCaseWithTmpdir() {
expectedVersionRequirement: VersionRequirement.Version,
expectedLevel: DeprecationLevel,
expectedMessage: String?,
expectedVersionKind: ProtoBuf.VersionRequirement.VersionKind,
expectedErrorCode: Int?,
vararg fqNames: String
) {
@@ -66,6 +67,7 @@ class VersionRequirementTest : TestCaseWithTmpdir() {
assertEquals(expectedVersionRequirement, requirement.version)
assertEquals(expectedLevel, requirement.level)
assertEquals(expectedMessage, requirement.message)
assertEquals(expectedVersionKind, requirement.kind)
assertEquals(expectedErrorCode, requirement.errorCode)
}
@@ -96,7 +98,7 @@ class VersionRequirementTest : TestCaseWithTmpdir() {
}
fun testSuspendFun() {
doTest(VersionRequirement.Version(1, 1), DeprecationLevel.ERROR, null, null,
doTest(VersionRequirement.Version(1, 1), DeprecationLevel.ERROR, null, ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION, null,
"test.topLevel",
"test.Foo.member",
"test.Foo.<init>",
@@ -109,7 +111,17 @@ class VersionRequirementTest : TestCaseWithTmpdir() {
}
fun testLanguageVersionViaAnnotation() {
doTest(VersionRequirement.Version(1, 1), DeprecationLevel.WARNING, "message", 42,
doTest(VersionRequirement.Version(1, 1), DeprecationLevel.WARNING, "message", ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION, 42,
"test.Klass",
"test.Konstructor.<init>",
"test.Typealias",
"test.function",
"test.property"
)
}
fun testApiVersionViaAnnotation() {
doTest(VersionRequirement.Version(1, 1), DeprecationLevel.WARNING, "message", ProtoBuf.VersionRequirement.VersionKind.API_VERSION, 42,
"test.Klass",
"test.Konstructor.<init>",
"test.Typealias",
@@ -33,7 +33,7 @@ class JsMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
companion object {
@JvmField
val INSTANCE = JsMetadataVersion(1, 1, 0)
val INSTANCE = JsMetadataVersion(1, 1, 1)
@JvmField
val INVALID_VERSION = JsMetadataVersion()
@@ -29,7 +29,7 @@ class JvmMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
companion object {
@JvmField
val INSTANCE = JvmMetadataVersion(1, 1, 8)
val INSTANCE = JvmMetadataVersion(1, 1, 9)
@JvmField
val INVALID_VERSION = JvmMetadataVersion()
@@ -424,6 +424,12 @@ message VersionRequirement {
HIDDEN = 2;
}
enum VersionKind {
LANGUAGE_VERSION = 0;
COMPILER_VERSION = 1;
API_VERSION = 2;
}
// Kotlin version, since which this declaration is accessible, in the following format (encoded version is "major.minor.patch"):
// (patch << 7) + (minor << 3) + major
// Compilers with version less than this value should report a diagnostic if this declaration is selected as the resolution result
@@ -441,6 +447,10 @@ message VersionRequirement {
// Diagnostic message
optional int32 message = 5 [(string_id_in_table) = true];
// Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
// (the "-api-version" argument value when compiling the call site) to be of at least the specified value
optional VersionKind version_kind = 6 [default = LANGUAGE_VERSION];
}
message VersionRequirementTable {
@@ -19913,6 +19913,25 @@ public final class ProtoBuf {
* </pre>
*/
int getMessage();
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
boolean hasVersionKind();
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind getVersionKind();
}
/**
* Protobuf type {@code org.jetbrains.kotlin.serialization.VersionRequirement}
@@ -19996,6 +20015,18 @@ public final class ProtoBuf {
message_ = input.readInt32();
break;
}
case 48: {
int rawValue = input.readEnum();
org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind value = org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind.valueOf(rawValue);
if (value == null) {
unknownFieldsCodedOutput.writeRawVarint32(tag);
unknownFieldsCodedOutput.writeRawVarint32(rawValue);
} else {
bitField0_ |= 0x00000020;
versionKind_ = value;
}
break;
}
}
}
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
@@ -20094,6 +20125,71 @@ public final class ProtoBuf {
// @@protoc_insertion_point(enum_scope:org.jetbrains.kotlin.serialization.VersionRequirement.Level)
}
/**
* Protobuf enum {@code org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind}
*/
public enum VersionKind
implements org.jetbrains.kotlin.protobuf.Internal.EnumLite {
/**
* <code>LANGUAGE_VERSION = 0;</code>
*/
LANGUAGE_VERSION(0, 0),
/**
* <code>COMPILER_VERSION = 1;</code>
*/
COMPILER_VERSION(1, 1),
/**
* <code>API_VERSION = 2;</code>
*/
API_VERSION(2, 2),
;
/**
* <code>LANGUAGE_VERSION = 0;</code>
*/
public static final int LANGUAGE_VERSION_VALUE = 0;
/**
* <code>COMPILER_VERSION = 1;</code>
*/
public static final int COMPILER_VERSION_VALUE = 1;
/**
* <code>API_VERSION = 2;</code>
*/
public static final int API_VERSION_VALUE = 2;
public final int getNumber() { return value; }
public static VersionKind valueOf(int value) {
switch (value) {
case 0: return LANGUAGE_VERSION;
case 1: return COMPILER_VERSION;
case 2: return API_VERSION;
default: return null;
}
}
public static org.jetbrains.kotlin.protobuf.Internal.EnumLiteMap<VersionKind>
internalGetValueMap() {
return internalValueMap;
}
private static org.jetbrains.kotlin.protobuf.Internal.EnumLiteMap<VersionKind>
internalValueMap =
new org.jetbrains.kotlin.protobuf.Internal.EnumLiteMap<VersionKind>() {
public VersionKind findValueByNumber(int number) {
return VersionKind.valueOf(number);
}
};
private final int value;
private VersionKind(int index, int value) {
this.value = value;
}
// @@protoc_insertion_point(enum_scope:org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind)
}
private int bitField0_;
public static final int VERSION_FIELD_NUMBER = 1;
private int version_;
@@ -20216,12 +20312,38 @@ public final class ProtoBuf {
return message_;
}
public static final int VERSION_KIND_FIELD_NUMBER = 6;
private org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind versionKind_;
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public boolean hasVersionKind() {
return ((bitField0_ & 0x00000020) == 0x00000020);
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind getVersionKind() {
return versionKind_;
}
private void initFields() {
version_ = 0;
versionFull_ = 0;
level_ = org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.Level.ERROR;
errorCode_ = 0;
message_ = 0;
versionKind_ = org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -20251,6 +20373,9 @@ public final class ProtoBuf {
if (((bitField0_ & 0x00000010) == 0x00000010)) {
output.writeInt32(5, message_);
}
if (((bitField0_ & 0x00000020) == 0x00000020)) {
output.writeEnum(6, versionKind_.getNumber());
}
output.writeRawBytes(unknownFields);
}
@@ -20280,6 +20405,10 @@ public final class ProtoBuf {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32Size(5, message_);
}
if (((bitField0_ & 0x00000020) == 0x00000020)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeEnumSize(6, versionKind_.getNumber());
}
size += unknownFields.size();
memoizedSerializedSize = size;
return size;
@@ -20384,6 +20513,8 @@ public final class ProtoBuf {
bitField0_ = (bitField0_ & ~0x00000008);
message_ = 0;
bitField0_ = (bitField0_ & ~0x00000010);
versionKind_ = org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION;
bitField0_ = (bitField0_ & ~0x00000020);
return this;
}
@@ -20427,6 +20558,10 @@ public final class ProtoBuf {
to_bitField0_ |= 0x00000010;
}
result.message_ = message_;
if (((from_bitField0_ & 0x00000020) == 0x00000020)) {
to_bitField0_ |= 0x00000020;
}
result.versionKind_ = versionKind_;
result.bitField0_ = to_bitField0_;
return result;
}
@@ -20448,6 +20583,9 @@ public final class ProtoBuf {
if (other.hasMessage()) {
setMessage(other.getMessage());
}
if (other.hasVersionKind()) {
setVersionKind(other.getVersionKind());
}
setUnknownFields(
getUnknownFields().concat(other.unknownFields));
return this;
@@ -20731,6 +20869,61 @@ public final class ProtoBuf {
return this;
}
private org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind versionKind_ = org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION;
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public boolean hasVersionKind() {
return ((bitField0_ & 0x00000020) == 0x00000020);
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind getVersionKind() {
return versionKind_;
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public Builder setVersionKind(org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind value) {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000020;
versionKind_ = value;
return this;
}
/**
* <code>optional .org.jetbrains.kotlin.serialization.VersionRequirement.VersionKind version_kind = 6 [default = LANGUAGE_VERSION];</code>
*
* <pre>
* Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
* (the "-api-version" argument value when compiling the call site) to be of at least the specified value
* </pre>
*/
public Builder clearVersionKind() {
bitField0_ = (bitField0_ & ~0x00000020);
versionKind_ = org.jetbrains.kotlin.serialization.ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION;
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.VersionRequirement)
}
@@ -33,6 +33,7 @@ class VersionRequirementTable private constructor(private val infos: List<ProtoB
class VersionRequirement(
val version: Version,
val kind: ProtoBuf.VersionRequirement.VersionKind,
val level: DeprecationLevel,
val errorCode: Int?,
val message: String?
@@ -117,7 +118,7 @@ class VersionRequirement(
val message = if (info.hasMessage()) nameResolver.getString(info.message) else null
return VersionRequirement(version, level, errorCode, message)
return VersionRequirement(version, info.versionKind, level, errorCode, message)
}
}
}
@@ -74,6 +74,14 @@ internal annotation class DynamicExtension
* to the user). The diagnostic severity can be specified with [level]: WARNING/ERROR mean that either a warning or an error
* is going to be reported, HIDDEN means that the declaration is going to be removed from resolution completely.
*
* [versionKind] specifies which version should be compared with the [version] value, when compiling the usage of the annotated declaration.
* Note that prior to 1.2, only [RequireKotlinVersionKind.LANGUAGE_VERSION] was supported, so the Kotlin compiler before 1.2 is going to
* treat any [RequireKotlin] as if it requires the language version. Since 1.2, the Kotlin compiler supports
* [RequireKotlinVersionKind.LANGUAGE_VERSION], [RequireKotlinVersionKind.COMPILER_VERSION] and [RequireKotlinVersionKind.API_VERSION].
* If the actual value of [versionKind] is something different (e.g. a new version kind, added in future versions of Kotlin),
* Kotlin 1.2 is going to ignore this [RequireKotlin] altogether, where as Kotlin before 1.2 is going to treat this as a requirement
* on the language version.
*
* This annotation is erased at compile time; its arguments are stored in a more compact form in the Kotlin metadata.
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.TYPEALIAS)
@@ -82,5 +90,15 @@ internal annotation class RequireKotlin(
val version: String,
val message: String = "",
val level: DeprecationLevel = DeprecationLevel.ERROR,
val versionKind: RequireKotlinVersionKind = RequireKotlinVersionKind.LANGUAGE_VERSION,
val errorCode: Int = -1
)
/**
* The kind of the version that is required by [RequireKotlin].
*/
internal enum class RequireKotlinVersionKind {
LANGUAGE_VERSION,
COMPILER_VERSION,
API_VERSION,
}