public override bool ParseFile(SourceCode sourceCode, int passNumber, ref CodeDocument document) { Param.RequireNotNull(sourceCode, "sourceCode"); Param.RequireGreaterThanOrEqualToZero(passNumber, "passNumber"); Param.Ignore(document); StyleCopTrace.In(sourceCode, passNumber, document); // The document is parsed on the first pass. On any subsequent passes, we do not do anything. if (passNumber == 0) { if (this.SkipAnalysisForDocument(sourceCode)) { return(false); } try { using (TextReader reader = sourceCode.Read()) { // Create the document. if (reader == null) { this.AddViolation(sourceCode, 1, Rules.FileMustBeReadable); } else { // Create the lexer object for the code string. CodeLexer lexer = new CodeLexer(this, sourceCode, new CodeReader(reader)); // Parse the document. CodeParser parser = new CodeParser(this, lexer); parser.ParseDocument(); document = parser.Document; } } } catch (SyntaxException syntaxex) { this.AddViolation(syntaxex.SourceCode, syntaxex.LineNumber, Rules.SyntaxException, syntaxex.Message); CsDocument csdocument = new CsDocument(sourceCode, this); csdocument.FileHeader = new FileHeader(string.Empty, new CsTokenList(csdocument.Tokens), new Reference <ICodePart>(csdocument)); document = csdocument; } } return(StyleCopTrace.Out(false)); }
private bool RegionEndCheckIfBlankOrCurly(SourceCode codeFile, int linenumber, bool allowCurly = true) { var myReader = codeFile.Read(); for (var i = 1; i <= linenumber; i++) { var data = myReader.ReadLine(); if (i == linenumber) { if (data.Trim() == string.Empty || (data.Trim().Contains("}") && allowCurly)) { return(true); } } } return(false); }
private bool RegionStartCheckIfBlankOrCurly(SourceCode codeFile, int linenumber, bool allowCurly = true) { var myReader = codeFile.Read(); for (var i = 1; i <= linenumber; i++) { var data = myReader.ReadLine(); if (i == linenumber) { //_logFile.WriteLine("LineNumber: {0} -- Text: {1}", linenumber, data); if (data.Trim() == string.Empty || (data.Trim().Contains("{") && allowCurly)) { return(true); } } } return(false); }
/// <summary> /// Parses the given file. /// </summary> /// <param name="sourceCode">The source code to parse.</param> /// <param name="passNumber">The current pass number.</param> /// <param name="document">The parsed representation of the file.</param> /// <returns>Returns false if no further analysis should be done on this file, or /// true if the file should be parsed again during the next pass.</returns> public override bool ParseFile(SourceCode sourceCode, int passNumber, ref ICodeDocument document) { Param.RequireNotNull(sourceCode, "sourceCode"); Param.RequireGreaterThanOrEqualToZero(passNumber, "passNumber"); Param.Ignore(document); // The document is parsed on the first pass. On any subsequent passes, we do not do anything. if (passNumber == 0) { try { using (TextReader reader = sourceCode.Read()) { // Create the document. if (reader == null) { this.AddViolation(sourceCode, 1, Rules.FileMustBeReadable); } else { CsLanguageService languageService = new CsLanguageService(); document = new CsDocumentWrapper( this, sourceCode, languageService.CreateCodeModel(reader, sourceCode.Name, sourceCode.Path)); } } } catch (SyntaxException syntaxex) { this.AddViolation(sourceCode, syntaxex.LineNumber, Rules.SyntaxException, syntaxex.Message); document = null; } } return(false); }
public override bool ParseFile(SourceCode sourceCode, int passNumber, ref CodeDocument document) { Param.RequireNotNull(sourceCode, "sourceCode"); Param.RequireGreaterThanOrEqualToZero(passNumber, "passNumber"); Param.Ignore(document); StyleCopTrace.In(sourceCode, passNumber, document); // The document is parsed on the first pass. On any subsequent passes, we do not do anything. if (passNumber == 0) { if (this.SkipAnalysisForDocument(sourceCode)) { return false; } try { using (TextReader reader = sourceCode.Read()) { // Create the document. if (reader == null) { this.AddViolation(sourceCode, 1, Rules.FileMustBeReadable); } else { // Create the lexer object for the code string. CodeLexer lexer = new CodeLexer(this, sourceCode, new CodeReader(reader)); // Parse the document. CodeParser parser = new CodeParser(this, lexer); parser.ParseDocument(); document = parser.Document; } } } catch (SyntaxException syntaxex) { this.AddViolation(syntaxex.SourceCode, syntaxex.LineNumber, Rules.SyntaxException, syntaxex.Message); CsDocument csdocument = new CsDocument(sourceCode, this); csdocument.FileHeader = new FileHeader(string.Empty, new CsTokenList(csdocument.Tokens), new Reference<ICodePart>(csdocument)); document = csdocument; } } return StyleCopTrace.Out(false); }