C# Class Microsoft.R.Core.Formatting.BraceHandler

Provides set of services for brace handling in formatting
Show file Open project: Microsoft/RTVS Class Usage Examples

Public Methods

Method Description
BraceHandler ( TokenStream tokens, TextBuilder tb ) : System
GetCloseCurlyBraceIndentSize ( RToken closeCurlyBraceToken, TextBuilder tb, Microsoft.R.Core.Formatting.RFormatOptions options ) : int

Given closing curly brace tries to find keyword that is associated with the scope and calculate indentation based on the keyword line.

GetMatchingBraceToken ( RTokenType tokenType ) : RTokenType
GetOpenCurlyBraceIndentSize ( RToken openCurlyBraceToken, TextBuilder tb, Microsoft.R.Core.Formatting.RFormatOptions options ) : int

Given opening curly brace tries to find keyword that is associated with the scope and calculate indentation based on the keyword line.

HandleBrace ( ) : void
IsInArguments ( ) : bool

Tells if scope is opening inside function or indexer arguments and hence user indentation of curly braces must be respected.

Private Methods

Method Description
AssociateKeywordPositionWithOpenBrace ( RToken openBrace, int keywordPosition ) : void

Associates keyword with the open brace. Used when formatter needs to determine indentation level of the new formatting scope when it encounters { token.

Closing curly indentation is defined by the line that either holds the opening curly brace or the line that holds keyword that defines the expression that the curly belongs to. Examples: x <- function(a) { } x <- function(a) { } First keyword is associated with the open brace, then, when brace pair closes, association is propagated to the closing brace and then to the opening curly. When curly pair closes formatter then finds appropriate indentation based on the line that contains the keyword token.

AssociateKeywordPositionWithToken ( RToken source, RToken target ) : void

Propagates keyword association to the target token. AssociateKeywordPositionWithOpenBrace

GetNearestNonWhitespaceIndex ( ) : int
TryPopMatchingBrace ( RToken token ) : RToken

Method Details

BraceHandler() public method

public BraceHandler ( TokenStream tokens, TextBuilder tb ) : System
tokens TokenStream
tb Microsoft.Languages.Core.Formatting.TextBuilder
return System

GetCloseCurlyBraceIndentSize() public method

Given closing curly brace tries to find keyword that is associated with the scope and calculate indentation based on the keyword line.
public GetCloseCurlyBraceIndentSize ( RToken closeCurlyBraceToken, TextBuilder tb, Microsoft.R.Core.Formatting.RFormatOptions options ) : int
closeCurlyBraceToken RToken
tb Microsoft.Languages.Core.Formatting.TextBuilder
options Microsoft.R.Core.Formatting.RFormatOptions
return int

GetMatchingBraceToken() public static method

public static GetMatchingBraceToken ( RTokenType tokenType ) : RTokenType
tokenType RTokenType
return RTokenType

GetOpenCurlyBraceIndentSize() public method

Given opening curly brace tries to find keyword that is associated with the scope and calculate indentation based on the keyword line.
public GetOpenCurlyBraceIndentSize ( RToken openCurlyBraceToken, TextBuilder tb, Microsoft.R.Core.Formatting.RFormatOptions options ) : int
openCurlyBraceToken RToken
tb Microsoft.Languages.Core.Formatting.TextBuilder
options Microsoft.R.Core.Formatting.RFormatOptions
return int

HandleBrace() public method

public HandleBrace ( ) : void
return void

IsInArguments() public method

Tells if scope is opening inside function or indexer arguments and hence user indentation of curly braces must be respected.
public IsInArguments ( ) : bool
return bool