|
|
|
@ -15,7 +15,6 @@ |
|
|
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics; |
|
|
|
@ -58,20 +57,24 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
public CSharpOutputVisitor (TextWriter textWriter, CSharpFormattingOptions formattingPolicy) |
|
|
|
public CSharpOutputVisitor (TextWriter textWriter, CSharpFormattingOptions formattingPolicy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (textWriter == null) |
|
|
|
if (textWriter == null) { |
|
|
|
throw new ArgumentNullException ("textWriter"); |
|
|
|
throw new ArgumentNullException ("textWriter"); |
|
|
|
if (formattingPolicy == null) |
|
|
|
} |
|
|
|
|
|
|
|
if (formattingPolicy == null) { |
|
|
|
throw new ArgumentNullException ("formattingPolicy"); |
|
|
|
throw new ArgumentNullException ("formattingPolicy"); |
|
|
|
|
|
|
|
} |
|
|
|
this.formatter = new TextWriterOutputFormatter (textWriter); |
|
|
|
this.formatter = new TextWriterOutputFormatter (textWriter); |
|
|
|
this.policy = formattingPolicy; |
|
|
|
this.policy = formattingPolicy; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public CSharpOutputVisitor (IOutputFormatter formatter, CSharpFormattingOptions formattingPolicy) |
|
|
|
public CSharpOutputVisitor (IOutputFormatter formatter, CSharpFormattingOptions formattingPolicy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (formatter == null) |
|
|
|
if (formatter == null) { |
|
|
|
throw new ArgumentNullException ("formatter"); |
|
|
|
throw new ArgumentNullException ("formatter"); |
|
|
|
if (formattingPolicy == null) |
|
|
|
} |
|
|
|
|
|
|
|
if (formattingPolicy == null) { |
|
|
|
throw new ArgumentNullException ("formattingPolicy"); |
|
|
|
throw new ArgumentNullException ("formattingPolicy"); |
|
|
|
|
|
|
|
} |
|
|
|
this.formatter = formatter; |
|
|
|
this.formatter = formatter; |
|
|
|
this.policy = formattingPolicy; |
|
|
|
this.policy = formattingPolicy; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -82,8 +85,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
// Ensure that nodes are visited in the proper nested order.
|
|
|
|
// Ensure that nodes are visited in the proper nested order.
|
|
|
|
// Jumps to different subtrees are allowed only for the child of a placeholder node.
|
|
|
|
// Jumps to different subtrees are allowed only for the child of a placeholder node.
|
|
|
|
Debug.Assert(containerStack.Count == 0 || node.Parent == containerStack.Peek() || containerStack.Peek().NodeType == NodeType.Pattern); |
|
|
|
Debug.Assert(containerStack.Count == 0 || node.Parent == containerStack.Peek() || containerStack.Peek().NodeType == NodeType.Pattern); |
|
|
|
if (positionStack.Count > 0) |
|
|
|
if (positionStack.Count > 0) { |
|
|
|
WriteSpecialsUpToNode(node); |
|
|
|
WriteSpecialsUpToNode(node); |
|
|
|
|
|
|
|
} |
|
|
|
containerStack.Push(node); |
|
|
|
containerStack.Push(node); |
|
|
|
positionStack.Push(node.FirstChild); |
|
|
|
positionStack.Push(node.FirstChild); |
|
|
|
formatter.StartNode(node); |
|
|
|
formatter.StartNode(node); |
|
|
|
@ -124,8 +128,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
void WriteSpecialsUpToRole(Role role, AstNode nextNode) |
|
|
|
void WriteSpecialsUpToRole(Role role, AstNode nextNode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (positionStack.Count == 0) |
|
|
|
if (positionStack.Count == 0) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
// Look for the role between the current position and the nextNode.
|
|
|
|
// Look for the role between the current position and the nextNode.
|
|
|
|
for (AstNode pos = positionStack.Peek(); pos != null && pos != nextNode; pos = pos.NextSibling) { |
|
|
|
for (AstNode pos = positionStack.Peek(); pos != null && pos != nextNode; pos = pos.NextSibling) { |
|
|
|
if (pos.Role == role) { |
|
|
|
if (pos.Role == role) { |
|
|
|
@ -145,8 +150,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
void WriteSpecialsUpToNode(AstNode node) |
|
|
|
void WriteSpecialsUpToNode(AstNode node) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (positionStack.Count == 0) |
|
|
|
if (positionStack.Count == 0) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
for (AstNode pos = positionStack.Peek(); pos != null; pos = pos.NextSibling) { |
|
|
|
for (AstNode pos = positionStack.Peek(); pos != null; pos = pos.NextSibling) { |
|
|
|
if (pos == node) { |
|
|
|
if (pos == node) { |
|
|
|
WriteSpecials(positionStack.Pop(), pos); |
|
|
|
WriteSpecials(positionStack.Pop(), pos); |
|
|
|
@ -169,10 +175,12 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
void Comma(AstNode nextNode, bool noSpaceAfterComma = false) |
|
|
|
void Comma(AstNode nextNode, bool noSpaceAfterComma = false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WriteSpecialsUpToRole(Roles.Comma, nextNode); |
|
|
|
WriteSpecialsUpToRole(Roles.Comma, nextNode); |
|
|
|
Space (policy.SpaceBeforeBracketComma); // TODO: Comma policy has changed.
|
|
|
|
Space(policy.SpaceBeforeBracketComma); |
|
|
|
|
|
|
|
// TODO: Comma policy has changed.
|
|
|
|
formatter.WriteToken(","); |
|
|
|
formatter.WriteToken(","); |
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
Space (!noSpaceAfterComma && policy.SpaceAfterBracketComma); // TODO: Comma policy has changed.
|
|
|
|
Space(!noSpaceAfterComma && policy.SpaceAfterBracketComma); |
|
|
|
|
|
|
|
// TODO: Comma policy has changed.
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
@ -182,11 +190,13 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Look if there's a comma after the current node, and insert it if it exists.
|
|
|
|
// Look if there's a comma after the current node, and insert it if it exists.
|
|
|
|
AstNode pos = positionStack.Peek(); |
|
|
|
AstNode pos = positionStack.Peek(); |
|
|
|
while (pos != null && pos.NodeType == NodeType.Whitespace) |
|
|
|
while (pos != null && pos.NodeType == NodeType.Whitespace) { |
|
|
|
pos = pos.NextSibling; |
|
|
|
pos = pos.NextSibling; |
|
|
|
if (pos != null && pos.Role == Roles.Comma) |
|
|
|
} |
|
|
|
|
|
|
|
if (pos != null && pos.Role == Roles.Comma) { |
|
|
|
Comma(null, noSpaceAfterComma: true); |
|
|
|
Comma(null, noSpaceAfterComma: true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Writes an optional semicolon, e.g. at the end of a type or namespace declaration.
|
|
|
|
/// Writes an optional semicolon, e.g. at the end of a type or namespace declaration.
|
|
|
|
@ -195,11 +205,13 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Look if there's a semicolon after the current node, and insert it if it exists.
|
|
|
|
// Look if there's a semicolon after the current node, and insert it if it exists.
|
|
|
|
AstNode pos = positionStack.Peek(); |
|
|
|
AstNode pos = positionStack.Peek(); |
|
|
|
while (pos != null && pos.NodeType == NodeType.Whitespace) |
|
|
|
while (pos != null && pos.NodeType == NodeType.Whitespace) { |
|
|
|
pos = pos.NextSibling; |
|
|
|
pos = pos.NextSibling; |
|
|
|
if (pos != null && pos.Role == Roles.Semicolon) |
|
|
|
} |
|
|
|
|
|
|
|
if (pos != null && pos.Role == Roles.Semicolon) { |
|
|
|
Semicolon(); |
|
|
|
Semicolon(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void WriteCommaSeparatedList(IEnumerable<AstNode> list) |
|
|
|
void WriteCommaSeparatedList(IEnumerable<AstNode> list) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -282,10 +294,12 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
void WriteKeyword(string token, Role tokenRole = null) |
|
|
|
void WriteKeyword(string token, Role tokenRole = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (tokenRole != null) |
|
|
|
if (tokenRole != null) { |
|
|
|
WriteSpecialsUpToRole(tokenRole); |
|
|
|
WriteSpecialsUpToRole(tokenRole); |
|
|
|
if (lastWritten == LastWritten.KeywordOrIdentifier) |
|
|
|
} |
|
|
|
|
|
|
|
if (lastWritten == LastWritten.KeywordOrIdentifier) { |
|
|
|
formatter.Space(); |
|
|
|
formatter.Space(); |
|
|
|
|
|
|
|
} |
|
|
|
formatter.WriteKeyword(token); |
|
|
|
formatter.WriteKeyword(token); |
|
|
|
lastWritten = LastWritten.KeywordOrIdentifier; |
|
|
|
lastWritten = LastWritten.KeywordOrIdentifier; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -303,11 +317,14 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
WriteSpecialsUpToRole(identifierRole ?? Roles.Identifier); |
|
|
|
WriteSpecialsUpToRole(identifierRole ?? Roles.Identifier); |
|
|
|
if (IsKeyword(identifier, containerStack.Peek())) { |
|
|
|
if (IsKeyword(identifier, containerStack.Peek())) { |
|
|
|
if (lastWritten == LastWritten.KeywordOrIdentifier) |
|
|
|
if (lastWritten == LastWritten.KeywordOrIdentifier) { |
|
|
|
Space (); // this space is not strictly required, so we call Space()
|
|
|
|
Space(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// this space is not strictly required, so we call Space()
|
|
|
|
formatter.WriteToken("@"); |
|
|
|
formatter.WriteToken("@"); |
|
|
|
} else if (lastWritten == LastWritten.KeywordOrIdentifier) { |
|
|
|
} else if (lastWritten == LastWritten.KeywordOrIdentifier) { |
|
|
|
formatter.Space (); // this space is strictly required, so we directly call the formatter
|
|
|
|
formatter.Space(); |
|
|
|
|
|
|
|
// this space is strictly required, so we directly call the formatter
|
|
|
|
} |
|
|
|
} |
|
|
|
formatter.WriteIdentifier(identifier); |
|
|
|
formatter.WriteIdentifier(identifier); |
|
|
|
lastWritten = LastWritten.KeywordOrIdentifier; |
|
|
|
lastWritten = LastWritten.KeywordOrIdentifier; |
|
|
|
@ -335,19 +352,20 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
formatter.Space(); |
|
|
|
formatter.Space(); |
|
|
|
} |
|
|
|
} |
|
|
|
formatter.WriteToken(token); |
|
|
|
formatter.WriteToken(token); |
|
|
|
if (token == "+") |
|
|
|
if (token == "+") { |
|
|
|
lastWritten = LastWritten.Plus; |
|
|
|
lastWritten = LastWritten.Plus; |
|
|
|
else if (token == "-") |
|
|
|
} else if (token == "-") { |
|
|
|
lastWritten = LastWritten.Minus; |
|
|
|
lastWritten = LastWritten.Minus; |
|
|
|
else if (token == "&") |
|
|
|
} else if (token == "&") { |
|
|
|
lastWritten = LastWritten.Ampersand; |
|
|
|
lastWritten = LastWritten.Ampersand; |
|
|
|
else if (token == "?") |
|
|
|
} else if (token == "?") { |
|
|
|
lastWritten = LastWritten.QuestionMark; |
|
|
|
lastWritten = LastWritten.QuestionMark; |
|
|
|
else if (token == "/") |
|
|
|
} else if (token == "/") { |
|
|
|
lastWritten = LastWritten.Division; |
|
|
|
lastWritten = LastWritten.Division; |
|
|
|
else |
|
|
|
} else { |
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
lastWritten = LastWritten.Other; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LPar() |
|
|
|
void LPar() |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -364,7 +382,8 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
void Semicolon() |
|
|
|
void Semicolon() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Role role = containerStack.Peek ().Role; // get the role of the current node
|
|
|
|
Role role = containerStack.Peek().Role; |
|
|
|
|
|
|
|
// get the role of the current node
|
|
|
|
if (!(role == ForStatement.InitializerRole || role == ForStatement.IteratorRole || role == UsingStatement.ResourceAcquisitionRole)) { |
|
|
|
if (!(role == ForStatement.InitializerRole || role == ForStatement.IteratorRole || role == UsingStatement.ResourceAcquisitionRole)) { |
|
|
|
WriteToken(Roles.Semicolon); |
|
|
|
WriteToken(Roles.Semicolon); |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
@ -427,21 +446,26 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static bool IsKeyword(string identifier, AstNode context) |
|
|
|
public static bool IsKeyword(string identifier, AstNode context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (unconditionalKeywords.Contains (identifier)) |
|
|
|
if (unconditionalKeywords.Contains(identifier)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
foreach (AstNode ancestor in context.Ancestors) { |
|
|
|
foreach (AstNode ancestor in context.Ancestors) { |
|
|
|
if (ancestor is QueryExpression && queryKeywords.Contains (identifier)) |
|
|
|
if (ancestor is QueryExpression && queryKeywords.Contains(identifier)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
if (identifier == "await") { |
|
|
|
if (identifier == "await") { |
|
|
|
// with lambdas/anonymous methods,
|
|
|
|
// with lambdas/anonymous methods,
|
|
|
|
if (ancestor is LambdaExpression) |
|
|
|
if (ancestor is LambdaExpression) { |
|
|
|
return ((LambdaExpression)ancestor).IsAsync; |
|
|
|
return ((LambdaExpression)ancestor).IsAsync; |
|
|
|
if (ancestor is AnonymousMethodExpression) |
|
|
|
} |
|
|
|
|
|
|
|
if (ancestor is AnonymousMethodExpression) { |
|
|
|
return ((AnonymousMethodExpression)ancestor).IsAsync; |
|
|
|
return ((AnonymousMethodExpression)ancestor).IsAsync; |
|
|
|
if (ancestor is EntityDeclaration) |
|
|
|
} |
|
|
|
|
|
|
|
if (ancestor is EntityDeclaration) { |
|
|
|
return (((EntityDeclaration)ancestor).Modifiers & Modifiers.Async) == Modifiers.Async; |
|
|
|
return (((EntityDeclaration)ancestor).Modifiers & Modifiers.Async) == Modifiers.Async; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
@ -478,8 +502,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
foreach (Identifier ident in identifiers) { |
|
|
|
foreach (Identifier ident in identifiers) { |
|
|
|
if (first) { |
|
|
|
if (first) { |
|
|
|
first = false; |
|
|
|
first = false; |
|
|
|
if (lastWritten == LastWritten.KeywordOrIdentifier) |
|
|
|
if (lastWritten == LastWritten.KeywordOrIdentifier) { |
|
|
|
formatter.Space(); |
|
|
|
formatter.Space(); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
WriteSpecialsUpToRole(Roles.Dot, ident); |
|
|
|
WriteSpecialsUpToRole(Roles.Dot, ident); |
|
|
|
formatter.WriteToken("."); |
|
|
|
formatter.WriteToken("."); |
|
|
|
@ -493,12 +518,13 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
void WriteEmbeddedStatement(Statement embeddedStatement) |
|
|
|
void WriteEmbeddedStatement(Statement embeddedStatement) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (embeddedStatement.IsNull) |
|
|
|
if (embeddedStatement.IsNull) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
BlockStatement block = embeddedStatement as BlockStatement; |
|
|
|
BlockStatement block = embeddedStatement as BlockStatement; |
|
|
|
if (block != null) |
|
|
|
if (block != null) { |
|
|
|
VisitBlockStatement(block); |
|
|
|
VisitBlockStatement(block); |
|
|
|
else { |
|
|
|
} else { |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
formatter.Indent(); |
|
|
|
formatter.Indent(); |
|
|
|
embeddedStatement.AcceptVisitor(this); |
|
|
|
embeddedStatement.AcceptVisitor(this); |
|
|
|
@ -508,11 +534,12 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
void WriteMethodBody(BlockStatement body) |
|
|
|
void WriteMethodBody(BlockStatement body) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (body.IsNull) |
|
|
|
if (body.IsNull) { |
|
|
|
Semicolon(); |
|
|
|
Semicolon(); |
|
|
|
else |
|
|
|
} else { |
|
|
|
VisitBlockStatement(body); |
|
|
|
VisitBlockStatement(body); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void WriteAttributes(IEnumerable<AttributeSection> attributes) |
|
|
|
void WriteAttributes(IEnumerable<AttributeSection> attributes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -578,10 +605,12 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
StartNode(arrayCreateExpression); |
|
|
|
StartNode(arrayCreateExpression); |
|
|
|
WriteKeyword(ArrayCreateExpression.NewKeywordRole); |
|
|
|
WriteKeyword(ArrayCreateExpression.NewKeywordRole); |
|
|
|
arrayCreateExpression.Type.AcceptVisitor(this); |
|
|
|
arrayCreateExpression.Type.AcceptVisitor(this); |
|
|
|
if (arrayCreateExpression.Arguments.Count > 0) |
|
|
|
if (arrayCreateExpression.Arguments.Count > 0) { |
|
|
|
WriteCommaSeparatedListInBrackets(arrayCreateExpression.Arguments); |
|
|
|
WriteCommaSeparatedListInBrackets(arrayCreateExpression.Arguments); |
|
|
|
foreach (var specifier in arrayCreateExpression.AdditionalArraySpecifiers) |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var specifier in arrayCreateExpression.AdditionalArraySpecifiers) { |
|
|
|
specifier.AcceptVisitor(this); |
|
|
|
specifier.AcceptVisitor(this); |
|
|
|
|
|
|
|
} |
|
|
|
arrayCreateExpression.Initializer.AcceptVisitor(this); |
|
|
|
arrayCreateExpression.Initializer.AcceptVisitor(this); |
|
|
|
EndNode(arrayCreateExpression); |
|
|
|
EndNode(arrayCreateExpression); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -615,22 +644,26 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
bool IsObjectOrCollectionInitializer(AstNode node) |
|
|
|
bool IsObjectOrCollectionInitializer(AstNode node) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!(node is ArrayInitializerExpression)) |
|
|
|
if (!(node is ArrayInitializerExpression)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (node.Parent is ObjectCreateExpression) |
|
|
|
} |
|
|
|
|
|
|
|
if (node.Parent is ObjectCreateExpression) { |
|
|
|
return node.Role == ObjectCreateExpression.InitializerRole; |
|
|
|
return node.Role == ObjectCreateExpression.InitializerRole; |
|
|
|
if (node.Parent is NamedExpression) |
|
|
|
} |
|
|
|
|
|
|
|
if (node.Parent is NamedExpression) { |
|
|
|
return node.Role == Roles.Expression; |
|
|
|
return node.Role == Roles.Expression; |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PrintInitializerElements(AstNodeCollection<Expression> elements) |
|
|
|
void PrintInitializerElements(AstNodeCollection<Expression> elements) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BraceStyle style; |
|
|
|
BraceStyle style; |
|
|
|
if (policy.PlaceArrayInitializersOnNewLine == ArrayInitializerPlacement.AlwaysNewLine) |
|
|
|
if (policy.PlaceArrayInitializersOnNewLine == ArrayInitializerPlacement.AlwaysNewLine) { |
|
|
|
style = BraceStyle.NextLine; |
|
|
|
style = BraceStyle.NextLine; |
|
|
|
else |
|
|
|
} else { |
|
|
|
style = BraceStyle.EndOfLine; |
|
|
|
style = BraceStyle.EndOfLine; |
|
|
|
|
|
|
|
} |
|
|
|
OpenBrace(style); |
|
|
|
OpenBrace(style); |
|
|
|
bool isFirst = true; |
|
|
|
bool isFirst = true; |
|
|
|
foreach (AstNode node in elements) { |
|
|
|
foreach (AstNode node in elements) { |
|
|
|
@ -863,8 +896,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
bool LambdaNeedsParenthesis(LambdaExpression lambdaExpression) |
|
|
|
bool LambdaNeedsParenthesis(LambdaExpression lambdaExpression) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (lambdaExpression.Parameters.Count != 1) |
|
|
|
if (lambdaExpression.Parameters.Count != 1) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
var p = lambdaExpression.Parameters.Single(); |
|
|
|
var p = lambdaExpression.Parameters.Single(); |
|
|
|
return !(p.Type.IsNull && p.ParameterModifier == ParameterModifier.None); |
|
|
|
return !(p.Type.IsNull && p.ParameterModifier == ParameterModifier.None); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -882,7 +916,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
public void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression) |
|
|
|
public void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression) |
|
|
|
{ |
|
|
|
{ |
|
|
|
StartNode(namedArgumentExpression); |
|
|
|
StartNode(namedArgumentExpression); |
|
|
|
WriteIdentifier (namedArgumentExpression.Identifier); |
|
|
|
namedArgumentExpression.IdentifierToken.AcceptVisitor(this); |
|
|
|
WriteToken(Roles.Colon); |
|
|
|
WriteToken(Roles.Colon); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
namedArgumentExpression.Expression.AcceptVisitor(this); |
|
|
|
namedArgumentExpression.Expression.AcceptVisitor(this); |
|
|
|
@ -892,7 +926,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
public void VisitNamedExpression(NamedExpression namedExpression) |
|
|
|
public void VisitNamedExpression(NamedExpression namedExpression) |
|
|
|
{ |
|
|
|
{ |
|
|
|
StartNode(namedExpression); |
|
|
|
StartNode(namedExpression); |
|
|
|
WriteIdentifier (namedExpression.Identifier); |
|
|
|
namedExpression.IdentifierToken.AcceptVisitor(this); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
@ -914,8 +948,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
objectCreateExpression.Type.AcceptVisitor(this); |
|
|
|
objectCreateExpression.Type.AcceptVisitor(this); |
|
|
|
bool useParenthesis = objectCreateExpression.Arguments.Any() || objectCreateExpression.Initializer.IsNull; |
|
|
|
bool useParenthesis = objectCreateExpression.Arguments.Any() || objectCreateExpression.Initializer.IsNull; |
|
|
|
// also use parenthesis if there is an '(' token
|
|
|
|
// also use parenthesis if there is an '(' token
|
|
|
|
if (!objectCreateExpression.LParToken.IsNull) |
|
|
|
if (!objectCreateExpression.LParToken.IsNull) { |
|
|
|
useParenthesis = true; |
|
|
|
useParenthesis = true; |
|
|
|
|
|
|
|
} |
|
|
|
if (useParenthesis) { |
|
|
|
if (useParenthesis) { |
|
|
|
Space(policy.SpaceBeforeMethodCallParentheses); |
|
|
|
Space(policy.SpaceBeforeMethodCallParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(objectCreateExpression.Arguments, policy.SpaceWithinMethodCallParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(objectCreateExpression.Arguments, policy.SpaceWithinMethodCallParentheses); |
|
|
|
@ -1004,12 +1039,13 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
// but we still support writing these to make life easier for code generators.
|
|
|
|
// but we still support writing these to make life easier for code generators.
|
|
|
|
WriteKeyword("float"); |
|
|
|
WriteKeyword("float"); |
|
|
|
WriteToken(Roles.Dot); |
|
|
|
WriteToken(Roles.Dot); |
|
|
|
if (float.IsPositiveInfinity (f)) |
|
|
|
if (float.IsPositiveInfinity(f)) { |
|
|
|
WriteIdentifier("PositiveInfinity"); |
|
|
|
WriteIdentifier("PositiveInfinity"); |
|
|
|
else if (float.IsNegativeInfinity (f)) |
|
|
|
} else if (float.IsNegativeInfinity(f)) { |
|
|
|
WriteIdentifier("NegativeInfinity"); |
|
|
|
WriteIdentifier("NegativeInfinity"); |
|
|
|
else |
|
|
|
} else { |
|
|
|
WriteIdentifier("NaN"); |
|
|
|
WriteIdentifier("NaN"); |
|
|
|
|
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
formatter.WriteToken(f.ToString("R", NumberFormatInfo.InvariantInfo) + "f"); |
|
|
|
formatter.WriteToken(f.ToString("R", NumberFormatInfo.InvariantInfo) + "f"); |
|
|
|
@ -1021,17 +1057,19 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
// but we still support writing these to make life easier for code generators.
|
|
|
|
// but we still support writing these to make life easier for code generators.
|
|
|
|
WriteKeyword("double"); |
|
|
|
WriteKeyword("double"); |
|
|
|
WriteToken(Roles.Dot); |
|
|
|
WriteToken(Roles.Dot); |
|
|
|
if (double.IsPositiveInfinity (f)) |
|
|
|
if (double.IsPositiveInfinity(f)) { |
|
|
|
WriteIdentifier("PositiveInfinity"); |
|
|
|
WriteIdentifier("PositiveInfinity"); |
|
|
|
else if (double.IsNegativeInfinity (f)) |
|
|
|
} else if (double.IsNegativeInfinity(f)) { |
|
|
|
WriteIdentifier("NegativeInfinity"); |
|
|
|
WriteIdentifier("NegativeInfinity"); |
|
|
|
else |
|
|
|
} else { |
|
|
|
WriteIdentifier("NaN"); |
|
|
|
WriteIdentifier("NaN"); |
|
|
|
|
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
string number = f.ToString("R", NumberFormatInfo.InvariantInfo); |
|
|
|
string number = f.ToString("R", NumberFormatInfo.InvariantInfo); |
|
|
|
if (number.IndexOf ('.') < 0 && number.IndexOf ('E') < 0) |
|
|
|
if (number.IndexOf('.') < 0 && number.IndexOf('E') < 0) { |
|
|
|
number += ".0"; |
|
|
|
number += ".0"; |
|
|
|
|
|
|
|
} |
|
|
|
formatter.WriteToken(number); |
|
|
|
formatter.WriteToken(number); |
|
|
|
// needs space if identifier follows number; this avoids mistaking the following identifier as type suffix
|
|
|
|
// needs space if identifier follows number; this avoids mistaking the following identifier as type suffix
|
|
|
|
lastWritten = LastWritten.KeywordOrIdentifier; |
|
|
|
lastWritten = LastWritten.KeywordOrIdentifier; |
|
|
|
@ -1060,8 +1098,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
|
|
|
|
|
|
|
|
static string ConvertCharLiteral(char ch) |
|
|
|
static string ConvertCharLiteral(char ch) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ch == '\'') |
|
|
|
if (ch == '\'') { |
|
|
|
return "\\'"; |
|
|
|
return "\\'"; |
|
|
|
|
|
|
|
} |
|
|
|
return ConvertChar(ch); |
|
|
|
return ConvertChar(ch); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1108,11 +1147,12 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
StringBuilder sb = new StringBuilder (); |
|
|
|
StringBuilder sb = new StringBuilder (); |
|
|
|
foreach (char ch in str) { |
|
|
|
foreach (char ch in str) { |
|
|
|
if (ch == '"') |
|
|
|
if (ch == '"') { |
|
|
|
sb.Append("\\\""); |
|
|
|
sb.Append("\\\""); |
|
|
|
else |
|
|
|
} else { |
|
|
|
sb.Append(ConvertChar(ch)); |
|
|
|
sb.Append(ConvertChar(ch)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return sb.ToString(); |
|
|
|
return sb.ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1180,8 +1220,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
WriteToken(opSymbol); |
|
|
|
WriteToken(opSymbol); |
|
|
|
} |
|
|
|
} |
|
|
|
unaryOperatorExpression.Expression.AcceptVisitor(this); |
|
|
|
unaryOperatorExpression.Expression.AcceptVisitor(this); |
|
|
|
if (opType == UnaryOperatorType.PostIncrement || opType == UnaryOperatorType.PostDecrement) |
|
|
|
if (opType == UnaryOperatorType.PostIncrement || opType == UnaryOperatorType.PostDecrement) { |
|
|
|
WriteToken(opSymbol); |
|
|
|
WriteToken(opSymbol); |
|
|
|
|
|
|
|
} |
|
|
|
EndNode(unaryOperatorExpression); |
|
|
|
EndNode(unaryOperatorExpression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1213,13 +1254,15 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
if (first) { |
|
|
|
if (first) { |
|
|
|
first = false; |
|
|
|
first = false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (!(clause is QueryContinuationClause)) |
|
|
|
if (!(clause is QueryContinuationClause)) { |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
clause.AcceptVisitor(this); |
|
|
|
clause.AcceptVisitor(this); |
|
|
|
} |
|
|
|
} |
|
|
|
if (indent) |
|
|
|
if (indent) { |
|
|
|
formatter.Unindent(); |
|
|
|
formatter.Unindent(); |
|
|
|
|
|
|
|
} |
|
|
|
EndNode(queryExpression); |
|
|
|
EndNode(queryExpression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1230,7 +1273,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteKeyword(QueryContinuationClause.IntoKeywordRole); |
|
|
|
WriteKeyword(QueryContinuationClause.IntoKeywordRole); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteIdentifier (queryContinuationClause.Identifier); |
|
|
|
queryContinuationClause.IdentifierToken.AcceptVisitor(this); |
|
|
|
EndNode(queryContinuationClause); |
|
|
|
EndNode(queryContinuationClause); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1240,7 +1283,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
WriteKeyword(QueryFromClause.FromKeywordRole); |
|
|
|
WriteKeyword(QueryFromClause.FromKeywordRole); |
|
|
|
queryFromClause.Type.AcceptVisitor(this); |
|
|
|
queryFromClause.Type.AcceptVisitor(this); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteIdentifier (queryFromClause.Identifier); |
|
|
|
queryFromClause.IdentifierToken.AcceptVisitor(this); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteKeyword(QueryFromClause.InKeywordRole); |
|
|
|
WriteKeyword(QueryFromClause.InKeywordRole); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
@ -1253,7 +1296,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
StartNode(queryLetClause); |
|
|
|
StartNode(queryLetClause); |
|
|
|
WriteKeyword(QueryLetClause.LetKeywordRole); |
|
|
|
WriteKeyword(QueryLetClause.LetKeywordRole); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteIdentifier (queryLetClause.Identifier); |
|
|
|
queryLetClause.IdentifierToken.AcceptVisitor(this); |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
@ -1370,10 +1413,11 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
} |
|
|
|
} |
|
|
|
WriteCommaSeparatedList(attributeSection.Attributes); |
|
|
|
WriteCommaSeparatedList(attributeSection.Attributes); |
|
|
|
WriteToken(Roles.RBracket); |
|
|
|
WriteToken(Roles.RBracket); |
|
|
|
if (attributeSection.Parent is ParameterDeclaration || attributeSection.Parent is TypeParameterDeclaration) |
|
|
|
if (attributeSection.Parent is ParameterDeclaration || attributeSection.Parent is TypeParameterDeclaration) { |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
else |
|
|
|
} else { |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
|
|
|
|
} |
|
|
|
EndNode(attributeSection); |
|
|
|
EndNode(attributeSection); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1385,7 +1429,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
WriteKeyword(Roles.DelegateKeyword); |
|
|
|
WriteKeyword(Roles.DelegateKeyword); |
|
|
|
delegateDeclaration.ReturnType.AcceptVisitor(this); |
|
|
|
delegateDeclaration.ReturnType.AcceptVisitor(this); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteIdentifier (delegateDeclaration.Name); |
|
|
|
delegateDeclaration.NameToken.AcceptVisitor(this); |
|
|
|
WriteTypeParameters(delegateDeclaration.TypeParameters); |
|
|
|
WriteTypeParameters(delegateDeclaration.TypeParameters); |
|
|
|
Space(policy.SpaceBeforeDelegateDeclarationParentheses); |
|
|
|
Space(policy.SpaceBeforeDelegateDeclarationParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(delegateDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(delegateDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
@ -1402,8 +1446,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
WriteKeyword(Roles.NamespaceKeyword); |
|
|
|
WriteKeyword(Roles.NamespaceKeyword); |
|
|
|
WriteQualifiedIdentifier(namespaceDeclaration.Identifiers); |
|
|
|
WriteQualifiedIdentifier(namespaceDeclaration.Identifiers); |
|
|
|
OpenBrace(policy.NamespaceBraceStyle); |
|
|
|
OpenBrace(policy.NamespaceBraceStyle); |
|
|
|
foreach (var member in namespaceDeclaration.Members) |
|
|
|
foreach (var member in namespaceDeclaration.Members) { |
|
|
|
member.AcceptVisitor(this); |
|
|
|
member.AcceptVisitor(this); |
|
|
|
|
|
|
|
} |
|
|
|
CloseBrace(policy.NamespaceBraceStyle); |
|
|
|
CloseBrace(policy.NamespaceBraceStyle); |
|
|
|
OptionalSemicolon(); |
|
|
|
OptionalSemicolon(); |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
@ -1434,7 +1479,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
braceStyle = policy.ClassBraceStyle; |
|
|
|
braceStyle = policy.ClassBraceStyle; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
WriteIdentifier(typeDeclaration.Name); |
|
|
|
typeDeclaration.NameToken.AcceptVisitor(this); |
|
|
|
WriteTypeParameters(typeDeclaration.TypeParameters); |
|
|
|
WriteTypeParameters(typeDeclaration.TypeParameters); |
|
|
|
if (typeDeclaration.BaseTypes.Any()) { |
|
|
|
if (typeDeclaration.BaseTypes.Any()) { |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
@ -1520,16 +1565,17 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
} else if (blockStatement.Parent is MethodDeclaration) { |
|
|
|
} else if (blockStatement.Parent is MethodDeclaration) { |
|
|
|
style = policy.MethodBraceStyle; |
|
|
|
style = policy.MethodBraceStyle; |
|
|
|
} else if (blockStatement.Parent is Accessor) { |
|
|
|
} else if (blockStatement.Parent is Accessor) { |
|
|
|
if (blockStatement.Parent.Role == PropertyDeclaration.GetterRole) |
|
|
|
if (blockStatement.Parent.Role == PropertyDeclaration.GetterRole) { |
|
|
|
style = policy.PropertyGetBraceStyle; |
|
|
|
style = policy.PropertyGetBraceStyle; |
|
|
|
else if (blockStatement.Parent.Role == PropertyDeclaration.SetterRole) |
|
|
|
} else if (blockStatement.Parent.Role == PropertyDeclaration.SetterRole) { |
|
|
|
style = policy.PropertySetBraceStyle; |
|
|
|
style = policy.PropertySetBraceStyle; |
|
|
|
else if (blockStatement.Parent.Role == CustomEventDeclaration.AddAccessorRole) |
|
|
|
} else if (blockStatement.Parent.Role == CustomEventDeclaration.AddAccessorRole) { |
|
|
|
style = policy.EventAddBraceStyle; |
|
|
|
style = policy.EventAddBraceStyle; |
|
|
|
else if (blockStatement.Parent.Role == CustomEventDeclaration.RemoveAccessorRole) |
|
|
|
} else if (blockStatement.Parent.Role == CustomEventDeclaration.RemoveAccessorRole) { |
|
|
|
style = policy.EventRemoveBraceStyle; |
|
|
|
style = policy.EventRemoveBraceStyle; |
|
|
|
else |
|
|
|
} else { |
|
|
|
style = policy.StatementBraceStyle; |
|
|
|
style = policy.StatementBraceStyle; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
style = policy.StatementBraceStyle; |
|
|
|
style = policy.StatementBraceStyle; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1622,7 +1668,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
Space(policy.SpacesWithinForeachParentheses); |
|
|
|
Space(policy.SpacesWithinForeachParentheses); |
|
|
|
foreachStatement.VariableType.AcceptVisitor(this); |
|
|
|
foreachStatement.VariableType.AcceptVisitor(this); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteIdentifier (foreachStatement.VariableName); |
|
|
|
foreachStatement.VariableNameToken.AcceptVisitor(this); |
|
|
|
WriteKeyword(ForeachStatement.InKeywordRole); |
|
|
|
WriteKeyword(ForeachStatement.InKeywordRole); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
foreachStatement.InExpression.AcceptVisitor(this); |
|
|
|
foreachStatement.InExpression.AcceptVisitor(this); |
|
|
|
@ -1761,14 +1807,17 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
Space(policy.SpacesWithinSwitchParentheses); |
|
|
|
Space(policy.SpacesWithinSwitchParentheses); |
|
|
|
RPar(); |
|
|
|
RPar(); |
|
|
|
OpenBrace(policy.StatementBraceStyle); |
|
|
|
OpenBrace(policy.StatementBraceStyle); |
|
|
|
if (!policy.IndentSwitchBody) |
|
|
|
if (!policy.IndentSwitchBody) { |
|
|
|
formatter.Unindent(); |
|
|
|
formatter.Unindent(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var section in switchStatement.SwitchSections) |
|
|
|
foreach (var section in switchStatement.SwitchSections) { |
|
|
|
section.AcceptVisitor(this); |
|
|
|
section.AcceptVisitor(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!policy.IndentSwitchBody) |
|
|
|
if (!policy.IndentSwitchBody) { |
|
|
|
formatter.Indent(); |
|
|
|
formatter.Indent(); |
|
|
|
|
|
|
|
} |
|
|
|
CloseBrace(policy.StatementBraceStyle); |
|
|
|
CloseBrace(policy.StatementBraceStyle); |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
EndNode(switchStatement); |
|
|
|
EndNode(switchStatement); |
|
|
|
@ -1779,21 +1828,24 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
StartNode(switchSection); |
|
|
|
StartNode(switchSection); |
|
|
|
bool first = true; |
|
|
|
bool first = true; |
|
|
|
foreach (var label in switchSection.CaseLabels) { |
|
|
|
foreach (var label in switchSection.CaseLabels) { |
|
|
|
if (!first) |
|
|
|
if (!first) { |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
|
|
|
|
} |
|
|
|
label.AcceptVisitor(this); |
|
|
|
label.AcceptVisitor(this); |
|
|
|
first = false; |
|
|
|
first = false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (policy.IndentCaseBody) |
|
|
|
if (policy.IndentCaseBody) { |
|
|
|
formatter.Indent(); |
|
|
|
formatter.Indent(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var statement in switchSection.Statements) { |
|
|
|
foreach (var statement in switchSection.Statements) { |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
statement.AcceptVisitor(this); |
|
|
|
statement.AcceptVisitor(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (policy.IndentCaseBody) |
|
|
|
if (policy.IndentCaseBody) { |
|
|
|
formatter.Unindent(); |
|
|
|
formatter.Unindent(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EndNode(switchSection); |
|
|
|
EndNode(switchSection); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1829,8 +1881,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
StartNode(tryCatchStatement); |
|
|
|
StartNode(tryCatchStatement); |
|
|
|
WriteKeyword(TryCatchStatement.TryKeywordRole); |
|
|
|
WriteKeyword(TryCatchStatement.TryKeywordRole); |
|
|
|
tryCatchStatement.TryBlock.AcceptVisitor(this); |
|
|
|
tryCatchStatement.TryBlock.AcceptVisitor(this); |
|
|
|
foreach (var catchClause in tryCatchStatement.CatchClauses) |
|
|
|
foreach (var catchClause in tryCatchStatement.CatchClauses) { |
|
|
|
catchClause.AcceptVisitor(this); |
|
|
|
catchClause.AcceptVisitor(this); |
|
|
|
|
|
|
|
} |
|
|
|
if (!tryCatchStatement.FinallyBlock.IsNull) { |
|
|
|
if (!tryCatchStatement.FinallyBlock.IsNull) { |
|
|
|
WriteKeyword(TryCatchStatement.FinallyKeywordRole); |
|
|
|
WriteKeyword(TryCatchStatement.FinallyKeywordRole); |
|
|
|
tryCatchStatement.FinallyBlock.AcceptVisitor(this); |
|
|
|
tryCatchStatement.FinallyBlock.AcceptVisitor(this); |
|
|
|
@ -1849,7 +1902,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
catchClause.Type.AcceptVisitor(this); |
|
|
|
catchClause.Type.AcceptVisitor(this); |
|
|
|
if (!string.IsNullOrEmpty(catchClause.VariableName)) { |
|
|
|
if (!string.IsNullOrEmpty(catchClause.VariableName)) { |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WriteIdentifier (catchClause.VariableName); |
|
|
|
catchClause.VariableNameToken.AcceptVisitor(this); |
|
|
|
} |
|
|
|
} |
|
|
|
Space(policy.SpacesWithinCatchParentheses); |
|
|
|
Space(policy.SpacesWithinCatchParentheses); |
|
|
|
RPar(); |
|
|
|
RPar(); |
|
|
|
@ -1964,7 +2017,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
WriteAttributes(constructorDeclaration.Attributes); |
|
|
|
WriteAttributes(constructorDeclaration.Attributes); |
|
|
|
WriteModifiers(constructorDeclaration.ModifierTokens); |
|
|
|
WriteModifiers(constructorDeclaration.ModifierTokens); |
|
|
|
TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration; |
|
|
|
TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration; |
|
|
|
|
|
|
|
StartNode(constructorDeclaration.NameToken); |
|
|
|
WriteIdentifier(type != null ? type.Name : constructorDeclaration.Name); |
|
|
|
WriteIdentifier(type != null ? type.Name : constructorDeclaration.Name); |
|
|
|
|
|
|
|
EndNode(constructorDeclaration.NameToken); |
|
|
|
Space(policy.SpaceBeforeConstructorDeclarationParentheses); |
|
|
|
Space(policy.SpaceBeforeConstructorDeclarationParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
if (!constructorDeclaration.Initializer.IsNull) { |
|
|
|
if (!constructorDeclaration.Initializer.IsNull) { |
|
|
|
@ -1997,7 +2052,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
WriteModifiers(destructorDeclaration.ModifierTokens); |
|
|
|
WriteModifiers(destructorDeclaration.ModifierTokens); |
|
|
|
WriteToken(DestructorDeclaration.TildeRole); |
|
|
|
WriteToken(DestructorDeclaration.TildeRole); |
|
|
|
TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration; |
|
|
|
TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration; |
|
|
|
|
|
|
|
StartNode(destructorDeclaration.NameToken); |
|
|
|
WriteIdentifier(type != null ? type.Name : destructorDeclaration.Name); |
|
|
|
WriteIdentifier(type != null ? type.Name : destructorDeclaration.Name); |
|
|
|
|
|
|
|
EndNode(destructorDeclaration.NameToken); |
|
|
|
Space(policy.SpaceBeforeConstructorDeclarationParentheses); |
|
|
|
Space(policy.SpaceBeforeConstructorDeclarationParentheses); |
|
|
|
LPar(); |
|
|
|
LPar(); |
|
|
|
RPar(); |
|
|
|
RPar(); |
|
|
|
@ -2010,7 +2067,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
StartNode(enumMemberDeclaration); |
|
|
|
StartNode(enumMemberDeclaration); |
|
|
|
WriteAttributes(enumMemberDeclaration.Attributes); |
|
|
|
WriteAttributes(enumMemberDeclaration.Attributes); |
|
|
|
WriteModifiers(enumMemberDeclaration.ModifierTokens); |
|
|
|
WriteModifiers(enumMemberDeclaration.ModifierTokens); |
|
|
|
WriteIdentifier (enumMemberDeclaration.Name); |
|
|
|
enumMemberDeclaration.NameToken.AcceptVisitor(this); |
|
|
|
if (!enumMemberDeclaration.Initializer.IsNull) { |
|
|
|
if (!enumMemberDeclaration.Initializer.IsNull) { |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
@ -2042,7 +2099,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
customEventDeclaration.ReturnType.AcceptVisitor(this); |
|
|
|
customEventDeclaration.ReturnType.AcceptVisitor(this); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WritePrivateImplementationType(customEventDeclaration.PrivateImplementationType); |
|
|
|
WritePrivateImplementationType(customEventDeclaration.PrivateImplementationType); |
|
|
|
WriteIdentifier (customEventDeclaration.Name); |
|
|
|
customEventDeclaration.NameToken.AcceptVisitor(this); |
|
|
|
OpenBrace(policy.EventBraceStyle); |
|
|
|
OpenBrace(policy.EventBraceStyle); |
|
|
|
// output add/remove in their original order
|
|
|
|
// output add/remove in their original order
|
|
|
|
foreach (AstNode node in customEventDeclaration.Children) { |
|
|
|
foreach (AstNode node in customEventDeclaration.Children) { |
|
|
|
@ -2084,7 +2141,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
public void VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer) |
|
|
|
public void VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
StartNode(fixedVariableInitializer); |
|
|
|
StartNode(fixedVariableInitializer); |
|
|
|
WriteIdentifier (fixedVariableInitializer.Name); |
|
|
|
fixedVariableInitializer.NameToken.AcceptVisitor(this); |
|
|
|
if (!fixedVariableInitializer.CountExpression.IsNull) { |
|
|
|
if (!fixedVariableInitializer.CountExpression.IsNull) { |
|
|
|
WriteToken(Roles.LBracket); |
|
|
|
WriteToken(Roles.LBracket); |
|
|
|
Space(policy.SpacesWithinBrackets); |
|
|
|
Space(policy.SpacesWithinBrackets); |
|
|
|
@ -2125,7 +2182,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
methodDeclaration.ReturnType.AcceptVisitor(this); |
|
|
|
methodDeclaration.ReturnType.AcceptVisitor(this); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WritePrivateImplementationType(methodDeclaration.PrivateImplementationType); |
|
|
|
WritePrivateImplementationType(methodDeclaration.PrivateImplementationType); |
|
|
|
WriteIdentifier (methodDeclaration.Name); |
|
|
|
methodDeclaration.NameToken.AcceptVisitor(this); |
|
|
|
WriteTypeParameters(methodDeclaration.TypeParameters); |
|
|
|
WriteTypeParameters(methodDeclaration.TypeParameters); |
|
|
|
Space(policy.SpaceBeforeMethodDeclarationParentheses); |
|
|
|
Space(policy.SpaceBeforeMethodDeclarationParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(methodDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(methodDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
@ -2181,10 +2238,12 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
parameterDeclaration.Type.AcceptVisitor(this); |
|
|
|
parameterDeclaration.Type.AcceptVisitor(this); |
|
|
|
if (!parameterDeclaration.Type.IsNull && !string.IsNullOrEmpty (parameterDeclaration.Name)) |
|
|
|
if (!parameterDeclaration.Type.IsNull && !string.IsNullOrEmpty(parameterDeclaration.Name)) { |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
if (!string.IsNullOrEmpty (parameterDeclaration.Name)) |
|
|
|
} |
|
|
|
WriteIdentifier (parameterDeclaration.Name); |
|
|
|
if (!string.IsNullOrEmpty(parameterDeclaration.Name)) { |
|
|
|
|
|
|
|
parameterDeclaration.NameToken.AcceptVisitor(this); |
|
|
|
|
|
|
|
} |
|
|
|
if (!parameterDeclaration.DefaultExpression.IsNull) { |
|
|
|
if (!parameterDeclaration.DefaultExpression.IsNull) { |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
@ -2202,7 +2261,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
propertyDeclaration.ReturnType.AcceptVisitor(this); |
|
|
|
propertyDeclaration.ReturnType.AcceptVisitor(this); |
|
|
|
Space(); |
|
|
|
Space(); |
|
|
|
WritePrivateImplementationType(propertyDeclaration.PrivateImplementationType); |
|
|
|
WritePrivateImplementationType(propertyDeclaration.PrivateImplementationType); |
|
|
|
WriteIdentifier (propertyDeclaration.Name); |
|
|
|
propertyDeclaration.NameToken.AcceptVisitor(this); |
|
|
|
OpenBrace(policy.PropertyBraceStyle); |
|
|
|
OpenBrace(policy.PropertyBraceStyle); |
|
|
|
// output get/set in their original order
|
|
|
|
// output get/set in their original order
|
|
|
|
foreach (AstNode node in propertyDeclaration.Children) { |
|
|
|
foreach (AstNode node in propertyDeclaration.Children) { |
|
|
|
@ -2221,7 +2280,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
public void VisitVariableInitializer(VariableInitializer variableInitializer) |
|
|
|
public void VisitVariableInitializer(VariableInitializer variableInitializer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
StartNode(variableInitializer); |
|
|
|
StartNode(variableInitializer); |
|
|
|
WriteIdentifier (variableInitializer.Name); |
|
|
|
variableInitializer.NameToken.AcceptVisitor(this); |
|
|
|
if (!variableInitializer.Initializer.IsNull) { |
|
|
|
if (!variableInitializer.Initializer.IsNull) { |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
Space(policy.SpaceAroundAssignment); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
WriteToken(Roles.Assign); |
|
|
|
@ -2234,9 +2293,10 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
public void VisitCompilationUnit(CompilationUnit compilationUnit) |
|
|
|
public void VisitCompilationUnit(CompilationUnit compilationUnit) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// don't do node tracking as we visit all children directly
|
|
|
|
// don't do node tracking as we visit all children directly
|
|
|
|
foreach (AstNode node in compilationUnit.Children) |
|
|
|
foreach (AstNode node in compilationUnit.Children) { |
|
|
|
node.AcceptVisitor(this); |
|
|
|
node.AcceptVisitor(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void VisitSimpleType(SimpleType simpleType) |
|
|
|
public void VisitSimpleType(SimpleType simpleType) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -2250,10 +2310,11 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
StartNode(memberType); |
|
|
|
StartNode(memberType); |
|
|
|
memberType.Target.AcceptVisitor(this); |
|
|
|
memberType.Target.AcceptVisitor(this); |
|
|
|
if (memberType.IsDoubleColon) |
|
|
|
if (memberType.IsDoubleColon) { |
|
|
|
WriteToken(Roles.DoubleColon); |
|
|
|
WriteToken(Roles.DoubleColon); |
|
|
|
else |
|
|
|
} else { |
|
|
|
WriteToken(Roles.Dot); |
|
|
|
WriteToken(Roles.Dot); |
|
|
|
|
|
|
|
} |
|
|
|
WriteIdentifier(memberType.MemberName); |
|
|
|
WriteIdentifier(memberType.MemberName); |
|
|
|
WriteTypeArguments(memberType.TypeArguments); |
|
|
|
WriteTypeArguments(memberType.TypeArguments); |
|
|
|
EndNode(memberType); |
|
|
|
EndNode(memberType); |
|
|
|
@ -2263,12 +2324,15 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
StartNode(composedType); |
|
|
|
StartNode(composedType); |
|
|
|
composedType.BaseType.AcceptVisitor(this); |
|
|
|
composedType.BaseType.AcceptVisitor(this); |
|
|
|
if (composedType.HasNullableSpecifier) |
|
|
|
if (composedType.HasNullableSpecifier) { |
|
|
|
WriteToken(ComposedType.NullableRole); |
|
|
|
WriteToken(ComposedType.NullableRole); |
|
|
|
for (int i = 0; i < composedType.PointerRank; i++) |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < composedType.PointerRank; i++) { |
|
|
|
WriteToken(ComposedType.PointerRole); |
|
|
|
WriteToken(ComposedType.PointerRole); |
|
|
|
foreach (var node in composedType.ArraySpecifiers) |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var node in composedType.ArraySpecifiers) { |
|
|
|
node.AcceptVisitor(this); |
|
|
|
node.AcceptVisitor(this); |
|
|
|
|
|
|
|
} |
|
|
|
EndNode(composedType); |
|
|
|
EndNode(composedType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -2334,7 +2398,7 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw new NotSupportedException ("Invalid value for VarianceModifier"); |
|
|
|
throw new NotSupportedException ("Invalid value for VarianceModifier"); |
|
|
|
} |
|
|
|
} |
|
|
|
WriteIdentifier (typeParameterDeclaration.Name); |
|
|
|
typeParameterDeclaration.NameToken.AcceptVisitor(this); |
|
|
|
EndNode(typeParameterDeclaration); |
|
|
|
EndNode(typeParameterDeclaration); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -2413,8 +2477,9 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
formatter.Indent(); |
|
|
|
formatter.Indent(); |
|
|
|
foreach (INode alternative in choice) { |
|
|
|
foreach (INode alternative in choice) { |
|
|
|
VisitNodeInPattern(alternative); |
|
|
|
VisitNodeInPattern(alternative); |
|
|
|
if (alternative != choice.Last ()) |
|
|
|
if (alternative != choice.Last()) { |
|
|
|
WriteToken(Roles.Comma); |
|
|
|
WriteToken(Roles.Comma); |
|
|
|
|
|
|
|
} |
|
|
|
NewLine(); |
|
|
|
NewLine(); |
|
|
|
} |
|
|
|
} |
|
|
|
formatter.Unindent(); |
|
|
|
formatter.Unindent(); |
|
|
|
@ -2482,9 +2547,10 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
StartNode(documentationReference); |
|
|
|
StartNode(documentationReference); |
|
|
|
if (!documentationReference.DeclaringType.IsNull) { |
|
|
|
if (!documentationReference.DeclaringType.IsNull) { |
|
|
|
documentationReference.DeclaringType.AcceptVisitor(this); |
|
|
|
documentationReference.DeclaringType.AcceptVisitor(this); |
|
|
|
if (documentationReference.EntityType != EntityType.TypeDefinition) |
|
|
|
if (documentationReference.EntityType != EntityType.TypeDefinition) { |
|
|
|
WriteToken(Roles.Dot); |
|
|
|
WriteToken(Roles.Dot); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
switch (documentationReference.EntityType) { |
|
|
|
switch (documentationReference.EntityType) { |
|
|
|
case EntityType.TypeDefinition: |
|
|
|
case EntityType.TypeDefinition: |
|
|
|
// we already printed the DeclaringType
|
|
|
|
// we already printed the DeclaringType
|
|
|
|
@ -2514,11 +2580,12 @@ namespace ICSharpCode.NRefactory.CSharp |
|
|
|
WriteTypeArguments(documentationReference.TypeArguments); |
|
|
|
WriteTypeArguments(documentationReference.TypeArguments); |
|
|
|
if (documentationReference.HasParameterList) { |
|
|
|
if (documentationReference.HasParameterList) { |
|
|
|
Space(policy.SpaceBeforeMethodDeclarationParentheses); |
|
|
|
Space(policy.SpaceBeforeMethodDeclarationParentheses); |
|
|
|
if (documentationReference.EntityType == EntityType.Indexer) |
|
|
|
if (documentationReference.EntityType == EntityType.Indexer) { |
|
|
|
WriteCommaSeparatedListInBrackets(documentationReference.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
WriteCommaSeparatedListInBrackets(documentationReference.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
else |
|
|
|
} else { |
|
|
|
WriteCommaSeparatedListInParenthesis(documentationReference.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
WriteCommaSeparatedListInParenthesis(documentationReference.Parameters, policy.SpaceWithinMethodDeclarationParentheses); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
EndNode(documentationReference); |
|
|
|
EndNode(documentationReference); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|