/// <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> /// 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(); }
/// <summary> /// Implement the Execute method. /// </summary> /// <param name="options"> /// The options. /// </param> /// <param name="file"> /// The file to use. /// </param> public void Execute(SpacingOptions options, ICSharpFile file) { StyleCopTrace.In(options, file); Param.RequireNotNull(options, "options"); Param.RequireNotNull(file, "file"); bool commasMustBeSpacedCorrectly = options.SA1001CommasMustBeSpacedCorrectly; bool singleLineCommentsMustBeginWithSingleSpace = options.SA1005SingleLineCommentsMustBeginWithSingleSpace; bool preprocessorKeywordsMustNotBePrecededBySpace = options.SA1006PreprocessorKeywordsMustNotBePrecededBySpace; bool negativeSignsMustBeSpacedCorrectly = options.SA1021NegativeSignsMustBeSpacedCorrectly; bool positiveSignsMustBeSpacedCorrectly = options.SA1022PositiveSignsMustBeSpacedCorrectly; bool codeMustNotContainMultipleWhitespaceInARow = options.SA1025CodeMustNotContainMultipleWhitespaceInARow; if (codeMustNotContainMultipleWhitespaceInARow) { this.CodeMustNotContainMultipleWhitespaceInARow(file.FirstChild); } if (commasMustBeSpacedCorrectly) { this.CommasMustBeSpacedCorrectly(file.FirstChild); } if (singleLineCommentsMustBeginWithSingleSpace) { this.SingleLineCommentsMustBeginWithSingleSpace(file.FirstChild); } if (preprocessorKeywordsMustNotBePrecededBySpace) { this.PreprocessorKeywordsMustNotBePrecededBySpace(file.FirstChild); } if (negativeSignsMustBeSpacedCorrectly) { this.NegativeAndPositiveSignsMustBeSpacedCorrectly(file.FirstChild, CSharpTokenType.MINUS); } if (positiveSignsMustBeSpacedCorrectly) { this.NegativeAndPositiveSignsMustBeSpacedCorrectly(file.FirstChild, CSharpTokenType.PLUS); } StyleCopTrace.Out(); }
/// <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); }
public FormattingSpacingViewModel(IServiceProvider serviceProvider, SpacingOptions page) : base(serviceProvider) { Items.Add(new TextBlock { Text = "Set spacing for function declarations" }); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space between function name and its opening parenthesis", () => page.FunctionDeclarationInsertSpaceAfterFunctionName, v => page.FunctionDeclarationInsertSpaceAfterFunctionName = v), FunctionSpacingPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space within argument list parenthesis", () => page.FunctionDeclarationInsertSpaceWithinArgumentListParentheses, v => page.FunctionDeclarationInsertSpaceWithinArgumentListParentheses = v), FunctionSpacingPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space within empty argument list parenthesis", () => page.FunctionDeclarationInsertSpaceWithinEmptyArgumentListParentheses, v => page.FunctionDeclarationInsertSpaceWithinEmptyArgumentListParentheses = v), FunctionSpacingPreview, this)); Items.Add(new TextBlock { Text = "Set spacing for function calls" }); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space between function name and its opening parenthesis", () => page.FunctionDeclarationInsertSpaceAfterFunctionName, v => page.FunctionCallInsertSpaceAfterFunctionName = v), FunctionSpacingPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space within argument list parenthesis", () => page.FunctionDeclarationInsertSpaceWithinArgumentListParentheses, v => page.FunctionCallInsertSpaceWithinArgumentListParentheses = v), FunctionSpacingPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space within empty argument list parenthesis", () => page.FunctionDeclarationInsertSpaceWithinEmptyArgumentListParentheses, v => page.FunctionCallInsertSpaceWithinEmptyArgumentListParentheses = v), FunctionSpacingPreview, this)); Items.Add(new TextBlock { Text = "Set other spacing options" }); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space after keywords in control flow statements", () => page.InsertSpaceAfterKeywordsInControlFlowStatements, v => page.InsertSpaceAfterKeywordsInControlFlowStatements = v), ControlFlowPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert spaces within parentheses of expressions", () => page.InsertSpacesWithinParenthesesOfExpressions, v => page.InsertSpacesWithinParenthesesOfExpressions = v), ExpressionParenthesesPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert spaces within parentheses of type casts", () => page.InsertSpacesWithinParenthesesOfTypeCasts, v => page.InsertSpacesWithinParenthesesOfTypeCasts = v), CastPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert spaces within parentheses of control flow statements", () => page.InsertSpacesWithinParenthesesOfControlFlowStatements, v => page.InsertSpacesWithinParenthesesOfControlFlowStatements = v), ControlFlowPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert spaces within parentheses of register or packoffset qualifiers", () => page.InsertSpacesWithinParenthesesOfRegisterOrPackOffsetQualifiers, v => page.InsertSpacesWithinParenthesesOfRegisterOrPackOffsetQualifiers = v), SemanticPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert spaces within array initializer braces", () => page.InsertSpacesWithinArrayInitializerBraces, v => page.InsertSpacesWithinArrayInitializerBraces = v), BracketsPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space after type cast", () => page.InsertSpaceAfterCast, v => page.InsertSpaceAfterCast = v), CastPreview, this)); Items.Add(new TextBlock { Text = "Set spacing for brackets" }); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space before open square bracket", () => page.InsertSpaceBeforeOpenSquareBracket, v => page.InsertSpaceBeforeOpenSquareBracket = v), BracketsPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space within empty square brackets", () => page.InsertSpaceWithinEmptySquareBrackets, v => page.InsertSpaceWithinEmptySquareBrackets = v), BracketsPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert spaces within square bracket", () => page.InsertSpacesWithinSquareBrackets, v => page.InsertSpacesWithinSquareBrackets = v), BracketsPreview, this)); Items.Add(new TextBlock { Text = "Set spacing for delimiters" }); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space before colon for base or interface in type declaration", () => page.InsertSpaceBeforeColonForBaseOrInterfaceInTypeDeclaration, v => page.InsertSpaceBeforeColonForBaseOrInterfaceInTypeDeclaration = v), BaseTypePreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space after colon for base or interface in type declaration", () => page.InsertSpaceAfterColonForBaseOrInterfaceInTypeDeclaration, v => page.InsertSpaceAfterColonForBaseOrInterfaceInTypeDeclaration = v), BaseTypePreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space before colon for semantic or register or packoffset", () => page.InsertSpaceBeforeColonForSemanticOrRegisterOrPackOffset, v => page.InsertSpaceBeforeColonForSemanticOrRegisterOrPackOffset = v), SemanticPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space after colon for semantic or register or packoffset", () => page.InsertSpaceAfterColonForSemanticOrRegisterOrPackOffset, v => page.InsertSpaceAfterColonForSemanticOrRegisterOrPackOffset = v), SemanticPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space before comma", () => page.InsertSpaceBeforeComma, v => page.InsertSpaceBeforeComma = v), CommaDotPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space after comma", () => page.InsertSpaceAfterComma, v => page.InsertSpaceAfterComma = v), CommaDotPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space before dot", () => page.InsertSpaceBeforeDot, v => page.InsertSpaceBeforeDot = v), CommaDotPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space after dot", () => page.InsertSpaceAfterDot, v => page.InsertSpaceAfterDot = v), CommaDotPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space before semicolon in \"for\" statement", () => page.InsertSpaceBeforeSemicolonInForStatement, v => page.InsertSpaceBeforeSemicolonInForStatement = v), ControlFlowPreview, this)); Items.Add(new CheckBoxOptionViewModel(new Option <bool>("Insert space after semicolon in \"for\" statement", () => page.InsertSpaceAfterSemicolonInForStatement, v => page.InsertSpaceAfterSemicolonInForStatement = v), ControlFlowPreview, this)); Items.Add(new TextBlock { Text = "Set spacing for operators" }); Items.Add(new RadioButtonViewModel <BinaryOperatorSpaces>(BinaryOperatorSpacesPreview, "binaryspaces", BinaryOperatorSpaces.RemoveSpaces, new Option <BinaryOperatorSpaces>("Remove spaces before and after binary operators", () => page.BinaryOperatorSpaces, v => page.BinaryOperatorSpaces = v), this)); Items.Add(new RadioButtonViewModel <BinaryOperatorSpaces>(BinaryOperatorSpacesPreview, "binaryspaces", BinaryOperatorSpaces.InsertSpaces, new Option <BinaryOperatorSpaces>("Insert space before and after binary operators", () => page.BinaryOperatorSpaces, v => page.BinaryOperatorSpaces = v), this)); }