private static bool CheckMatch(IList <ErrorDescription> expectedErrorList, int fromError, int toError, out int expectedErrors) { expectedErrors = expectedErrorList.Count; if (toError - fromError != expectedErrors) { return(false); } // * Checks all the errors for (int errorNumber = fromError; errorNumber < toError; errorNumber++) { IError error = ErrorManager.Instance.GetError(errorNumber); bool found = false; foreach (ErrorDescription errorDescription in expectedErrorList) { if (errorDescription.Equals(error)) { found = true; } } if (!found) { ErrorAdapter ea = error as ErrorAdapter; if (ea != null) { Console.Error.WriteLine("Unexpected " + ea.ErrorType + " [" + ea.Location.Line + "," + ea.Location.Column + "]:" + ea.Description); } else { Console.Error.WriteLine("Unexpected error: " + ErrorManager.Instance.GetError(errorNumber)); } return(false); } } return(true); }
//public bool checkErrors(ITextBuffer source) //{ // int errorCount = ErrorManager.Instance.ErrorCount; // if (errorCount > 0) // { // IError errorFound = null; // Span errorSpan; // int errorPosition = 0, errorLineNumber; // string filePath = source.Properties.GetProperty<ITextDocument>(typeof(ITextDocument)).FilePath; // for (int i = 0; i < errorCount; i++) // { // errorFound = ErrorManager.Instance.GetError(i); // if (errorFound is ErrorAdapter) // { // ErrorAdapter error = (ErrorAdapter)errorFound; // var textView = FileUtilities.Instance.GetIVsTextView(error.Location.FileName); // if (filePath != error.Location.FileName) continue; // var file = StaDynLanguage.StaDynAST.ProjectFileAST.Instance.getAstFile(error.Location.FileName); // var textView = StaDynLanguage.Utils.FileUtilities.Instance.GetIVsTextView(file.FileName); // errorLineNumber = error.Location.Line > 0 ? error.Location.Line - 1 : 0; // int v; // textView.GetNearestPosition(errorLineNumber, error.Location.Column, out errorPosition, out v); // errorPosition = source.CurrentSnapshot.GetLineFromLineNumber(errorLineNumber).Start.Position + error.Location.Column; // errorSpan = new Span(errorPosition, 3); // this.addError(ValidationErrorSeverity.Error, ValidationErrorType.Semantic, error.Description, errorSpan); // } // else // this.addError(ValidationErrorSeverity.Error, ValidationErrorType.Semantic, "Parse Error", new Span(0, 3)); // } // return true; // } // return false; //} public void refreshErrorList() { int errorCount = ErrorManager.Instance.ErrorCount; if (errorCount > 0) { IError errorFound = null; int errorLineNumber; for (int i = 0; i < errorCount; i++) { errorFound = ErrorManager.Instance.GetError(i); if (errorFound is ErrorAdapter) { ErrorAdapter error = (ErrorAdapter)errorFound; errorLineNumber = error.Location.Line > 0 ? error.Location.Line - 1 : 0; this.addError(ValidationErrorSeverity.Error, ValidationErrorType.Semantic, error.Description, error.Location.FileName, errorLineNumber, error.Location.Column); } else { this.addError(ValidationErrorSeverity.Error, ValidationErrorType.Semantic, "Parse Error", "", 0, 0); } } } }
public override bool Equals(object obj) { // * Two error descriptions ErrorDescription errorDescription = obj as ErrorDescription; if (errorDescription != null) { if (this.Line != 0 && errorDescription.line != 0 && this.Line != errorDescription.line) { return(false); } if (this.Column != 0 && errorDescription.column != 0 && this.Column != errorDescription.column) { return(false); } if (this.Type != null && errorDescription.type != null && !this.Type.Equals(errorDescription.type)) { return(false); } return(true); } // * An error description and an ErrorAdapter ErrorAdapter errorAdapter = obj as ErrorAdapter; if (errorAdapter != null) { if (this.Line != 0 && this.Line != errorAdapter.Location.Line) { return(false); } if (this.Column != 0 && this.Column != errorAdapter.Location.Column) { return(false); } if (!this.Type.Equals("") && !this.type.Equals(errorAdapter.GetType().ToString())) { return(false); } return(true); } return(false); }