2
// AstFormattingVisitor_Expressions.cs
5
// Mike KrĆ¼ger <mkrueger@xamarin.com>
7
// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
30
namespace ICSharpCode.NRefactory.CSharp
32
partial class FormattingVisitor : DepthFirstAstVisitor
34
public override void VisitComposedType(ComposedType composedType)
36
var spec = composedType.ArraySpecifiers.FirstOrDefault();
38
ForceSpacesBefore(spec.LBracketToken, policy.SpaceBeforeArrayDeclarationBrackets);
40
if (composedType.HasNullableSpecifier)
41
ForceSpacesBefore(composedType.NullableSpecifierToken, false);
43
if (composedType.PointerRank > 0)
44
foreach (var token in composedType.PointerTokens)
45
ForceSpacesBefore(token, false);
47
base.VisitComposedType(composedType);
50
public override void VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression)
52
if (!anonymousMethodExpression.Body.IsNull) {
53
if (anonymousMethodExpression.Body.LBraceToken.GetNextNode(NoWhitespacePredicate) != anonymousMethodExpression.Body.RBraceToken) {
54
FixOpenBrace(policy.AnonymousMethodBraceStyle, anonymousMethodExpression.Body.LBraceToken);
55
VisitBlockWithoutFixingBraces(anonymousMethodExpression.Body, policy.IndentBlocks);
56
FixClosingBrace(policy.AnonymousMethodBraceStyle, anonymousMethodExpression.Body.RBraceToken);
58
VisitBlockWithoutFixingBraces(anonymousMethodExpression.Body, policy.IndentBlocks);
62
base.VisitAnonymousMethodExpression(anonymousMethodExpression);
65
public override void VisitAssignmentExpression(AssignmentExpression assignmentExpression)
67
ForceSpacesAround(assignmentExpression.OperatorToken, policy.SpaceAroundAssignment);
68
base.VisitAssignmentExpression(assignmentExpression);
71
public override void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression)
73
bool forceSpaces = false;
74
switch (binaryOperatorExpression.Operator) {
75
case BinaryOperatorType.Equality:
76
case BinaryOperatorType.InEquality:
77
forceSpaces = policy.SpaceAroundEqualityOperator;
79
case BinaryOperatorType.GreaterThan:
80
case BinaryOperatorType.GreaterThanOrEqual:
81
case BinaryOperatorType.LessThan:
82
case BinaryOperatorType.LessThanOrEqual:
83
forceSpaces = policy.SpaceAroundRelationalOperator;
85
case BinaryOperatorType.ConditionalAnd:
86
case BinaryOperatorType.ConditionalOr:
87
forceSpaces = policy.SpaceAroundLogicalOperator;
89
case BinaryOperatorType.BitwiseAnd:
90
case BinaryOperatorType.BitwiseOr:
91
case BinaryOperatorType.ExclusiveOr:
92
forceSpaces = policy.SpaceAroundBitwiseOperator;
94
case BinaryOperatorType.Add:
95
case BinaryOperatorType.Subtract:
96
forceSpaces = policy.SpaceAroundAdditiveOperator;
98
case BinaryOperatorType.Multiply:
99
case BinaryOperatorType.Divide:
100
case BinaryOperatorType.Modulus:
101
forceSpaces = policy.SpaceAroundMultiplicativeOperator;
103
case BinaryOperatorType.ShiftLeft:
104
case BinaryOperatorType.ShiftRight:
105
forceSpaces = policy.SpaceAroundShiftOperator;
107
case BinaryOperatorType.NullCoalescing:
108
forceSpaces = policy.SpaceAroundNullCoalescingOperator;
111
ForceSpacesAround(binaryOperatorExpression.OperatorToken, forceSpaces);
113
base.VisitBinaryOperatorExpression(binaryOperatorExpression);
114
// Handle line breaks in binary opeartor expression.
115
if (binaryOperatorExpression.Left.EndLocation.Line != binaryOperatorExpression.Right.StartLocation.Line) {
116
curIndent.Push(IndentType.Block);
117
if (binaryOperatorExpression.OperatorToken.StartLocation.Line == binaryOperatorExpression.Right.StartLocation.Line) {
118
FixStatementIndentation(binaryOperatorExpression.OperatorToken.StartLocation);
120
FixStatementIndentation(binaryOperatorExpression.Right.StartLocation);
126
public override void VisitConditionalExpression(ConditionalExpression conditionalExpression)
128
ForceSpacesBefore(conditionalExpression.QuestionMarkToken, policy.SpaceBeforeConditionalOperatorCondition);
129
ForceSpacesAfter(conditionalExpression.QuestionMarkToken, policy.SpaceAfterConditionalOperatorCondition);
130
ForceSpacesBefore(conditionalExpression.ColonToken, policy.SpaceBeforeConditionalOperatorSeparator);
131
ForceSpacesAfter(conditionalExpression.ColonToken, policy.SpaceAfterConditionalOperatorSeparator);
132
base.VisitConditionalExpression(conditionalExpression);
135
public override void VisitCastExpression(CastExpression castExpression)
137
if (castExpression.RParToken != null) {
138
ForceSpacesAfter(castExpression.LParToken, policy.SpacesWithinCastParentheses);
139
ForceSpacesBefore(castExpression.RParToken, policy.SpacesWithinCastParentheses);
141
ForceSpacesAfter(castExpression.RParToken, policy.SpaceAfterTypecast);
143
base.VisitCastExpression(castExpression);
146
void ForceSpacesAround(AstNode node, bool forceSpaces)
151
ForceSpacesBefore(node, forceSpaces);
152
ForceSpacesAfter(node, forceSpaces);
155
void FormatCommas(AstNode parent, bool before, bool after)
160
foreach (CSharpTokenNode comma in parent.Children.Where (node => node.Role == Roles.Comma)) {
161
ForceSpacesAfter(comma, after);
162
ForceSpacesBefore(comma, before);
166
bool DoWrap (Wrapping wrapping, AstNode wrapNode, int argumentCount)
168
return wrapping == Wrapping.WrapAlways ||
169
options.WrapLineLength > 0 && argumentCount > 1 && wrapping == Wrapping.WrapIfTooLong && wrapNode.StartLocation.Column >= options.WrapLineLength;
172
void FormatArguments(AstNode node)
174
Wrapping methodCallArgumentWrapping;
175
NewLinePlacement newLineAferMethodCallOpenParentheses;
176
bool doAlignToFirstArgument;
177
NewLinePlacement methodClosingParenthesesOnNewLine;
178
bool spaceWithinMethodCallParentheses;
179
bool spaceWithinEmptyParentheses;
180
bool spaceAfterMethodCallParameterComma;
181
bool spaceBeforeMethodCallParameterComma;
183
CSharpTokenNode rParToken, lParToken;
184
List<AstNode> arguments;
186
var constructorDeclaration = node as ConstructorDeclaration;
187
if (constructorDeclaration != null) {
188
methodCallArgumentWrapping = policy.MethodDeclarationParameterWrapping;
189
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodDeclarationOpenParentheses;
190
methodClosingParenthesesOnNewLine = policy.MethodDeclarationClosingParenthesesOnNewLine;
191
doAlignToFirstArgument = policy.AlignToFirstMethodDeclarationParameter;
192
spaceWithinMethodCallParentheses = policy.SpaceWithinConstructorDeclarationParentheses;
193
spaceAfterMethodCallParameterComma = policy.SpaceAfterConstructorDeclarationParameterComma;
194
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeConstructorDeclarationParameterComma;
195
spaceWithinEmptyParentheses = policy.SpaceBetweenEmptyMethodDeclarationParentheses;
196
lParToken = constructorDeclaration.LParToken;
197
rParToken = constructorDeclaration.RParToken;
198
arguments = constructorDeclaration.Parameters.Cast<AstNode> ().ToList ();
199
} else if (node is IndexerDeclaration) {
200
var indexer = (IndexerDeclaration)node;
201
methodCallArgumentWrapping = policy.IndexerDeclarationParameterWrapping;
202
newLineAferMethodCallOpenParentheses = policy.NewLineAferIndexerDeclarationOpenBracket;
203
methodClosingParenthesesOnNewLine = policy.IndexerDeclarationClosingBracketOnNewLine;
204
doAlignToFirstArgument = policy.AlignToFirstIndexerDeclarationParameter;
205
spaceWithinMethodCallParentheses = policy.SpaceWithinIndexerDeclarationBracket;
206
spaceAfterMethodCallParameterComma = policy.SpaceAfterIndexerDeclarationParameterComma;
207
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeIndexerDeclarationParameterComma;
208
spaceWithinEmptyParentheses = policy.SpaceBetweenEmptyMethodDeclarationParentheses;
209
lParToken = indexer.LBracketToken;
210
rParToken = indexer.RBracketToken;
211
arguments = indexer.Parameters.Cast<AstNode> ().ToList ();
212
} else if (node is OperatorDeclaration) {
213
var op = (OperatorDeclaration)node;
214
methodCallArgumentWrapping = policy.MethodDeclarationParameterWrapping;
215
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodDeclarationOpenParentheses;
216
methodClosingParenthesesOnNewLine = policy.MethodDeclarationClosingParenthesesOnNewLine;
217
doAlignToFirstArgument = policy.AlignToFirstMethodDeclarationParameter;
218
spaceWithinMethodCallParentheses = policy.SpaceWithinMethodDeclarationParentheses;
219
spaceAfterMethodCallParameterComma = policy.SpaceAfterMethodDeclarationParameterComma;
220
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeMethodDeclarationParameterComma;
221
spaceWithinEmptyParentheses = policy.SpaceBetweenEmptyMethodDeclarationParentheses;
222
lParToken = op.LParToken;
223
rParToken = op.RParToken;
224
arguments = op.Parameters.Cast<AstNode> ().ToList ();
225
} else if (node is MethodDeclaration) {
226
var methodDeclaration = node as MethodDeclaration;
227
methodCallArgumentWrapping = policy.MethodDeclarationParameterWrapping;
228
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodDeclarationOpenParentheses;
229
methodClosingParenthesesOnNewLine = policy.MethodDeclarationClosingParenthesesOnNewLine;
230
doAlignToFirstArgument = policy.AlignToFirstMethodDeclarationParameter;
231
spaceWithinMethodCallParentheses = policy.SpaceWithinMethodDeclarationParentheses;
232
spaceAfterMethodCallParameterComma = policy.SpaceAfterMethodDeclarationParameterComma;
233
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeMethodDeclarationParameterComma;
234
spaceWithinEmptyParentheses = policy.SpaceBetweenEmptyMethodDeclarationParentheses;
235
lParToken = methodDeclaration.LParToken;
236
rParToken = methodDeclaration.RParToken;
237
arguments = methodDeclaration.Parameters.Cast<AstNode> ().ToList ();
238
} else if (node is IndexerExpression) {
239
var indexer = (IndexerExpression)node;
240
methodCallArgumentWrapping = policy.IndexerArgumentWrapping;
241
newLineAferMethodCallOpenParentheses = policy.NewLineAferIndexerOpenBracket;
242
doAlignToFirstArgument = policy.AlignToFirstIndexerArgument;
243
methodClosingParenthesesOnNewLine = policy.IndexerClosingBracketOnNewLine;
244
spaceWithinMethodCallParentheses = policy.SpacesWithinBrackets;
245
spaceAfterMethodCallParameterComma = policy.SpaceAfterBracketComma;
246
spaceWithinEmptyParentheses = spaceWithinMethodCallParentheses;
247
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeBracketComma;
248
rParToken = indexer.RBracketToken;
249
lParToken = indexer.LBracketToken;
250
arguments = indexer.Arguments.Cast<AstNode> ().ToList ();
251
} else if (node is ObjectCreateExpression) {
252
var oce = node as ObjectCreateExpression;
253
methodCallArgumentWrapping = policy.MethodCallArgumentWrapping;
254
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodCallOpenParentheses;
255
doAlignToFirstArgument = policy.AlignToFirstMethodCallArgument;
256
methodClosingParenthesesOnNewLine = policy.MethodCallClosingParenthesesOnNewLine;
257
spaceWithinMethodCallParentheses = policy.SpacesWithinNewParentheses;
258
spaceAfterMethodCallParameterComma = policy.SpaceAfterNewParameterComma;
259
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeNewParameterComma;
260
spaceWithinEmptyParentheses = policy.SpacesBetweenEmptyNewParentheses;
262
rParToken = oce.RParToken;
263
lParToken = oce.LParToken;
264
arguments = oce.Arguments.Cast<AstNode> ().ToList ();
266
InvocationExpression invocationExpression = node as InvocationExpression;
267
methodCallArgumentWrapping = policy.MethodCallArgumentWrapping;
268
newLineAferMethodCallOpenParentheses = policy.NewLineAferMethodCallOpenParentheses;
269
methodClosingParenthesesOnNewLine = policy.MethodCallClosingParenthesesOnNewLine;
270
doAlignToFirstArgument = policy.AlignToFirstMethodCallArgument;
271
spaceWithinMethodCallParentheses = policy.SpaceWithinMethodCallParentheses;
272
spaceAfterMethodCallParameterComma = policy.SpaceAfterMethodCallParameterComma;
273
spaceBeforeMethodCallParameterComma = policy.SpaceBeforeMethodCallParameterComma;
274
spaceWithinEmptyParentheses = policy.SpaceBetweenEmptyMethodCallParentheses;
276
rParToken = invocationExpression.RParToken;
277
lParToken = invocationExpression.LParToken;
278
arguments = invocationExpression.Arguments.Cast<AstNode> ().ToList ();
281
if (formatter.FormattingMode == ICSharpCode.NRefactory.CSharp.FormattingMode.OnTheFly)
282
methodCallArgumentWrapping = Wrapping.DoNotChange;
283
int argumentStart = 1;
284
var firstarg = arguments.FirstOrDefault();
285
if (firstarg != null && firstarg.GetPrevNode().Role == Roles.NewLine) {
286
doAlignToFirstArgument = false;
290
bool wrapMethodCall = DoWrap(methodCallArgumentWrapping, rParToken, arguments.Count);
291
if (wrapMethodCall && arguments.Any()) {
292
if (ShouldBreakLine (newLineAferMethodCallOpenParentheses, lParToken)) {
293
curIndent.Push(IndentType.Continuation);
294
foreach (var arg in arguments) {
295
FixStatementIndentation(arg.StartLocation);
299
if (!doAlignToFirstArgument) {
300
curIndent.Push(IndentType.Continuation);
301
foreach (var arg in arguments.Skip (argumentStart)) {
302
FixStatementIndentation(arg.StartLocation);
306
int extraSpaces = arguments.First().StartLocation.Column - 1 - curIndent.IndentString.Length;
307
curIndent.ExtraSpaces += extraSpaces;
308
foreach (var arg in arguments.Skip(argumentStart)) {
309
FixStatementIndentation(arg.StartLocation);
311
curIndent.ExtraSpaces -= extraSpaces;
315
if (!rParToken.IsNull) {
316
if (ShouldBreakLine (methodClosingParenthesesOnNewLine, rParToken)) {
317
FixStatementIndentation(rParToken.StartLocation);
318
} else if (methodClosingParenthesesOnNewLine == NewLinePlacement.SameLine) {
319
ForceSpacesBeforeRemoveNewLines(rParToken, spaceWithinMethodCallParentheses);
323
foreach (var arg in arguments.Skip(argumentStart)) {
324
if (arg.GetPrevSibling(NoWhitespacePredicate) != null) {
325
if (methodCallArgumentWrapping == Wrapping.DoNotWrap) {
326
ForceSpacesBeforeRemoveNewLines(arg, spaceAfterMethodCallParameterComma && arg.GetPrevSibling(NoWhitespacePredicate).Role == Roles.Comma);
328
if (!doAlignToFirstArgument && arg.PrevSibling.Role == Roles.NewLine) {
329
curIndent.Push(IndentType.Continuation);
330
FixStatementIndentation(arg.StartLocation);
333
if (arg.PrevSibling.StartLocation.Line == arg.StartLocation.Line) {
334
ForceSpacesBefore(arg, spaceAfterMethodCallParameterComma && arg.GetPrevSibling(NoWhitespacePredicate).Role == Roles.Comma);
336
int extraSpaces = arguments.First().StartLocation.Column - 1 - curIndent.IndentString.Length;
337
curIndent.ExtraSpaces += extraSpaces;
338
FixStatementIndentation(arg.StartLocation);
339
curIndent.ExtraSpaces -= extraSpaces;
344
arg.AcceptVisitor(this);
346
if (!rParToken.IsNull) {
347
if (methodCallArgumentWrapping == Wrapping.DoNotWrap) {
348
ForceSpacesBeforeRemoveNewLines(rParToken, arguments.Any() ? spaceWithinMethodCallParentheses : spaceWithinEmptyParentheses);
350
bool sameLine = rParToken.GetPrevNode(n => n.Role == Roles.Argument || n.Role == Roles.Parameter || n.Role == Roles.LPar || n.Role == Roles.Comma).EndLocation.Line == rParToken.StartLocation.Line;
352
ForceSpacesBeforeRemoveNewLines(rParToken, arguments.Any() ? spaceWithinMethodCallParentheses : spaceWithinEmptyParentheses);
354
FixStatementIndentation(rParToken.StartLocation);
359
if (!rParToken.IsNull) {
360
foreach (CSharpTokenNode comma in rParToken.Parent.Children.Where(n => n.Role == Roles.Comma)) {
361
ForceSpacesBefore(comma, spaceBeforeMethodCallParameterComma);
366
public override void VisitInvocationExpression(InvocationExpression invocationExpression)
368
ForceSpacesBefore(invocationExpression.LParToken, policy.SpaceBeforeMethodCallParentheses);
369
if (invocationExpression.Arguments.Any()) {
370
ForceSpacesAfter(invocationExpression.LParToken, policy.SpaceWithinMethodCallParentheses);
372
ForceSpacesAfter(invocationExpression.LParToken, policy.SpaceBetweenEmptyMethodCallParentheses);
373
ForceSpacesBefore(invocationExpression.RParToken, policy.SpaceBetweenEmptyMethodCallParentheses);
376
if (!invocationExpression.Target.IsNull)
377
invocationExpression.Target.AcceptVisitor(this);
379
if (invocationExpression.Target is MemberReferenceExpression) {
380
var mt = (MemberReferenceExpression)invocationExpression.Target;
381
if (mt.Target is InvocationExpression) {
382
if (DoWrap(policy.ChainedMethodCallWrapping, mt.DotToken, 2)) {
383
curIndent.Push(IndentType.Continuation);
384
FixStatementIndentation(mt.DotToken.StartLocation);
387
if (policy.ChainedMethodCallWrapping == Wrapping.DoNotWrap)
388
ForceSpacesBeforeRemoveNewLines(mt.DotToken, false);
392
FormatArguments(invocationExpression);
395
public override void VisitIndexerExpression(IndexerExpression indexerExpression)
397
ForceSpacesBefore(indexerExpression.LBracketToken, policy.SpacesBeforeBrackets);
398
ForceSpacesAfter(indexerExpression.LBracketToken, policy.SpacesWithinBrackets);
400
if (!indexerExpression.Target.IsNull)
401
indexerExpression.Target.AcceptVisitor(this);
403
FormatArguments(indexerExpression);
409
public override void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
411
ForceSpacesAfter(parenthesizedExpression.LParToken, policy.SpacesWithinParentheses);
412
ForceSpacesBefore(parenthesizedExpression.RParToken, policy.SpacesWithinParentheses);
413
base.VisitParenthesizedExpression(parenthesizedExpression);
416
public override void VisitSizeOfExpression(SizeOfExpression sizeOfExpression)
418
ForceSpacesBefore(sizeOfExpression.LParToken, policy.SpaceBeforeSizeOfParentheses);
419
ForceSpacesAfter(sizeOfExpression.LParToken, policy.SpacesWithinSizeOfParentheses);
420
ForceSpacesBefore(sizeOfExpression.RParToken, policy.SpacesWithinSizeOfParentheses);
421
base.VisitSizeOfExpression(sizeOfExpression);
424
public override void VisitTypeOfExpression(TypeOfExpression typeOfExpression)
426
ForceSpacesBefore(typeOfExpression.LParToken, policy.SpaceBeforeTypeOfParentheses);
427
ForceSpacesAfter(typeOfExpression.LParToken, policy.SpacesWithinTypeOfParentheses);
428
ForceSpacesBefore(typeOfExpression.RParToken, policy.SpacesWithinTypeOfParentheses);
429
base.VisitTypeOfExpression(typeOfExpression);
432
public override void VisitCheckedExpression(CheckedExpression checkedExpression)
434
ForceSpacesAfter(checkedExpression.LParToken, policy.SpacesWithinCheckedExpressionParantheses);
435
ForceSpacesBefore(checkedExpression.RParToken, policy.SpacesWithinCheckedExpressionParantheses);
436
base.VisitCheckedExpression(checkedExpression);
439
public override void VisitUncheckedExpression(UncheckedExpression uncheckedExpression)
441
ForceSpacesAfter(uncheckedExpression.LParToken, policy.SpacesWithinCheckedExpressionParantheses);
442
ForceSpacesBefore(uncheckedExpression.RParToken, policy.SpacesWithinCheckedExpressionParantheses);
443
base.VisitUncheckedExpression(uncheckedExpression);
446
public override void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression)
448
ForceSpacesBefore(objectCreateExpression.LParToken, policy.SpaceBeforeNewParentheses);
450
if (objectCreateExpression.Arguments.Any()) {
451
if (!objectCreateExpression.LParToken.IsNull)
452
ForceSpacesAfter(objectCreateExpression.LParToken, policy.SpacesWithinNewParentheses);
454
if (!objectCreateExpression.LParToken.IsNull)
455
ForceSpacesAfter(objectCreateExpression.LParToken, policy.SpacesBetweenEmptyNewParentheses);
458
if (!objectCreateExpression.Type.IsNull)
459
objectCreateExpression.Type.AcceptVisitor(this);
460
objectCreateExpression.Initializer.AcceptVisitor(this);
461
FormatArguments(objectCreateExpression);
465
public override void VisitArrayCreateExpression(ArrayCreateExpression arrayObjectCreateExpression)
467
FormatCommas(arrayObjectCreateExpression, policy.SpaceBeforeMethodCallParameterComma, policy.SpaceAfterMethodCallParameterComma);
468
base.VisitArrayCreateExpression(arrayObjectCreateExpression);
471
public override void VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression)
473
if (DoWrap(policy.ArrayInitializerWrapping, arrayInitializerExpression.RBraceToken, arrayInitializerExpression.Elements.Count)) {
474
FixOpenBrace(policy.ArrayInitializerBraceStyle, arrayInitializerExpression.LBraceToken);
475
curIndent.Push(IndentType.Block);
476
foreach (var init in arrayInitializerExpression.Elements) {
477
FixStatementIndentation(init.StartLocation);
478
init.AcceptVisitor(this);
481
FixClosingBrace(policy.ArrayInitializerBraceStyle, arrayInitializerExpression.RBraceToken);
482
} else if (policy.ArrayInitializerWrapping == Wrapping.DoNotWrap) {
483
ForceSpacesBeforeRemoveNewLines(arrayInitializerExpression.LBraceToken);
484
ForceSpacesBeforeRemoveNewLines(arrayInitializerExpression.RBraceToken);
485
foreach (var init in arrayInitializerExpression.Elements) {
486
ForceSpacesBeforeRemoveNewLines(init);
487
init.AcceptVisitor(this);
490
var lBrace = arrayInitializerExpression.LBraceToken;
491
var rBrace = arrayInitializerExpression.RBraceToken;
493
foreach (var child in arrayInitializerExpression.Children) {
494
if (child.Role == Roles.LBrace) {
495
if (lBrace.StartLocation.Line == rBrace.StartLocation.Line && policy.AllowOneLinedArrayInitialziers) {
496
ForceSpaceBefore(child, true);
497
ForceSpacesAfter(child, true);
499
FixOpenBrace(policy.ArrayInitializerBraceStyle, child);
501
curIndent.Push(IndentType.Block);
504
if (child.Role == Roles.RBrace) {
506
if (lBrace.StartLocation.Line == rBrace.StartLocation.Line && policy.AllowOneLinedArrayInitialziers) {
507
ForceSpaceBefore(child, true);
510
FixClosingBrace(policy.ArrayInitializerBraceStyle, child);
514
if (child.Role == Roles.Expression) {
515
if (child.PrevSibling.Role == Roles.NewLine)
516
FixIndentation(child);
517
if (child.PrevSibling.Role == Roles.Comma)
518
ForceSpaceBefore(child, true);
519
if (child.NextSibling.Role == Roles.Comma)
520
ForceSpacesAfter(child, false);
524
child.AcceptVisitor(this);
529
public override void VisitLambdaExpression(LambdaExpression lambdaExpression)
531
ForceSpacesAfter(lambdaExpression.ArrowToken, true);
532
ForceSpacesBefore(lambdaExpression.ArrowToken, true);
534
base.VisitLambdaExpression(lambdaExpression);
537
public override void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression)
539
ForceSpacesAfter(namedArgumentExpression.ColonToken, policy.SpaceInNamedArgumentAfterDoubleColon);
540
base.VisitNamedArgumentExpression(namedArgumentExpression);
543
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression)
545
ForceSpacesAfter(memberReferenceExpression.DotToken, false);
546
base.VisitMemberReferenceExpression(memberReferenceExpression);