/// <summary> /// Checks the placement of brackets within the given document. /// </summary> /// <param name="document">The document to check.</param> public override void AnalyzeDocument(ICodeDocument document) { Param.RequireNotNull(document, "document"); CsDocument csdocument = document.AsCsDocument(); if (csdocument != null && !csdocument.Generated) { csdocument.WalkCodeModel(this.VisitCodeUnit); // Check line spacing rules. this.CheckLineSpacing(csdocument); } }
/// <summary> /// Analyzes or fixes the given document. /// </summary> /// <param name="document">The document.</param> private void ProcessDocument(ICodeDocument document) { Param.AssertNotNull(document, "document"); CsDocument csdocument = document.AsCsDocument(); Settings settings = new Settings(); settings.DoNotUseRegions = this.IsRuleEnabled(document, Rules.DoNotUseRegions.ToString()); settings.DoNotPlaceRegionsWithinElements = this.IsRuleEnabled(document, Rules.DoNotPlaceRegionsWithinElements.ToString()); if (csdocument != null && !csdocument.Generated) { // Checks various formatting rules. csdocument.WalkCodeModel <Settings>(this.VisitCodeUnit, settings); // Check statement formatting rules. this.CheckStatementFormattingRulesForElement(csdocument); // Check the class member rules. this.CheckClassMemberRulesForElements(csdocument, null, null); } }
/// <summary> /// Checks the methods within the given document. /// </summary> /// <param name="document">The document to check.</param> public override void AnalyzeDocument(ICodeDocument document) { Param.RequireNotNull(document, "document"); CsDocument csdocument = document.AsCsDocument(); if (csdocument != null && !csdocument.Generated) { // Check the access modifier rules. TopLevelElements topLevelElements = new TopLevelElements(); csdocument.WalkCodeModel <TopLevelElements>(this.VisitCodeUnit, 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.ContainsModifier(TokenType.Partial) || (!string.IsNullOrEmpty(name) && string.Compare(name, classElement.FullyQualifiedName, 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.FullyQualifiedName; } } // 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; } } } }