From 9a23a7f3c5d499dd6ddb018383e355f3ab9146a1 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 4 Jul 2014 18:42:29 -0500 Subject: [PATCH] Map java.util.UUID to System.Guid --- reference/sharpen-all-options.txt | 1 + .../Antlr4.Runtime/Atn/ATNDeserializer.cs | 28 +++++++++---------- .../Antlr4.Runtime/Atn/ATNSerializer.cs | 4 +-- .../CSharp/Antlr4.Runtime/Atn/ATNSimulator.cs | 4 +-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/reference/sharpen-all-options.txt b/reference/sharpen-all-options.txt index efcd0492c..790305ee9 100644 --- a/reference/sharpen-all-options.txt +++ b/reference/sharpen-all-options.txt @@ -143,6 +143,7 @@ -typeMapping java.util.concurrent.Semaphore System.Threading.Semaphore -typeMapping java.util.Enumeration System.Collections.Generic.IEnumeration -typeMapping java.lang.ProcessBuilder System.Diagnostics.ProcessStartInfo +-typeMapping java.util.UUID System.Guid -propertyMapping java.lang.Class.getSimpleName Name -propertyMapping java.nio.charset.Charset.defaultCharset Default -propertyMapping java.util.Locale.getDefault CurrentCulture diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs index fdbba2b3f..0d3b97265 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs @@ -50,7 +50,7 @@ namespace Antlr4.Runtime.Atn /// This is the earliest supported serialized UUID. /// This is the earliest supported serialized UUID. - private static readonly UUID BaseSerializedUuid; + private static readonly Guid BaseSerializedUuid; /// /// This UUID indicates an extension of @@ -59,7 +59,7 @@ namespace Antlr4.Runtime.Atn /// /// instances. /// - private static readonly UUID AddedLexerActions; + private static readonly Guid AddedLexerActions; /// /// This list contains all of the currently supported UUIDs, ordered by when @@ -69,17 +69,17 @@ namespace Antlr4.Runtime.Atn /// This list contains all of the currently supported UUIDs, ordered by when /// the feature first appeared in this branch. /// - private static readonly IList SupportedUuids; + private static readonly IList SupportedUuids; /// This is the current serialized UUID. /// This is the current serialized UUID. - public static readonly UUID SerializedUuid; + public static readonly Guid SerializedUuid; static ATNDeserializer() { - BaseSerializedUuid = UUID.FromString("E4178468-DF95-44D0-AD87-F22A5D5FB6D3"); - AddedLexerActions = UUID.FromString("AB35191A-1603-487E-B75A-479B831EAF6D"); - SupportedUuids = new List(); + BaseSerializedUuid = Guid.FromString("E4178468-DF95-44D0-AD87-F22A5D5FB6D3"); + AddedLexerActions = Guid.FromString("AB35191A-1603-487E-B75A-479B831EAF6D"); + SupportedUuids = new List(); SupportedUuids.Add(BaseSerializedUuid); SupportedUuids.Add(AddedLexerActions); SerializedUuid = AddedLexerActions; @@ -105,19 +105,19 @@ namespace Antlr4.Runtime.Atn /// /// Determines if a particular serialized representation of an ATN supports /// a particular feature, identified by the - /// + /// /// used for serializing /// the ATN at the time the feature was first introduced. /// /// /// The - /// + /// /// marking the first time the feature was /// supported in the serialized ATN. /// /// /// The - /// + /// /// of the actual serialized ATN which is /// currently being deserialized. /// @@ -134,7 +134,7 @@ namespace Antlr4.Runtime.Atn /// false /// . /// - protected internal virtual bool IsFeatureSupported(UUID feature, UUID actualUuid) + protected internal virtual bool IsFeatureSupported(Guid feature, Guid actualUuid) { int featureIndex = SupportedUuids.IndexOf(feature); if (featureIndex < 0) @@ -159,7 +159,7 @@ namespace Antlr4.Runtime.Atn string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with version %d (expected %d).", version, SerializedVersion); throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason)); } - UUID uuid = ToUUID(data, p); + Guid uuid = ToUUID(data, p); p += 8; if (!SupportedUuids.Contains(uuid)) { @@ -1096,11 +1096,11 @@ nextState_break: ; return lowOrder | ((long)ToInt32(data, offset + 2) << 32); } - protected internal static UUID ToUUID(char[] data, int offset) + protected internal static Guid ToUUID(char[] data, int offset) { long leastSigBits = ToLong(data, offset); long mostSigBits = ToLong(data, offset + 4); - return new UUID(mostSigBits, leastSigBits); + return new Guid(mostSigBits, leastSigBits); } [NotNull] diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs index 35cf28b9a..446af2ef3 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs @@ -480,7 +480,7 @@ namespace Antlr4.Runtime.Atn string reason = string.Format("Could not deserialize ATN with version %d (expected %d).", version, ATNDeserializer.SerializedVersion); throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason)); } - UUID uuid = ATNDeserializer.ToUUID(data, p); + Guid uuid = ATNDeserializer.ToUUID(data, p); p += 8; if (!uuid.Equals(ATNDeserializer.SerializedUuid)) { @@ -699,7 +699,7 @@ namespace Antlr4.Runtime.Atn return new Antlr4.Runtime.Atn.ATNSerializer(atn, ruleNames, tokenNames).Decode(data); } - private void SerializeUUID(List data, UUID uuid) + private void SerializeUUID(List data, Guid uuid) { SerializeLong(data, uuid.GetLeastSignificantBits()); SerializeLong(data, uuid.GetMostSignificantBits()); diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ATNSimulator.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ATNSimulator.cs index 40df4942b..e70830d05 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/ATNSimulator.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/ATNSimulator.cs @@ -51,7 +51,7 @@ namespace Antlr4.Runtime.Atn /// This is the current serialized UUID. [System.ObsoleteAttribute(@"Use ATNDeserializer.CheckCondition(bool) instead.")] [Obsolete] - public static readonly UUID SerializedUuid; + public static readonly Guid SerializedUuid; static ATNSimulator() { @@ -145,7 +145,7 @@ namespace Antlr4.Runtime.Atn [Obsolete] [System.ObsoleteAttribute(@"Use ATNDeserializer.ToUUID(char[], int) instead.")] - public static UUID ToUUID(char[] data, int offset) + public static Guid ToUUID(char[] data, int offset) { return ATNDeserializer.ToUUID(data, offset); }