diff --git a/Antlr4.Runtime/Atn/ATN.cs b/Antlr4.Runtime/Atn/ATN.cs index f3c1cd117..c81a847a4 100644 --- a/Antlr4.Runtime/Atn/ATN.cs +++ b/Antlr4.Runtime/Atn/ATN.cs @@ -27,6 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System.Collections.Concurrent; using System.Collections.Generic; using Antlr4.Runtime.Atn; using Antlr4.Runtime.Dfa; @@ -81,8 +82,8 @@ namespace Antlr4.Runtime.Atn /// used during construction from grammar AST internal int stateNumber = 0; - private readonly IConcurrentMap contextCache - = new ConcurrentHashMap(); + private readonly ConcurrentDictionary contextCache + = new ConcurrentDictionary(); [NotNull] public DFA[] decisionToDFA = new DFA[0]; @@ -90,7 +91,7 @@ namespace Antlr4.Runtime.Atn [NotNull] public DFA[] modeToDFA = new DFA[0]; - protected internal readonly IConcurrentMap LL1Table = new ConcurrentHashMap + protected internal readonly ConcurrentDictionary LL1Table = new ConcurrentDictionary (); /// Used for runtime deserialization of ATNs from strings diff --git a/Antlr4.Runtime/Atn/ATNConfig.cs b/Antlr4.Runtime/Atn/ATNConfig.cs index 554ea2ff5..e09035534 100644 --- a/Antlr4.Runtime/Atn/ATNConfig.cs +++ b/Antlr4.Runtime/Atn/ATNConfig.cs @@ -396,10 +396,11 @@ namespace Antlr4.Runtime.Atn PredictionContext current = workList.Pop(); for (int i = 0; i < current.Size; i++) { - builder.Append(" s").Append(Sharpen.Runtime.IdentityHashCode(current)); + builder.Append(" s").Append(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode + (current)); builder.Append("->"); - builder.Append("s").Append(Sharpen.Runtime.IdentityHashCode(current.GetParent(i)) - ); + builder.Append("s").Append(System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode + (current.GetParent(i))); builder.Append("[label=\"").Append(current.GetReturnState(i)).Append("\"];\n"); if (visited.Put(current.GetParent(i), current.GetParent(i)) == null) { diff --git a/Antlr4.Runtime/Atn/ATNConfigSet.cs b/Antlr4.Runtime/Atn/ATNConfigSet.cs index 3626a3b02..736a1356b 100644 --- a/Antlr4.Runtime/Atn/ATNConfigSet.cs +++ b/Antlr4.Runtime/Atn/ATNConfigSet.cs @@ -38,7 +38,7 @@ using Sharpen; namespace Antlr4.Runtime.Atn { /// Sam Harwell - public class ATNConfigSet : ICollection + public class ATNConfigSet : ISet { /// /// This maps (state, alt) -> merged @@ -224,9 +224,9 @@ namespace Antlr4.Runtime.Atn this.outermostConfigSet = outermostConfigSet; } - public virtual ICollection GetStates() + public virtual ISet GetStates() { - ICollection states = new HashSet(); + ISet states = new HashSet(); foreach (ATNConfig c in this.configs) { states.AddItem(c.GetState()); diff --git a/Antlr4.Runtime/Atn/ATNSimulator.cs b/Antlr4.Runtime/Atn/ATNSimulator.cs index 78ae6a7ed..39e66bc09 100644 --- a/Antlr4.Runtime/Atn/ATNSimulator.cs +++ b/Antlr4.Runtime/Atn/ATNSimulator.cs @@ -137,11 +137,11 @@ namespace Antlr4.Runtime.Atn // delay the assignment of loop back and end states until we know all the state instances have been initialized foreach (Tuple pair in loopBackStateNumbers) { - pair.GetItem1().loopBackState = atn.states[pair.GetItem2()]; + pair.Item1.loopBackState = atn.states[pair.Item2]; } foreach (Tuple pair_1 in endStateNumbers) { - pair_1.GetItem1().endState = (BlockEndState)atn.states[pair_1.GetItem2()]; + pair_1.Item1.endState = (BlockEndState)atn.states[pair_1.Item2]; } int numNonGreedyStates = ToInt(data[p++]); for (int i_2 = 0; i_2 < numNonGreedyStates; i_2++) diff --git a/Antlr4.Runtime/Atn/ArrayPredictionContext.cs b/Antlr4.Runtime/Atn/ArrayPredictionContext.cs index 3c4cdbb06..2a47bcc62 100644 --- a/Antlr4.Runtime/Atn/ArrayPredictionContext.cs +++ b/Antlr4.Runtime/Atn/ArrayPredictionContext.cs @@ -228,8 +228,8 @@ namespace Antlr4.Runtime.Atn >()); } - private bool Equals(Antlr4.Runtime.Atn.ArrayPredictionContext other, ICollection< - PredictionContextCache.IdentityCommutativePredictionContextOperands> visited) + private bool Equals(Antlr4.Runtime.Atn.ArrayPredictionContext other, ISet visited) { IDeque selfWorkList = new ArrayDeque(); IDeque otherWorkList = new ArrayDeque(); diff --git a/Antlr4.Runtime/Atn/LL1Analyzer.cs b/Antlr4.Runtime/Atn/LL1Analyzer.cs index a7316c7b0..48a6dabc9 100644 --- a/Antlr4.Runtime/Atn/LL1Analyzer.cs +++ b/Antlr4.Runtime/Atn/LL1Analyzer.cs @@ -74,7 +74,7 @@ namespace Antlr4.Runtime.Atn for (int alt = 1; alt <= s.NumberOfTransitions; alt++) { look[alt] = new IntervalSet(); - ICollection lookBusy = new HashSet(); + ISet lookBusy = new HashSet(); bool seeThruPreds = false; // fail to get lookahead upon pred Look(s.Transition(alt - 1).target, PredictionContext.EmptyFull, look[alt], lookBusy @@ -138,7 +138,7 @@ namespace Antlr4.Runtime.Atn /// indicating we reached the end of the ruled out having to match a token. /// protected internal virtual void Look(ATNState s, PredictionContext ctx, IntervalSet - look, ICollection lookBusy, bool seeThruPreds, bool addEOF) + look, ISet lookBusy, bool seeThruPreds, bool addEOF) { // System.out.println("_LOOK("+s.stateNumber+", ctx="+ctx); ATNConfig c = ATNConfig.Create(s, 0, ctx); diff --git a/Antlr4.Runtime/Atn/ParserATNSimulator.cs b/Antlr4.Runtime/Atn/ParserATNSimulator.cs index 5e134314c..59f2a40bc 100644 --- a/Antlr4.Runtime/Atn/ParserATNSimulator.cs +++ b/Antlr4.Runtime/Atn/ParserATNSimulator.cs @@ -1286,7 +1286,7 @@ namespace Antlr4.Runtime.Atn contextCache = PredictionContextCache.Uncached; } ATNConfigSet currentConfigs = sourceConfigs; - ICollection closureBusy = new HashSet(); + ISet closureBusy = new HashSet(); while (currentConfigs.Count > 0) { ATNConfigSet intermediate = new ATNConfigSet(); @@ -1304,8 +1304,8 @@ namespace Antlr4.Runtime.Atn } protected internal virtual void Closure(ATNConfig config, ATNConfigSet configs, ATNConfigSet - intermediate, ICollection closureBusy, bool collectPredicates, bool - hasMoreContexts, PredictionContextCache contextCache, int depth) + intermediate, ISet closureBusy, bool collectPredicates, bool hasMoreContexts + , PredictionContextCache contextCache, int depth) { if (!optimize_closure_busy && !closureBusy.AddItem(config)) { diff --git a/Antlr4.Runtime/Atn/PredictionContext.cs b/Antlr4.Runtime/Atn/PredictionContext.cs index 36cea0e9f..e17db806a 100644 --- a/Antlr4.Runtime/Atn/PredictionContext.cs +++ b/Antlr4.Runtime/Atn/PredictionContext.cs @@ -27,6 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System.Collections.Concurrent; using System.Collections.Generic; using System.Text; using Antlr4.Runtime; @@ -339,7 +340,7 @@ namespace Antlr4.Runtime.Atn } public static Antlr4.Runtime.Atn.PredictionContext GetCachedContext(Antlr4.Runtime.Atn.PredictionContext - context, IConcurrentMap contextCache, PredictionContext.IdentityHashMap visited) { if (context.IsEmpty) diff --git a/Antlr4.Runtime/Atn/SemanticContext.cs b/Antlr4.Runtime/Atn/SemanticContext.cs index f8db934a4..a0a53e2bc 100644 --- a/Antlr4.Runtime/Atn/SemanticContext.cs +++ b/Antlr4.Runtime/Atn/SemanticContext.cs @@ -202,7 +202,7 @@ namespace Antlr4.Runtime.Atn public AND(SemanticContext a, SemanticContext b) { - ICollection operands = new HashSet(); + ISet operands = new HashSet(); if (a is SemanticContext.AND) { Sharpen.Collections.AddAll(operands, Arrays.AsList(((SemanticContext.AND)a).opnds @@ -278,7 +278,7 @@ namespace Antlr4.Runtime.Atn public OR(SemanticContext a, SemanticContext b) { - ICollection operands = new HashSet(); + ISet operands = new HashSet(); if (a is SemanticContext.OR) { Sharpen.Collections.AddAll(operands, Arrays.AsList(((SemanticContext.OR)a).opnds) diff --git a/Antlr4.Runtime/CommonToken.cs b/Antlr4.Runtime/CommonToken.cs index 7908bb22c..37fc2cfe6 100644 --- a/Antlr4.Runtime/CommonToken.cs +++ b/Antlr4.Runtime/CommonToken.cs @@ -82,10 +82,10 @@ namespace Antlr4.Runtime this.channel = channel; this.start = start; this.stop = stop; - if (source.GetItem1() != null) + if (source.Item1 != null) { - this.line = source.GetItem1().Line; - this.charPositionInLine = source.GetItem1().Column; + this.line = source.Item1.Line; + this.charPositionInLine = source.Item1.Column; } } @@ -248,7 +248,7 @@ namespace Antlr4.Runtime { get { - return source.GetItem1(); + return source.Item1; } } @@ -256,7 +256,7 @@ namespace Antlr4.Runtime { get { - return source.GetItem2(); + return source.Item2; } } diff --git a/Antlr4.Runtime/CommonTokenFactory.cs b/Antlr4.Runtime/CommonTokenFactory.cs index 3f343b311..a827678f7 100644 --- a/Antlr4.Runtime/CommonTokenFactory.cs +++ b/Antlr4.Runtime/CommonTokenFactory.cs @@ -77,9 +77,9 @@ namespace Antlr4.Runtime } else { - if (copyText && source.GetItem2() != null) + if (copyText && source.Item2 != null) { - t.Text = source.GetItem2().GetText(Interval.Of(start, stop)); + t.Text = source.Item2.GetText(Interval.Of(start, stop)); } } return t; diff --git a/Antlr4.Runtime/Dfa/AbstractEdgeMap`1.cs b/Antlr4.Runtime/Dfa/AbstractEdgeMap`1.cs index 61a521716..ef2c4c2b1 100644 --- a/Antlr4.Runtime/Dfa/AbstractEdgeMap`1.cs +++ b/Antlr4.Runtime/Dfa/AbstractEdgeMap`1.cs @@ -104,7 +104,7 @@ namespace Antlr4.Runtime.Dfa public abstract bool ContainsKey(int arg1); - public abstract ICollection> EntrySet(); + public abstract ISet> EntrySet(); public abstract T Get(int arg1); diff --git a/Antlr4.Runtime/Dfa/ArrayEdgeMap`1.cs b/Antlr4.Runtime/Dfa/ArrayEdgeMap`1.cs index 67915ef61..12b82f8d7 100644 --- a/Antlr4.Runtime/Dfa/ArrayEdgeMap`1.cs +++ b/Antlr4.Runtime/Dfa/ArrayEdgeMap`1.cs @@ -175,7 +175,7 @@ namespace Antlr4.Runtime.Dfa return result; } - public override ICollection> EntrySet() + public override ISet> EntrySet() { return new ArrayEdgeMap.EntrySet(this); } diff --git a/Antlr4.Runtime/Dfa/DFA.cs b/Antlr4.Runtime/Dfa/DFA.cs index 543ec7432..09df58164 100644 --- a/Antlr4.Runtime/Dfa/DFA.cs +++ b/Antlr4.Runtime/Dfa/DFA.cs @@ -27,6 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System.Collections.Concurrent; using Antlr4.Runtime.Atn; using Antlr4.Runtime.Dfa; using Antlr4.Runtime.Misc; @@ -47,7 +48,7 @@ namespace Antlr4.Runtime.Dfa /// only allows you to see if it's there). /// [NotNull] - public readonly IConcurrentMap states = new ConcurrentHashMap + public readonly ConcurrentDictionary states = new ConcurrentDictionary (); [Nullable] diff --git a/Antlr4.Runtime/Dfa/IEdgeMap`1.cs b/Antlr4.Runtime/Dfa/IEdgeMap`1.cs index 0ad02e18c..1a865a698 100644 --- a/Antlr4.Runtime/Dfa/IEdgeMap`1.cs +++ b/Antlr4.Runtime/Dfa/IEdgeMap`1.cs @@ -62,6 +62,6 @@ namespace Antlr4.Runtime.Dfa IDictionary ToMap(); [NotNull] - ICollection> EntrySet(); + ISet> EntrySet(); } } diff --git a/Antlr4.Runtime/Dfa/SingletonEdgeMap`1.cs b/Antlr4.Runtime/Dfa/SingletonEdgeMap`1.cs index 16706e1b9..b62aa4b56 100644 --- a/Antlr4.Runtime/Dfa/SingletonEdgeMap`1.cs +++ b/Antlr4.Runtime/Dfa/SingletonEdgeMap`1.cs @@ -149,7 +149,7 @@ namespace Antlr4.Runtime.Dfa return Sharpen.Collections.SingletonMap(key, value); } - public override ICollection> EntrySet() + public override ISet> EntrySet() { return new SingletonEdgeMap.EntrySet(this); } diff --git a/Antlr4.Runtime/Dfa/SparseEdgeMap`1.cs b/Antlr4.Runtime/Dfa/SparseEdgeMap`1.cs index 54582f7e9..50f50af8e 100644 --- a/Antlr4.Runtime/Dfa/SparseEdgeMap`1.cs +++ b/Antlr4.Runtime/Dfa/SparseEdgeMap`1.cs @@ -204,7 +204,7 @@ namespace Antlr4.Runtime.Dfa return result; } - public override ICollection> EntrySet() + public override ISet> EntrySet() { return new SparseEdgeMap.EntrySet(this); } diff --git a/Antlr4.Runtime/Misc/Array2DHashSet`1.cs b/Antlr4.Runtime/Misc/Array2DHashSet`1.cs index d2495232e..d16354d5d 100644 --- a/Antlr4.Runtime/Misc/Array2DHashSet`1.cs +++ b/Antlr4.Runtime/Misc/Array2DHashSet`1.cs @@ -39,7 +39,7 @@ namespace Antlr4.Runtime.Misc /// Sharpen.ISet<E> /// implementation with closed hashing (open addressing). /// - public class Array2DHashSet : ICollection + public class Array2DHashSet : ISet { public const int InitalCapacity = 16; diff --git a/Antlr4.Runtime/Misc/DoubleKeyMap`3.cs b/Antlr4.Runtime/Misc/DoubleKeyMap`3.cs index aaee917c6..bdca4fb5c 100644 --- a/Antlr4.Runtime/Misc/DoubleKeyMap`3.cs +++ b/Antlr4.Runtime/Misc/DoubleKeyMap`3.cs @@ -89,13 +89,13 @@ namespace Antlr4.Runtime.Misc } /// get all primary keys - public virtual ICollection KeySet() + public virtual ISet KeySet() { return data.Keys; } /// get all secondary keys associated with a primary key - public virtual ICollection KeySet(Key1 k1) + public virtual ISet KeySet(Key1 k1) { IDictionary data2 = data.Get(k1); if (data2 == null) diff --git a/Antlr4.Runtime/Misc/FlexibleHashMap`2.cs b/Antlr4.Runtime/Misc/FlexibleHashMap`2.cs index d14d0b9e7..94e5b242b 100644 --- a/Antlr4.Runtime/Misc/FlexibleHashMap`2.cs +++ b/Antlr4.Runtime/Misc/FlexibleHashMap`2.cs @@ -189,7 +189,7 @@ namespace Antlr4.Runtime.Misc throw new NotSupportedException(); } - public virtual ICollection Keys + public virtual ISet Keys { get { @@ -217,7 +217,7 @@ namespace Antlr4.Runtime.Misc } } - public virtual ICollection> EntrySet() + public virtual ISet> EntrySet() { throw new NotSupportedException(); } diff --git a/Antlr4.Runtime/Misc/IntervalSet.cs b/Antlr4.Runtime/Misc/IntervalSet.cs index a44e22ade..724250dcb 100644 --- a/Antlr4.Runtime/Misc/IntervalSet.cs +++ b/Antlr4.Runtime/Misc/IntervalSet.cs @@ -740,9 +740,9 @@ namespace Antlr4.Runtime.Misc return values; } - public virtual ICollection ToSet() + public virtual ISet ToSet() { - ICollection s = new HashSet(); + ISet s = new HashSet(); foreach (Interval I in intervals) { int a = I.a; diff --git a/Antlr4.Runtime/Misc/RuleDependencyChecker.cs b/Antlr4.Runtime/Misc/RuleDependencyChecker.cs index edca97dc8..6d3cd2b5e 100644 --- a/Antlr4.Runtime/Misc/RuleDependencyChecker.cs +++ b/Antlr4.Runtime/Misc/RuleDependencyChecker.cs @@ -46,7 +46,7 @@ namespace Antlr4.Runtime.Misc private static readonly Logger Logger = Logger.GetLogger(typeof(Antlr4.Runtime.Misc.RuleDependencyChecker ).FullName); - private static readonly ICollection checkedTypes = new HashSet(); + private static readonly ISet checkedTypes = new HashSet(); public static void CheckDependencies<_T0>(Type<_T0> dependentClass) { @@ -69,7 +69,7 @@ namespace Antlr4.Runtime.Misc { continue; } - CheckDependencies(dependencies, dependencies[0].GetItem1().Recognizer()); + CheckDependencies(dependencies, dependencies[0].Item1.Recognizer()); } } @@ -98,25 +98,24 @@ namespace Antlr4.Runtime.Misc StringBuilder incompatible = new StringBuilder(); foreach (Tuple dependency in dependencies) { - if (!recognizerClass.IsAssignableFrom(dependency.GetItem1().Recognizer())) + if (!recognizerClass.IsAssignableFrom(dependency.Item1.Recognizer())) { continue; } - if (dependency.GetItem1().Rule() < 0 || dependency.GetItem1().Rule() >= ruleVersions - .Length) + if (dependency.Item1.Rule() < 0 || dependency.Item1.Rule() >= ruleVersions.Length) { incompatible.Append(string.Format("Element %s dependent on unknown rule %d@%d in %s\n" - , dependency.GetItem2().ToString(), dependency.GetItem1().Rule(), dependency. - GetItem1().Version(), dependency.GetItem1().Recognizer().Name)); + , dependency.Item2.ToString(), dependency.Item1.Rule(), dependency.Item1.Version + (), dependency.Item1.Recognizer().Name)); } else { - if (ruleVersions[dependency.GetItem1().Rule()] != dependency.GetItem1().Version()) + if (ruleVersions[dependency.Item1.Rule()] != dependency.Item1.Version()) { incompatible.Append(string.Format("Element %s dependent on rule %s@%d (found @%d) in %s\n" - , dependency.GetItem2().ToString(), ruleNames[dependency.GetItem1().Rule()], - dependency.GetItem1().Version(), ruleVersions[dependency.GetItem1().Rule()], - dependency.GetItem1().Recognizer().Name)); + , dependency.Item2.ToString(), ruleNames[dependency.Item1.Rule()], dependency + .Item1.Version(), ruleVersions[dependency.Item1.Rule()], dependency.Item1.Recognizer + ().Name)); } } } diff --git a/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs b/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs index 203b0fb7d..44d81ba8e 100644 --- a/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs +++ b/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs @@ -59,8 +59,8 @@ namespace Antlr4.Runtime.Misc { } - public override bool Process<_T0>(ICollection<_T0> annotations, IRoundEnvironment - roundEnv) + public override bool Process<_T0>(ISet<_T0> annotations, IRoundEnvironment roundEnv + ) { if (!CheckClassNameConstants()) { @@ -71,7 +71,7 @@ namespace Antlr4.Runtime.Misc = new Dictionary>>(); foreach (Tuple dependency in dependencies) { - ITypeMirror recognizerType = GetRecognizerType(dependency.GetItem1()); + ITypeMirror recognizerType = GetRecognizerType(dependency.Item1); IList> list = recognizerDependencies.Get(recognizerType ); if (list == null) @@ -141,42 +141,41 @@ namespace Antlr4.Runtime.Misc { try { - if (!processingEnv.GetTypeUtils().IsAssignable(GetRecognizerType(dependency.GetItem1 - ()), recognizerType)) + if (!processingEnv.GetTypeUtils().IsAssignable(GetRecognizerType(dependency.Item1 + ), recognizerType)) { continue; } // this is the rule in the dependency set with the highest version number - int effectiveRule = dependency.GetItem1().Rule(); + int effectiveRule = dependency.Item1.Rule(); if (effectiveRule < 0 || effectiveRule >= ruleVersions.Length) { Tuple ruleReferenceElement = FindRuleDependencyProperty (dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule); string message = string.Format("Rule dependency on unknown rule %d@%d in %s", dependency - .GetItem1().Rule(), dependency.GetItem1().Version(), GetRecognizerType(dependency - .GetItem1()).ToString()); + .Item1.Rule(), dependency.Item1.Version(), GetRecognizerType(dependency.Item1 + ).ToString()); if (ruleReferenceElement != null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency - .GetItem2(), ruleReferenceElement.GetItem1(), ruleReferenceElement.GetItem2() - ); + .Item2, ruleReferenceElement.Item1, ruleReferenceElement.Item2); } else { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency - .GetItem2()); + .Item2); } continue; } - EnumSet dependents = EnumSet.Of(Dependents.Self, dependency.GetItem1( - ).Dependents()); + EnumSet dependents = EnumSet.Of(Dependents.Self, dependency.Item1.Dependents + ()); ReportUnimplementedDependents(dependency, dependents); BitArray checked = new BitArray(); int highestRequiredDependency = CheckDependencyVersion(dependency, ruleNames, ruleVersions , effectiveRule, null); if (dependents.Contains(Dependents.Parents)) { - BitArray parents = relations.parents[dependency.GetItem1().Rule()]; + BitArray parents = relations.parents[dependency.Item1.Rule()]; for (int parent = parents.NextSetBit(0); parent >= 0; parent = parents.NextSetBit (parent + 1)) { @@ -192,7 +191,7 @@ namespace Antlr4.Runtime.Misc } if (dependents.Contains(Dependents.Children)) { - BitArray children = relations.children[dependency.GetItem1().Rule()]; + BitArray children = relations.children[dependency.Item1.Rule()]; for (int child = children.NextSetBit(0); child >= 0; child = children.NextSetBit( child + 1)) { @@ -208,7 +207,7 @@ namespace Antlr4.Runtime.Misc } if (dependents.Contains(Dependents.Ancestors)) { - BitArray ancestors = relations.GetAncestors(dependency.GetItem1().Rule()); + BitArray ancestors = relations.GetAncestors(dependency.Item1.Rule()); for (int ancestor = ancestors.NextSetBit(0); ancestor >= 0; ancestor = ancestors. NextSetBit(ancestor + 1)) { @@ -224,7 +223,7 @@ namespace Antlr4.Runtime.Misc } if (dependents.Contains(Dependents.Descendants)) { - BitArray descendants = relations.GetDescendants(dependency.GetItem1().Rule()); + BitArray descendants = relations.GetDescendants(dependency.Item1.Rule()); for (int descendant = descendants.NextSetBit(0); descendant >= 0; descendant = descendants .NextSetBit(descendant + 1)) { @@ -239,37 +238,37 @@ namespace Antlr4.Runtime.Misc highestRequiredDependency = Math.Max(highestRequiredDependency, required); } } - int declaredVersion = dependency.GetItem1().Version(); + int declaredVersion = dependency.Item1.Version(); if (declaredVersion > highestRequiredDependency) { Tuple versionElement = FindRuleDependencyProperty (dependency, RuleDependencyProcessor.RuleDependencyProperty.Version); string message = string.Format("Rule dependency version mismatch: %s has maximum dependency version %d (expected %d) in %s" - , ruleNames[dependency.GetItem1().Rule()], highestRequiredDependency, declaredVersion - , GetRecognizerType(dependency.GetItem1()).ToString()); + , ruleNames[dependency.Item1.Rule()], highestRequiredDependency, declaredVersion + , GetRecognizerType(dependency.Item1).ToString()); if (versionElement != null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency - .GetItem2(), versionElement.GetItem1(), versionElement.GetItem2()); + .Item2, versionElement.Item1, versionElement.Item2); } else { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency - .GetItem2()); + .Item2); } } } catch (AnnotationTypeMismatchException) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, string.Format("Could not validate rule dependencies for element %s" - , dependency.GetItem2().ToString()), dependency.GetItem2()); + , dependency.Item2.ToString()), dependency.Item2); } } } - private static readonly ICollection ImplementedDependents = EnumSet.Of - (Dependents.Self, Dependents.Parents, Dependents.Children, Dependents.Ancestors - , Dependents.Descendants); + private static readonly ISet ImplementedDependents = EnumSet.Of(Dependents + .Self, Dependents.Parents, Dependents.Children, Dependents.Ancestors, Dependents + .Descendants); private void ReportUnimplementedDependents(Tuple dependency , EnumSet dependents) @@ -286,16 +285,16 @@ namespace Antlr4.Runtime.Misc .Rule); } string message = string.Format("Cannot validate the following dependents of rule %d: %s" - , dependency.GetItem1().Rule(), unimplemented); + , dependency.Item1.Rule(), unimplemented); if (dependentsElement != null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, message, dependency - .GetItem2(), dependentsElement.GetItem1(), dependentsElement.GetItem2()); + .Item2, dependentsElement.Item1, dependentsElement.Item2); } else { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, message, dependency - .GetItem2()); + .Item2); } } } @@ -303,7 +302,7 @@ namespace Antlr4.Runtime.Misc private int CheckDependencyVersion(Tuple dependency, string [] ruleNames, int[] ruleVersions, int relatedRule, string relation) { - string ruleName = ruleNames[dependency.GetItem1().Rule()]; + string ruleName = ruleNames[dependency.Item1.Rule()]; string path; if (relation == null) { @@ -315,24 +314,24 @@ namespace Antlr4.Runtime.Misc path = string.Format("rule %s (%s of %s)", mismatchedRuleName, relation, ruleName ); } - int declaredVersion = dependency.GetItem1().Version(); + int declaredVersion = dependency.Item1.Version(); int actualVersion = ruleVersions[relatedRule]; if (actualVersion > declaredVersion) { Tuple versionElement = FindRuleDependencyProperty (dependency, RuleDependencyProcessor.RuleDependencyProperty.Version); string message = string.Format("Rule dependency version mismatch: %s has version %d (expected <= %d) in %s" - , path, actualVersion, declaredVersion, GetRecognizerType(dependency.GetItem1 - ()).ToString()); + , path, actualVersion, declaredVersion, GetRecognizerType(dependency.Item1).ToString + ()); if (versionElement != null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency - .GetItem2(), versionElement.GetItem1(), versionElement.GetItem2()); + .Item2, versionElement.Item1, versionElement.Item2); } else { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency - .GetItem2()); + .Item2); } } return actualVersion; @@ -489,7 +488,7 @@ namespace Antlr4.Runtime.Misc { IList> result = new List>(); - ICollection elements = roundEnv.GetElementsAnnotatedWith(typeof(RuleDependency + ISet elements = roundEnv.GetElementsAnnotatedWith(typeof(RuleDependency )); foreach (IElement element in elements) { @@ -533,7 +532,7 @@ namespace Antlr4.Runtime.Misc (RuleDependencyClassName); ITypeElement ruleDependenciesTypeElement = processingEnv.GetElementUtils().GetTypeElement (RuleDependenciesClassName); - IList mirrors = dependency.GetItem2().GetAnnotationMirrors(); + IList mirrors = dependency.Item2.GetAnnotationMirrors(); foreach (IAnnotationMirror annotationMirror in mirrors) { if (processingEnv.GetTypeUtils().IsSameType(ruleDependencyTypeElement.AsType(), annotationMirror @@ -562,7 +561,7 @@ namespace Antlr4.Runtime.Misc if (!(annotationValue.GetValue() is IList)) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected array of RuleDependency annotations for annotation property 'value()'." - , dependency.GetItem2(), annotationMirror, annotationValue); + , dependency.Item2, annotationMirror, annotationValue); break; } IList annotationValueList = (IList)annotationValue.GetValue(); @@ -571,7 +570,7 @@ namespace Antlr4.Runtime.Misc if (!(obj is IAnnotationMirror)) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected RuleDependency annotation mirror for element of property 'value()'." - , dependency.GetItem2(), annotationMirror, annotationValue); + , dependency.Item2, annotationMirror, annotationValue); break; } IAnnotationValue element = FindRuleDependencyProperty(dependency, (IAnnotationMirror @@ -585,8 +584,7 @@ namespace Antlr4.Runtime.Misc else { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unexpected annotation property %s." - , value.Key.ToString()), dependency.GetItem2(), annotationMirror, value.Value - ); + , value.Key.ToString()), dependency.Item2, annotationMirror, value.Value); } } } @@ -616,10 +614,10 @@ namespace Antlr4.Runtime.Misc if (!(annotationValue.GetValue() is int)) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected int constant for annotation property 'rule()'." - , dependency.GetItem2(), annotationMirror, annotationValue); + , dependency.Item2, annotationMirror, annotationValue); return null; } - if ((int)annotationValue.GetValue() != dependency.GetItem1().Rule()) + if ((int)annotationValue.GetValue() != dependency.Item1.Rule()) { // this is a valid dependency annotation, but not the one we're looking for return null; @@ -633,11 +631,11 @@ namespace Antlr4.Runtime.Misc if (!(annotationValue.GetValue() is ITypeMirror)) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected Class constant for annotation property 'recognizer()'." - , dependency.GetItem2(), annotationMirror, annotationValue); + , dependency.Item2, annotationMirror, annotationValue); return null; } ITypeMirror annotationRecognizer = (ITypeMirror)annotationValue.GetValue(); - ITypeMirror expectedRecognizer = GetRecognizerType(dependency.GetItem1()); + ITypeMirror expectedRecognizer = GetRecognizerType(dependency.Item1); if (!processingEnv.GetTypeUtils().IsSameType(expectedRecognizer, annotationRecognizer )) { @@ -653,10 +651,10 @@ namespace Antlr4.Runtime.Misc if (!(annotationValue.GetValue() is int)) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected int constant for annotation property 'version()'." - , dependency.GetItem2(), annotationMirror, annotationValue); + , dependency.Item2, annotationMirror, annotationValue); return null; } - if ((int)annotationValue.GetValue() != dependency.GetItem1().Version()) + if ((int)annotationValue.GetValue() != dependency.Item1.Version()) { // this is a valid dependency annotation, but not the one we're looking for return null; @@ -702,7 +700,7 @@ namespace Antlr4.Runtime.Misc if (recognizerValue == null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Could not find 'recognizer()' element in annotation." - , dependency.GetItem2(), annotationMirror); + , dependency.Item2, annotationMirror); } if (property == RuleDependencyProcessor.RuleDependencyProperty.Recognizer) { @@ -711,7 +709,7 @@ namespace Antlr4.Runtime.Misc if (ruleValue == null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Could not find 'rule()' element in annotation." - , dependency.GetItem2(), annotationMirror); + , dependency.Item2, annotationMirror); } if (property == RuleDependencyProcessor.RuleDependencyProperty.Rule) { @@ -720,7 +718,7 @@ namespace Antlr4.Runtime.Misc if (versionValue == null) { processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Could not find 'version()' element in annotation." - , dependency.GetItem2(), annotationMirror); + , dependency.Item2, annotationMirror); } return null; } diff --git a/Antlr4.Runtime/Parser.cs b/Antlr4.Runtime/Parser.cs index 97908fc75..a0b18f474 100644 --- a/Antlr4.Runtime/Parser.cs +++ b/Antlr4.Runtime/Parser.cs @@ -99,7 +99,7 @@ namespace Antlr4.Runtime { if (ctx.children is ArrayList) { - ((List)ctx.children).TrimToSize(); + ((List)ctx.children).TrimExcess(); } } } diff --git a/reference/sharpen-all-options.txt b/reference/sharpen-all-options.txt index 5bea99aa8..bfa4510b7 100644 --- a/reference/sharpen-all-options.txt +++ b/reference/sharpen-all-options.txt @@ -46,6 +46,7 @@ -methodMapping java.util.List<>.remove RemoveAt -methodMapping java.util.IList<>.remove RemoveAt -methodMapping java.util.ArrayList.remove RemoveAt +-methodMapping java.util.ArrayList.trimToSize TrimExcess -methodMapping java.lang.Integer.toOctalString Sharpen.Extensions.ToOctalString -methodMapping java.lang.Integer.toHexString Sharpen.Extensions.ToHexString -methodMapping java.lang.Integer.bitCount Sharpen.Extensions.BitCount @@ -67,6 +68,7 @@ -methodMapping java.lang.Character.toLowerCase System.Char.ToLower -methodMapping java.lang.Character.toUpperCase System.Char.ToUpper -methodMapping java.util.HashMap<,>.containsKey ContainsKey +-methodMapping java.lang.System.identityHashCode System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode -methodMapping java.lang.System.gc System.GC.Collect -methodMapping java.lang.System.runFinalization System.GC.WaitForPendingFinalizers -methodMapping java.lang.System.getenv(String) System.Environment.GetEnvironmentVariable @@ -99,7 +101,9 @@ -typeMapping java.lang.Comparable System.IComparable -typeMapping java.util.Comparator<> System.Collections.Generic.IComparer -typeMapping java.util.HashSet<> System.Collections.Generic.HashSet --typeMapping java.util.HashSet<> System.Collections.Generic.HashSet +-typeMapping java.util.Set<> System.Collections.Generic.ISet +-typeMapping java.util.concurrent.ConcurrentMap<,> System.Collections.Concurrent.ConcurrentDictionary +-typeMapping java.util.concurrent.ConcurrentHashMap<,> System.Collections.Concurrent.ConcurrentDictionary -typeMapping java.io.File Sharpen.FilePath -typeMapping java.lang.StringBuilder System.Text.StringBuilder -typeMapping java.nio.charset.Charset System.Text.Encoding @@ -185,7 +189,13 @@ -typeMapping org.antlr.v4.runtime.misc.Tuple System.Tuple -typeMapping org.antlr.v4.runtime.misc.Tuple2<,> System.Tuple +-propertyMapping org.antlr.v4.runtime.misc.Tuple2.getItem1 Item1 +-propertyMapping org.antlr.v4.runtime.misc.Tuple2.getItem2 Item2 -typeMapping org.antlr.v4.runtime.misc.Tuple3<,,> System.Tuple +-propertyMapping org.antlr.v4.runtime.misc.Tuple3.getItem1 Item1 +-propertyMapping org.antlr.v4.runtime.misc.Tuple3.getItem2 Item2 +-propertyMapping org.antlr.v4.runtime.misc.Tuple3.getItem3 Item3 + -typeMapping org.antlr.v4.runtime.misc.IntegerList System.Collections.Generic.List -typeMapping org.antlr.v4.runtime.ANTLRErrorListener<> IAntlrErrorListener