/// <summary> /// The execute transaction inner. /// </summary> /// <param name="solution"> /// The solution. /// </param> /// <param name="textControl"> /// The text control. /// </param> public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl) { IElement element = Utils.GetElementAtCaret(solution, textControl); if (element != null) { IDestructorDeclaration destructorDeclaration = element.GetContainingElement <IDestructorDeclaration>(true); if (destructorDeclaration != null) { new DocumentationRules().EnsureDestructorSummaryDocBeginsWithStandardText(destructorDeclaration); } } }
/// <summary> /// Ensures that the destructor documentation starts with the standard text summary. /// </summary> /// <remarks> /// Keeps the existing comment, but prepends the standard text. /// </remarks> /// <param name="destructorDeclaration"> /// The destructor <see cref="IDeclaration"/>. /// </param> public void EnsureDestructorSummaryDocBeginsWithStandardText(IDestructorDeclaration destructorDeclaration) { if (destructorDeclaration == null) { return; } DeclarationHeader declarationHeader = new DeclarationHeader(destructorDeclaration); if (declarationHeader.IsMissing || declarationHeader.IsInherited || !declarationHeader.HasSummary) { return; } IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, destructorDeclaration.GetSolution()); if (!settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation)) { return; } string destructorDescriptionText = Utils.CreateDestructorDescriptionText(destructorDeclaration, true); string xmlComment = Utils.GetTextFromDeclarationHeader(declarationHeader.XmlNode); string textWeShouldStartWith = string.Format(CultureInfo.InvariantCulture, CachedCodeStrings.HeaderSummaryForDestructor, destructorDescriptionText); if (!xmlComment.StartsWith(textWeShouldStartWith, StringComparison.Ordinal)) { string summaryText = Utils.CreateSummaryForDestructorDeclaration(destructorDeclaration); declarationHeader.SummaryXmlNode.InnerXml = Environment.NewLine + summaryText; declarationHeader.Update(); } }
/// <summary> /// Ensures that the destructor documentation starts with the standard text summary. /// </summary> /// <remarks> /// Keeps the existing comment, but prepends the standard text. /// </remarks> /// <param name="destructorDeclaration"> /// The destructor <see cref="IDeclaration"/>. /// </param> public void EnsureDestructorSummaryDocBeginsWithStandardText(IDestructorDeclaration destructorDeclaration) { DeclarationHeader declarationHeader = new DeclarationHeader(destructorDeclaration); if (declarationHeader.IsMissing || declarationHeader.IsInherited || !declarationHeader.HasSummary) { return; } string destructorDescriptionText = Utils.CreateDestructorDescriptionText(destructorDeclaration, true); string xmlComment = Utils.GetTextFromDeclarationHeader(declarationHeader.XmlNode); string textWeShouldStartWith = string.Format(CultureInfo.InvariantCulture, HeaderSummaryForDestructor, destructorDescriptionText); if (!xmlComment.StartsWith(textWeShouldStartWith, StringComparison.Ordinal)) { string summaryText = Utils.CreateSummaryForDestructorDeclaration(destructorDeclaration); declarationHeader.SummaryXmlNode.InnerXml = Environment.NewLine + summaryText; declarationHeader.Update(); } }
/// <summary> /// Gets a string of the summary for this destructor. /// </summary> /// <param name="destructorDeclaration"> /// The destructor to produce the summary for. /// </param> /// <returns> /// A string of the destructor summary text. /// </returns> public static string CreateSummaryForDestructorDeclaration(IDestructorDeclaration destructorDeclaration) { string summaryText = string.Empty; DeclarationHeader declarationHeader = new DeclarationHeader(destructorDeclaration); if (declarationHeader.IsInherited) { return declarationHeader.XmlNode.InnerXml; } if (declarationHeader.HasSummary) { summaryText = declarationHeader.SummaryXmlNode.InnerXml; } if (!StyleCopOptions.Instance.InsertTextIntoDocumentation) { return summaryText; } string destructorDescriptionText = Utils.CreateDestructorDescriptionText(destructorDeclaration, true); string newXmlText = string.Format(CultureInfo.InvariantCulture, HeaderSummaryForDestructorXml, destructorDescriptionText); return newXmlText + " " + summaryText; }
/// <summary> /// Returns the text that the destructor should have from the containing type declaration with either with 'less than' and 'greater than' signs escaped or not. /// </summary> /// <param name="destructorDeclaration"> /// The destructor to use. /// </param> /// <param name="encodeHtmlTags"> /// If True then <see cref="ITypeParameterOfTypeDeclaration"/> will have {} instead of < and >. /// </param> /// <returns> /// A string of the text. /// </returns> public static string CreateDestructorDescriptionText(IDestructorDeclaration destructorDeclaration, bool encodeHtmlTags) { ICSharpTypeDeclaration containingTypeDeclaration = destructorDeclaration.GetContainingTypeDeclaration(); string newName = destructorDeclaration.DeclaredName.Substring(1); if (containingTypeDeclaration.TypeParameters.Count > 0) { newName += encodeHtmlTags ? "{" : "<"; for (int i = 0; i < containingTypeDeclaration.TypeParameters.Count; i++) { ITypeParameterOfTypeDeclaration parameterDeclaration = containingTypeDeclaration.TypeParameters[i]; newName += parameterDeclaration.DeclaredName; if (i < containingTypeDeclaration.TypeParameters.Count - 1) { newName += ","; } } newName += encodeHtmlTags ? "}" : ">"; } return newName; }
/// <summary> /// Gets a string of the summary for this destructor. /// </summary> /// <param name="destructorDeclaration"> /// The destructor to produce the summary for. /// </param> /// <returns> /// A string of the destructor summary text. /// </returns> public static string CreateSummaryForDestructorDeclaration(IDestructorDeclaration destructorDeclaration) { string summaryText = string.Empty; DeclarationHeader declarationHeader = new DeclarationHeader(destructorDeclaration); if (declarationHeader.IsInherited) { return declarationHeader.XmlNode.InnerXml; } if (declarationHeader.HasSummary) { summaryText = declarationHeader.SummaryXmlNode.InnerXml; } IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, destructorDeclaration.GetSolution()); if (!settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation)) { return summaryText; } string destructorDescriptionText = CreateDestructorDescriptionText(destructorDeclaration, true); string newXmlText = string.Format(CultureInfo.InvariantCulture, HeaderSummaryForDestructorXml, destructorDescriptionText); return newXmlText + " " + summaryText; }