diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt new file mode 100644 index 000000000..c8e46bb80 --- /dev/null +++ b/ThirdPartyNotices.txt @@ -0,0 +1,219 @@ +java.interop uses third-party libraries or other resources that may be +distributed under licenses different than the java.interop software. + +In the event that we accidentally failed to list a required notice, please +bring it to our attention. Post an issue or email us: + + dotnet@microsoft.com + +The attached notices are provided for information only. + +1. JetBrains/kotlin (https://github.com/JetBrains/kotlin/) + +%% JetBrains/kotlin NOTICES AND INFORMATION BEGIN HERE +====================================================== + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2000-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +====================================================== + +END OF JetBrains/kotlin NOTICES AND INFORMATION diff --git a/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs b/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs index fe7635030..0aee8a5d5 100644 --- a/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs +++ b/src/Xamarin.Android.Tools.Bytecode/ClassPath.cs @@ -8,6 +8,7 @@ using System.Xml.Linq; using System.Xml.XPath; using System.Text; +using Xamarin.Android.Tools.Bytecode.Kotlin; namespace Xamarin.Android.Tools.Bytecode { @@ -298,6 +299,9 @@ public XElement ToXElement () // This optional behavior is to bring compatibility with old behavior. if (AutoRename) FixUpParametersFromClasses (); + + KotlinFixups.Fixup (classFiles); + var packagesDictionary = GetPackages (); var api = new XElement ("api", GetApiSource (), diff --git a/src/Xamarin.Android.Tools.Bytecode/Kotlin/JvmNameResolver.cs b/src/Xamarin.Android.Tools.Bytecode/Kotlin/JvmNameResolver.cs new file mode 100644 index 000000000..a61ae4fb1 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Kotlin/JvmNameResolver.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using org.jetbrains.kotlin.metadata.jvm; + +namespace Xamarin.Android.Tools.Bytecode +{ + // https://github.com/JetBrains/kotlin/blob/master/core/metadata.jvm/src/org/jetbrains/kotlin/metadata/jvm/deserialization/JvmNameResolver.kt + class JvmNameResolver + { + readonly List records = new List (); + readonly List strings; + + public JvmNameResolver (StringTableTypes table, List strings) + { + foreach (var t in table.Records) + for (var i = 0; i < t.Range; i++) + records.Add (t); + + this.strings = strings; + } + + public string GetString (int index) + { + var record = records [index]; + + string val; + + // Get string from: + // - Embedded in string record table + // - Predefined string + // - Constant pool + if (!string.IsNullOrEmpty (record.String)) + val = record.String; + else if (record.PredefinedIndex > 0) + val = predefined_strings [record.PredefinedIndex]; + else + val = strings [index]; + + if (record.SubstringIndexs?.Length >= 2) { + var begin = record.SubstringIndexs [0]; + var end = record.SubstringIndexs [1]; + + if (begin > 0 && begin <= end && end <= val.Length) + val = val.Substring (begin, end); + } + + if (record.ReplaceChars?.Length >= 2) { + var from = (char) record.ReplaceChars [0]; + var to = (char) record.ReplaceChars [1]; + + val = val.Replace (from, to); + } + + if (record.operation == StringTableTypes.Record.Operation.InternalToClassId) + val = val.Replace ('$', '.'); + else if (record.operation == StringTableTypes.Record.Operation.DescToClassId) { + if (val.Length >= 2) + val = val.Substring (1, val.Length - 1); + + val = val.Replace ('$', '.'); + } + + return val; + } + + static readonly string [] predefined_strings = new string [] { + "kotlin/Any", + "kotlin/Nothing", + "kotlin/Unit", + "kotlin/Throwable", + "kotlin/Number", + + "kotlin/Byte", "kotlin/Double", "kotlin/Float", "kotlin/Int", + "kotlin/Long", "kotlin/Short", "kotlin/Boolean", "kotlin/Char", + + "kotlin/CharSequence", + "kotlin/String", + "kotlin/Comparable", + "kotlin/Enum", + + "kotlin/Array", + "kotlin/ByteArray", "kotlin/DoubleArray", "kotlin/FloatArray", "kotlin/IntArray", + "kotlin/LongArray", "kotlin/ShortArray", "kotlin/BooleanArray", "kotlin/CharArray", + + "kotlin/Cloneable", + "kotlin/Annotation", + + "kotlin/collections/Iterable", "kotlin/collections/MutableIterable", + "kotlin/collections/Collection", "kotlin/collections/MutableCollection", + "kotlin/collections/List", "kotlin/collections/MutableList", + "kotlin/collections/Set", "kotlin/collections/MutableSet", + "kotlin/collections/Map", "kotlin/collections/MutableMap", + "kotlin/collections/Map.Entry", "kotlin/collections/MutableMap.MutableEntry", + + "kotlin/collections/Iterator", "kotlin/collections/MutableIterator", + "kotlin/collections/ListIterator", "kotlin/collections/MutableListIterator" + }; + } +} diff --git a/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinBitEncoding.cs b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinBitEncoding.cs new file mode 100644 index 000000000..06edf06f5 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinBitEncoding.cs @@ -0,0 +1,157 @@ +using System; +using System.IO; +using System.Linq; + +namespace Xamarin.Android.Tools.Bytecode +{ + // https://github.com/JetBrains/kotlin/blob/master/core/metadata.jvm/src/org/jetbrains/kotlin/metadata/jvm/deserialization/BitEncoding.java + public static class KotlinBitEncoding + { + const char UTF8_MODE_MARKER = (char) 0; + const char _8TO7_MODE_MARKER = unchecked((char) -1); + + public static byte [] DecodeBytes (string [] data) + { + if (data.Length > 0 && !string.IsNullOrEmpty (data [0])) { + var possibleMarker = data [0] [0]; + + if (possibleMarker == UTF8_MODE_MARKER) + return StringsToBytes (DropMarker (data)); + + if (possibleMarker == _8TO7_MODE_MARKER) + data = DropMarker (data); + } + + var bytes = CombineStringArrayIntoBytes (data); + + // Adding 0x7f modulo max byte value is equivalent to subtracting 1 the same modulo, which is inverse to what happens in encodeBytes + AddModuloByte (bytes, 0x7f); + + return Decode7to8 (bytes); + } + + public static int ReadRawVarint32 (Stream input) + { + var firstByte = input.ReadByte (); + + if ((firstByte & 128) == 0) + return firstByte; + + var result = firstByte & 127; + + int offset; + int b; + + for (offset = 7; offset < 32; offset += 7) { + + b = input.ReadByte (); + + if (b == -1) + throw new InvalidDataException ("Unable to read varint32 from stream"); + + result |= (b & 127) << offset; + + if ((b & 128) == 0) + return result; + } + + while (offset < 64) { + + b = input.ReadByte (); + + if (b == -1) + throw new InvalidDataException ("Unable to read varint32 from stream"); + + if ((b & 128) == 0) + return result; + + offset += 7; + } + + throw new InvalidDataException ("Unable to read varint32 from stream"); + } + + static string [] DropMarker (string [] data) + { + // Clone because the clients should be able to use the passed array for their own purposes. + // This is cheap because the size of the array is 1 or 2 almost always. + var result = (string []) data.Clone (); + result [0] = result [0].Substring (1); + + return result; + } + + static byte [] StringsToBytes (string [] strings) + { + var length = strings.Sum (s => s.Length); + var result = new byte [length]; + + var i = 0; + + foreach (var s in strings) + foreach (var c in s) + result [i++] = (byte) c; + + return result; + } + + static byte [] CombineStringArrayIntoBytes (string [] data) + { + var resultLength = 0; + + foreach (var s in data) + resultLength += s.Length; + + var result = new byte [resultLength]; + var p = 0; + + foreach (var s in data) + for (int i = 0, n = s.Length; i < n; i++) + result [p++] = (byte) s [i]; + + return result; + } + + static void AddModuloByte (byte [] data, int increment) + { + for (int i = 0, n = data.Length; i < n; i++) { + data [i] = (byte) ((data [i] + increment) & 0x7f); + } + } + + static byte [] Decode7to8 (byte [] data) + { + // floor(7 * data.length / 8) + var resultLength = 7 * data.Length / 8; + + var result = new byte [resultLength]; + + // We maintain a pointer to an input bit in the same fashion as in encode8to7(): it's represented as two numbers: index of the + // current byte in the input and index of the bit in the byte + var byteIndex = 0; + var bit = 0; + + // A resulting byte is comprised of 8 bits, starting from the current bit. Since each input byte only "contains 7 bytes", a + // resulting byte always consists of two parts: several most significant bits of the current byte and several least significant bits + // of the next byte + for (var i = 0; i < resultLength; i++) { + var firstPart = (int) (((uint) (data [byteIndex] & 0xff)) >> bit); + + byteIndex++; + + var secondPart = (data [byteIndex] & ((1 << (bit + 1)) - 1)) << 7 - bit; + + result [i] = (byte) (firstPart + secondPart); + + if (bit == 6) { + byteIndex++; + bit = 0; + } else { + bit++; + } + } + + return result; + } + } +} diff --git a/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinClassMetadata.cs b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinClassMetadata.cs new file mode 100644 index 000000000..1f7944df3 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinClassMetadata.cs @@ -0,0 +1,560 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using org.jetbrains.kotlin.metadata.jvm; +using Type = org.jetbrains.kotlin.metadata.jvm.Type; + +namespace Xamarin.Android.Tools.Bytecode +{ + public class KotlinClass + { + public string CompanionObjectName { get; set; } + public List Constructors { get; set; } + public List EnumEntries { get; set; } + public KotlinClassFlags Flags { get; set; } + public string FullyQualifiedName { get; set; } + public List Functions { get; set; } + public List NestedClassNames { get; set; } = new List (); + public List Properties { get; set; } + public List SealedSubclassFullyQualifiedNames { get; set; } + public List SuperTypeIds { get; set; } + public List SuperTypes { get; set; } + public List TypeAliases { get; set; } + public List TypeParameters { get; set; } + public KotlinTypeTable TypeTable { get; set; } + public int [] VersionRequirements { get; set; } + public KotlinVersionRequirementTable VersionRequirementTable { get; set; } + + internal static KotlinClass FromProtobuf (Class c, JvmNameResolver resolver) + { + return new KotlinClass { + CompanionObjectName = c.CompanionObjectName > 0 ? resolver.GetString (c.CompanionObjectName) : null, + Constructors = c.Constructors?.Select (ctor => KotlinConstructor.FromProtobuf (ctor, resolver)).ToList (), + EnumEntries = c.EnumEntries?.Select (e => resolver.GetString (e.Name)).ToList (), + Flags = (KotlinClassFlags)c.Flags, + FullyQualifiedName = c.FqName > 0 ? resolver.GetString (c.FqName) : null, + Functions = c.Functions?.Select (f => KotlinFunction.FromProtobuf (f, resolver)).ToList (), + NestedClassNames = c.NestedClassNames?.Select (n => resolver.GetString (n)).ToList (), + Properties = c.Properties?.Select (p => KotlinProperty.FromProtobuf (p, resolver)).ToList (), + SealedSubclassFullyQualifiedNames = c.SealedSubclassFqNames?.Select (n => resolver.GetString (n)).ToList (), + SuperTypeIds = c.SupertypeIds?.Select (n => resolver.GetString (n)).ToList (), + SuperTypes = c.Supertypes?.Select (st => KotlinType.FromProtobuf (st, resolver)).ToList (), + TypeAliases = c.TypeAlias?.Select (tp => KotlinTypeAlias.FromProtobuf (tp, resolver)).ToList (), + TypeParameters = c.TypeParameters?.Select (tp => KotlinTypeParameter.FromProtobuf (tp, resolver)).ToList (), + VersionRequirements = c.VersionRequirements, + TypeTable = KotlinTypeTable.FromProtobuf (c.TypeTable, resolver), + VersionRequirementTable = KotlinVersionRequirementTable.FromProtobuf (c.VersionRequirementTable, resolver) + }; + } + } + + public class KotlinConstructor + { + public int Flags { get; set; } + public List ValueParameters { get; set; } + public int [] VersionRequirements { get; set; } + + internal static KotlinConstructor FromProtobuf (Constructor c, JvmNameResolver resolver) + { + if (c is null) + return null; + + return new KotlinConstructor { + Flags = c.Flags, + ValueParameters = c.ValueParameters?.Select (vp => KotlinValueParameter.FromProtobuf (vp, resolver)).ToList (), + VersionRequirements = c.VersionRequirements + }; + } + } + + public class KotlinAnnotation + { + public int Id { get; set; } + public List Arguments { get; set; } + + internal static KotlinAnnotation FromProtobuf (org.jetbrains.kotlin.metadata.jvm.Annotation a, JvmNameResolver resolver) + { + if (a is null) + return null; + + return new KotlinAnnotation { + Id = a.Id, + Arguments = a.Arguments?.Select (vp => KotlinAnnotationArgument.FromProtobuf (vp, resolver)).ToList () + }; + } + } + + public class KotlinAnnotationArgument + { + public int NameId { get; set; } + public KotlinAnnotationArgumentValue Value { get; set; } + + internal static KotlinAnnotationArgument FromProtobuf (org.jetbrains.kotlin.metadata.jvm.Annotation.Argument a, JvmNameResolver resolver) + { + if (a is null) + return null; + + return new KotlinAnnotationArgument { + NameId = a.NameId, + Value = KotlinAnnotationArgumentValue.FromProtobuf (a.value, resolver) + }; + } + } + + public class KotlinAnnotationArgumentValue + { + public KotlinAnnotationArgumentType Type { get; set; } + public long IntValue { get; set; } + public float FloatValue { get; set; } + public double DoubleValue { get; set; } + public string StringValue { get; set; } + public int ClassId { get; set; } + public int EnumValueId { get; set; } + public KotlinAnnotation Annotation { get; set; } + public List ArrayElements { get; set; } + public int ArrayDimensionCount { get; set; } + public int Flags { get; set; } + + internal static KotlinAnnotationArgumentValue FromProtobuf (org.jetbrains.kotlin.metadata.jvm.Annotation.Argument.Value value, JvmNameResolver resolver) + { + if (value is null) + return null; + + return new KotlinAnnotationArgumentValue { + Type = (KotlinAnnotationArgumentType) value.type, + IntValue = value.IntValue, + FloatValue = value.FloatValue, + DoubleValue = value.DoubleValue, + StringValue = resolver.GetString (value.StringValue), + ClassId = value.ClassId, + EnumValueId = value.EnumValueId, + Annotation = KotlinAnnotation.FromProtobuf (value.Annotation, resolver), + ArrayDimensionCount = value.ArrayDimensionCount, + ArrayElements = value.ArrayElements?.Select (vp => KotlinAnnotationArgumentValue.FromProtobuf (vp, resolver)).ToList (), + Flags = value.Flags + }; + } + } + + public class KotlinEffect + { + public KotlinEffectType EffectType { get; set; } + public List EffectConstructorArguments { get; set; } + public KotlinExpression ConclusionOfConditionalEffect { get; set; } + public KotlinInvocationKind Kind { get; set; } + + internal static KotlinEffect FromProtobuf (Effect ef, JvmNameResolver resolver) + { + if (ef is null) + return null; + + return new KotlinEffect { + EffectType = (KotlinEffectType) ef.effect_type, + EffectConstructorArguments = ef.EffectConstructorArguments?.Select (vp => KotlinExpression.FromProtobuf (vp, resolver)).ToList (), + ConclusionOfConditionalEffect = KotlinExpression.FromProtobuf (ef.ConclusionOfConditionalEffect, resolver), + Kind = (KotlinInvocationKind) ef.Kind + }; + } + } + + public class KotlinExpression + { + public int Flags { get; set; } + public int ValueParameterReference { get; set; } + public KotlinConstantValue ConstantValue { get; set; } + public KotlinType IsInstanceType { get; set; } + public int IsInstanceTypeId { get; set; } + public List AndArguments { get; set; } + public List OrArguments { get; set; } + + internal static KotlinExpression FromProtobuf (Expression exp, JvmNameResolver resolver) + { + if (exp is null) + return null; + + return new KotlinExpression { + Flags = exp.Flags, + ValueParameterReference = exp.ValueParameterReference, + ConstantValue = (KotlinConstantValue) exp.constant_value, + IsInstanceType = KotlinType.FromProtobuf (exp.IsInstanceType, resolver), + IsInstanceTypeId = exp.IsInstanceTypeId, + AndArguments = exp.AndArguments?.Select (tp => KotlinExpression.FromProtobuf (tp, resolver)).ToList (), + OrArguments = exp.OrArguments?.Select (vp => KotlinExpression.FromProtobuf (vp, resolver)).ToList () + }; + } + } + + public class KotlinFunction + { + public int Flags { get; set; } + public string Name { get; set; } + public KotlinType ReturnType { get; set; } + public int ReturnTypeId { get; set; } + public List TypeParameters { get; set; } + public KotlinType ReceiverType { get; set; } + public int ReceiverTypeId { get; set; } + public List ValueParameters { get; set; } + public KotlinTypeTable TypeTable { get; set; } + public int [] VersionRequirements { get; set; } + public KotlinContract Contract { get; set; } + + internal static KotlinFunction FromProtobuf (Function f, JvmNameResolver resolver) + { + if (f is null) + return null; + + return new KotlinFunction { + Flags = f.Flags, + Name = resolver.GetString (f.Name), + ReturnType = KotlinType.FromProtobuf (f.ReturnType, resolver), + ReturnTypeId = f.ReturnTypeId, + ReceiverType = KotlinType.FromProtobuf (f.ReceiverType, resolver), + ReceiverTypeId = f.ReceiverTypeId, + TypeParameters = f.TypeParameters?.Select (tp => KotlinTypeParameter.FromProtobuf (tp, resolver)).ToList (), + ValueParameters = f.ValueParameters?.Select (vp => KotlinValueParameter.FromProtobuf (vp, resolver)).ToList (), + VersionRequirements = f.VersionRequirements + }; + } + } + + public class KotlinContract + { + public List Effects { get; set; } + + internal static KotlinContract FromProtobuf (Contract c, JvmNameResolver resolver) + { + return new KotlinContract { + Effects = c.Effects?.Select (tp => KotlinEffect.FromProtobuf (tp, resolver)).ToList () + }; + } + } + + public class KotlinProperty + { + public int Flags { get; set; } + public string Name { get; set; } + public KotlinType ReturnType { get; set; } + public int ReturnTypeId { get; set; } + public List TypeParameters { get; set; } + public KotlinType ReceiverType { get; set; } + public int ReceiverTypeId { get; set; } + public KotlinValueParameter SetterValueParameter { get; set; } + public int GetterFlags { get; set; } + public int SetterFlags { get; set; } + public int [] VersionRequirements { get; set; } + + internal static KotlinProperty FromProtobuf (Property p, JvmNameResolver resolver) + { + if (p is null) + return null; + + return new KotlinProperty { + Flags = p.Flags, + Name = resolver.GetString (p.Name), + ReturnTypeId = p.ReturnTypeId, + ReturnType = KotlinType.FromProtobuf (p.ReturnType, resolver), + ReceiverType = KotlinType.FromProtobuf (p.ReceiverType, resolver), + ReceiverTypeId = p.ReceiverTypeId, + SetterValueParameter = KotlinValueParameter.FromProtobuf (p.SetterValueParameter, resolver), + GetterFlags = p.GetterFlags, + SetterFlags = p.SetterFlags, + TypeParameters = p.TypeParameters?.Select (tp => KotlinTypeParameter.FromProtobuf (tp, resolver)).ToList (), + VersionRequirements = p.VersionRequirements + }; + } + } + + public class KotlinType + { + public List Arguments { get; set; } + public bool Nullable { get; set; } + public int FlexibleTypeCapabilitiesId { get; set; } + public KotlinType FlexibleUpperBound { get; set; } + public int FlexibleUpperBoundId { get; set; } + public string ClassName { get; set; } + public int TypeParameter { get; set; } + public string TypeParameterName { get; set; } + public string TypeAliasName { get; set; } + public KotlinType OuterType { get; set; } + public int OuterTypeId { get; set; } + public KotlinType AbbreviatedType { get; set; } + public int AbbreviatedTypeId { get; set; } + public int Flags { get; set; } + + internal static KotlinType FromProtobuf (Type t, JvmNameResolver resolver) + { + if (t is null) + return null; + + return new KotlinType { + Arguments = t.Arguments?.Select (a => KotlinTypeArgument.FromProtobuf (a, resolver)).ToList (), + Nullable = t.Nullable, + FlexibleTypeCapabilitiesId = t.FlexibleTypeCapabilitiesId, + FlexibleUpperBound = FromProtobuf (t.FlexibleUpperBound, resolver), + ClassName = t.ClassName > 0 ? resolver.GetString (t.ClassName) : null, + TypeParameter = t.TypeParameter, + TypeParameterName = t.TypeParameterName > 0 ? resolver.GetString (t.TypeParameterName) : null, + OuterType = FromProtobuf (t.OuterType, resolver), + OuterTypeId = t.OuterTypeId, + AbbreviatedType = FromProtobuf (t.AbbreviatedType, resolver), + AbbreviatedTypeId = t.AbbreviatedTypeId, + Flags = t.Flags + }; + } + } + + public class KotlinTypeAlias + { + public int Flags { get; set; } + public string Name { get; set; } + public List TypeParameters { get; set; } + public KotlinType UnderlyingType { get; set; } + public int UnderlyingTypeId { get; set; } + public KotlinType ExpandedType { get; set; } + public int ExpandedTypeId { get; set; } + public List Annotations { get; set; } + public int [] VersionRequirements { get; set; } + + internal static KotlinTypeAlias FromProtobuf (TypeAlias ta, JvmNameResolver resolver) + { + if (ta is null) + return null; + + return new KotlinTypeAlias { + Flags = ta.Flags, + Name = resolver.GetString (ta.Name), + TypeParameters = ta.TypeParameters?.Select (tp => KotlinTypeParameter.FromProtobuf (tp, resolver)).ToList (), + UnderlyingType = KotlinType.FromProtobuf (ta.UnderlyingType, resolver), + UnderlyingTypeId = ta.UnderlyingTypeId, + ExpandedType = KotlinType.FromProtobuf (ta.ExpandedType, resolver), + ExpandedTypeId = ta.ExpandedTypeId, + VersionRequirements = ta.VersionRequirements + }; + } + } + + public class KotlinTypeArgument + { + public KotlinProjection Projection { get; set; } + public KotlinType Type { get; set; } + public int TypeId { get; set; } + + internal static KotlinTypeArgument FromProtobuf (Type.Argument ta, JvmNameResolver resolver) + { + if (ta is null) + return null; + + return new KotlinTypeArgument { + Projection = (KotlinProjection) ta.projection, + Type = KotlinType.FromProtobuf (ta.Type, resolver), + TypeId = ta.TypeId + }; + } + } + + public class KotlinTypeParameter + { + public int Id { get; set; } + public string Name { get; set; } + public bool Reified { get; set; } + public KotlinVariance Variance { get; set; } + public List UpperBounds { get; set; } + public int [] UpperBoundsIds { get; set; } + + internal static KotlinTypeParameter FromProtobuf (TypeParameter vp, JvmNameResolver resolver) + { + if (vp is null) + return null; + + return new KotlinTypeParameter { + Id = vp.Id, + Name = resolver.GetString (vp.Name), + Reified = vp.Reified, + Variance = (KotlinVariance) vp.variance, + UpperBounds = vp.UpperBounds?.Select (ub => KotlinType.FromProtobuf (ub, resolver)).ToList (), + UpperBoundsIds = vp.UpperBoundIds + }; + } + } + + public class KotlinTypeTable + { + public List Types { get; set; } + public int FirstNullable { get; set; } + + internal static KotlinTypeTable FromProtobuf (TypeTable ta, JvmNameResolver resolver) + { + if (ta is null) + return null; + + return new KotlinTypeTable { + Types = ta.Types?.Select (t => KotlinType.FromProtobuf (t, resolver)).ToList (), + FirstNullable = ta.FirstNullable + }; + } + } + + public class KotlinVersionRequirement + { + public int Version { get; set; } + public int VersionFull { get; set; } + public KotlinVersionLevel Level { get; set; } + public int ErrorCode { get; set; } + public int Message { get; set; } + public KotlinVersionKind VersionKind { get; set; } + + internal static KotlinVersionRequirement FromProtobuf (VersionRequirement vr, JvmNameResolver resolver) + { + if (vr is null) + return null; + + return new KotlinVersionRequirement { + Version = vr.Version, + VersionFull = vr.VersionFull, + Level = (KotlinVersionLevel) vr.level, + ErrorCode = vr.ErrorCode, + Message = vr.Message, + VersionKind = (KotlinVersionKind) vr.version_kind + }; + } + } + + public class KotlinVersionRequirementTable + { + public List Requirements { get; set; } + + internal static KotlinVersionRequirementTable FromProtobuf (VersionRequirementTable vrt, JvmNameResolver resolver) + { + if (vrt is null) + return null; + + return new KotlinVersionRequirementTable { + Requirements = vrt.Requirements?.Select (t => KotlinVersionRequirement.FromProtobuf (t, resolver)).ToList () + }; + } + } + + public class KotlinValueParameter + { + public int Flags { get; set; } + public string Name { get; set; } + public KotlinType Type { get; set; } + public int TypeId { get; set; } + public KotlinType VarArgElementType { get; set; } + public int VarArgElementTypeId { get; set; } + + internal static KotlinValueParameter FromProtobuf (ValueParameter vp, JvmNameResolver resolver) + { + if (vp is null) + return null; + + return new KotlinValueParameter { + Flags = vp.Flags, + Name = resolver.GetString (vp.Name), + Type = KotlinType.FromProtobuf (vp.Type, resolver), + TypeId = vp.TypeId, + VarArgElementType = KotlinType.FromProtobuf (vp.VarargElementType, resolver), + VarArgElementTypeId = vp.VarargElementTypeId + }; + } + } + + public enum KotlinVariance + { + In = 0, + Out = 1, + Inv = 2, + } + + public enum KotlinProjection + { + In = 0, + Out = 1, + Inv = 2, + Star = 3, + } + + public enum KotlinEffectType + { + ReturnsConstant = 0, + Calls = 1, + ReturnsNotNull = 2, + } + + public enum KotlinInvocationKind + { + AtMostOnce = 0, + ExactlyOnce = 1, + AtLeastOnce = 2, + } + + public enum KotlinConstantValue + { + True = 0, + False = 1, + Null = 2, + } + + public enum KotlinVersionLevel + { + Warning = 0, + Error = 1, + Hidden = 2, + } + + public enum KotlinVersionKind + { + LanguageVersion = 0, + CompilerVersion = 1, + ApiVersion = 2, + } + + public enum KotlinAnnotationArgumentType + { + Byte = 0, + Char = 1, + Short = 2, + Int = 3, + Long = 4, + Float = 5, + Double = 6, + Boolean = 7, + String = 8, + Class = 9, + Enum = 10, + Annotation = 11, + Array = 12, + } + + [Flags] + public enum KotlinClassFlags + { + HasAnnotations = 0b00_00_000_1, + + Internal = 0b00_00_000_0, + Private = 0b00_00_001_0, + Protected = 0b00_00_010_0, + Public = 0b00_00_011_0, + PrivateToThis = 0b00_00_100_0, + Local = 0b00_00_101_0, + + Final = 0b00_00_000_0, + Open = 0b00_01_000_0, + Abstract = 0b00_10_000_0, + Sealed = 0b00_11_000_0, + + Class = 0b000_00_000_0, + Interface = 0b001_00_000_0, + EnumClass = 0b010_00_000_0, + EnumEntry = 0b011_00_000_0, + AnnotationClass = 0b100_00_000_0, + Object = 0b101_00_000_0, + CompanionObject = 0b111_00_000_0, + + IsInner = 0b_00001_000_00_000_0, + IsData = 0b_00010_000_00_000_0, + IsExternalClass = 0b_00100_000_00_000_0, + IsExpectClass = 0b_01000_000_00_000_0, + IsInlineClass = 0b_10000_000_00_000_0 + } +} diff --git a/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs new file mode 100644 index 000000000..1165a6f5a --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xamarin.Android.Tools.Bytecode.Kotlin +{ + static class KotlinFixups + { + public static void Fixup (IList classes) + { + foreach (var c in classes) { + // See if this is a Kotlin class + var attr = c.Attributes.OfType ().FirstOrDefault (); + var kotlin = attr?.Annotations.SingleOrDefault (a => a.Type == "Lkotlin/Metadata;"); + + if (kotlin is null) + continue; + + try { + var km = KotlinMetadata.FromAnnotation (kotlin); + + if (km.Kind == KotlinMetadataKind.Class) { + var class_metadata = km.AsClassMetadata (); + + FixupClassVisibility (c, class_metadata); + } else { + // We don't have explicit support for other types of Kotlin constructs yet, + // so they are unlikely to work. Mark them as private and consumers + // can override that if they want to fix them up. + c.AccessFlags = ClassAccessFlags.Private; + } + } catch (Exception ex) { + Log.Warning (0, $"class-parse: warning: Unable to parse Kotlin metadata on '{c.ThisClass.Name}': {ex}"); + } + } + } + + static void FixupClassVisibility (ClassFile klass, KotlinClass metadata) + { + // We don't have explicit support for these types of Kotlin constructs yet, + // so they are unlikely to work. Mark them as private and consumers + // can override that if they want to fix them up. + if (metadata.Flags.HasFlag (KotlinClassFlags.AnnotationClass) || metadata.Flags.HasFlag (KotlinClassFlags.CompanionObject) || metadata.Flags.HasFlag (KotlinClassFlags.Object)) + klass.AccessFlags = ClassAccessFlags.Private; + + // Hide class if it isn't Public/Protected + if (!metadata.Flags.HasFlag (KotlinClassFlags.Public) && !metadata.Flags.HasFlag (KotlinClassFlags.Protected)) + klass.AccessFlags = ClassAccessFlags.Private; + } + } +} diff --git a/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinMetadata.cs b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinMetadata.cs new file mode 100644 index 000000000..30e84c1b2 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinMetadata.cs @@ -0,0 +1,114 @@ +using System; +using System.IO; +using System.Linq; +using ProtoBuf; + +namespace Xamarin.Android.Tools.Bytecode +{ + // https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/jvm/runtime/kotlin/Metadata.kt + public class KotlinMetadata + { + public KotlinMetadataKind Kind { get; set; } + + // The version of the metadata provided in the arguments of this annotation. + public Version MetadataVersion { get; set; } + + // The version of the bytecode interface (naming conventions, signatures) of the class file annotated with this annotation. + public Version ByteCodeVersion { get; set; } + + // Metadata in a custom format. The format may be different (or even absent) for different kinds. + public string [] Data1 { get; set; } + + // An addition to [d1]: array of strings which occur in metadata, written in plain text so that strings already present + // in the constant pool are reused. These strings may be then indexed in the metadata by an integer index in this array. + public string [] Data2 { get; set; } + + public static KotlinMetadata FromAnnotation (Annotation annotation) + { + var km = new KotlinMetadata { + ByteCodeVersion = ParseVersion (annotation, "bv"), + Kind = (KotlinMetadataKind) ParseInteger (GetValue (annotation, "k")), + MetadataVersion = ParseVersion (annotation, "mv") + }; + + km.Data1 = GetValues (annotation, "d1"); + km.Data2 = GetValues (annotation, "d2"); + + return km; + } + + public KotlinClass AsClassMetadata () + { + if (Kind != KotlinMetadataKind.Class) + return null; + + var md = KotlinBitEncoding.DecodeBytes (Data1); + + using (var ms = ToMemoryStream (md)) { + + // The first element is the length of the string table + var first = ms.ReadByte (); + + if (first == -1) + return null; + + ms.Position = 0; + + var size = KotlinBitEncoding.ReadRawVarint32 (ms); + + using (var partial = new PartialStream (ms, ms.Position, size)) { + + // Read the string table from the stream + var string_table = Serializer.Deserialize (partial); + var resolver = new JvmNameResolver (string_table, Data2.ToList ()); + + partial.MoveNext (); + + // Read the metadata structure from the stream + var metadata = Serializer.Deserialize (partial); + return KotlinClass.FromProtobuf (metadata, resolver); + } + } + } + + static MemoryStream ToMemoryStream (byte [] bytes) => new MemoryStream (bytes); + + static Version ParseVersion (Annotation annotation, string key) + { + var value = GetValue (annotation, key); + + if (value is null) + return null; + + var values = value.Trim ('[', ']').Split (',').Select (v => ParseInteger (v)).ToArray (); + + return new Version (values [0], values [1], values [2]); + } + + static string GetValue (Annotation annotation, string key) + { + return (annotation.Values.FirstOrDefault (v => v.Key == key).Value as AnnotationElementConstant)?.Value; + } + + static string[] GetValues (Annotation annotation, string key) + { + return (annotation.Values.FirstOrDefault (v => v.Key == key).Value as AnnotationElementArray)?.Values.Cast ().Select (c => c.Value).ToArray (); + } + + static int ParseInteger (string value) + { + value = value.Replace ("Integer", "").Trim ('(', ')', ' '); + + return int.Parse (value); + } + } + + public enum KotlinMetadataKind + { + Class = 1, + File = 2, + SyntheticClass = 3, + MultiFileClassFacade = 4, + MultiFileClassPart = 5 + } +} diff --git a/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinProtobufDefinition.cs b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinProtobufDefinition.cs new file mode 100644 index 000000000..16aa67176 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinProtobufDefinition.cs @@ -0,0 +1,1438 @@ +// This file was generated by a tool; you should avoid making direct changes. +// Consider using 'partial classes' to extend these types +// Input: my.proto + +#pragma warning disable CS1591, CS0612, CS3021, IDE1006 +namespace org.jetbrains.kotlin.metadata.jvm +{ + + [global::ProtoBuf.ProtoContract ()] + partial class StringTable : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"string")] + public global::System.Collections.Generic.List Strings { get; set; } = new global::System.Collections.Generic.List (); + + } + + [global::ProtoBuf.ProtoContract ()] + partial class QualifiedNameTable : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"qualified_name")] + public global::System.Collections.Generic.List QualifiedNames { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoContract ()] + public partial class QualifiedName : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"parent_qualified_name")] + [global::System.ComponentModel.DefaultValue (-1)] + public int ParentQualifiedName { + get { return __pbn__ParentQualifiedName ?? -1; } + set { __pbn__ParentQualifiedName = value; } + } + public bool ShouldSerializeParentQualifiedName () => __pbn__ParentQualifiedName != null; + public void ResetParentQualifiedName () => __pbn__ParentQualifiedName = null; + private int? __pbn__ParentQualifiedName; + + [global::ProtoBuf.ProtoMember (2, Name = @"short_name", IsRequired = true)] + public int ShortName { get; set; } + + [global::ProtoBuf.ProtoMember (3)] + [global::System.ComponentModel.DefaultValue (Kind.Package)] + public Kind kind { + get { return __pbn__kind ?? Kind.Package; } + set { __pbn__kind = value; } + } + public bool ShouldSerializekind () => __pbn__kind != null; + public void Resetkind () => __pbn__kind = null; + private Kind? __pbn__kind; + + [global::ProtoBuf.ProtoContract ()] + public enum Kind + { + [global::ProtoBuf.ProtoEnum (Name = @"CLASS")] + Class = 0, + [global::ProtoBuf.ProtoEnum (Name = @"PACKAGE")] + Package = 1, + [global::ProtoBuf.ProtoEnum (Name = @"LOCAL")] + Local = 2, + } + + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Annotation : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"id", IsRequired = true)] + public int Id { get; set; } + + [global::ProtoBuf.ProtoMember (2, Name = @"argument")] + public global::System.Collections.Generic.List Arguments { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoContract ()] + public partial class Argument : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"name_id", IsRequired = true)] + public int NameId { get; set; } + + [global::ProtoBuf.ProtoMember (2, IsRequired = true)] + public Value value { get; set; } + + [global::ProtoBuf.ProtoContract ()] + public partial class Value : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1)] + [global::System.ComponentModel.DefaultValue (Type.Byte)] + public Type type { + get { return __pbn__type ?? Type.Byte; } + set { __pbn__type = value; } + } + public bool ShouldSerializetype () => __pbn__type != null; + public void Resettype () => __pbn__type = null; + private Type? __pbn__type; + + [global::ProtoBuf.ProtoMember (2, Name = @"int_value", DataFormat = global::ProtoBuf.DataFormat.ZigZag)] + public long IntValue { + get { return __pbn__IntValue.GetValueOrDefault (); } + set { __pbn__IntValue = value; } + } + public bool ShouldSerializeIntValue () => __pbn__IntValue != null; + public void ResetIntValue () => __pbn__IntValue = null; + private long? __pbn__IntValue; + + [global::ProtoBuf.ProtoMember (3, Name = @"float_value")] + public float FloatValue { + get { return __pbn__FloatValue.GetValueOrDefault (); } + set { __pbn__FloatValue = value; } + } + public bool ShouldSerializeFloatValue () => __pbn__FloatValue != null; + public void ResetFloatValue () => __pbn__FloatValue = null; + private float? __pbn__FloatValue; + + [global::ProtoBuf.ProtoMember (4, Name = @"double_value")] + public double DoubleValue { + get { return __pbn__DoubleValue.GetValueOrDefault (); } + set { __pbn__DoubleValue = value; } + } + public bool ShouldSerializeDoubleValue () => __pbn__DoubleValue != null; + public void ResetDoubleValue () => __pbn__DoubleValue = null; + private double? __pbn__DoubleValue; + + [global::ProtoBuf.ProtoMember (5, Name = @"string_value")] + public int StringValue { + get { return __pbn__StringValue.GetValueOrDefault (); } + set { __pbn__StringValue = value; } + } + public bool ShouldSerializeStringValue () => __pbn__StringValue != null; + public void ResetStringValue () => __pbn__StringValue = null; + private int? __pbn__StringValue; + + [global::ProtoBuf.ProtoMember (6, Name = @"class_id")] + public int ClassId { + get { return __pbn__ClassId.GetValueOrDefault (); } + set { __pbn__ClassId = value; } + } + public bool ShouldSerializeClassId () => __pbn__ClassId != null; + public void ResetClassId () => __pbn__ClassId = null; + private int? __pbn__ClassId; + + [global::ProtoBuf.ProtoMember (7, Name = @"enum_value_id")] + public int EnumValueId { + get { return __pbn__EnumValueId.GetValueOrDefault (); } + set { __pbn__EnumValueId = value; } + } + public bool ShouldSerializeEnumValueId () => __pbn__EnumValueId != null; + public void ResetEnumValueId () => __pbn__EnumValueId = null; + private int? __pbn__EnumValueId; + + [global::ProtoBuf.ProtoMember (8, Name = @"annotation")] + public Annotation Annotation { get; set; } + + [global::ProtoBuf.ProtoMember (9, Name = @"array_element")] + public global::System.Collections.Generic.List ArrayElements { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (11, Name = @"array_dimension_count")] + [global::System.ComponentModel.DefaultValue (0)] + public int ArrayDimensionCount { + get { return __pbn__ArrayDimensionCount ?? 0; } + set { __pbn__ArrayDimensionCount = value; } + } + public bool ShouldSerializeArrayDimensionCount () => __pbn__ArrayDimensionCount != null; + public void ResetArrayDimensionCount () => __pbn__ArrayDimensionCount = null; + private int? __pbn__ArrayDimensionCount; + + [global::ProtoBuf.ProtoMember (10, Name = @"flags")] + [global::System.ComponentModel.DefaultValue (0)] + public int Flags { + get { return __pbn__Flags ?? 0; } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoContract ()] + public enum Type + { + [global::ProtoBuf.ProtoEnum (Name = @"BYTE")] + Byte = 0, + [global::ProtoBuf.ProtoEnum (Name = @"CHAR")] + Char = 1, + [global::ProtoBuf.ProtoEnum (Name = @"SHORT")] + Short = 2, + [global::ProtoBuf.ProtoEnum (Name = @"INT")] + Int = 3, + [global::ProtoBuf.ProtoEnum (Name = @"LONG")] + Long = 4, + [global::ProtoBuf.ProtoEnum (Name = @"FLOAT")] + Float = 5, + [global::ProtoBuf.ProtoEnum (Name = @"DOUBLE")] + Double = 6, + [global::ProtoBuf.ProtoEnum (Name = @"BOOLEAN")] + Boolean = 7, + [global::ProtoBuf.ProtoEnum (Name = @"STRING")] + String = 8, + [global::ProtoBuf.ProtoEnum (Name = @"CLASS")] + Class = 9, + [global::ProtoBuf.ProtoEnum (Name = @"ENUM")] + Enum = 10, + [global::ProtoBuf.ProtoEnum (Name = @"ANNOTATION")] + Annotation = 11, + [global::ProtoBuf.ProtoEnum (Name = @"ARRAY")] + Array = 12, + } + + } + + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Type : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (2, Name = @"argument")] + public global::System.Collections.Generic.List Arguments { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (3, Name = @"nullable")] + [global::System.ComponentModel.DefaultValue (false)] + public bool Nullable { + get { return __pbn__Nullable ?? false; } + set { __pbn__Nullable = value; } + } + public bool ShouldSerializeNullable () => __pbn__Nullable != null; + public void ResetNullable () => __pbn__Nullable = null; + private bool? __pbn__Nullable; + + [global::ProtoBuf.ProtoMember (4, Name = @"flexible_type_capabilities_id")] + public int FlexibleTypeCapabilitiesId { + get { return __pbn__FlexibleTypeCapabilitiesId.GetValueOrDefault (); } + set { __pbn__FlexibleTypeCapabilitiesId = value; } + } + public bool ShouldSerializeFlexibleTypeCapabilitiesId () => __pbn__FlexibleTypeCapabilitiesId != null; + public void ResetFlexibleTypeCapabilitiesId () => __pbn__FlexibleTypeCapabilitiesId = null; + private int? __pbn__FlexibleTypeCapabilitiesId; + + [global::ProtoBuf.ProtoMember (5, Name = @"flexible_upper_bound")] + public Type FlexibleUpperBound { get; set; } + + [global::ProtoBuf.ProtoMember (8, Name = @"flexible_upper_bound_id")] + public int FlexibleUpperBoundId { + get { return __pbn__FlexibleUpperBoundId.GetValueOrDefault (); } + set { __pbn__FlexibleUpperBoundId = value; } + } + public bool ShouldSerializeFlexibleUpperBoundId () => __pbn__FlexibleUpperBoundId != null; + public void ResetFlexibleUpperBoundId () => __pbn__FlexibleUpperBoundId = null; + private int? __pbn__FlexibleUpperBoundId; + + [global::ProtoBuf.ProtoMember (6, Name = @"class_name")] + public int ClassName { + get { return __pbn__ClassName.GetValueOrDefault (); } + set { __pbn__ClassName = value; } + } + public bool ShouldSerializeClassName () => __pbn__ClassName != null; + public void ResetClassName () => __pbn__ClassName = null; + private int? __pbn__ClassName; + + [global::ProtoBuf.ProtoMember (7, Name = @"type_parameter")] + public int TypeParameter { + get { return __pbn__TypeParameter.GetValueOrDefault (); } + set { __pbn__TypeParameter = value; } + } + public bool ShouldSerializeTypeParameter () => __pbn__TypeParameter != null; + public void ResetTypeParameter () => __pbn__TypeParameter = null; + private int? __pbn__TypeParameter; + + [global::ProtoBuf.ProtoMember (9, Name = @"type_parameter_name")] + public int TypeParameterName { + get { return __pbn__TypeParameterName.GetValueOrDefault (); } + set { __pbn__TypeParameterName = value; } + } + public bool ShouldSerializeTypeParameterName () => __pbn__TypeParameterName != null; + public void ResetTypeParameterName () => __pbn__TypeParameterName = null; + private int? __pbn__TypeParameterName; + + [global::ProtoBuf.ProtoMember (12, Name = @"type_alias_name")] + public int TypeAliasName { + get { return __pbn__TypeAliasName.GetValueOrDefault (); } + set { __pbn__TypeAliasName = value; } + } + public bool ShouldSerializeTypeAliasName () => __pbn__TypeAliasName != null; + public void ResetTypeAliasName () => __pbn__TypeAliasName = null; + private int? __pbn__TypeAliasName; + + [global::ProtoBuf.ProtoMember (10, Name = @"outer_type")] + public Type OuterType { get; set; } + + [global::ProtoBuf.ProtoMember (11, Name = @"outer_type_id")] + public int OuterTypeId { + get { return __pbn__OuterTypeId.GetValueOrDefault (); } + set { __pbn__OuterTypeId = value; } + } + public bool ShouldSerializeOuterTypeId () => __pbn__OuterTypeId != null; + public void ResetOuterTypeId () => __pbn__OuterTypeId = null; + private int? __pbn__OuterTypeId; + + [global::ProtoBuf.ProtoMember (13, Name = @"abbreviated_type")] + public Type AbbreviatedType { get; set; } + + [global::ProtoBuf.ProtoMember (14, Name = @"abbreviated_type_id")] + public int AbbreviatedTypeId { + get { return __pbn__AbbreviatedTypeId.GetValueOrDefault (); } + set { __pbn__AbbreviatedTypeId = value; } + } + public bool ShouldSerializeAbbreviatedTypeId () => __pbn__AbbreviatedTypeId != null; + public void ResetAbbreviatedTypeId () => __pbn__AbbreviatedTypeId = null; + private int? __pbn__AbbreviatedTypeId; + + [global::ProtoBuf.ProtoMember (1, Name = @"flags")] + public int Flags { + get { return __pbn__Flags.GetValueOrDefault (); } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoContract ()] + public partial class Argument : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1)] + [global::System.ComponentModel.DefaultValue (Projection.Inv)] + public Projection projection { + get { return __pbn__projection ?? Projection.Inv; } + set { __pbn__projection = value; } + } + public bool ShouldSerializeprojection () => __pbn__projection != null; + public void Resetprojection () => __pbn__projection = null; + private Projection? __pbn__projection; + + [global::ProtoBuf.ProtoMember (2, Name = @"type")] + public Type Type { get; set; } + + [global::ProtoBuf.ProtoMember (3, Name = @"type_id")] + public int TypeId { + get { return __pbn__TypeId.GetValueOrDefault (); } + set { __pbn__TypeId = value; } + } + public bool ShouldSerializeTypeId () => __pbn__TypeId != null; + public void ResetTypeId () => __pbn__TypeId = null; + private int? __pbn__TypeId; + + [global::ProtoBuf.ProtoContract ()] + public enum Projection + { + [global::ProtoBuf.ProtoEnum (Name = @"IN")] + In = 0, + [global::ProtoBuf.ProtoEnum (Name = @"OUT")] + Out = 1, + [global::ProtoBuf.ProtoEnum (Name = @"INV")] + Inv = 2, + [global::ProtoBuf.ProtoEnum (Name = @"STAR")] + Star = 3, + } + + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class TypeParameter : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"id", IsRequired = true)] + public int Id { get; set; } + + [global::ProtoBuf.ProtoMember (2, Name = @"name", IsRequired = true)] + public int Name { get; set; } + + [global::ProtoBuf.ProtoMember (3, Name = @"reified")] + [global::System.ComponentModel.DefaultValue (false)] + public bool Reified { + get { return __pbn__Reified ?? false; } + set { __pbn__Reified = value; } + } + public bool ShouldSerializeReified () => __pbn__Reified != null; + public void ResetReified () => __pbn__Reified = null; + private bool? __pbn__Reified; + + [global::ProtoBuf.ProtoMember (4)] + [global::System.ComponentModel.DefaultValue (Variance.Inv)] + public Variance variance { + get { return __pbn__variance ?? Variance.Inv; } + set { __pbn__variance = value; } + } + public bool ShouldSerializevariance () => __pbn__variance != null; + public void Resetvariance () => __pbn__variance = null; + private Variance? __pbn__variance; + + [global::ProtoBuf.ProtoMember (5, Name = @"upper_bound")] + public global::System.Collections.Generic.List UpperBounds { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (6, Name = @"upper_bound_id", IsPacked = true)] + public int [] UpperBoundIds { get; set; } + + [global::ProtoBuf.ProtoContract ()] + public enum Variance + { + [global::ProtoBuf.ProtoEnum (Name = @"IN")] + In = 0, + [global::ProtoBuf.ProtoEnum (Name = @"OUT")] + Out = 1, + [global::ProtoBuf.ProtoEnum (Name = @"INV")] + Inv = 2, + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Class : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"flags")] + [global::System.ComponentModel.DefaultValue (6)] + public int Flags { + get { return __pbn__Flags ?? 6; } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoMember (3, Name = @"fq_name", IsRequired = true)] + public int FqName { get; set; } + + [global::ProtoBuf.ProtoMember (4, Name = @"companion_object_name")] + public int CompanionObjectName { + get { return __pbn__CompanionObjectName.GetValueOrDefault (); } + set { __pbn__CompanionObjectName = value; } + } + public bool ShouldSerializeCompanionObjectName () => __pbn__CompanionObjectName != null; + public void ResetCompanionObjectName () => __pbn__CompanionObjectName = null; + private int? __pbn__CompanionObjectName; + + [global::ProtoBuf.ProtoMember (5, Name = @"type_parameter")] + public global::System.Collections.Generic.List TypeParameters { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (6, Name = @"supertype")] + public global::System.Collections.Generic.List Supertypes { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (2, Name = @"supertype_id", IsPacked = true)] + public int [] SupertypeIds { get; set; } + + [global::ProtoBuf.ProtoMember (7, Name = @"nested_class_name", IsPacked = true)] + public int [] NestedClassNames { get; set; } + + [global::ProtoBuf.ProtoMember (8, Name = @"constructor")] + public global::System.Collections.Generic.List Constructors { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (9, Name = @"function")] + public global::System.Collections.Generic.List Functions { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (10, Name = @"property")] + public global::System.Collections.Generic.List Properties { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (11, Name = @"type_alias")] + public global::System.Collections.Generic.List TypeAlias { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (13, Name = @"enum_entry")] + public global::System.Collections.Generic.List EnumEntries { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (16, Name = @"sealed_subclass_fq_name", IsPacked = true)] + public int [] SealedSubclassFqNames { get; set; } + + [global::ProtoBuf.ProtoMember (30, Name = @"type_table")] + public TypeTable TypeTable { get; set; } + + [global::ProtoBuf.ProtoMember (31, Name = @"version_requirement")] + public int [] VersionRequirements { get; set; } + + [global::ProtoBuf.ProtoMember (32, Name = @"version_requirement_table")] + public VersionRequirementTable VersionRequirementTable { get; set; } + + [global::ProtoBuf.ProtoContract ()] + public enum Kind + { + [global::ProtoBuf.ProtoEnum (Name = @"CLASS")] + Class = 0, + [global::ProtoBuf.ProtoEnum (Name = @"INTERFACE")] + Interface = 1, + [global::ProtoBuf.ProtoEnum (Name = @"ENUM_CLASS")] + EnumClass = 2, + [global::ProtoBuf.ProtoEnum (Name = @"ENUM_ENTRY")] + EnumEntry = 3, + [global::ProtoBuf.ProtoEnum (Name = @"ANNOTATION_CLASS")] + AnnotationClass = 4, + [global::ProtoBuf.ProtoEnum (Name = @"OBJECT")] + Object = 5, + [global::ProtoBuf.ProtoEnum (Name = @"COMPANION_OBJECT")] + CompanionObject = 6, + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Package : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (3, Name = @"function")] + public global::System.Collections.Generic.List Functions { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (4, Name = @"property")] + public global::System.Collections.Generic.List Properties { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (5, Name = @"type_alias")] + public global::System.Collections.Generic.List TypeAlias { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (30, Name = @"type_table")] + public TypeTable TypeTable { get; set; } + + [global::ProtoBuf.ProtoMember (32, Name = @"version_requirement_table")] + public VersionRequirementTable VersionRequirementTable { get; set; } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class TypeTable : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"type")] + public global::System.Collections.Generic.List Types { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (2, Name = @"first_nullable")] + [global::System.ComponentModel.DefaultValue (-1)] + public int FirstNullable { + get { return __pbn__FirstNullable ?? -1; } + set { __pbn__FirstNullable = value; } + } + public bool ShouldSerializeFirstNullable () => __pbn__FirstNullable != null; + public void ResetFirstNullable () => __pbn__FirstNullable = null; + private int? __pbn__FirstNullable; + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Constructor : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"flags")] + [global::System.ComponentModel.DefaultValue (6)] + public int Flags { + get { return __pbn__Flags ?? 6; } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoMember (2, Name = @"value_parameter")] + public global::System.Collections.Generic.List ValueParameters { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (31, Name = @"version_requirement")] + public int [] VersionRequirements { get; set; } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Function : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (9, Name = @"flags")] + [global::System.ComponentModel.DefaultValue (6)] + public int Flags { + get { return __pbn__Flags ?? 6; } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoMember (1, Name = @"old_flags")] + [global::System.ComponentModel.DefaultValue (6)] + public int OldFlags { + get { return __pbn__OldFlags ?? 6; } + set { __pbn__OldFlags = value; } + } + public bool ShouldSerializeOldFlags () => __pbn__OldFlags != null; + public void ResetOldFlags () => __pbn__OldFlags = null; + private int? __pbn__OldFlags; + + [global::ProtoBuf.ProtoMember (2, Name = @"name", IsRequired = true)] + public int Name { get; set; } + + [global::ProtoBuf.ProtoMember (3, Name = @"return_type")] + public Type ReturnType { get; set; } + + [global::ProtoBuf.ProtoMember (7, Name = @"return_type_id")] + public int ReturnTypeId { + get { return __pbn__ReturnTypeId.GetValueOrDefault (); } + set { __pbn__ReturnTypeId = value; } + } + public bool ShouldSerializeReturnTypeId () => __pbn__ReturnTypeId != null; + public void ResetReturnTypeId () => __pbn__ReturnTypeId = null; + private int? __pbn__ReturnTypeId; + + [global::ProtoBuf.ProtoMember (4, Name = @"type_parameter")] + public global::System.Collections.Generic.List TypeParameters { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (5, Name = @"receiver_type")] + public Type ReceiverType { get; set; } + + [global::ProtoBuf.ProtoMember (8, Name = @"receiver_type_id")] + public int ReceiverTypeId { + get { return __pbn__ReceiverTypeId.GetValueOrDefault (); } + set { __pbn__ReceiverTypeId = value; } + } + public bool ShouldSerializeReceiverTypeId () => __pbn__ReceiverTypeId != null; + public void ResetReceiverTypeId () => __pbn__ReceiverTypeId = null; + private int? __pbn__ReceiverTypeId; + + [global::ProtoBuf.ProtoMember (6, Name = @"value_parameter")] + public global::System.Collections.Generic.List ValueParameters { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (30, Name = @"type_table")] + public TypeTable TypeTable { get; set; } + + [global::ProtoBuf.ProtoMember (31, Name = @"version_requirement")] + public int [] VersionRequirements { get; set; } + + [global::ProtoBuf.ProtoMember (32, Name = @"contract")] + public Contract Contract { get; set; } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Property : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (11, Name = @"flags")] + [global::System.ComponentModel.DefaultValue (518)] + public int Flags { + get { return __pbn__Flags ?? 518; } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoMember (1, Name = @"old_flags")] + [global::System.ComponentModel.DefaultValue (2054)] + public int OldFlags { + get { return __pbn__OldFlags ?? 2054; } + set { __pbn__OldFlags = value; } + } + public bool ShouldSerializeOldFlags () => __pbn__OldFlags != null; + public void ResetOldFlags () => __pbn__OldFlags = null; + private int? __pbn__OldFlags; + + [global::ProtoBuf.ProtoMember (2, Name = @"name", IsRequired = true)] + public int Name { get; set; } + + [global::ProtoBuf.ProtoMember (3, Name = @"return_type")] + public Type ReturnType { get; set; } + + [global::ProtoBuf.ProtoMember (9, Name = @"return_type_id")] + public int ReturnTypeId { + get { return __pbn__ReturnTypeId.GetValueOrDefault (); } + set { __pbn__ReturnTypeId = value; } + } + public bool ShouldSerializeReturnTypeId () => __pbn__ReturnTypeId != null; + public void ResetReturnTypeId () => __pbn__ReturnTypeId = null; + private int? __pbn__ReturnTypeId; + + [global::ProtoBuf.ProtoMember (4, Name = @"type_parameter")] + public global::System.Collections.Generic.List TypeParameters { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (5, Name = @"receiver_type")] + public Type ReceiverType { get; set; } + + [global::ProtoBuf.ProtoMember (10, Name = @"receiver_type_id")] + public int ReceiverTypeId { + get { return __pbn__ReceiverTypeId.GetValueOrDefault (); } + set { __pbn__ReceiverTypeId = value; } + } + public bool ShouldSerializeReceiverTypeId () => __pbn__ReceiverTypeId != null; + public void ResetReceiverTypeId () => __pbn__ReceiverTypeId = null; + private int? __pbn__ReceiverTypeId; + + [global::ProtoBuf.ProtoMember (6, Name = @"setter_value_parameter")] + public ValueParameter SetterValueParameter { get; set; } + + [global::ProtoBuf.ProtoMember (7, Name = @"getter_flags")] + public int GetterFlags { + get { return __pbn__GetterFlags.GetValueOrDefault (); } + set { __pbn__GetterFlags = value; } + } + public bool ShouldSerializeGetterFlags () => __pbn__GetterFlags != null; + public void ResetGetterFlags () => __pbn__GetterFlags = null; + private int? __pbn__GetterFlags; + + [global::ProtoBuf.ProtoMember (8, Name = @"setter_flags")] + public int SetterFlags { + get { return __pbn__SetterFlags.GetValueOrDefault (); } + set { __pbn__SetterFlags = value; } + } + public bool ShouldSerializeSetterFlags () => __pbn__SetterFlags != null; + public void ResetSetterFlags () => __pbn__SetterFlags = null; + private int? __pbn__SetterFlags; + + [global::ProtoBuf.ProtoMember (31, Name = @"version_requirement")] + public int [] VersionRequirements { get; set; } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class ValueParameter : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"flags")] + [global::System.ComponentModel.DefaultValue (0)] + public int Flags { + get { return __pbn__Flags ?? 0; } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoMember (2, Name = @"name", IsRequired = true)] + public int Name { get; set; } + + [global::ProtoBuf.ProtoMember (3, Name = @"type")] + public Type Type { get; set; } + + [global::ProtoBuf.ProtoMember (5, Name = @"type_id")] + public int TypeId { + get { return __pbn__TypeId.GetValueOrDefault (); } + set { __pbn__TypeId = value; } + } + public bool ShouldSerializeTypeId () => __pbn__TypeId != null; + public void ResetTypeId () => __pbn__TypeId = null; + private int? __pbn__TypeId; + + [global::ProtoBuf.ProtoMember (4, Name = @"vararg_element_type")] + public Type VarargElementType { get; set; } + + [global::ProtoBuf.ProtoMember (6, Name = @"vararg_element_type_id")] + public int VarargElementTypeId { + get { return __pbn__VarargElementTypeId.GetValueOrDefault (); } + set { __pbn__VarargElementTypeId = value; } + } + public bool ShouldSerializeVarargElementTypeId () => __pbn__VarargElementTypeId != null; + public void ResetVarargElementTypeId () => __pbn__VarargElementTypeId = null; + private int? __pbn__VarargElementTypeId; + + } + + [global::ProtoBuf.ProtoContract ()] + partial class TypeAlias : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"flags")] + [global::System.ComponentModel.DefaultValue (6)] + public int Flags { + get { return __pbn__Flags ?? 6; } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoMember (2, Name = @"name", IsRequired = true)] + public int Name { get; set; } + + [global::ProtoBuf.ProtoMember (3, Name = @"type_parameter")] + public global::System.Collections.Generic.List TypeParameters { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (4, Name = @"underlying_type")] + public Type UnderlyingType { get; set; } + + [global::ProtoBuf.ProtoMember (5, Name = @"underlying_type_id")] + public int UnderlyingTypeId { + get { return __pbn__UnderlyingTypeId.GetValueOrDefault (); } + set { __pbn__UnderlyingTypeId = value; } + } + public bool ShouldSerializeUnderlyingTypeId () => __pbn__UnderlyingTypeId != null; + public void ResetUnderlyingTypeId () => __pbn__UnderlyingTypeId = null; + private int? __pbn__UnderlyingTypeId; + + [global::ProtoBuf.ProtoMember (6, Name = @"expanded_type")] + public Type ExpandedType { get; set; } + + [global::ProtoBuf.ProtoMember (7, Name = @"expanded_type_id")] + public int ExpandedTypeId { + get { return __pbn__ExpandedTypeId.GetValueOrDefault (); } + set { __pbn__ExpandedTypeId = value; } + } + public bool ShouldSerializeExpandedTypeId () => __pbn__ExpandedTypeId != null; + public void ResetExpandedTypeId () => __pbn__ExpandedTypeId = null; + private int? __pbn__ExpandedTypeId; + + [global::ProtoBuf.ProtoMember (8, Name = @"annotation")] + public global::System.Collections.Generic.List Annotations { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (31, Name = @"version_requirement")] + public int [] VersionRequirements { get; set; } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class EnumEntry : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"name")] + public int Name { + get { return __pbn__Name.GetValueOrDefault (); } + set { __pbn__Name = value; } + } + public bool ShouldSerializeName () => __pbn__Name != null; + public void ResetName () => __pbn__Name = null; + private int? __pbn__Name; + + } + + [global::ProtoBuf.ProtoContract ()] + partial class VersionRequirement : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"version")] + public int Version { + get { return __pbn__Version.GetValueOrDefault (); } + set { __pbn__Version = value; } + } + public bool ShouldSerializeVersion () => __pbn__Version != null; + public void ResetVersion () => __pbn__Version = null; + private int? __pbn__Version; + + [global::ProtoBuf.ProtoMember (2, Name = @"version_full")] + public int VersionFull { + get { return __pbn__VersionFull.GetValueOrDefault (); } + set { __pbn__VersionFull = value; } + } + public bool ShouldSerializeVersionFull () => __pbn__VersionFull != null; + public void ResetVersionFull () => __pbn__VersionFull = null; + private int? __pbn__VersionFull; + + [global::ProtoBuf.ProtoMember (3)] + [global::System.ComponentModel.DefaultValue (Level.Error)] + public Level level { + get { return __pbn__level ?? Level.Error; } + set { __pbn__level = value; } + } + public bool ShouldSerializelevel () => __pbn__level != null; + public void Resetlevel () => __pbn__level = null; + private Level? __pbn__level; + + [global::ProtoBuf.ProtoMember (4, Name = @"error_code")] + public int ErrorCode { + get { return __pbn__ErrorCode.GetValueOrDefault (); } + set { __pbn__ErrorCode = value; } + } + public bool ShouldSerializeErrorCode () => __pbn__ErrorCode != null; + public void ResetErrorCode () => __pbn__ErrorCode = null; + private int? __pbn__ErrorCode; + + [global::ProtoBuf.ProtoMember (5, Name = @"message")] + public int Message { + get { return __pbn__Message.GetValueOrDefault (); } + set { __pbn__Message = value; } + } + public bool ShouldSerializeMessage () => __pbn__Message != null; + public void ResetMessage () => __pbn__Message = null; + private int? __pbn__Message; + + [global::ProtoBuf.ProtoMember (6)] + [global::System.ComponentModel.DefaultValue (VersionKind.LanguageVersion)] + public VersionKind version_kind { + get { return __pbn__version_kind ?? VersionKind.LanguageVersion; } + set { __pbn__version_kind = value; } + } + public bool ShouldSerializeversion_kind () => __pbn__version_kind != null; + public void Resetversion_kind () => __pbn__version_kind = null; + private VersionKind? __pbn__version_kind; + + [global::ProtoBuf.ProtoContract ()] + public enum Level + { + [global::ProtoBuf.ProtoEnum (Name = @"WARNING")] + Warning = 0, + [global::ProtoBuf.ProtoEnum (Name = @"ERROR")] + Error = 1, + [global::ProtoBuf.ProtoEnum (Name = @"HIDDEN")] + Hidden = 2, + } + + [global::ProtoBuf.ProtoContract ()] + public enum VersionKind + { + [global::ProtoBuf.ProtoEnum (Name = @"LANGUAGE_VERSION")] + LanguageVersion = 0, + [global::ProtoBuf.ProtoEnum (Name = @"COMPILER_VERSION")] + CompilerVersion = 1, + [global::ProtoBuf.ProtoEnum (Name = @"API_VERSION")] + ApiVersion = 2, + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class VersionRequirementTable : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"requirement")] + public global::System.Collections.Generic.List Requirements { get; set; } = new global::System.Collections.Generic.List (); + + } + + [global::ProtoBuf.ProtoContract ()] + partial class PackageFragment : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"strings")] + public StringTable Strings { get; set; } + + [global::ProtoBuf.ProtoMember (2, Name = @"qualified_names")] + public QualifiedNameTable QualifiedNames { get; set; } + + [global::ProtoBuf.ProtoMember (3, Name = @"package")] + public Package Package { get; set; } + + [global::ProtoBuf.ProtoMember (4, Name = @"class")] + public global::System.Collections.Generic.List Classes { get; set; } = new global::System.Collections.Generic.List (); + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Contract : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"effect")] + public global::System.Collections.Generic.List Effects { get; set; } = new global::System.Collections.Generic.List (); + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Effect : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1)] + [global::System.ComponentModel.DefaultValue (EffectType.ReturnsConstant)] + public EffectType effect_type { + get { return __pbn__effect_type ?? EffectType.ReturnsConstant; } + set { __pbn__effect_type = value; } + } + public bool ShouldSerializeeffect_type () => __pbn__effect_type != null; + public void Reseteffect_type () => __pbn__effect_type = null; + private EffectType? __pbn__effect_type; + + [global::ProtoBuf.ProtoMember (2, Name = @"effect_constructor_argument")] + public global::System.Collections.Generic.List EffectConstructorArguments { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (3, Name = @"conclusion_of_conditional_effect")] + public Expression ConclusionOfConditionalEffect { get; set; } + + [global::ProtoBuf.ProtoMember (4, Name = @"kind")] + [global::System.ComponentModel.DefaultValue (InvocationKind.AtMostOnce)] + public InvocationKind Kind { + get { return __pbn__Kind ?? InvocationKind.AtMostOnce; } + set { __pbn__Kind = value; } + } + public bool ShouldSerializeKind () => __pbn__Kind != null; + public void ResetKind () => __pbn__Kind = null; + private InvocationKind? __pbn__Kind; + + [global::ProtoBuf.ProtoContract ()] + public enum EffectType + { + [global::ProtoBuf.ProtoEnum (Name = @"RETURNS_CONSTANT")] + ReturnsConstant = 0, + [global::ProtoBuf.ProtoEnum (Name = @"CALLS")] + Calls = 1, + [global::ProtoBuf.ProtoEnum (Name = @"RETURNS_NOT_NULL")] + ReturnsNotNull = 2, + } + + [global::ProtoBuf.ProtoContract ()] + public enum InvocationKind + { + [global::ProtoBuf.ProtoEnum (Name = @"AT_MOST_ONCE")] + AtMostOnce = 0, + [global::ProtoBuf.ProtoEnum (Name = @"EXACTLY_ONCE")] + ExactlyOnce = 1, + [global::ProtoBuf.ProtoEnum (Name = @"AT_LEAST_ONCE")] + AtLeastOnce = 2, + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class Expression : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"flags")] + [global::System.ComponentModel.DefaultValue (0)] + public int Flags { + get { return __pbn__Flags ?? 0; } + set { __pbn__Flags = value; } + } + public bool ShouldSerializeFlags () => __pbn__Flags != null; + public void ResetFlags () => __pbn__Flags = null; + private int? __pbn__Flags; + + [global::ProtoBuf.ProtoMember (2, Name = @"value_parameter_reference")] + public int ValueParameterReference { + get { return __pbn__ValueParameterReference.GetValueOrDefault (); } + set { __pbn__ValueParameterReference = value; } + } + public bool ShouldSerializeValueParameterReference () => __pbn__ValueParameterReference != null; + public void ResetValueParameterReference () => __pbn__ValueParameterReference = null; + private int? __pbn__ValueParameterReference; + + [global::ProtoBuf.ProtoMember (3)] + [global::System.ComponentModel.DefaultValue (ConstantValue.True)] + public ConstantValue constant_value { + get { return __pbn__constant_value ?? ConstantValue.True; } + set { __pbn__constant_value = value; } + } + public bool ShouldSerializeconstant_value () => __pbn__constant_value != null; + public void Resetconstant_value () => __pbn__constant_value = null; + private ConstantValue? __pbn__constant_value; + + [global::ProtoBuf.ProtoMember (4, Name = @"is_instance_type")] + public Type IsInstanceType { get; set; } + + [global::ProtoBuf.ProtoMember (5, Name = @"is_instance_type_id")] + public int IsInstanceTypeId { + get { return __pbn__IsInstanceTypeId.GetValueOrDefault (); } + set { __pbn__IsInstanceTypeId = value; } + } + public bool ShouldSerializeIsInstanceTypeId () => __pbn__IsInstanceTypeId != null; + public void ResetIsInstanceTypeId () => __pbn__IsInstanceTypeId = null; + private int? __pbn__IsInstanceTypeId; + + [global::ProtoBuf.ProtoMember (6, Name = @"and_argument")] + public global::System.Collections.Generic.List AndArguments { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (7, Name = @"or_argument")] + public global::System.Collections.Generic.List OrArguments { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoContract ()] + public enum ConstantValue + { + [global::ProtoBuf.ProtoEnum (Name = @"TRUE")] + True = 0, + [global::ProtoBuf.ProtoEnum (Name = @"FALSE")] + False = 1, + [global::ProtoBuf.ProtoEnum (Name = @"NULL")] + Null = 2, + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class StringTableTypes : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"record")] + public global::System.Collections.Generic.List Records { get; set; } = new global::System.Collections.Generic.List (); + + [global::ProtoBuf.ProtoMember (5, Name = @"local_name", IsPacked = true)] + public int [] LocalNames { get; set; } + + [global::ProtoBuf.ProtoContract ()] + public partial class Record : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"range")] + [global::System.ComponentModel.DefaultValue (1)] + public int Range { + get { return __pbn__Range ?? 1; } + set { __pbn__Range = value; } + } + public bool ShouldSerializeRange () => __pbn__Range != null; + public void ResetRange () => __pbn__Range = null; + private int? __pbn__Range; + + [global::ProtoBuf.ProtoMember (2, Name = @"predefined_index")] + public int PredefinedIndex { + get { return __pbn__PredefinedIndex.GetValueOrDefault (); } + set { __pbn__PredefinedIndex = value; } + } + public bool ShouldSerializePredefinedIndex () => __pbn__PredefinedIndex != null; + public void ResetPredefinedIndex () => __pbn__PredefinedIndex = null; + private int? __pbn__PredefinedIndex; + + [global::ProtoBuf.ProtoMember (6, Name = @"string")] + [global::System.ComponentModel.DefaultValue ("")] + public string String { + get { return __pbn__String ?? ""; } + set { __pbn__String = value; } + } + public bool ShouldSerializeString () => __pbn__String != null; + public void ResetString () => __pbn__String = null; + private string __pbn__String; + + [global::ProtoBuf.ProtoMember (3)] + [global::System.ComponentModel.DefaultValue (Operation.None)] + public Operation operation { + get { return __pbn__operation ?? Operation.None; } + set { __pbn__operation = value; } + } + public bool ShouldSerializeoperation () => __pbn__operation != null; + public void Resetoperation () => __pbn__operation = null; + private Operation? __pbn__operation; + + [global::ProtoBuf.ProtoMember (4, Name = @"substring_index", IsPacked = true)] + public int [] SubstringIndexs { get; set; } + + [global::ProtoBuf.ProtoMember (5, Name = @"replace_char", IsPacked = true)] + public int [] ReplaceChars { get; set; } + + [global::ProtoBuf.ProtoContract ()] + public enum Operation + { + [global::ProtoBuf.ProtoEnum (Name = @"NONE")] + None = 0, + [global::ProtoBuf.ProtoEnum (Name = @"INTERNAL_TO_CLASS_ID")] + InternalToClassId = 1, + [global::ProtoBuf.ProtoEnum (Name = @"DESC_TO_CLASS_ID")] + DescToClassId = 2, + } + + } + + } + + [global::ProtoBuf.ProtoContract ()] + partial class JvmMethodSignature : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"name")] + public int Name { + get { return __pbn__Name.GetValueOrDefault (); } + set { __pbn__Name = value; } + } + public bool ShouldSerializeName () => __pbn__Name != null; + public void ResetName () => __pbn__Name = null; + private int? __pbn__Name; + + [global::ProtoBuf.ProtoMember (2, Name = @"desc")] + public int Desc { + get { return __pbn__Desc.GetValueOrDefault (); } + set { __pbn__Desc = value; } + } + public bool ShouldSerializeDesc () => __pbn__Desc != null; + public void ResetDesc () => __pbn__Desc = null; + private int? __pbn__Desc; + + } + + [global::ProtoBuf.ProtoContract ()] + partial class JvmFieldSignature : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"name")] + public int Name { + get { return __pbn__Name.GetValueOrDefault (); } + set { __pbn__Name = value; } + } + public bool ShouldSerializeName () => __pbn__Name != null; + public void ResetName () => __pbn__Name = null; + private int? __pbn__Name; + + [global::ProtoBuf.ProtoMember (2, Name = @"desc")] + public int Desc { + get { return __pbn__Desc.GetValueOrDefault (); } + set { __pbn__Desc = value; } + } + public bool ShouldSerializeDesc () => __pbn__Desc != null; + public void ResetDesc () => __pbn__Desc = null; + private int? __pbn__Desc; + + } + + [global::ProtoBuf.ProtoContract ()] + partial class JvmPropertySignature : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject (bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject (ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember (1, Name = @"field")] + public JvmFieldSignature Field { get; set; } + + [global::ProtoBuf.ProtoMember (2, Name = @"synthetic_method")] + public JvmMethodSignature SyntheticMethod { get; set; } + + [global::ProtoBuf.ProtoMember (3, Name = @"getter")] + public JvmMethodSignature Getter { get; set; } + + [global::ProtoBuf.ProtoMember (4, Name = @"setter")] + public JvmMethodSignature Setter { get; set; } + + } + + [global::ProtoBuf.ProtoContract ()] + enum Modality + { + [global::ProtoBuf.ProtoEnum (Name = @"FINAL")] + Final = 0, + [global::ProtoBuf.ProtoEnum (Name = @"OPEN")] + Open = 1, + [global::ProtoBuf.ProtoEnum (Name = @"ABSTRACT")] + Abstract = 2, + [global::ProtoBuf.ProtoEnum (Name = @"SEALED")] + Sealed = 3, + } + + [global::ProtoBuf.ProtoContract ()] + enum Visibility + { + [global::ProtoBuf.ProtoEnum (Name = @"INTERNAL")] + Internal = 0, + [global::ProtoBuf.ProtoEnum (Name = @"PRIVATE")] + Private = 1, + [global::ProtoBuf.ProtoEnum (Name = @"PROTECTED")] + Protected = 2, + [global::ProtoBuf.ProtoEnum (Name = @"PUBLIC")] + Public = 3, + [global::ProtoBuf.ProtoEnum (Name = @"PRIVATE_TO_THIS")] + PrivateToThis = 4, + [global::ProtoBuf.ProtoEnum (Name = @"LOCAL")] + Local = 5, + } + + [global::ProtoBuf.ProtoContract ()] + enum MemberKind + { + [global::ProtoBuf.ProtoEnum (Name = @"DECLARATION")] + Declaration = 0, + [global::ProtoBuf.ProtoEnum (Name = @"FAKE_OVERRIDE")] + FakeOverride = 1, + [global::ProtoBuf.ProtoEnum (Name = @"DELEGATION")] + Delegation = 2, + [global::ProtoBuf.ProtoEnum (Name = @"SYNTHESIZED")] + Synthesized = 3, + } + + static class Extensions + { + //public static bool GetSkipInComparison (this global::Google.Protobuf.Reflection.FieldOptions obj) + // => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 50000); + + //public static void SetSkipInComparison (this global::Google.Protobuf.Reflection.FieldOptions obj, bool value) + // => global::ProtoBuf.Extensible.AppendValue (obj, 50000, value); + + //public static bool GetNameIdInTable (this global::Google.Protobuf.Reflection.FieldOptions obj) + // => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 50001); + + //public static void SetNameIdInTable (this global::Google.Protobuf.Reflection.FieldOptions obj, bool value) + // => global::ProtoBuf.Extensible.AppendValue (obj, 50001, value); + + //public static bool GetFqNameIdInTable (this global::Google.Protobuf.Reflection.FieldOptions obj) + // => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 50002); + + //public static void SetFqNameIdInTable (this global::Google.Protobuf.Reflection.FieldOptions obj, bool value) + // => global::ProtoBuf.Extensible.AppendValue (obj, 50002, value); + + //public static bool GetStringIdInTable (this global::Google.Protobuf.Reflection.FieldOptions obj) + // => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 50003); + + //public static void SetStringIdInTable (this global::Google.Protobuf.Reflection.FieldOptions obj, bool value) + // => global::ProtoBuf.Extensible.AppendValue (obj, 50003, value); + + public static JvmMethodSignature GetConstructorSignature (this Constructor obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 100); + + public static void SetConstructorSignature (this Constructor obj, JvmMethodSignature value) + => global::ProtoBuf.Extensible.AppendValue (obj, 100, value); + + public static JvmMethodSignature GetMethodSignature (this Function obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 100); + + public static void SetMethodSignature (this Function obj, JvmMethodSignature value) + => global::ProtoBuf.Extensible.AppendValue (obj, 100, value); + + public static int GetLambdaClassOriginName (this Function obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 101); + + public static void SetLambdaClassOriginName (this Function obj, int value) + => global::ProtoBuf.Extensible.AppendValue (obj, 101, value); + + public static JvmPropertySignature GetPropertySignature (this Property obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 100); + + public static void SetPropertySignature (this Property obj, JvmPropertySignature value) + => global::ProtoBuf.Extensible.AppendValue (obj, 100, value); + + public static int GetFlags (this Property obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 101); + + public static void SetFlags (this Property obj, int value) + => global::ProtoBuf.Extensible.AppendValue (obj, 101, value); + + public static global::System.Collections.Generic.IEnumerable GetTypeAnnotations (this Type obj) + => obj == null ? null : global::ProtoBuf.Extensible.GetValues (obj, 100); + + public static void AddTypeAnnotations (this Type obj, Annotation value) + => global::ProtoBuf.Extensible.AppendValue (obj, 100, value); + + public static bool GetIsRaw (this Type obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 101); + + public static void SetIsRaw (this Type obj, bool value) + => global::ProtoBuf.Extensible.AppendValue (obj, 101, value); + + public static global::System.Collections.Generic.IEnumerable GetTypeParameterAnnotations (this TypeParameter obj) + => obj == null ? null : global::ProtoBuf.Extensible.GetValues (obj, 100); + + public static void AddTypeParameterAnnotations (this TypeParameter obj, Annotation value) + => global::ProtoBuf.Extensible.AppendValue (obj, 100, value); + + public static int GetClassModuleName (this Class obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 101); + + public static void SetClassModuleName (this Class obj, int value) + => global::ProtoBuf.Extensible.AppendValue (obj, 101, value); + + public static global::System.Collections.Generic.IEnumerable GetClassLocalVariables (this Class obj) + => obj == null ? null : global::ProtoBuf.Extensible.GetValues (obj, 102); + + public static void AddClassLocalVariables (this Class obj, Property value) + => global::ProtoBuf.Extensible.AppendValue (obj, 102, value); + + public static int GetAnonymousObjectOriginName (this Class obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 103); + + public static void SetAnonymousObjectOriginName (this Class obj, int value) + => global::ProtoBuf.Extensible.AppendValue (obj, 103, value); + + public static int GetPackageModuleName (this Package obj) + => obj == null ? default : global::ProtoBuf.Extensible.GetValue (obj, 101); + + public static void SetPackageModuleName (this Package obj, int value) + => global::ProtoBuf.Extensible.AppendValue (obj, 101, value); + + public static global::System.Collections.Generic.IEnumerable GetPackageLocalVariables (this Package obj) + => obj == null ? null : global::ProtoBuf.Extensible.GetValues (obj, 102); + + public static void AddPackageLocalVariables (this Package obj, Property value) + => global::ProtoBuf.Extensible.AppendValue (obj, 102, value); + + } +} + +#pragma warning restore CS1591, CS0612, CS3021, IDE1006 diff --git a/src/Xamarin.Android.Tools.Bytecode/Kotlin/PartialStream.cs b/src/Xamarin.Android.Tools.Bytecode/Kotlin/PartialStream.cs new file mode 100644 index 000000000..95053cb6b --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Kotlin/PartialStream.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; + +namespace Xamarin.Android.Tools.Bytecode +{ + // This takes a Stream that contains several separate messages and provides callers + // a slice of it so it appears like a Stream that only contains a single message. + // This is more efficient than copying each message into a separate Stream. + public class PartialStream : Stream + { + readonly Stream stream; + long start; + long length; + + public PartialStream (Stream stream, long start) : this (stream, start, stream.Length - start) { } + + public PartialStream (Stream stream, long start, long length) + { + this.stream = stream; + this.start = start; + this.length = length; + + this.stream.Position = start; + } + + public void MoveNext () => MoveNext (stream.Length - start - length); + + // Move to the next message in the original Stream + public void MoveNext (long length) + { + start += this.length; + this.length = length; + } + + public override bool CanRead => stream.CanRead; + + public override bool CanSeek => false; + + public override bool CanWrite => false; + + public override long Length => length; + + public override long Position { + get => stream.Position - start; + set => stream.Position = value + start; + } + + public override void Flush () => stream.Flush (); + + public override int Read (byte [] buffer, int offset, int count) => stream.Read (buffer, offset, (int) Math.Min (count, Length - Position)); + + public override long Seek (long offset, SeekOrigin origin) => throw new NotImplementedException (); + + public override void SetLength (long value) => throw new NotImplementedException (); + + public override void Write (byte [] buffer, int offset, int count) => throw new NotImplementedException (); + } +} diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/ClassFileFixture.cs b/src/Xamarin.Android.Tools.Bytecode/Tests/ClassFileFixture.cs index 2eac73bc6..14c852bc2 100644 --- a/src/Xamarin.Android.Tools.Bytecode/Tests/ClassFileFixture.cs +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/ClassFileFixture.cs @@ -13,8 +13,13 @@ public class ClassFileFixture { protected static ClassFile LoadClassFile (string resource) { - using (var s = Assembly.GetExecutingAssembly ().GetManifestResourceStream (resource)) { - return new ClassFile (s); + // Look for resources that end with our name, this allows us to + // avoid the LogicalName stuff + var assembly = Assembly.GetExecutingAssembly (); + var name = assembly.GetManifestResourceNames ().FirstOrDefault (n => n.EndsWith (resource, StringComparison.OrdinalIgnoreCase)) ?? resource; + + using (var stream = assembly.GetManifestResourceStream (name)) { + return new ClassFile (stream); } } diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/KotlinMetadataTests.cs b/src/Xamarin.Android.Tools.Bytecode/Tests/KotlinMetadataTests.cs new file mode 100644 index 000000000..1a8da6a85 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/KotlinMetadataTests.cs @@ -0,0 +1,73 @@ +using System; +using Xamarin.Android.Tools.Bytecode; +using NUnit.Framework; +using System.Linq; + +namespace Xamarin.Android.Tools.BytecodeTests +{ + [TestFixture] + public class KotlinMetadataTests : ClassFileFixture + { + [Test] + public void PublicKotlinClassFile () + { + var meta = GetMetadataForClassFile ("PublicClass.class"); + + Assert.AreEqual (KotlinMetadataKind.Class, meta.Kind); + + var klass_meta = meta.AsClassMetadata (); + + Assert.True (klass_meta.Flags.HasFlag (KotlinClassFlags.Public)); + } + + [Test] + public void PrivateKotlinClassFile () + { + var meta = GetMetadataForClassFile ("PrivateClass.class"); + + Assert.AreEqual (KotlinMetadataKind.Class, meta.Kind); + + var klass_meta = meta.AsClassMetadata (); + + Assert.True (klass_meta.Flags.HasFlag (KotlinClassFlags.Private)); + } + + [Test] + public void InternalKotlinClassFile () + { + var meta = GetMetadataForClassFile ("InternalClass.class"); + + Assert.AreEqual (KotlinMetadataKind.Class, meta.Kind); + + var klass_meta = meta.AsClassMetadata (); + + Assert.True (klass_meta.Flags.HasFlag (KotlinClassFlags.Internal)); + } + + [Test] + public void ProtectedKotlinClassFile () + { + var meta = GetMetadataForClassFile ("PublicClass$ProtectedClass.class"); + + Assert.AreEqual (KotlinMetadataKind.Class, meta.Kind); + + var klass_meta = meta.AsClassMetadata (); + + Assert.True (klass_meta.Flags.HasFlag (KotlinClassFlags.Protected)); + } + + private KotlinMetadata GetMetadataForClassFile (string file) + { + var c = LoadClassFile (file); + var attr = c.Attributes.OfType ().FirstOrDefault (); + var kotlin = attr?.Annotations.FirstOrDefault (a => a.Type == "Lkotlin/Metadata;"); + + Assert.NotNull (kotlin); + + var meta = KotlinMetadata.FromAnnotation (kotlin); + + return meta; + } + } +} + diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj b/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj index df7c1560b..e9ceff1fa 100644 --- a/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj @@ -46,6 +46,7 @@ + @@ -62,6 +63,7 @@ BuildClasses; + BuildKotlinClasses; $(BuildDependsOn) @@ -168,6 +170,7 @@ + \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.targets b/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.targets index 7090d5673..b902b9075 100644 --- a/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.targets +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/Xamarin.Android.Tools.Bytecode-Tests.targets @@ -3,6 +3,7 @@ + + + + + + \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/InternalClass.class b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/InternalClass.class new file mode 100644 index 000000000..aa615c801 Binary files /dev/null and b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/InternalClass.class differ diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/InternalClass.kt b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/InternalClass.kt new file mode 100644 index 000000000..8cd461778 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/InternalClass.kt @@ -0,0 +1 @@ +internal class InternalClass \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PrivateClass.class b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PrivateClass.class new file mode 100644 index 000000000..c6721027c Binary files /dev/null and b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PrivateClass.class differ diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PrivateClass.kt b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PrivateClass.kt new file mode 100644 index 000000000..fdf66c409 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PrivateClass.kt @@ -0,0 +1 @@ +private class PrivateClass \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass$ProtectedClass.class b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass$ProtectedClass.class new file mode 100644 index 000000000..d3ea5a8b4 Binary files /dev/null and b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass$ProtectedClass.class differ diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass.class b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass.class new file mode 100644 index 000000000..a5bc823f5 Binary files /dev/null and b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass.class differ diff --git a/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass.kt b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass.kt new file mode 100644 index 000000000..e809d056b --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/Tests/kotlin/PublicClass.kt @@ -0,0 +1,3 @@ +class PublicClass { + protected class ProtectedClass { } +} \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.Bytecode/Xamarin.Android.Tools.Bytecode.csproj b/src/Xamarin.Android.Tools.Bytecode/Xamarin.Android.Tools.Bytecode.csproj index 5808c2471..3e48c133a 100644 --- a/src/Xamarin.Android.Tools.Bytecode/Xamarin.Android.Tools.Bytecode.csproj +++ b/src/Xamarin.Android.Tools.Bytecode/Xamarin.Android.Tools.Bytecode.csproj @@ -11,6 +11,7 @@ AnyCPU 8.0.30703 2.0 + 7.2 true @@ -31,7 +32,13 @@ true + + ..\..\packages\protobuf-net.2.4.0\lib\net40\protobuf-net.dll + + + + @@ -41,6 +48,13 @@ + + + + + + + @@ -53,5 +67,8 @@ + + + - + \ No newline at end of file diff --git a/src/Xamarin.Android.Tools.Bytecode/packages.config b/src/Xamarin.Android.Tools.Bytecode/packages.config new file mode 100644 index 000000000..f118a84c3 --- /dev/null +++ b/src/Xamarin.Android.Tools.Bytecode/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file