Fix string.Format syntax (fixes #40)

This commit is contained in:
Sam Harwell 2014-04-27 21:52:52 -05:00
parent 2ace0f628a
commit d0e425cf35
9 changed files with 25 additions and 25 deletions

View File

@ -151,14 +151,14 @@ namespace Antlr4.Runtime.Atn
int version = ToInt(data[p++]); int version = ToInt(data[p++]);
if (version != SerializedVersion) if (version != SerializedVersion)
{ {
string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with version %d (expected %d).", version, SerializedVersion); string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with version {0} (expected {1}).", version, SerializedVersion);
throw new NotSupportedException(reason); throw new NotSupportedException(reason);
} }
Guid uuid = ToUUID(data, p); Guid uuid = ToUUID(data, p);
p += 8; p += 8;
if (!SupportedUuids.Contains(uuid)) if (!SupportedUuids.Contains(uuid))
{ {
string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID %s (expected %s or a legacy UUID).", uuid, SerializedUuid); string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID {0} (expected {1} or a legacy UUID).", uuid, SerializedUuid);
throw new NotSupportedException(reason); throw new NotSupportedException(reason);
} }
bool supportsLexerActions = IsFeatureSupported(AddedLexerActions, uuid); bool supportsLexerActions = IsFeatureSupported(AddedLexerActions, uuid);
@ -1263,7 +1263,7 @@ nextState_break: ;
default: default:
{ {
string message = string.Format(CultureInfo.CurrentCulture, "The specified state type %d is not valid.", type); string message = string.Format(CultureInfo.CurrentCulture, "The specified state type {0} is not valid.", type);
throw new ArgumentException(message); throw new ArgumentException(message);
} }
} }
@ -1317,7 +1317,7 @@ nextState_break: ;
default: default:
{ {
string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type %d is not valid.", type); string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type {0} is not valid.", type);
throw new ArgumentException(message); throw new ArgumentException(message);
} }
} }

View File

@ -445,7 +445,7 @@ namespace Antlr4.Runtime.Atn
default: default:
{ {
string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type %s is not valid.", action.GetActionType()); string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type {0} is not valid.", action.GetActionType());
throw new ArgumentException(message); throw new ArgumentException(message);
} }
} }
@ -477,14 +477,14 @@ namespace Antlr4.Runtime.Atn
int version = ATNDeserializer.ToInt(data[p++]); int version = ATNDeserializer.ToInt(data[p++]);
if (version != ATNDeserializer.SerializedVersion) if (version != ATNDeserializer.SerializedVersion)
{ {
string reason = string.Format("Could not deserialize ATN with version %d (expected %d).", version, ATNDeserializer.SerializedVersion); string reason = string.Format("Could not deserialize ATN with version {0} (expected {1}).", version, ATNDeserializer.SerializedVersion);
throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason)); throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason));
} }
UUID uuid = ATNDeserializer.ToUUID(data, p); UUID uuid = ATNDeserializer.ToUUID(data, p);
p += 8; p += 8;
if (!uuid.Equals(ATNDeserializer.SerializedUuid)) if (!uuid.Equals(ATNDeserializer.SerializedUuid))
{ {
string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID %s (expected %s).", uuid, ATNDeserializer.SerializedUuid); string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID {0} (expected {1}).", uuid, ATNDeserializer.SerializedUuid);
throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason)); throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason));
} }
p++; p++;

View File

@ -139,7 +139,7 @@ namespace Antlr4.Runtime.Atn
public override string ToString() public override string ToString()
{ {
return string.Format("channel(%d)", channel); return string.Format("channel({0})", channel);
} }
} }
} }

View File

@ -137,7 +137,7 @@ namespace Antlr4.Runtime.Atn
public override string ToString() public override string ToString()
{ {
return string.Format("mode(%d)", mode); return string.Format("mode({0})", mode);
} }
} }
} }

View File

@ -136,7 +136,7 @@ namespace Antlr4.Runtime.Atn
public override string ToString() public override string ToString()
{ {
return string.Format("pushMode(%d)", mode); return string.Format("pushMode({0})", mode);
} }
} }
} }

View File

@ -132,7 +132,7 @@ namespace Antlr4.Runtime.Atn
public override string ToString() public override string ToString()
{ {
return string.Format("type(%d)", type); return string.Format("type({0})", type);
} }
} }
} }

View File

@ -80,7 +80,7 @@ namespace Antlr4.Runtime.Misc
} }
foreach (KeyValuePair<ITypeMirror, IList<Tuple<RuleDependency, IElement>>> entry in recognizerDependencies.EntrySet()) foreach (KeyValuePair<ITypeMirror, IList<Tuple<RuleDependency, IElement>>> entry in recognizerDependencies.EntrySet())
{ {
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Note, string.Format("ANTLR 4: Validating %d dependencies on rules in %s.", entry.Value.Count, entry.Key.ToString())); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Note, string.Format("ANTLR 4: Validating {0} dependencies on rules in {1}.", entry.Value.Count, entry.Key.ToString()));
CheckDependencies(entry.Value, entry.Key); CheckDependencies(entry.Value, entry.Key);
} }
return true; return true;
@ -100,7 +100,7 @@ namespace Antlr4.Runtime.Misc
Args.NotNull("clazz", clazz); Args.NotNull("clazz", clazz);
if (!className.Equals(clazz.GetCanonicalName())) if (!className.Equals(clazz.GetCanonicalName()))
{ {
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unable to process rule dependencies due to class name mismatch: %s != %s", className, clazz.GetCanonicalName())); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unable to process rule dependencies due to class name mismatch: {0} != {1}", className, clazz.GetCanonicalName()));
return false; return false;
} }
return true; return true;
@ -111,7 +111,7 @@ namespace Antlr4.Runtime.Misc
try try
{ {
dependency.Recognizer(); dependency.Recognizer();
string message = string.Format("Expected %s to get the %s.", typeof(MirroredTypeException).Name, typeof(ITypeMirror).Name); string message = string.Format("Expected {0} to get the {1}.", typeof(MirroredTypeException).Name, typeof(ITypeMirror).Name);
throw new NotSupportedException(message); throw new NotSupportedException(message);
} }
catch (MirroredTypeException ex) catch (MirroredTypeException ex)
@ -138,7 +138,7 @@ namespace Antlr4.Runtime.Misc
if (effectiveRule < 0 || effectiveRule >= ruleVersions.Length) if (effectiveRule < 0 || effectiveRule >= ruleVersions.Length)
{ {
Tuple<IAnnotationMirror, IAnnotationValue> ruleReferenceElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule); Tuple<IAnnotationMirror, IAnnotationValue> ruleReferenceElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule);
string message = string.Format("Rule dependency on unknown rule %d@%d in %s", dependency.Item1.Rule(), dependency.Item1.Version(), GetRecognizerType(dependency.Item1).ToString()); string message = string.Format("Rule dependency on unknown rule {0}@{1} in {2}", dependency.Item1.Rule(), dependency.Item1.Version(), GetRecognizerType(dependency.Item1).ToString());
if (ruleReferenceElement != null) if (ruleReferenceElement != null)
{ {
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, ruleReferenceElement.Item1, ruleReferenceElement.Item2); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, ruleReferenceElement.Item1, ruleReferenceElement.Item2);
@ -213,7 +213,7 @@ namespace Antlr4.Runtime.Misc
if (declaredVersion > highestRequiredDependency) if (declaredVersion > highestRequiredDependency)
{ {
Tuple<IAnnotationMirror, IAnnotationValue> versionElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Version); Tuple<IAnnotationMirror, IAnnotationValue> 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.Item1.Rule()], highestRequiredDependency, declaredVersion, GetRecognizerType(dependency.Item1).ToString()); string message = string.Format("Rule dependency version mismatch: {0} has maximum dependency version {1} (expected {2}) in {3}", ruleNames[dependency.Item1.Rule()], highestRequiredDependency, declaredVersion, GetRecognizerType(dependency.Item1).ToString());
if (versionElement != null) if (versionElement != null)
{ {
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, versionElement.Item1, versionElement.Item2); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, versionElement.Item1, versionElement.Item2);
@ -226,7 +226,7 @@ namespace Antlr4.Runtime.Misc
} }
catch (AnnotationTypeMismatchException) catch (AnnotationTypeMismatchException)
{ {
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, string.Format("Could not validate rule dependencies for element %s", dependency.Item2.ToString()), dependency.Item2); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, string.Format("Could not validate rule dependencies for element {0}", dependency.Item2.ToString()), dependency.Item2);
} }
} }
} }
@ -244,7 +244,7 @@ namespace Antlr4.Runtime.Misc
{ {
dependentsElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule); dependentsElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule);
} }
string message = string.Format("Cannot validate the following dependents of rule %d: %s", dependency.Item1.Rule(), unimplemented); string message = string.Format("Cannot validate the following dependents of rule {0}: {1}", dependency.Item1.Rule(), unimplemented);
if (dependentsElement != null) if (dependentsElement != null)
{ {
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, message, dependency.Item2, dependentsElement.Item1, dependentsElement.Item2); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, message, dependency.Item2, dependentsElement.Item1, dependentsElement.Item2);
@ -267,14 +267,14 @@ namespace Antlr4.Runtime.Misc
else else
{ {
string mismatchedRuleName = ruleNames[relatedRule]; string mismatchedRuleName = ruleNames[relatedRule];
path = string.Format("rule %s (%s of %s)", mismatchedRuleName, relation, ruleName); path = string.Format("rule {0} ({1} of {2})", mismatchedRuleName, relation, ruleName);
} }
int declaredVersion = dependency.Item1.Version(); int declaredVersion = dependency.Item1.Version();
int actualVersion = ruleVersions[relatedRule]; int actualVersion = ruleVersions[relatedRule];
if (actualVersion > declaredVersion) if (actualVersion > declaredVersion)
{ {
Tuple<IAnnotationMirror, IAnnotationValue> versionElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Version); Tuple<IAnnotationMirror, IAnnotationValue> 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.Item1).ToString()); string message = string.Format("Rule dependency version mismatch: {0} has version {1} (expected <= {2}) in {3}", path, actualVersion, declaredVersion, GetRecognizerType(dependency.Item1).ToString());
if (versionElement != null) if (versionElement != null)
{ {
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, versionElement.Item1, versionElement.Item2); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, versionElement.Item1, versionElement.Item2);
@ -314,7 +314,7 @@ namespace Antlr4.Runtime.Misc
int index = (int)constantValue; int index = (int)constantValue;
if (index < 0 || index >= versions.Length) if (index < 0 || index >= versions.Length)
{ {
string message = string.Format("Rule index %d for rule '%s' out of bounds for recognizer %s.", index, name, recognizerClass.ToString()); string message = string.Format("Rule index {0} for rule '{1}' out of bounds for recognizer {2}.", index, name, recognizerClass.ToString());
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, element); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, element);
continue; continue;
} }
@ -326,7 +326,7 @@ namespace Antlr4.Runtime.Misc
IExecutableElement ruleMethod = GetRuleMethod(recognizerClass, name); IExecutableElement ruleMethod = GetRuleMethod(recognizerClass, name);
if (ruleMethod == null) if (ruleMethod == null)
{ {
string message = string.Format("Could not find rule method for rule '%s' in recognizer %s.", name, recognizerClass.ToString()); string message = string.Format("Could not find rule method for rule '{0}' in recognizer {1}.", name, recognizerClass.ToString());
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, element); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, element);
continue; continue;
} }
@ -507,7 +507,7 @@ namespace Antlr4.Runtime.Misc
} }
else else
{ {
processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unexpected annotation property %s.", value.Key.ToString()), dependency.Item2, annotationMirror, value.Value); processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unexpected annotation property {0}.", value.Key.ToString()), dependency.Item2, annotationMirror, value.Value);
} }
} }
} }

View File

@ -277,7 +277,7 @@ namespace Antlr4.Runtime
{ {
if (!Precpred(_ctx, ((PrecedencePredicateTransition)transition).precedence)) if (!Precpred(_ctx, ((PrecedencePredicateTransition)transition).precedence))
{ {
throw new FailedPredicateException(this, string.Format("precpred(_ctx, %d)", ((PrecedencePredicateTransition)transition).precedence)); throw new FailedPredicateException(this, string.Format("precpred(_ctx, {0})", ((PrecedencePredicateTransition)transition).precedence));
} }
break; break;
} }

View File

@ -298,7 +298,7 @@ namespace Antlr4.Runtime.Tree.Pattern
/// <summary><inheritDoc></inheritDoc></summary> /// <summary><inheritDoc></inheritDoc></summary>
public override string ToString() public override string ToString()
{ {
return string.Format("Match %s; found %d labels", Succeeded() ? "succeeded" : "failed", GetLabels().Count); return string.Format("Match {0}; found {1} labels", Succeeded() ? "succeeded" : "failed", GetLabels().Count);
} }
} }
} }