/// <summary> /// Process clean-up on file. /// </summary> /// <param name="projectFile"> /// The project file to process. /// </param> /// <param name="rangeMarker"> /// The range marker to process. /// </param> /// <param name="profile"> /// The code cleanup settings to use. /// </param> /// <param name="progressIndicator"> /// The progress indicator. /// </param> public void Process( IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JetBrains.Application.Progress.IProgressIndicator progressIndicator) { if (!this.IsAvailable(projectFile)) { return; } ISolution solution = projectFile.GetSolution(); ICSharpFile file = projectFile.GetDominantPsiFile <CSharpLanguage>() as ICSharpFile; if (file == null) { return; } StyleCopCodeCleanupOptions options = profile.GetSetting(Descriptor); if (!options.FixViolations) { return; } var services = solution.GetPsiServices(); services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, options.CreateXmlDocStubs)); StyleCopTrace.Out(); }
/// <summary> /// Loads the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Load(CodeCleanupProfile profile, XmlElement element) { ReadabilityOptions options = new ReadabilityOptions(); XmlElement optionsElement = (XmlElement)element.SelectSingleNode(this.Name); if (optionsElement != null) { try { options.SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists")); options.SA1106CodeMustNotContainEmptyStatements = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1106CodeMustNotContainEmptyStatements")); options.SA1108BlockStatementsMustNotContainEmbeddedComments = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1108BlockStatementsMustNotContainEmbeddedComments")); options.SA1109BlockStatementsMustNotContainEmbeddedRegions = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1109BlockStatementsMustNotContainEmbeddedRegions")); options.SA1120CommentsMustContainText = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1120CommentsMustContainText")); options.SA1121UseBuiltInTypeAlias = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1121UseBuiltInTypeAlias")); options.SA1122UseStringEmptyForEmptyStrings = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1122UseStringEmptyForEmptyStrings")); options.SA1123DoNotPlaceRegionsWithinElements = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1123DoNotPlaceRegionsWithinElements")); options.SA1124CodeMustNotContainEmptyRegions = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1124CodeMustNotContainEmptyRegions")); } catch (ArgumentException) { } } profile.SetSetting(this, options); }
public void Process(IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { IFile file = sourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance); if (file == null) { return; } if (!profile.GetSetting(DescriptorInstance)) { return; } file.GetPsiServices().Transactions.Execute("Reflow & Retag XML Documentation Comments", () => { using (_shellLocks.UsingWriteLock()) { foreach (var documentBlockOwner in file.Descendants <IDocCommentBlockOwner>()) { CommentReflowAndRetagAction.ReflowAndRetagCommentBlockNode( documentBlockOwner.GetSolution(), null, documentBlockOwner.DocCommentBlock); } }; }); }
/// <summary> /// Loads the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Load(CodeCleanupProfile profile, XmlElement element) { OrderingOptions options = new OrderingOptions(); XmlElement optionsElement = (XmlElement)element.SelectSingleNode(this.Name); if (optionsElement != null) { try { options.AlphabeticalUsingDirectives = (AlphabeticalUsingsStyle) Enum.Parse(typeof(AlphabeticalUsingsStyle), JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "AlphabeticalUsingDirectives")); options.ExpandUsingDirectives = (ExpandUsingsStyle)Enum.Parse(typeof(ExpandUsingsStyle), JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "ExpandUsingDirectives")); options.SA1212PropertyAccessorsMustFollowOrder = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1212PropertyAccessorsMustFollowOrder")); options.SA1213EventAccessorsMustFollowOrder = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1213EventAccessorsMustFollowOrder")); } catch (ArgumentException) { } } profile.SetSetting(this, options); }
/// <summary> /// Process clean-up on file. /// </summary> /// <param name="projectFile"> /// The project file to process. /// </param> /// <param name="rangeMarker"> /// The range marker to process. /// </param> /// <param name="profile"> /// The code cleanup settings to use. /// </param> /// <param name="progressIndicator"> /// The progress indicator. /// </param> public void Process( IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JB::JetBrains.Application.Progress.IProgressIndicator progressIndicator) { if (projectFile == null) { return; } if (!this.IsAvailable(projectFile)) { return; } ISolution solution = projectFile.GetSolution(); ICSharpFile file = projectFile.GetPsiFile <CSharpLanguage>() as ICSharpFile; if (file == null) { return; } PsiManager.GetInstance(solution).DoTransaction(() => this.InternalProcess(profile, file), "Code cleanup"); StyleCopTrace.Out(); }
/// <summary> /// Process clean-up on file. /// </summary> /// <param name="projectFile"> /// The project file to process. /// </param> /// <param name="rangeMarker"> /// The range marker to process. /// </param> /// <param name="profile"> /// The code cleanup settings to use. /// </param> /// <param name="progressIndicator"> /// The progress indicator. /// </param> public void Process( IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JetBrains.Application.Progress.IProgressIndicator progressIndicator) { if (!this.IsAvailable(projectFile)) { return; } ISolution solution = projectFile.GetSolution(); ICSharpFile file = projectFile.GetDominantPsiFile <CSharpLanguage>() as ICSharpFile; if (file == null) { return; } if (!profile.GetSetting(FIX_VIOLATIONS)) { return; } var services = solution.GetPsiServices(); services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, profile.GetSetting(CREATE_XML_DOC_STUB))); StyleCopTrace.Out(); }
public void Process(IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { var file = sourceFile.GetNonInjectedPsiFile <CSharpLanguage>(); if (file == null) { return; } if (!profile.GetSetting(DescriptorInstance)) { return; } CSharpElementFactory elementFactory = CSharpElementFactory.GetInstance(sourceFile.PsiModule); file.GetPsiServices().PsiManager.DoTransaction( () => { using (_shellLocks.UsingWriteLock()) file.ProcessChildren <IExpression>( expression => { ConstantValue value = expression.ConstantValue; if (value.IsInteger() && Convert.ToInt32(value.Value) == int.MaxValue) { ModificationUtil.ReplaceChild(expression, elementFactory.CreateExpression("int.MaxValue")); } } ); }, "Code cleanup"); }
/// <summary> /// Get default setting for given profile type. /// </summary> /// <param name="profile"> /// The code cleanup profile to use. /// </param> /// <param name="profileType"> /// Determine if it is a full or reformat <see cref="CodeCleanup.DefaultProfileType"/>. /// </param> public void SetDefaultSetting(CodeCleanupProfile profile, CodeCleanup.DefaultProfileType profileType) { // Default option are set in the constructors. OrderingOptions orderingOptions = new OrderingOptions(); profile.SetSetting(OrderingDescriptor, orderingOptions); LayoutOptions layoutOptions = new LayoutOptions(); profile.SetSetting(LayoutDescriptor, layoutOptions); DocumentationOptions documentationOptions = new DocumentationOptions(); profile.SetSetting(DocumentationDescriptor, documentationOptions); SpacingOptions spacingOptions = new SpacingOptions(); profile.SetSetting(SpacingDescriptor, spacingOptions); ReadabilityOptions readabilityOptions = new ReadabilityOptions(); profile.SetSetting(ReadabilityDescriptor, readabilityOptions); MaintainabilityOptions maintainabilityOptions = new MaintainabilityOptions(); profile.SetSetting(MaintainabilityDescriptor, maintainabilityOptions); }
/// <summary> /// Loads the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Load(CodeCleanupProfile profile, XmlElement element) { SpacingOptions options = new SpacingOptions(); XmlElement optionsElement = (XmlElement)element.SelectSingleNode(this.Name); if (optionsElement != null) { try { options.SA1001CommasMustBeSpacedCorrectly = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1001CommasMustBeSpacedCorrectly")); options.SA1005SingleLineCommentsMustBeginWithSingleSpace = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1005SingleLineCommentsMustBeginWithSingleSpace")); options.SA1006PreprocessorKeywordsMustNotBePrecededBySpace = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1006PreprocessorKeywordsMustNotBePrecededBySpace")); options.SA1021NegativeSignsMustBeSpacedCorrectly = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1021NegativeSignsMustBeSpacedCorrectly")); options.SA1022PositiveSignsMustBeSpacedCorrectly = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1022PositiveSignsMustBeSpacedCorrectly")); options.SA1025CodeMustNotContainMultipleWhitespaceInARow = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1025CodeMustNotContainMultipleWhitespaceInARow")); } catch (ArgumentException) { } } profile.SetSetting(this, options); }
public void Process(IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { var file = sourceFile.GetNonInjectedPsiFile<CSharpLanguage>(); if (file == null) return; if (!profile.GetSetting(DescriptorInstance)) return; CSharpElementFactory elementFactory = CSharpElementFactory.GetInstance(sourceFile.PsiModule); file.GetPsiServices().PsiManager.DoTransaction( () => { using (_shellLocks.UsingWriteLock()) file.ProcessChildren<IExpression>( expression => { ConstantValue value = expression.ConstantValue; if (value.IsInteger() && Convert.ToInt32(value.Value) == int.MaxValue) ModificationUtil.ReplaceChild(expression, elementFactory.CreateExpression("int.MaxValue")); } ); }, "Code cleanup"); }
/// <summary> /// Loads the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Load(CodeCleanupProfile profile, XmlElement element) { LayoutOptions options = new LayoutOptions(); XmlElement optionsElement = (XmlElement)element.SelectSingleNode(this.Name); if (optionsElement != null) { try { options.SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine")); options.SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine")); options.SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine")); options.SA1511WhileDoFooterMustNotBePrecededByBlankLine = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1511WhileDoFooterMustNotBePrecededByBlankLine")); options.SA1512SingleLineCommentsMustNotBeFollowedByBlankLine = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1512SingleLineCommentsMustNotBeFollowedByBlankLine")); options.SA1513ClosingCurlyBracketMustBeFollowedByBlankLine = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1513ClosingCurlyBracketMustBeFollowedByBlankLine")); options.SA1514ElementDocumentationHeaderMustBePrecededByBlankLine = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1514ElementDocumentationHeaderMustBePrecededByBlankLine")); options.SA1515SingleLineCommentMustBeProceededByBlankLine = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1515SingleLineCommentMustBeProceededByBlankLine")); } catch (ArgumentException) { } } profile.SetSetting(this, options); }
/// <summary> /// Saves the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Save(CodeCleanupProfile profile, XmlElement element) { MaintainabilityOptions options = profile.GetSetting(this); XmlElement optionsElement = JB::JetBrains.Util.XmlUtil.CreateElement(element, this.Name); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1119StatementMustNotUseUnnecessaryParenthesis", options.SA1119StatementMustNotUseUnnecessaryParenthesis.ToString()); }
protected override CodeCleanupProfile GetProfile( CodeCleanupSettingsComponent codeCleanupSettings, ITextControl textControl) { var profile = new CodeCleanupProfile( false, "<Profile name=\"Usings order and spacing\"><FixUsingsOrderAndSpacing>True</FixUsingsOrderAndSpacing></Profile>"); return profile; }
protected override CodeCleanupProfile GetProfile( CodeCleanupSettingsComponent codeCleanupSettings, ITextControl textControl) { var profile = new CodeCleanupProfile( false, "<Profile name=\"Usings order and spacing\"><FixUsingsOrderAndSpacing>True</FixUsingsOrderAndSpacing></Profile>"); return(profile); }
public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarkerMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { ISolution solution = sourceFile.GetSolution(); if (!profile.GetSetting(OurDescriptor)) { return; } INTriplesFile[] files = sourceFile.GetPsiFiles <NTriplesLanguage>().Cast <INTriplesFile>().ToArray(); using (progressIndicator.SafeTotal("Reformat Psi", files.Length)) { foreach (INTriplesFile file in files) { using (IProgressIndicator pi = progressIndicator.CreateSubProgress(1)) { using (WriteLockCookie.Create()) { var languageService = file.Language.LanguageService(); Assertion.Assert(languageService != null, "languageService != null"); var formatter = languageService.CodeFormatter; Assertion.Assert(formatter != null, "formatter != null"); PsiManager.GetInstance(sourceFile.GetSolution()).DoTransaction( delegate { if (rangeMarkerMarker != null && rangeMarkerMarker.IsValid) { formatter.Format( solution, rangeMarkerMarker.DocumentRange, CodeFormatProfile.DEFAULT, true, false, pi); } else { formatter.FormatFile( file, CodeFormatProfile.DEFAULT, pi); } }, "Code cleanup"); } } } } }
/// <summary> /// Saves the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Save(CodeCleanupProfile profile, XmlElement element) { OrderingOptions options = profile.GetSetting(this); XmlElement optionsElement = JB::JetBrains.Util.XmlUtil.CreateElement(element, this.Name); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue(optionsElement, "AlphabeticalUsingDirectives", options.AlphabeticalUsingDirectives.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue(optionsElement, "ExpandUsingDirectives", options.ExpandUsingDirectives.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1212PropertyAccessorsMustFollowOrder", options.SA1212PropertyAccessorsMustFollowOrder.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1213EventAccessorsMustFollowOrder", options.SA1213EventAccessorsMustFollowOrder.ToString()); }
public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarkerMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { ISolution solution = sourceFile.GetSolution(); if (!profile.GetSetting(OurDescriptor)) { return; } INTriplesFile[] files = sourceFile.GetPsiFiles<NTriplesLanguage>().Cast<INTriplesFile>().ToArray(); using (progressIndicator.SafeTotal("Reformat Psi", files.Length)) { foreach (INTriplesFile file in files) { using (IProgressIndicator pi = progressIndicator.CreateSubProgress(1)) { using (WriteLockCookie.Create()) { var languageService = file.Language.LanguageService(); Assertion.Assert(languageService != null, "languageService != null"); var formatter = languageService.CodeFormatter; Assertion.Assert(formatter != null, "formatter != null"); PsiManager.GetInstance(sourceFile.GetSolution()).DoTransaction( delegate { if (rangeMarkerMarker != null && rangeMarkerMarker.IsValid) { formatter.Format( solution, rangeMarkerMarker.DocumentRange, CodeFormatProfile.DEFAULT, true, false, pi); } else { formatter.FormatFile( file, CodeFormatProfile.DEFAULT, pi); } }, "Code cleanup"); } } } } }
public void SetDefaultSetting(CodeCleanupProfile profile, CodeCleanup.DefaultProfileType profileType) { switch (profileType) { case CodeCleanup.DefaultProfileType.FULL: case CodeCleanup.DefaultProfileType.REFORMAT: profile.SetSetting(OurDescriptor, true); break; default: throw new ArgumentOutOfRangeException("profileType"); } }
/// <inheritdoc/> public void SetDefaultSetting(CodeCleanupProfile profile, CodeCleanup.DefaultProfileType profileType) { switch (profileType) { case CodeCleanup.DefaultProfileType.FULL: profile.SetSetting(DescriptorInstance, true); break; default: profile.SetSetting(DescriptorInstance, false); break; } }
public void Process(IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator, IUserDataHolder cache) { var solution = sourceFile.GetSolution(); if (!profile.GetSetting(ourDescriptor)) { return; } var psiServices = sourceFile.GetPsiServices(); IShaderLabFile[] files; using (new ReleaseLockCookie(psiServices.Locks, LockKind.FullWrite)) { psiServices.Locks.AssertReadAccessAllowed(); files = sourceFile.GetPsiFiles <ShaderLabLanguage>().Cast <IShaderLabFile>().ToArray(); } using (progressIndicator.SafeTotal(Name, files.Length)) { foreach (var file in files) { using (var indicator = progressIndicator.CreateSubProgress(1)) { var service = file.Language.LanguageService(); if (service == null) { return; } var formatter = service.CodeFormatter; sourceFile.GetPsiServices().Transactions.Execute("Code cleanup", delegate { if (rangeMarker != null && rangeMarker.IsValid) { CodeFormatterHelper.Format(file.Language, solution, rangeMarker.DocumentRange, CodeFormatProfile.DEFAULT, true, false, indicator); } else { formatter.FormatFile( file, CodeFormatProfile.DEFAULT, indicator); } }); } } } }
/// <summary> /// Process clean-up on file. /// </summary> /// <param name="projectFile"> /// The project file to process. /// </param> /// <param name="range"> /// The range marker to process. /// </param> /// <param name="profile"> /// The code cleanup settings to use. /// </param> /// <param name="canIncrementalUpdate"> /// Determines whether we can incrementally update. /// </param> /// <param name="progressIndicator"> /// The progress indicator. /// </param> public void Process( IProjectFile projectFile, IPsiRangeMarker range, CodeCleanupProfile profile, out bool canIncrementalUpdate, JB::JetBrains.Application.Progress.IProgressIndicator progressIndicator) { StyleCopTrace.In(projectFile, range, profile, progressIndicator); canIncrementalUpdate = true; if (projectFile == null) { return; } if (!this.IsAvailable(projectFile)) { return; } ISolution solution = projectFile.GetSolution(); PsiManagerImpl psiManager = PsiManagerImpl.GetInstance(solution); ICSharpFile file = psiManager.GetPsiFile(projectFile, PsiLanguageType.GetByProjectFile(projectFile)) as ICSharpFile; if (file == null) { return; } DocumentationOptions documentationOptions = profile.GetSetting(DocumentationDescriptor); LayoutOptions layoutOptions = profile.GetSetting(LayoutDescriptor); MaintainabilityOptions maintainabilityOptions = profile.GetSetting(MaintainabilityDescriptor); OrderingOptions orderingOptions = profile.GetSetting(OrderingDescriptor); ReadabilityOptions readabilityOptions = profile.GetSetting(ReadabilityDescriptor); SpacingOptions spacingOptions = profile.GetSetting(SpacingDescriptor); // Process the file for all the different Code Cleanups we have here // we do them in a very specific order. Do not change it. new ReadabilityRules().Execute(readabilityOptions, file); new MaintainabilityRules().Execute(maintainabilityOptions, file); new DocumentationRules().Execute(documentationOptions, file); new LayoutRules().Execute(layoutOptions, file); new SpacingRules().Execute(spacingOptions, file); new OrderingRules().Execute(orderingOptions, file); StyleCopTrace.Out(); }
public void SetDefaultSetting(CodeCleanupProfile profile, Feature.Services.CodeCleanup.CodeCleanup.DefaultProfileType profileType) { switch (profileType) { case Feature.Services.CodeCleanup.CodeCleanup.DefaultProfileType.FULL: profile.SetSetting(DescriptorInstance, true); break; case Feature.Services.CodeCleanup.CodeCleanup.DefaultProfileType.REFORMAT: profile.SetSetting(DescriptorInstance, false); break; default: throw new ArgumentOutOfRangeException("profileType"); } }
/// <summary> /// Loads the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Load(CodeCleanupProfile profile, XmlElement element) { DocumentationOptions options = new DocumentationOptions(); XmlElement optionsElement = (XmlElement)element.SelectSingleNode(this.Name); if (optionsElement != null) { try { options.SA1600ElementsMustBeDocumented = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1600ElementsMustBeDocumented")); options.SA1604ElementDocumentationMustHaveSummary = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1604ElementDocumentationMustHaveSummary")); options.SA1609PropertyDocumentationMustHaveValue = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1609PropertyDocumentationMustHaveValueDocumented")); options.SA1611ElementParametersMustBeDocumented = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1611ElementParametersMustBeDocumented")); options.SA1615ElementReturnValueMustBeDocumented = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1615ElementReturnValueMustBeDocumented")); options.SA1617VoidReturnValueMustNotBeDocumented = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1617VoidReturnValueMustNotBeDocumented")); options.SA1618GenericTypeParametersMustBeDocumented = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1618GenericTypeParametersMustBeDocumented")); options.SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes")); options.SA1628DocumentationTextMustBeginWithACapitalLetter = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1628DocumentationTextMustBeginWithACapitalLetter")); options.SA1629DocumentationTextMustEndWithAPeriod = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1629DocumentationTextMustEndWithAPeriod")); options.SA1633SA1641UpdateFileHeader = (UpdateFileHeaderStyle) Enum.Parse(typeof(UpdateFileHeaderStyle), JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1633SA1641UpdateFileHeader")); options.SA1639FileHeaderMustHaveSummary = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1639FileHeaderMustHaveSummary")); options.SA1642ConstructorSummaryDocumentationMustBeginWithStandardText = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1642ConstructorSummaryDocumentationMustBeginWithStandardText")); options.SA1643DestructorSummaryDocumentationMustBeginWithStandardText = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1643DestructorSummaryDocumentationMustBeginWithStandardText")); options.SA1644DocumentationHeadersMustNotContainBlankLines = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1644DocumentationHeadersMustNotContainBlankLines")); } catch (ArgumentException) { } } profile.SetSetting(this, options); }
public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { var settingsStore = sourceFile.GetSettingsStore(); var settings = settingsStore.GetKey<XamlAttributeOrderingSettings>(SettingsOptimization.OptimizeDefault); if (!profile.GetSetting(DescriptorInstance) || !settings.Enable) { return; } foreach (var xamlFile in sourceFile.GetPsiFiles<XamlLanguage>().OfType<IXamlFile>()) { sourceFile.GetPsiServices().Transactions.Execute("Code cleanup", () => { var comparer = new AttributesComparer(settings); xamlFile.ProcessDescendants(new ReorderAttributesProcessor(comparer)); }); } }
/// <inheritdoc/> public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { IPsiServices psiServices = sourceFile.GetPsiServices(); IPsiFiles psiFiles = psiServices.Files; IContextBoundSettingsStore settings = sourceFile.GetSettingsStore(); var orderUsingSettings = settings.GetKey <OrderUsingsSettings>(SettingsOptimization.DoMeSlowly); OrderUsingsConfiguration config = null; if (!string.IsNullOrWhiteSpace(orderUsingSettings.OrderSpecificationXml)) { config = ConfigurationSerializer.FromXml(new StringReader(orderUsingSettings.OrderSpecificationXml)); } if (config == null) { return; } var file = psiFiles.GetDominantPsiFile <CSharpLanguage>(sourceFile) as ICSharpFile; if (file == null) { return; } if (!profile.GetSetting(DescriptorInstance)) { return; } file.GetPsiServices().Transactions.Execute( "Code cleanup", () => { using (_shellLocks.UsingWriteLock()) { CleanUsings(file, config); WalkNamespaceDeclarations(file.NamespaceDeclarations, config); } }); }
/// <summary> /// Saves the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Save(CodeCleanupProfile profile, XmlElement element) { SpacingOptions options = profile.GetSetting(this); XmlElement optionsElement = JB::JetBrains.Util.XmlUtil.CreateElement(element, this.Name); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1001CommasMustBeSpacedCorrectly", options.SA1001CommasMustBeSpacedCorrectly.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1005SingleLineCommentsMustBeginWithSingleSpace", options.SA1005SingleLineCommentsMustBeginWithSingleSpace.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1006PreprocessorKeywordsMustNotBePrecededBySpace", options.SA1006PreprocessorKeywordsMustNotBePrecededBySpace.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1021NegativeSignsMustBeSpacedCorrectly", options.SA1021NegativeSignsMustBeSpacedCorrectly.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1022PositiveSignsMustBeSpacedCorrectly", options.SA1022PositiveSignsMustBeSpacedCorrectly.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1025CodeMustNotContainMultipleWhitespaceInARow", options.SA1025CodeMustNotContainMultipleWhitespaceInARow.ToString()); }
/// <summary> /// Processes all the cleanup. /// </summary> /// <param name="profile"> /// The current profile to use. /// </param> /// <param name="file"> /// The file to clean. /// </param> private void InternalProcess(CodeCleanupProfile profile, ICSharpFile file) { DocumentationOptions documentationOptions = profile.GetSetting(DocumentationDescriptor); LayoutOptions layoutOptions = profile.GetSetting(LayoutDescriptor); MaintainabilityOptions maintainabilityOptions = profile.GetSetting(MaintainabilityDescriptor); OrderingOptions orderingOptions = profile.GetSetting(OrderingDescriptor); ReadabilityOptions readabilityOptions = profile.GetSetting(ReadabilityDescriptor); SpacingOptions spacingOptions = profile.GetSetting(SpacingDescriptor); // Process the file for all the different Code Cleanups we have here // we do them in a very specific order. Do not change it. new ReadabilityRules(this.shellLocks).Execute(readabilityOptions, file); new MaintainabilityRules().Execute(maintainabilityOptions, file); new DocumentationRules().Execute(documentationOptions, file); new LayoutRules().Execute(layoutOptions, file); new SpacingRules().Execute(spacingOptions, file); new OrderingRules().Execute(orderingOptions, file); }
/// <inheritdoc/> public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { IPsiServices psiServices = sourceFile.GetPsiServices(); IPsiFiles psiFiles = psiServices.Files; IContextBoundSettingsStore settings = sourceFile.GetSettingsStore(); var orderUsingSettings = settings.GetKey<OrderUsingsSettings>(SettingsOptimization.DoMeSlowly); OrderUsingsConfiguration config = null; if (!string.IsNullOrWhiteSpace(orderUsingSettings.OrderSpecificationXml)) { config = ConfigurationSerializer.FromXml(new StringReader(orderUsingSettings.OrderSpecificationXml)); } if (config == null) { return; } var file = psiFiles.GetDominantPsiFile<CSharpLanguage>(sourceFile) as ICSharpFile; if (file == null) { return; } if (!profile.GetSetting(DescriptorInstance)) { return; } file.GetPsiServices().Transactions.Execute( "Code cleanup", () => { using (_shellLocks.UsingWriteLock()) { CleanUsings(file, config); WalkNamespaceDeclarations(file.NamespaceDeclarations, config); } }); }
/// <summary> /// Loads the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Load(CodeCleanupProfile profile, XmlElement element) { MaintainabilityOptions options = new MaintainabilityOptions(); XmlElement optionsElement = (XmlElement)element.SelectSingleNode(this.Name); if (optionsElement != null) { try { options.SA1119StatementMustNotUseUnnecessaryParenthesis = bool.Parse(JB::JetBrains.Util.XmlUtil.ReadLeafElementValue(optionsElement, "SA1119StatementMustNotUseUnnecessaryParenthesis")); } catch (ArgumentException) { } } profile.SetSetting(this, options); }
public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { var settingsStore = sourceFile.GetSettingsStore(); var settings = settingsStore.GetKey <XamlAttributeOrderingSettings>(SettingsOptimization.OptimizeDefault); if (!profile.GetSetting(DescriptorInstance) || !settings.Enable) { return; } foreach (var xamlFile in sourceFile.GetPsiFiles <XamlLanguage>().OfType <IXamlFile>()) { sourceFile.GetPsiServices().Transactions.Execute("Code cleanup", () => { var comparer = new AttributesComparer(settings); xamlFile.ProcessDescendants(new ReorderAttributesProcessor(comparer)); }); } }
public void Process(IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { var file = sourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance); if (file == null) { return; } if (!profile.GetSetting(DescriptorInstance)) { return; } file.GetPsiServices().Transactions.Execute("Reflow XML Documentation Comments", () => { using (_shellLocks.UsingWriteLock()) file.ProcessChildren <IDocCommentBlockNode>(node => CommentReflowAction.ReFlowCommentBlockNode(file.GetSolution(), progressIndicator, node)); }); }
/// <summary> /// Saves the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Save(CodeCleanupProfile profile, XmlElement element) { DocumentationOptions options = profile.GetSetting(this); XmlElement optionsElement = JB::JetBrains.Util.XmlUtil.CreateElement(element, this.Name); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue(optionsElement, "SA1600ElementsMustBeDocumented", options.SA1600ElementsMustBeDocumented.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1604ElementDocumentationMustHaveSummary", options.SA1604ElementDocumentationMustHaveSummary.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1609PropertyDocumentationMustHaveValueDocumented", options.SA1609PropertyDocumentationMustHaveValue.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1611ElementParametersMustBeDocumented", options.SA1611ElementParametersMustBeDocumented.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1615ElementReturnValueMustBeDocumented", options.SA1615ElementReturnValueMustBeDocumented.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1617VoidReturnValueMustNotBeDocumented", options.SA1617VoidReturnValueMustNotBeDocumented.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1618GenericTypeParametersMustBeDocumented", options.SA1618GenericTypeParametersMustBeDocumented.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes", options.SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1628DocumentationTextMustBeginWithACapitalLetter", options.SA1628DocumentationTextMustBeginWithACapitalLetter.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1629DocumentationTextMustEndWithAPeriod", options.SA1629DocumentationTextMustEndWithAPeriod.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue(optionsElement, "SA1633SA1641UpdateFileHeader", options.SA1633SA1641UpdateFileHeader.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue(optionsElement, "SA1639FileHeaderMustHaveSummary", options.SA1639FileHeaderMustHaveSummary.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1642ConstructorSummaryDocumentationMustBeginWithStandardText", options.SA1642ConstructorSummaryDocumentationMustBeginWithStandardText.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1643DestructorSummaryDocumentationMustBeginWithStandardText", options.SA1643DestructorSummaryDocumentationMustBeginWithStandardText.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1644DocumentationHeadersMustNotContainBlankLines", options.SA1644DocumentationHeadersMustNotContainBlankLines.ToString()); }
/// <summary> /// Saves the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Save(CodeCleanupProfile profile, XmlElement element) { LayoutOptions options = profile.GetSetting(this); XmlElement optionsElement = JB::JetBrains.Util.XmlUtil.CreateElement(element, this.Name); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine", options.SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine", options.SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine", options.SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1511WhileDoFooterMustNotBePrecededByBlankLine", options.SA1511WhileDoFooterMustNotBePrecededByBlankLine.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1512SingleLineCommentsMustNotBeFollowedByBlankLine", options.SA1512SingleLineCommentsMustNotBeFollowedByBlankLine.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1513ClosingCurlyBracketMustBeFollowedByBlankLine", options.SA1513ClosingCurlyBracketMustBeFollowedByBlankLine.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1514ElementDocumentationHeaderMustBePrecededByBlankLine", options.SA1514ElementDocumentationHeaderMustBePrecededByBlankLine.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1515SingleLineCommentMustBeProceededByBlankLine", options.SA1515SingleLineCommentMustBeProceededByBlankLine.ToString()); }
/// <summary> /// Saves the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <param name="element"> /// The element. /// </param> public override void Save(CodeCleanupProfile profile, XmlElement element) { ReadabilityOptions options = profile.GetSetting(this); XmlElement optionsElement = JB::JetBrains.Util.XmlUtil.CreateElement(element, this.Name); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists", options.SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1106CodeMustNotContainEmptyStatements", options.SA1106CodeMustNotContainEmptyStatements.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1108BlockStatementsMustNotContainEmbeddedComments", options.SA1108BlockStatementsMustNotContainEmbeddedComments.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1109BlockStatementsMustNotContainEmbeddedRegions", options.SA1109BlockStatementsMustNotContainEmbeddedRegions.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue(optionsElement, "SA1120CommentsMustContainText", options.SA1120CommentsMustContainText.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue(optionsElement, "SA1121UseBuiltInTypeAlias", options.SA1121UseBuiltInTypeAlias.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1122UseStringEmptyForEmptyStrings", options.SA1122UseStringEmptyForEmptyStrings.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1123DoNotPlaceRegionsWithinElements", options.SA1123DoNotPlaceRegionsWithinElements.ToString()); JB::JetBrains.Util.XmlUtil.CreateLeafElementWithValue( optionsElement, "SA1124CodeMustNotContainEmptyRegions", options.SA1124CodeMustNotContainEmptyRegions.ToString()); }
/// <summary> /// Presents the specified profile. /// </summary> /// <param name="profile"> /// The profile. /// </param> /// <returns> /// Specified profile. /// </returns> public override string Present(CodeCleanupProfile profile) { return(profile.GetSetting(this).ToString()); }
/// <summary> /// Get default setting for given profile type. /// </summary> /// <param name="profile"> /// The code cleanup profile to use. /// </param> /// <param name="profileType"> /// Determine if it is a full or reformat <see cref="CodeCleanup.DefaultProfileType"/>. /// </param> public void SetDefaultSetting(CodeCleanupProfile profile, CodeCleanup.DefaultProfileType profileType) { profile.SetSetting(Descriptor, true); }
/// <summary> /// Process clean-up on file. /// </summary> /// <param name="projectFile"> /// The project file to process. /// </param> /// <param name="rangeMarker"> /// The range marker to process. /// </param> /// <param name="profile"> /// The code cleanup settings to use. /// </param> /// <param name="progressIndicator"> /// The progress indicator. /// </param> public void Process( IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JB::JetBrains.Application.Progress.IProgressIndicator progressIndicator) { if (projectFile == null) { return; } if (!this.IsAvailable(projectFile)) { return; } ISolution solution = projectFile.GetSolution(); ICSharpFile file = projectFile.GetPsiFile<CSharpLanguage>() as ICSharpFile; if (file == null) { return; } PsiManager.GetInstance(solution).DoTransaction(() => this.InternalProcess(profile, file), "Code cleanup"); StyleCopTrace.Out(); }
/// <summary> /// Process clean-up on file. /// </summary> /// <param name="projectFile"> /// The project file to process. /// </param> /// <param name="rangeMarker"> /// The range marker to process. /// </param> /// <param name="profile"> /// The code cleanup settings to use. /// </param> /// <param name="progressIndicator"> /// The progress indicator. /// </param> public void Process( IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JetBrains.Application.Progress.IProgressIndicator progressIndicator) { if (projectFile == null) { return; } if (!this.IsAvailable(projectFile)) { return; } ISolution solution = projectFile.GetSolution(); ICSharpFile file = projectFile.GetDominantPsiFile<CSharpLanguage>() as ICSharpFile; if (file == null) { return; } var services = solution.GetPsiServices(); services.Transactions.Execute("Code cleanup", () => this.InternalProcess(profile, file)); StyleCopTrace.Out(); }
/// <summary> /// Executes ContextAction, optionally returns post-execute method. /// </summary> /// <param name="solution">Current solution.</param> /// <param name="progress">Progress indicator to use for long operations.</param> protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { var node = _commentNode.GetContainingNode<IDocCommentBlockNode>(); if (null == node) return null; var settingsStore = Shell.Instance .GetComponent<ISettingsStore>() .BindToContextTransient(ContextRange.ApplicationWide); var cleanupSettings = settingsStore.GetKey<CodeCleanupSettings>(SettingsOptimization.OptimizeDefault); string profileContent = cleanupSettings.Profiles.Get(cleanupSettings.SilentCleanupProfile, string.Empty); if (!string.IsNullOrEmpty(profileContent)) { CodeCleanupProfile profile = new CodeCleanupProfile(false, profileContent); int caret = 0; CodeCleanup cleanup = CodeCleanup.GetInstance(solution); cleanup.Run(_provider.SourceFile, node.GetDocumentRange(), ref caret, profile, progress); } return null; }
public void SetDefaultSetting(CodeCleanupProfile profile, CodeCleanup.DefaultProfileType profileType) { }
public static IEnumerable<IProcessor> GetActivatedProcessors(CodeCleanupProfile profile) { return AvailableProcessors.Where(processor => processor.IsProcessingActivated(profile)); }