|
|
|
|
@ -211,20 +211,29 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -211,20 +211,29 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Writes an optional comma, e.g. at the end of an enum declaration
|
|
|
|
|
/// Writes an optional comma, e.g. at the end of an enum declaration or in an array initializer
|
|
|
|
|
/// </summary>
|
|
|
|
|
void OptionalComma() |
|
|
|
|
{ |
|
|
|
|
// Look for the role between the current position and the nextNode.
|
|
|
|
|
for (AstNode pos = positionStack.Peek(); pos != null; pos = pos.NextSibling) { |
|
|
|
|
if (pos.Role == AstNode.Roles.Comma) { |
|
|
|
|
Comma(null, noSpaceAfterComma: true); |
|
|
|
|
break; |
|
|
|
|
} else if (pos.NodeType != NodeType.Whitespace) { |
|
|
|
|
// only skip over whitespace and comma nodes
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Look if there's a comma after the current node, and insert it if it exists.
|
|
|
|
|
AstNode pos = positionStack.Peek(); |
|
|
|
|
while (pos != null && pos.NodeType == NodeType.Whitespace) |
|
|
|
|
pos = pos.NextSibling; |
|
|
|
|
if (pos != null && pos.Role == AstNode.Roles.Comma) |
|
|
|
|
Comma(null, noSpaceAfterComma: true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Writes an optional semicolon, e.g. at the end of a type or namespace declaration.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void OptionalSemicolon() |
|
|
|
|
{ |
|
|
|
|
// Look if there's a semicolon after the current node, and insert it if it exists.
|
|
|
|
|
AstNode pos = positionStack.Peek(); |
|
|
|
|
while (pos != null && pos.NodeType == NodeType.Whitespace) |
|
|
|
|
pos = pos.NextSibling; |
|
|
|
|
if (pos != null && pos.Role == AstNode.Roles.Semicolon) |
|
|
|
|
Semicolon(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WriteCommaSeparatedList (IEnumerable<AstNode> list) |
|
|
|
|
@ -362,7 +371,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -362,7 +371,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
|
|
|
|
|
void RPar () |
|
|
|
|
{ |
|
|
|
|
WriteToken (")", AstNode.Roles.LPar); |
|
|
|
|
WriteToken (")", AstNode.Roles.RPar); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -595,10 +604,27 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -595,10 +604,27 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
public object VisitArrayInitializerExpression (ArrayInitializerExpression arrayInitializerExpression, object data) |
|
|
|
|
{ |
|
|
|
|
StartNode (arrayInitializerExpression); |
|
|
|
|
PrintInitializerElements(arrayInitializerExpression.Elements); |
|
|
|
|
bool bracesAreOptional = arrayInitializerExpression.Elements.Count == 1 |
|
|
|
|
&& IsObjectInitializer(arrayInitializerExpression.Parent); |
|
|
|
|
if (bracesAreOptional && arrayInitializerExpression.LBraceToken.IsNull) { |
|
|
|
|
arrayInitializerExpression.Elements.Single().AcceptVisitor(this, data); |
|
|
|
|
} else { |
|
|
|
|
PrintInitializerElements(arrayInitializerExpression.Elements); |
|
|
|
|
} |
|
|
|
|
return EndNode (arrayInitializerExpression); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool IsObjectInitializer(AstNode node) |
|
|
|
|
{ |
|
|
|
|
if (!(node is ArrayInitializerExpression)) |
|
|
|
|
return false; |
|
|
|
|
if (node.Parent is ObjectCreateExpression) |
|
|
|
|
return node.Role == ObjectCreateExpression.InitializerRole; |
|
|
|
|
if (node.Parent is NamedExpression) |
|
|
|
|
return node.Role == NamedExpression.Roles.Expression; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PrintInitializerElements(AstNodeCollection<Expression> elements) |
|
|
|
|
{ |
|
|
|
|
BraceStyle style; |
|
|
|
|
@ -617,6 +643,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -617,6 +643,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
} |
|
|
|
|
node.AcceptVisitor(this, null); |
|
|
|
|
} |
|
|
|
|
OptionalComma(); |
|
|
|
|
NewLine(); |
|
|
|
|
CloseBrace(style); |
|
|
|
|
} |
|
|
|
|
@ -902,7 +929,6 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -902,7 +929,6 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
{ |
|
|
|
|
StartNode (anonymousTypeCreateExpression); |
|
|
|
|
WriteKeyword ("new"); |
|
|
|
|
Space (); |
|
|
|
|
PrintInitializerElements(anonymousTypeCreateExpression.Initializers); |
|
|
|
|
return EndNode (anonymousTypeCreateExpression); |
|
|
|
|
} |
|
|
|
|
@ -1327,9 +1353,10 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -1327,9 +1353,10 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
{ |
|
|
|
|
StartNode (attribute); |
|
|
|
|
attribute.Type.AcceptVisitor (this, data); |
|
|
|
|
Space (policy.SpaceBeforeMethodCallParentheses); |
|
|
|
|
if (attribute.Arguments.Count != 0 || !attribute.GetChildByRole (AstNode.Roles.LPar).IsNull) |
|
|
|
|
if (attribute.Arguments.Count != 0 || !attribute.GetChildByRole (AstNode.Roles.LPar).IsNull) { |
|
|
|
|
Space (policy.SpaceBeforeMethodCallParentheses); |
|
|
|
|
WriteCommaSeparatedListInParenthesis (attribute.Arguments, policy.SpaceWithinMethodCallParentheses); |
|
|
|
|
} |
|
|
|
|
return EndNode (attribute); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1379,6 +1406,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -1379,6 +1406,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
foreach (var member in namespaceDeclaration.Members) |
|
|
|
|
member.AcceptVisitor (this, data); |
|
|
|
|
CloseBrace (policy.NamespaceBraceStyle); |
|
|
|
|
OptionalSemicolon (); |
|
|
|
|
NewLine (); |
|
|
|
|
return EndNode (namespaceDeclaration); |
|
|
|
|
} |
|
|
|
|
@ -1438,6 +1466,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -1438,6 +1466,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
CloseBrace (braceStyle); |
|
|
|
|
OptionalSemicolon (); |
|
|
|
|
NewLine (); |
|
|
|
|
return EndNode (typeDeclaration); |
|
|
|
|
} |
|
|
|
|
@ -1867,6 +1896,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -1867,6 +1896,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
public object VisitVariableDeclarationStatement (VariableDeclarationStatement variableDeclarationStatement, object data) |
|
|
|
|
{ |
|
|
|
|
StartNode (variableDeclarationStatement); |
|
|
|
|
WriteModifiers (variableDeclarationStatement.GetChildrenByRole (VariableDeclarationStatement.ModifierRole)); |
|
|
|
|
variableDeclarationStatement.Type.AcceptVisitor (this, data); |
|
|
|
|
Space (); |
|
|
|
|
WriteCommaSeparatedList (variableDeclarationStatement.Variables); |
|
|
|
|
|