Browse Source

Added AST formatting visitor.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
2bee26ad27
  1. 34
      ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs
  2. 1583
      ICSharpCode.NRefactory/CSharp/Formatter/AstFormattingVisitor.cs
  3. 805
      ICSharpCode.NRefactory/CSharp/Formatter/CSharpFormattingPolicy.cs
  4. 64
      ICSharpCode.NRefactory/CSharp/Formatter/Change.cs
  5. 51
      ICSharpCode.NRefactory/CSharp/Formatter/ITextEditorAdapter.cs
  6. 34
      ICSharpCode.NRefactory/CSharp/Formatter/Indent.cs
  7. 190
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  8. 3
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

34
ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs

@ -616,12 +616,42 @@ namespace ICSharpCode.NRefactory.CSharp @@ -616,12 +616,42 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal abstract bool DoMatch(AstNode other, Match match);
internal virtual bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
internal virtual bool DoMatchCollection (Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
return DoMatch(pos, match);
return DoMatch (pos, match);
}
#endregion
public AstNode GetNextNode ()
{
if (NextSibling != null)
return NextSibling;
if (Parent != null)
return Parent.GetNextNode ();
return null;
}
public AstNode GetPrevNode ()
{
if (PrevSibling != null)
return PrevSibling;
if (Parent != null)
return Parent.GetPrevNode ();
return null;
}
// filters all non c# nodes (comments, white spaces or pre processor directives)
public AstNode GetCSharpNodeBefore (AstNode node)
{
var n = node.PrevSibling;
while (n != null) {
if (n.Role != Roles.Comment)
return n;
n = n.GetPrevNode ();
}
return null;
}
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class
static readonly Role<AstNode> RootRole = new Role<AstNode>("Root");

1583
ICSharpCode.NRefactory/CSharp/Formatter/AstFormattingVisitor.cs

File diff suppressed because it is too large Load Diff

805
ICSharpCode.NRefactory/CSharp/Formatter/CSharpFormattingPolicy.cs

File diff suppressed because it is too large Load Diff

64
ICSharpCode.NRefactory/CSharp/Formatter/Change.cs

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
//
// Change.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 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 DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory
{
public class Change
{
public int Offset {
get;
set;
}
int removedChars;
public int RemovedChars {
get {
return removedChars;
}
set {
if (value < 0)
throw new ArgumentOutOfRangeException ("RemovedChars", "needs to be >= 0");
removedChars = value;
}
}
public string InsertedText {
get;
set;
}
public Change (int offset, int removedChars, string insertedText)
{
this.removedChars = removedChars;
this.Offset = offset;
this.InsertedText = insertedText;
}
}
}

51
ICSharpCode.NRefactory/CSharp/Formatter/ITextEditorAdapter.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
//
// ITextEditorAdapter.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 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 DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory
{
public interface ITextEditorAdapter
{
bool TabsToSpaces { get; }
int TabSize { get; }
string EolMarker { get; }
int Length { get; }
int LocationToOffset (int line, int col);
char GetCharAt (int offset);
string GetTextAt (int offset, int length);
int LineCount { get; }
int GetEditableLength (int lineNumber);
string GetIndentation (int lineNumber);
int GetLineOffset (int lineNumber);
int GetLineLength (int lineNumber);
int GetLineEndOffset (int lineNumber);
}
}

34
ICSharpCode.NRefactory/CSharp/Formatter/Indent.cs

@ -33,44 +33,54 @@ namespace ICSharpCode.NRefactory.CSharp @@ -33,44 +33,54 @@ namespace ICSharpCode.NRefactory.CSharp
get;
set;
}
public int ExtraSpaces {
get;
set;
}
public bool TabsToSpaces {
get;
set;
}
public int TabSize {
get;
set;
}
public Indent ()
{
}
public Indent (int level, int extraSpaces)
{
this.Level = level;
this.ExtraSpaces = extraSpaces;
}
public static Indent operator+(Indent left, Indent right)
public static Indent operator+ (Indent left, Indent right)
{
return new Indent (left.Level + right.Level, left.ExtraSpaces + right.ExtraSpaces);
}
public static Indent operator-(Indent left, Indent right)
public static Indent operator- (Indent left, Indent right)
{
return new Indent (left.Level - right.Level, left.ExtraSpaces - right.ExtraSpaces);
}
public string IndentString {
get {
return new string ('\t', Level) + new string (' ', ExtraSpaces);
return (TabsToSpaces ? new string (' ', Level * TabSize) : new string ('\t', Level)) + new string (' ', ExtraSpaces);
}
}
public string SingleIndent {
get {
return "\t";
return TabsToSpaces ? new string (' ', TabSize) : "\t";
}
}
public override string ToString ()
{
return string.Format ("[Indent: Level={0}, ExtraSpaces={1}]", Level, ExtraSpaces);

190
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -152,10 +152,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -152,10 +152,10 @@ namespace ICSharpCode.NRefactory.CSharp
void Comma(AstNode nextNode, bool noSpaceAfterComma = false)
{
WriteSpecialsUpToRole(AstNode.Roles.Comma, nextNode);
Space(policy.SpacesBeforeComma);
Space(policy.SpaceBeforeBracketComma); // TODO: Comma policy has changed.
formatter.WriteToken(",");
lastWritten = LastWritten.Other;
Space(!noSpaceAfterComma && policy.SpacesAfterComma);
Space(!noSpaceAfterComma && policy.SpaceAfterBracketComma); // TODO: Comma policy has changed.
}
void WriteCommaSeparatedList(IEnumerable<AstNode> list)
@ -461,8 +461,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -461,8 +461,8 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(anonymousMethodExpression);
WriteKeyword("delegate");
if (anonymousMethodExpression.HasParameterList) {
Space(policy.BeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(anonymousMethodExpression.Parameters, policy.WithinMethodDeclarationParentheses);
Space(policy.SpaceBeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(anonymousMethodExpression.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
}
anonymousMethodExpression.Body.AcceptVisitor(this, data);
return EndNode(anonymousMethodExpression);
@ -473,8 +473,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -473,8 +473,8 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(argListExpression);
WriteKeyword("__arglist");
if (!argListExpression.IsAccess) {
Space(policy.BeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(argListExpression.Arguments, policy.WithinMethodCallParentheses);
Space(policy.SpaceBeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(argListExpression.Arguments, policy.SpaceWithinMethodCallParentheses);
}
return EndNode(argListExpression);
}
@ -530,9 +530,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -530,9 +530,9 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(assignmentExpression);
assignmentExpression.Left.AcceptVisitor(this, data);
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
WriteToken(AssignmentExpression.GetOperatorSymbol(assignmentExpression.Operator), AssignmentExpression.OperatorRole);
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
assignmentExpression.Right.AcceptVisitor(this, data);
return EndNode(assignmentExpression);
}
@ -553,34 +553,34 @@ namespace ICSharpCode.NRefactory.CSharp @@ -553,34 +553,34 @@ namespace ICSharpCode.NRefactory.CSharp
case BinaryOperatorType.BitwiseAnd:
case BinaryOperatorType.BitwiseOr:
case BinaryOperatorType.ExclusiveOr:
spacePolicy = policy.AroundBitwiseOperatorParentheses;
spacePolicy = policy.SpaceAroundBitwiseOperator;
break;
case BinaryOperatorType.ConditionalAnd:
case BinaryOperatorType.ConditionalOr:
spacePolicy = policy.AroundLogicalOperatorParentheses;
spacePolicy = policy.SpaceAroundLogicalOperator;
break;
case BinaryOperatorType.GreaterThan:
case BinaryOperatorType.GreaterThanOrEqual:
case BinaryOperatorType.LessThanOrEqual:
case BinaryOperatorType.LessThan:
spacePolicy = policy.AroundRelationalOperatorParentheses;
spacePolicy = policy.SpaceAroundRelationalOperator;
break;
case BinaryOperatorType.Equality:
case BinaryOperatorType.InEquality:
spacePolicy = policy.AroundEqualityOperatorParentheses;
spacePolicy = policy.SpaceAroundEqualityOperator;
break;
case BinaryOperatorType.Add:
case BinaryOperatorType.Subtract:
spacePolicy = policy.AroundAdditiveOperatorParentheses;
spacePolicy = policy.SpaceAroundAdditiveOperator;
break;
case BinaryOperatorType.Multiply:
case BinaryOperatorType.Divide:
case BinaryOperatorType.Modulus:
spacePolicy = policy.AroundMultiplicativeOperatorParentheses;
spacePolicy = policy.SpaceAroundMultiplicativeOperator;
break;
case BinaryOperatorType.ShiftLeft:
case BinaryOperatorType.ShiftRight:
spacePolicy = policy.AroundShiftOperatorParentheses;
spacePolicy = policy.SpaceAroundShiftOperator;
break;
case BinaryOperatorType.NullCoalescing:
spacePolicy = true;
@ -599,11 +599,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -599,11 +599,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(castExpression);
LPar();
Space(policy.WithinCastParentheses);
Space(policy.SpacesWithinCastParentheses);
castExpression.Type.AcceptVisitor(this, data);
Space(policy.WithinCastParentheses);
Space(policy.SpacesWithinCastParentheses);
RPar();
Space(policy.SpacesAfterTypecast);
Space(policy.SpaceAfterTypecast);
castExpression.Expression.AcceptVisitor(this, data);
return EndNode(castExpression);
}
@ -613,9 +613,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -613,9 +613,9 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(checkedExpression);
WriteKeyword("checked");
LPar();
Space(policy.WithinCheckedExpressionParantheses);
Space(policy.SpacesWithinCheckedExpressionParantheses);
checkedExpression.Expression.AcceptVisitor(this, data);
Space(policy.WithinCheckedExpressionParantheses);
Space(policy.SpacesWithinCheckedExpressionParantheses);
RPar();
return EndNode(checkedExpression);
}
@ -625,15 +625,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -625,15 +625,15 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(conditionalExpression);
conditionalExpression.Condition.AcceptVisitor(this, data);
Space(policy.ConditionalOperatorBeforeConditionSpace);
Space(policy.SpaceBeforeConditionalOperatorCondition);
WriteToken("?", ConditionalExpression.QuestionMarkRole);
Space(policy.ConditionalOperatorAfterConditionSpace);
Space(policy.SpaceAfterConditionalOperatorCondition);
conditionalExpression.TrueExpression.AcceptVisitor(this, data);
Space(policy.ConditionalOperatorBeforeSeparatorSpace);
Space(policy.SpaceBeforeConditionalOperatorSeparator);
WriteToken(":", ConditionalExpression.ColonRole);
Space(policy.ConditionalOperatorAfterSeparatorSpace);
Space(policy.SpaceAfterConditionalOperatorSeparator);
conditionalExpression.FalseExpression.AcceptVisitor(this, data);
@ -646,9 +646,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -646,9 +646,9 @@ namespace ICSharpCode.NRefactory.CSharp
WriteKeyword("default");
LPar();
Space(policy.WithinTypeOfParentheses);
Space(policy.SpacesWithinTypeOfParentheses);
defaultValueExpression.Type.AcceptVisitor(this, data);
Space(policy.WithinTypeOfParentheses);
Space(policy.SpacesWithinTypeOfParentheses);
RPar();
return EndNode(defaultValueExpression);
@ -686,7 +686,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -686,7 +686,7 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(indexerExpression);
indexerExpression.Target.AcceptVisitor(this, data);
Space(policy.BeforeMethodCallParentheses);
Space(policy.SpaceBeforeMethodCallParentheses);
WriteCommaSeparatedListInBrackets(indexerExpression.Arguments);
return EndNode(indexerExpression);
}
@ -695,8 +695,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -695,8 +695,8 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(invocationExpression);
invocationExpression.Target.AcceptVisitor(this, data);
Space(policy.BeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(invocationExpression.Arguments, policy.WithinMethodCallParentheses);
Space(policy.SpaceBeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(invocationExpression.Arguments, policy.SpaceWithinMethodCallParentheses);
return EndNode(invocationExpression);
}
@ -714,7 +714,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -714,7 +714,7 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(lambdaExpression);
if (LambdaNeedsParenthesis(lambdaExpression)) {
WriteCommaSeparatedListInParenthesis(lambdaExpression.Parameters, policy.WithinMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(lambdaExpression.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
} else {
lambdaExpression.Parameters.Single().AcceptVisitor(this, data);
}
@ -765,8 +765,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -765,8 +765,8 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(objectCreateExpression);
WriteKeyword("new");
objectCreateExpression.Type.AcceptVisitor(this, data);
Space(policy.BeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(objectCreateExpression.Arguments, policy.WithinMethodCallParentheses);
Space(policy.SpaceBeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(objectCreateExpression.Arguments, policy.SpaceWithinMethodCallParentheses);
objectCreateExpression.Initializer.AcceptVisitor(this, data);
return EndNode(objectCreateExpression);
}
@ -775,9 +775,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -775,9 +775,9 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(parenthesizedExpression);
LPar();
Space(policy.WithinParentheses);
Space(policy.SpacesWithinParentheses);
parenthesizedExpression.Expression.AcceptVisitor(this, data);
Space(policy.WithinParentheses);
Space(policy.SpacesWithinParentheses);
RPar();
return EndNode(parenthesizedExpression);
}
@ -946,9 +946,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -946,9 +946,9 @@ namespace ICSharpCode.NRefactory.CSharp
WriteKeyword("sizeof");
LPar();
Space(policy.WithinSizeOfParentheses);
Space(policy.SpacesWithinSizeOfParentheses);
sizeOfExpression.Type.AcceptVisitor(this, data);
Space(policy.WithinSizeOfParentheses);
Space(policy.SpacesWithinSizeOfParentheses);
RPar();
return EndNode(sizeOfExpression);
@ -976,9 +976,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -976,9 +976,9 @@ namespace ICSharpCode.NRefactory.CSharp
WriteKeyword("typeof");
LPar();
Space(policy.WithinTypeOfParentheses);
Space(policy.SpacesWithinTypeOfParentheses);
typeOfExpression.Type.AcceptVisitor(this, data);
Space(policy.WithinTypeOfParentheses);
Space(policy.SpacesWithinTypeOfParentheses);
RPar();
return EndNode(typeOfExpression);
@ -1009,9 +1009,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1009,9 +1009,9 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(uncheckedExpression);
WriteKeyword("unchecked");
LPar();
Space(policy.WithinCheckedExpressionParantheses);
Space(policy.SpacesWithinCheckedExpressionParantheses);
uncheckedExpression.Expression.AcceptVisitor(this, data);
Space(policy.WithinCheckedExpressionParantheses);
Space(policy.SpacesWithinCheckedExpressionParantheses);
RPar();
return EndNode(uncheckedExpression);
}
@ -1062,9 +1062,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1062,9 +1062,9 @@ namespace ICSharpCode.NRefactory.CSharp
WriteKeyword("let");
Space();
WriteIdentifier(queryLetClause.Identifier);
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
WriteToken("=", QueryLetClause.Roles.Assign);
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
queryLetClause.Expression.AcceptVisitor(this, data);
return EndNode(queryLetClause);
}
@ -1159,9 +1159,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1159,9 +1159,9 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(attribute);
attribute.Type.AcceptVisitor(this, data);
Space(policy.BeforeMethodCallParentheses);
Space(policy.SpaceBeforeMethodCallParentheses);
if (attribute.Arguments.Count != 0 || !attribute.GetChildByRole(AstNode.Roles.LPar).IsNull)
WriteCommaSeparatedListInParenthesis(attribute.Arguments, policy.WithinMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(attribute.Arguments, policy.SpaceWithinMethodCallParentheses);
return EndNode(attribute);
}
@ -1193,8 +1193,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1193,8 +1193,8 @@ namespace ICSharpCode.NRefactory.CSharp
Space();
WriteIdentifier(delegateDeclaration.Name);
WriteTypeParameters(delegateDeclaration.TypeParameters);
Space(policy.BeforeDelegateDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(delegateDeclaration.Parameters, policy.WithinMethodDeclarationParentheses);
Space(policy.SpaceBeforeDelegateDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(delegateDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
foreach (Constraint constraint in delegateDeclaration.Constraints) {
constraint.AcceptVisitor(this, data);
}
@ -1278,9 +1278,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1278,9 +1278,9 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(usingAliasDeclaration);
WriteKeyword("using");
WriteIdentifier(usingAliasDeclaration.Alias, UsingAliasDeclaration.AliasRole);
Space(policy.AroundEqualityOperatorParentheses);
Space(policy.SpaceAroundEqualityOperator);
WriteToken("=", AstNode.Roles.Assign);
Space(policy.AroundEqualityOperatorParentheses);
Space(policy.SpaceAroundEqualityOperator);
usingAliasDeclaration.Import.AcceptVisitor(this, data);
Semicolon();
return EndNode(usingAliasDeclaration);
@ -1362,11 +1362,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1362,11 +1362,11 @@ namespace ICSharpCode.NRefactory.CSharp
WriteKeyword("do", DoWhileStatement.DoKeywordRole);
WriteEmbeddedStatement(doWhileStatement.EmbeddedStatement);
WriteKeyword("while", DoWhileStatement.WhileKeywordRole);
Space(policy.WhileParentheses);
Space(policy.SpaceBeforeWhileParentheses);
LPar();
Space(policy.WithinWhileParentheses);
Space(policy.SpacesWithinWhileParentheses);
doWhileStatement.Condition.AcceptVisitor(this, data);
Space(policy.WithinWhileParentheses);
Space(policy.SpacesWithinWhileParentheses);
RPar();
Semicolon();
return EndNode(doWhileStatement);
@ -1403,16 +1403,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1403,16 +1403,16 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(foreachStatement);
WriteKeyword("foreach");
Space(policy.ForeachParentheses);
Space(policy.SpaceBeforeForeachParentheses);
LPar();
Space(policy.WithinForEachParentheses);
Space(policy.SpacesWithinForeachParentheses);
foreachStatement.VariableType.AcceptVisitor(this, data);
Space();
WriteIdentifier(foreachStatement.VariableName);
WriteKeyword("in", ForeachStatement.Roles.InKeyword);
Space();
foreachStatement.InExpression.AcceptVisitor(this, data);
Space(policy.WithinForEachParentheses);
Space(policy.SpacesWithinForeachParentheses);
RPar();
WriteEmbeddedStatement(foreachStatement.EmbeddedStatement);
return EndNode(foreachStatement);
@ -1422,21 +1422,23 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1422,21 +1422,23 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(forStatement);
WriteKeyword("for");
Space(policy.ForParentheses);
Space(policy.SpaceBeforeForParentheses);
LPar();
Space(policy.WithinForParentheses);
Space(policy.SpacesWithinForParentheses);
WriteCommaSeparatedList(forStatement.Initializers.SafeCast<Statement, AstNode>());
Space (policy.SpaceBeforeForSemicolon);
WriteToken(";", AstNode.Roles.Semicolon);
Space(policy.SpacesAfterSemicolon);
Space (policy.SpaceAfterForSemicolon);
forStatement.Condition.AcceptVisitor(this, data);
Space (policy.SpaceBeforeForSemicolon);
WriteToken(";", AstNode.Roles.Semicolon);
Space(policy.SpacesAfterSemicolon);
Space(policy.SpaceAfterForSemicolon);
WriteCommaSeparatedList(forStatement.Iterators.SafeCast<Statement, AstNode>());
Space(policy.WithinForParentheses);
Space(policy.SpacesWithinForParentheses);
RPar();
WriteEmbeddedStatement(forStatement.EmbeddedStatement);
return EndNode(forStatement);
@ -1475,11 +1477,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1475,11 +1477,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(ifElseStatement);
WriteKeyword("if", IfElseStatement.IfKeywordRole);
Space(policy.IfParentheses);
Space(policy.SpaceBeforeIfParentheses);
LPar();
Space(policy.WithinIfParentheses);
Space(policy.SpacesWithinIfParentheses);
ifElseStatement.Condition.AcceptVisitor(this, data);
Space(policy.WithinIfParentheses);
Space(policy.SpacesWithinIfParentheses);
RPar();
WriteEmbeddedStatement(ifElseStatement.TrueStatement);
if (!ifElseStatement.FalseStatement.IsNull) {
@ -1502,11 +1504,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1502,11 +1504,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(lockStatement);
WriteKeyword("lock");
Space(policy.LockParentheses);
Space(policy.SpaceBeforeLockParentheses);
LPar();
Space(policy.WithinLockParentheses);
Space(policy.SpacesWithinLockParentheses);
lockStatement.Expression.AcceptVisitor(this, data);
Space(policy.WithinLockParentheses);
Space(policy.SpacesWithinLockParentheses);
RPar();
WriteEmbeddedStatement(lockStatement.EmbeddedStatement);
return EndNode(lockStatement);
@ -1528,11 +1530,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1528,11 +1530,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(switchStatement);
WriteKeyword("switch");
Space(policy.SwitchParentheses);
Space(policy.SpaceBeforeSwitchParentheses);
LPar();
Space(policy.WithinSwitchParentheses);
Space(policy.SpacesWithinSwitchParentheses);
switchStatement.Expression.AcceptVisitor(this, data);
Space(policy.WithinSwitchParentheses);
Space(policy.SpacesWithinSwitchParentheses);
RPar();
OpenBrace(policy.StatementBraceStyle);
foreach (var section in switchStatement.SwitchSections)
@ -1602,13 +1604,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1602,13 +1604,13 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(catchClause);
WriteKeyword("catch");
if (!catchClause.Type.IsNull) {
Space(policy.CatchParentheses);
Space(policy.SpaceBeforeCatchParentheses);
LPar();
Space(policy.WithinCatchParentheses);
Space(policy.SpacesWithinCatchParentheses);
catchClause.Type.AcceptVisitor(this, data);
Space();
WriteIdentifier(catchClause.VariableName);
Space(policy.WithinCatchParentheses);
Space(policy.SpacesWithinCatchParentheses);
RPar();
}
catchClause.Body.AcceptVisitor(this, data);
@ -1635,13 +1637,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1635,13 +1637,13 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(usingStatement);
WriteKeyword("using");
Space(policy.UsingParentheses);
Space(policy.SpaceBeforeUsingParentheses);
LPar();
Space(policy.WithinUsingParentheses);
Space(policy.SpacesWithinUsingParentheses);
usingStatement.ResourceAcquisition.AcceptVisitor(this, data);
Space(policy.WithinUsingParentheses);
Space(policy.SpacesWithinUsingParentheses);
RPar();
WriteEmbeddedStatement(usingStatement.EmbeddedStatement);
@ -1663,11 +1665,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1663,11 +1665,11 @@ namespace ICSharpCode.NRefactory.CSharp
{
StartNode(whileStatement);
WriteKeyword("while", WhileStatement.WhileKeywordRole);
Space(policy.WhileParentheses);
Space(policy.SpaceBeforeWhileParentheses);
LPar();
Space(policy.WithinWhileParentheses);
Space(policy.SpacesWithinWhileParentheses);
whileStatement.Condition.AcceptVisitor(this, data);
Space(policy.WithinWhileParentheses);
Space(policy.SpacesWithinWhileParentheses);
RPar();
WriteEmbeddedStatement(whileStatement.EmbeddedStatement);
return EndNode(whileStatement);
@ -1720,8 +1722,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1720,8 +1722,8 @@ namespace ICSharpCode.NRefactory.CSharp
WriteModifiers(constructorDeclaration.ModifierTokens);
TypeDeclaration type = constructorDeclaration.Parent as TypeDeclaration;
WriteIdentifier(type != null ? type.Name : constructorDeclaration.Name);
Space(policy.BeforeConstructorDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, policy.WithinMethodDeclarationParentheses);
Space(policy.SpaceBeforeConstructorDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(constructorDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
if (!constructorDeclaration.Initializer.IsNull) {
Space();
constructorDeclaration.Initializer.AcceptVisitor(this, data);
@ -1740,8 +1742,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1740,8 +1742,8 @@ namespace ICSharpCode.NRefactory.CSharp
} else {
WriteKeyword("base");
}
Space(policy.BeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(constructorInitializer.Arguments, policy.WithinMethodCallParentheses);
Space(policy.SpaceBeforeMethodCallParentheses);
WriteCommaSeparatedListInParenthesis(constructorInitializer.Arguments, policy.SpaceWithinMethodCallParentheses);
return EndNode(constructorInitializer);
}
@ -1753,7 +1755,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1753,7 +1755,7 @@ namespace ICSharpCode.NRefactory.CSharp
WriteToken("~", DestructorDeclaration.TildeRole);
TypeDeclaration type = destructorDeclaration.Parent as TypeDeclaration;
WriteIdentifier(type != null ? type.Name : destructorDeclaration.Name);
Space(policy.BeforeConstructorDeclarationParentheses);
Space(policy.SpaceBeforeConstructorDeclarationParentheses);
LPar();
RPar();
WriteMethodBody(destructorDeclaration.Body);
@ -1767,9 +1769,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1767,9 +1769,9 @@ namespace ICSharpCode.NRefactory.CSharp
WriteModifiers(enumMemberDeclaration.ModifierTokens);
WriteIdentifier(enumMemberDeclaration.Name);
if (!enumMemberDeclaration.Initializer.IsNull) {
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
WriteToken("=", EnumMemberDeclaration.Roles.Assign);
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
enumMemberDeclaration.Initializer.AcceptVisitor(this, data);
}
return EndNode(enumMemberDeclaration);
@ -1830,8 +1832,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1830,8 +1832,8 @@ namespace ICSharpCode.NRefactory.CSharp
indexerDeclaration.ReturnType.AcceptVisitor(this, data);
WritePrivateImplementationType(indexerDeclaration.PrivateImplementationType);
WriteKeyword("this");
Space(policy.BeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInBrackets(indexerDeclaration.Parameters, policy.WithinMethodDeclarationParentheses);
Space(policy.SpaceBeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInBrackets(indexerDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
OpenBrace(policy.PropertyBraceStyle);
// output get/set in their original order
foreach (AstNode node in indexerDeclaration.Children) {
@ -1854,8 +1856,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1854,8 +1856,8 @@ namespace ICSharpCode.NRefactory.CSharp
WritePrivateImplementationType(methodDeclaration.PrivateImplementationType);
WriteIdentifier(methodDeclaration.Name);
WriteTypeParameters(methodDeclaration.TypeParameters);
Space(policy.BeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(methodDeclaration.Parameters, policy.WithinMethodDeclarationParentheses);
Space(policy.SpaceBeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(methodDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
foreach (Constraint constraint in methodDeclaration.Constraints) {
constraint.AcceptVisitor(this, data);
}
@ -1884,8 +1886,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1884,8 +1886,8 @@ namespace ICSharpCode.NRefactory.CSharp
} else {
WriteToken(OperatorDeclaration.GetToken(operatorDeclaration.OperatorType), OperatorDeclaration.OperatorTypeRole);
}
Space(policy.BeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(operatorDeclaration.Parameters, policy.WithinMethodDeclarationParentheses);
Space(policy.SpaceBeforeMethodDeclarationParentheses);
WriteCommaSeparatedListInParenthesis(operatorDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
WriteMethodBody(operatorDeclaration.Body);
return EndNode(operatorDeclaration);
}
@ -1914,9 +1916,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1914,9 +1916,9 @@ namespace ICSharpCode.NRefactory.CSharp
if (!string.IsNullOrEmpty(parameterDeclaration.Name))
WriteIdentifier(parameterDeclaration.Name);
if (!parameterDeclaration.DefaultExpression.IsNull) {
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
WriteToken("=", ParameterDeclaration.Roles.Assign);
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
parameterDeclaration.DefaultExpression.AcceptVisitor(this, data);
}
return EndNode(parameterDeclaration);
@ -1950,9 +1952,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1950,9 +1952,9 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(variableInitializer);
WriteIdentifier(variableInitializer.Name);
if (!variableInitializer.Initializer.IsNull) {
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
WriteToken("=", VariableInitializer.Roles.Assign);
Space(policy.AroundAssignmentParentheses);
Space(policy.SpaceAroundAssignment);
variableInitializer.Initializer.AcceptVisitor(this, data);
}
return EndNode(variableInitializer);

3
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -344,6 +344,9 @@ @@ -344,6 +344,9 @@
<Compile Include="CSharp\Ast\Statements\DoWhileStatement.cs" />
<Compile Include="CSharp\Ast\Statements\YieldBreakStatement.cs" />
<Compile Include="CSharp\Ast\Expressions\EmptyExpression.cs" />
<Compile Include="CSharp\Formatter\AstFormattingVisitor.cs" />
<Compile Include="CSharp\Formatter\ITextEditorAdapter.cs" />
<Compile Include="CSharp\Formatter\Change.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="CSharp\" />

Loading…
Cancel
Save