/// <summary> /// Initializes a new instance of the <see cref="UvssError"/> class. /// </summary> /// <param name="diagnosticInfo">The diagnostic info associated with the error, if any.</param> /// <param name="line">The index of the line in the source text at which the error occurred.</param> /// <param name="column">The index of the column in the source text at which the error occurred.</param> /// <param name="message">The error message.</param> private UvssError(DiagnosticInfo diagnosticInfo, Int32 line, Int32 column, String message) { this.diagnosticInfo = diagnosticInfo; this.line = line; this.column = column; this.message = message; }
/// <summary> /// Initializes a new instance of the <see cref="Error"/> class. /// </summary> /// <param name="file">The path to the file that contains the error.</param> /// <param name="span">The snapshot span that contains the error.</param> /// <param name="diagnosticInfo">The diagnostic information that this error represents.</param> internal Error(String file, SnapshotSpan span, DiagnosticInfo diagnosticInfo) { Contract.Require(file, nameof(file)); Contract.Require(diagnosticInfo, nameof(diagnosticInfo)); this.File = file; this.Span = span; this.DiagnosticInfo = diagnosticInfo; }
/// <summary> /// Adds a diagnostic indicating that a property trigger condition is missing its comparison operator /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportPropertyTriggerMissingComparisonOperator(ref ICollection<DiagnosticInfo> collection, SyntaxToken node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.MissingToken, DiagnosticSeverity.Error, span, $"Comparison operator expected"); var nodeDiagnosticsArray = node.GetDiagnosticsArray(); var nodeDiagnostics = (ICollection<DiagnosticInfo>)nodeDiagnosticsArray?.ToList(); Report(ref nodeDiagnostics, diagnostic); node.SetDiagnostics(nodeDiagnostics); }
/// <summary> /// Adds a diagnostic indicating that an easing function is unrecognized /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportUnrecognizedEasingFunction(ref ICollection<DiagnosticInfo> collection, UvssIdentifierBaseSyntax node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.UnrecognizedEasingFunction, DiagnosticSeverity.Error, span, $"Unrecognized easing function '{node.Text}'"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that a loop type is unrecognized /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportUnrecognizedLoopType(ref ICollection<DiagnosticInfo> collection, UvssIdentifierBaseSyntax node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.UnrecognizedLoopType, DiagnosticSeverity.Error, span, $"Unrecognized loop type '{node.Text}' (should be 'none' or 'loop' or 'reverse')"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that an unexpected token was encountered in the body of a trigger /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="trivia">The unexpected node.</param> internal static void ReportUnexpectedTokenInTriggerBody(ref ICollection<DiagnosticInfo> collection, SkippedTokensTriviaSyntax trivia) { Contract.Require(trivia, nameof(trivia)); var span = new TextSpan(0, trivia.Width); var diagnostic = new DiagnosticInfo(trivia, DiagnosticID.TriggerActionExpected, DiagnosticSeverity.Error, span, $"Trigger action expected"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that a directive is not recognized /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportUnknownDirective(ref ICollection<DiagnosticInfo> collection, UvssDirectiveSyntax node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.UnknownDirective, DiagnosticSeverity.Error, span, $"Unrecognized directive"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that a visual transition has too many arguments in its argument list /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportTransitionHasTooManyArguments(ref ICollection<DiagnosticInfo> collection, SyntaxNode node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.TransitionHasTooManyArguments, DiagnosticSeverity.Error, span, "Transition has too many arguments"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that an unexpected token was encountered in the body of a document /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="trivia">The unexpected node.</param> internal static void ReportUnexpectedTokenInDocumentContent(ref ICollection<DiagnosticInfo> collection, SkippedTokensTriviaSyntax trivia) { Contract.Require(trivia, nameof(trivia)); var span = new TextSpan(0, trivia.Width); var diagnostic = new DiagnosticInfo(trivia, DiagnosticID.RuleSetOrStoryboardExpected, DiagnosticSeverity.Error, span, $"Rule set or storyboard expected"); Report(ref collection, diagnostic); }
/// <summary> /// Creates a new <see cref="UvssError"/> instance from the specified diagnostic info. /// </summary> /// <param name="diagnosticInfo">The diagnostic info from which to create the error.</param> /// <returns>The <see cref="UvssError"/> instance which was created.</returns> public static UvssError FromDiagnosticInfo(DiagnosticInfo diagnosticInfo) { Contract.Require(diagnosticInfo, nameof(diagnosticInfo)); return new UvssError(diagnosticInfo, 0, 0, null); }
/// <summary> /// Adds a diagnostic indicating that a directive was encountered at an invalid position /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportDirectiveAtInvalidPosition(ref ICollection<DiagnosticInfo> collection, UvssDirectiveSyntax node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.DirectiveAtInvalidPosition, DiagnosticSeverity.Error, span, $"Directives are only valid at the start of a document"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that a selector part could not be completely parsed /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportInvalidSelectorPart(ref ICollection<DiagnosticInfo> collection, UvssInvalidSelectorPartSyntax node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.InvalidSelectorPart, DiagnosticSeverity.Error, span, $"Invalid selector part"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that an expected node was missing /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The missing node.</param> internal static void ReportMissingNode(ref ICollection<DiagnosticInfo> collection, SyntaxNode node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.MissingToken, DiagnosticSeverity.Error, span, $"{GetSyntaxKindFriendlyName(node.Kind)} expected"); var nodeDiagnosticsArray = node.GetDiagnosticsArray(); var nodeDiagnostics = (ICollection<DiagnosticInfo>)nodeDiagnosticsArray?.ToList(); Report(ref nodeDiagnostics, diagnostic); node.SetDiagnostics(nodeDiagnostics); }
/// <summary> /// Adds a diagnostic indicating that an index must be an integer value /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportIndexMustBeIntegerValue(ref ICollection<DiagnosticInfo> collection, SyntaxToken node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.IndexMustBeIntegerValue, DiagnosticSeverity.Error, span, $"Index must be integer value"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that a trigger is incomplete /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportIncompleteTrigger(ref ICollection<DiagnosticInfo> collection, UvssIncompleteTriggerSyntax node) { Contract.Require(node, nameof(node)); var span = new TextSpan(node.TriggerKeyword.Width, 0); var diagnostic = new DiagnosticInfo(node.TriggerKeyword, DiagnosticID.IncompleteTrigger, DiagnosticSeverity.Error, span, "Trigger type expected ('property' or 'event')"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that an event trigger has an incomplete argument list /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportEventTriggerHasTooFewArguments(ref ICollection<DiagnosticInfo> collection, SyntaxNode node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.EventTriggerHasTooFewArguments, DiagnosticSeverity.Error, span, "Event trigger argument lists must contain at least one argument"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that an event trigger has duplicate arguments in its argument list /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> /// <param name="duplicateTokenText">The text of the duplicated token.</param> internal static void ReportEventTriggerHasDuplicateArguments(ref ICollection<DiagnosticInfo> collection, SyntaxNode node, String duplicateTokenText) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.EventTriggerHasDuplicateArguments, DiagnosticSeverity.Error, span, $"Event trigger has duplicate argument '{duplicateTokenText}'"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that a directive was encountered at an invalid position /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportDirectiveMustBeFirstNonWhiteSpaceOnLine(ref ICollection<DiagnosticInfo> collection, UvssDirectiveSyntax node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.DirectiveMustBeFirstNonWhiteSpaceOnLine, DiagnosticSeverity.Error, span, $"Directive must appear as the first non-whitespace character on a line"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic indicating that a visual transition has an incomplete argument list /// to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="node">The syntax node which is associated with the diagnostic.</param> internal static void ReportTransitionHasTooFewArguments(ref ICollection<DiagnosticInfo> collection, SyntaxNode node) { Contract.Require(node, nameof(node)); var span = new TextSpan(0, node.Width); var diagnostic = new DiagnosticInfo(node, DiagnosticID.TransitionHasTooFewArguments, DiagnosticSeverity.Error, span, "Transition arguments must specify at least a visual state group and a destination state"); Report(ref collection, diagnostic); }
/// <summary> /// Adds a diagnostic to the specified collection of diagnostics. /// </summary> /// <param name="collection">The collection to which to add the diagnostic.</param> /// <param name="diagnostic">The diagnostic to add to the collection.</param> internal static void Report(ref ICollection<DiagnosticInfo> collection, DiagnosticInfo diagnostic) { Contract.Require(diagnostic, nameof(diagnostic)); if (collection == null) collection = new List<DiagnosticInfo>(); collection.Add(diagnostic); }