public override void AnalyzeDocument(CodeDocument document) { CsDocument csDocument = (CsDocument)document; csDocument.WalkDocument( new CodeWalkerElementVisitor <object>(this.VisitElement)); }
/// <summary> /// Gets first code element at specified line number. /// </summary> public static ICodeElement GetElementByLine(CsDocument document, int lineNumber) { object[] args = new object[] { lineNumber, null }; document.WalkDocument(FindByLineElementVisitor, null, args); return((ICodeElement)args[1]); }
/// <summary> /// Gets first expression at specified line number. /// </summary> public static Expression GetExpressionByLine(CsDocument document, int lineNumber) { object[] args = new object[] { lineNumber, null }; document.WalkDocument(null, null, FindByLineExpressionVisitor, args); return((Expression)args[1]); }
/// <summary> /// Gets first code element at specified line number. /// </summary> /// <remarks> /// Returns object because it is ICodeElement for 4.4 and CodeElement for 4.3. /// </remarks> public static object GetElementByLine(CsDocument document, int lineNumber) { object[] args = new object[] { lineNumber, null }; document.WalkDocument(FindByLineElementVisitor, null, args); return args[1]; }
public override void AnalyzeDocument(CodeDocument document) { CsDocument csdocument = (CsDocument)document; if (csdocument.RootElement != null && !csdocument.RootElement.Generated) { csdocument.WalkDocument(new CodeWalkerElementVisitor <object>(VisitElement)); } }
public override void AnalyzeDocument(CodeDocument codeDocument) { Param.RequireNotNull(codeDocument, "codeDocument"); CsDocument csharpDocument = (CsDocument)codeDocument; if (csharpDocument.RootElement != null && !csharpDocument.RootElement.Generated) { csharpDocument.WalkDocument(VisitElement, null, null); } }
/// <summary> /// Extremely simple analyzer for demo purposes. /// </summary> public override void AnalyzeDocument(CodeDocument document) { CsDocument doc = (CsDocument)document; // skipping wrong or auto-generated documents if (doc.RootElement == null || doc.RootElement.Generated) { return; } // check all class entries doc.WalkDocument(CheckClasses); }
/// <summary> /// Checks the methods within the given document. /// </summary> /// <param name="document">The document to check.</param> public override void AnalyzeDocument(CodeDocument document) { Param.RequireNotNull(document, "document"); CsDocument csdocument = (CsDocument)document; if (csdocument.RootElement != null && !csdocument.RootElement.Generated) { // Check the access modifier rules. TopLevelElements topLevelElements = new TopLevelElements(); csdocument.WalkDocument <TopLevelElements>( new CodeWalkerElementVisitor <TopLevelElements>(this.ProcessElement), new CodeWalkerStatementVisitor <TopLevelElements>(this.ProcessStatement), new CodeWalkerExpressionVisitor <TopLevelElements>(this.ProcessExpression), topLevelElements); // If there is more than one top-level class in the file, make sure they are all // partial classes and are all of the same type. if (topLevelElements.Classes.Count > 1) { string name = string.Empty; foreach (Class classElement in topLevelElements.Classes) { if (!classElement.Declaration.ContainsModifier(CsTokenType.Partial) || (!string.IsNullOrEmpty(name) && string.Compare(name, classElement.FullNamespaceName, StringComparison.Ordinal) != 0)) { // Set the violation line number to the second class in the file. int count = 0; foreach (Class c in topLevelElements.Classes) { if (count == 1) { this.AddViolation(c, c.LineNumber, Rules.FileMayOnlyContainASingleClass); break; } ++count; } break; } name = classElement.FullNamespaceName; } } // If there is more than one namespace in the file, this is a violation. if (topLevelElements.Namespaces.Count > 1) { // Set the violation line number to the second namespace in the file. int count = 0; foreach (Namespace n in topLevelElements.Namespaces) { if (count == 1) { this.AddViolation(n, n.LineNumber, Rules.FileMayOnlyContainASingleNamespace); break; } ++count; } } } }
/// <summary> /// Gets first expression at specified line number. /// </summary> public static Expression GetExpressionByLine(CsDocument document, int lineNumber) { object[] args = { lineNumber, null }; document.WalkDocument(null, null, FindByLineExpressionVisitor, args); return (Expression)args[1]; }
/// <summary> /// Checks the contents of the documentation for the elements in the document. /// </summary> /// <param name="document"> /// The document to check. /// </param> private void CheckElementDocumentation(CsDocument document) { Param.AssertNotNull(document, "document"); // Get the settings. AnalyzerSettings settings = new AnalyzerSettings(); settings.IgnorePrivates = DocumentationRules.IgnorePrivatesDefaultValue; settings.IgnoreInternals = DocumentationRules.IgnoreInternalsDefaultValue; settings.RequireFields = DocumentationRules.IncludeFieldsDefaultValue; if (document.Settings != null) { BooleanProperty setting = document.Settings.GetAddInSetting(this, DocumentationRules.IgnorePrivates) as BooleanProperty; if (setting != null) { settings.IgnorePrivates = setting.Value; } setting = document.Settings.GetAddInSetting(this, DocumentationRules.IgnoreInternals) as BooleanProperty; if (setting != null) { settings.IgnoreInternals = setting.Value; } setting = document.Settings.GetAddInSetting(this, DocumentationRules.IncludeFieldsProperty) as BooleanProperty; if (setting != null) { settings.RequireFields = setting.Value; } } document.WalkDocument(this.CheckDocumentationForElement, settings); }