// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Collections.Generic; using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.Formatting.Rules; /// <summary> /// Provide a custom formatting operation provider that can intercept/filter/replace default formatting operations. /// </summary> /// <remarks>All methods defined in this class can be called concurrently. Must be thread-safe.</remarks> internal abstract class AbstractFormattingRule { public virtual AbstractFormattingRule WithOptions(SyntaxFormattingOptions options) => this; /// <summary> /// Returns SuppressWrappingIfOnSingleLineOperations under a node either by itself or by /// filtering/replacing operations returned by NextOperation /// </summary> public virtual void AddSuppressOperations(ArrayBuilder<SuppressOperation> list, SyntaxNode node, in NextSuppressOperationAction nextOperation) => nextOperation.Invoke(); /// <summary> /// returns AnchorIndentationOperations under a node either by itself or by filtering/replacing operations returned by NextOperation /// </summary> public virtual void AddAnchorIndentationOperations(List<AnchorIndentationOperation> list, SyntaxNode node, in NextAnchorIndentationOperationAction nextOperation) => nextOperation.Invoke(); /// <summary> /// returns IndentBlockOperations under a node either by itself or by filtering/replacing operations returned by NextOperation /// </summary> public virtual void AddIndentBlockOperations(List<IndentBlockOperation> list, SyntaxNode node, in NextIndentBlockOperationAction nextOperation) => nextOperation.Invoke(); /// <summary> /// returns AlignTokensOperations under a node either by itself or by filtering/replacing operations returned by NextOperation /// </summary> public virtual void AddAlignTokensOperations(List<AlignTokensOperation> list, SyntaxNode node, in NextAlignTokensOperationAction nextOperation) => nextOperation.Invoke(); /// <summary> /// returns AdjustNewLinesOperation between two tokens either by itself or by filtering/replacing a operation returned by NextOperation /// </summary> public virtual AdjustNewLinesOperation? GetAdjustNewLinesOperation(in SyntaxToken previousToken, in SyntaxToken currentToken, in NextGetAdjustNewLinesOperation nextOperation) => nextOperation.Invoke(in previousToken, in currentToken); /// <summary> /// returns AdjustSpacesOperation between two tokens either by itself or by filtering/replacing a operation returned by NextOperation /// </summary> public virtual AdjustSpacesOperation? GetAdjustSpacesOperation(in SyntaxToken previousToken, in SyntaxToken currentToken, in NextGetAdjustSpacesOperation nextOperation) => nextOperation.Invoke(in previousToken, in currentToken); } |