Browse Source

* Src/PrettyPrinter/CSharp/OutputFormatter.cs:

* Src/PrettyPrinter/CSharp/PrettyPrintOptions.cs:
* Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs: Added some
  formatting options.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3854 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mike Krüger 17 years ago
parent
commit
175c1b9082
  1. 187
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  2. 7
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/OutputFormatter.cs
  3. 171
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/PrettyPrintOptions.cs

187
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -6,6 +6,7 @@
// </file> // </file>
using System; using System;
using System.Linq;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -243,6 +244,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{ {
outputFormatter.PrintIdentifier(attribute.Name); outputFormatter.PrintIdentifier(attribute.Name);
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
this.AppendCommaSeparatedList(attribute.PositionalArguments); this.AppendCommaSeparatedList(attribute.PositionalArguments);
if (attribute.NamedArguments != null && attribute.NamedArguments.Count > 0) { if (attribute.NamedArguments != null && attribute.NamedArguments.Count > 0) {
@ -256,6 +260,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
} }
} }
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -480,7 +487,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
bool withinParentheses = this.prettyPrintOptions.WithinMethodDeclarationParentheses && delegateDeclaration.Parameters.Any ();
if (withinParentheses) {
outputFormatter.Space();
}
AppendCommaSeparatedList(delegateDeclaration.Parameters); AppendCommaSeparatedList(delegateDeclaration.Parameters);
if (withinParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
foreach (TemplateDefinition templateDefinition in delegateDeclaration.Templates) { foreach (TemplateDefinition templateDefinition in delegateDeclaration.Templates) {
TrackVisit(templateDefinition, data); TrackVisit(templateDefinition, data);
@ -719,11 +733,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
bool withinParentheses = this.prettyPrintOptions.WithinMethodDeclarationParentheses && methodDeclaration.Parameters.Any ();
if (withinParentheses) {
outputFormatter.Space();
}
if (methodDeclaration.IsExtensionMethod) { if (methodDeclaration.IsExtensionMethod) {
outputFormatter.PrintToken(Tokens.This); outputFormatter.PrintToken(Tokens.This);
outputFormatter.Space(); outputFormatter.Space();
} }
AppendCommaSeparatedList(methodDeclaration.Parameters); AppendCommaSeparatedList(methodDeclaration.Parameters);
if (withinParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
foreach (TemplateDefinition templateDefinition in methodDeclaration.Templates) { foreach (TemplateDefinition templateDefinition in methodDeclaration.Templates) {
TrackVisit(templateDefinition, null); TrackVisit(templateDefinition, null);
@ -860,7 +881,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
bool withinParentheses = this.prettyPrintOptions.WithinMethodDeclarationParentheses && constructorDeclaration.Parameters.Any ();
if (withinParentheses) {
outputFormatter.Space();
}
AppendCommaSeparatedList(constructorDeclaration.Parameters); AppendCommaSeparatedList(constructorDeclaration.Parameters);
if (withinParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
TrackVisit(constructorDeclaration.ConstructorInitializer, data); TrackVisit(constructorDeclaration.ConstructorInitializer, data);
OutputBlock(constructorDeclaration.Body, this.prettyPrintOptions.ConstructorBraceStyle); OutputBlock(constructorDeclaration.Body, this.prettyPrintOptions.ConstructorBraceStyle);
@ -881,7 +909,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.This); outputFormatter.PrintToken(Tokens.This);
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
AppendCommaSeparatedList(constructorInitializer.Arguments); AppendCommaSeparatedList(constructorInitializer.Arguments);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -1210,7 +1244,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinIfParentheses) {
outputFormatter.Space();
}
TrackVisit(ifElseStatement.Condition, data); TrackVisit(ifElseStatement.Condition, data);
if (this.prettyPrintOptions.WithinIfParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
PrintIfSection(ifElseStatement.TrueStatement); PrintIfSection(ifElseStatement.TrueStatement);
@ -1257,7 +1297,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinIfParentheses) {
outputFormatter.Space();
}
TrackVisit(elseIfSection.Condition, data); TrackVisit(elseIfSection.Condition, data);
if (this.prettyPrintOptions.WithinIfParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
WriteEmbeddedStatement(elseIfSection.EmbeddedStatement); WriteEmbeddedStatement(elseIfSection.EmbeddedStatement);
@ -1272,6 +1318,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinForParentheses) {
outputFormatter.Space();
}
outputFormatter.DoIndent = false; outputFormatter.DoIndent = false;
outputFormatter.DoNewLine = false; outputFormatter.DoNewLine = false;
outputFormatter.EmitSemicolon = false; outputFormatter.EmitSemicolon = false;
@ -1307,6 +1356,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
} }
} }
if (this.prettyPrintOptions.WithinForParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.EmitSemicolon = true; outputFormatter.EmitSemicolon = true;
outputFormatter.DoNewLine = true; outputFormatter.DoNewLine = true;
@ -1353,7 +1405,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinSwitchParentheses) {
outputFormatter.Space();
}
TrackVisit(switchStatement.SwitchExpression, data); TrackVisit(switchStatement.SwitchExpression, data);
if (this.prettyPrintOptions.WithinSwitchParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintToken(Tokens.OpenCurlyBrace); outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
@ -1498,6 +1556,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinWhileParentheses) {
outputFormatter.Space();
}
if (doLoopStatement.ConditionType == ConditionType.Until) { if (doLoopStatement.ConditionType == ConditionType.Until) {
outputFormatter.PrintToken(Tokens.Not); outputFormatter.PrintToken(Tokens.Not);
@ -1513,6 +1574,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (doLoopStatement.ConditionType == ConditionType.Until) { if (doLoopStatement.ConditionType == ConditionType.Until) {
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
if (this.prettyPrintOptions.WithinWhileParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
@ -1547,6 +1611,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinForEachParentheses) {
outputFormatter.Space();
}
TrackVisit(foreachStatement.TypeReference, data); TrackVisit(foreachStatement.TypeReference, data);
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintIdentifier(foreachStatement.VariableName); outputFormatter.PrintIdentifier(foreachStatement.VariableName);
@ -1554,6 +1621,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.In); outputFormatter.PrintToken(Tokens.In);
outputFormatter.Space(); outputFormatter.Space();
TrackVisit(foreachStatement.Expression, data); TrackVisit(foreachStatement.Expression, data);
if (this.prettyPrintOptions.WithinForEachParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
WriteEmbeddedStatement(foreachStatement.EmbeddedStatement); WriteEmbeddedStatement(foreachStatement.EmbeddedStatement);
@ -1568,7 +1638,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinLockParentheses) {
outputFormatter.Space();
}
TrackVisit(lockStatement.LockExpression, data); TrackVisit(lockStatement.LockExpression, data);
if (this.prettyPrintOptions.WithinLockParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
WriteEmbeddedStatement(lockStatement.EmbeddedStatement); WriteEmbeddedStatement(lockStatement.EmbeddedStatement);
@ -1583,7 +1659,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (prettyPrintOptions.WithinUsingParentheses) {
outputFormatter.Space();
}
PrintStatementInline(usingStatement.ResourceAcquisition, data); PrintStatementInline(usingStatement.ResourceAcquisition, data);
if (prettyPrintOptions.WithinUsingParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
WriteEmbeddedStatement(usingStatement.EmbeddedStatement); WriteEmbeddedStatement(usingStatement.EmbeddedStatement);
@ -1635,11 +1717,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinCatchParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintIdentifier(catchClause.TypeReference.Type); outputFormatter.PrintIdentifier(catchClause.TypeReference.Type);
if (catchClause.VariableName.Length > 0) { if (catchClause.VariableName.Length > 0) {
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintIdentifier(catchClause.VariableName); outputFormatter.PrintIdentifier(catchClause.VariableName);
} }
if (this.prettyPrintOptions.WithinCatchParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
WriteEmbeddedStatement(catchClause.StatementBlock); WriteEmbeddedStatement(catchClause.StatementBlock);
@ -1664,7 +1752,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinCheckedExpressionParantheses) {
outputFormatter.Space();
}
PrintStatementInline(fixedStatement.PointerDeclaration, data); PrintStatementInline(fixedStatement.PointerDeclaration, data);
if (this.prettyPrintOptions.WithinCheckedExpressionParantheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
WriteEmbeddedStatement(fixedStatement.EmbeddedStatement); WriteEmbeddedStatement(fixedStatement.EmbeddedStatement);
@ -1711,6 +1805,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.For); outputFormatter.PrintToken(Tokens.For);
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinForParentheses) {
outputFormatter.Space();
}
if (forNextStatement.LoopVariableExpression.IsNull) { if (forNextStatement.LoopVariableExpression.IsNull) {
if (!forNextStatement.TypeReference.IsNull) { if (!forNextStatement.TypeReference.IsNull) {
TrackVisit(forNextStatement.TypeReference, data); TrackVisit(forNextStatement.TypeReference, data);
@ -1757,6 +1854,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
TrackVisit(forNextStatement.Step, data); TrackVisit(forNextStatement.Step, data);
} }
if (this.prettyPrintOptions.WithinForParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
WriteEmbeddedStatement(forNextStatement.EmbeddedStatement); WriteEmbeddedStatement(forNextStatement.EmbeddedStatement);
@ -1922,9 +2022,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
TrackVisit(binaryOperatorExpression.Left, data); TrackVisit(binaryOperatorExpression.Left, data);
PrintFormattedComma(); PrintFormattedComma();
TrackVisit(binaryOperatorExpression.Right, data); TrackVisit(binaryOperatorExpression.Right, data);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
case BinaryOperatorType.DictionaryAccess: case BinaryOperatorType.DictionaryAccess:
@ -2058,11 +2164,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
case BinaryOperatorType.Equality: case BinaryOperatorType.Equality:
case BinaryOperatorType.ReferenceEquality: case BinaryOperatorType.ReferenceEquality:
if (prettyPrintOptions.AroundRelationalOperatorParentheses) { if (prettyPrintOptions.AroundEqualityOperatorParentheses) {
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.Equal); outputFormatter.PrintToken(Tokens.Equal);
if (prettyPrintOptions.AroundRelationalOperatorParentheses) { if (prettyPrintOptions.AroundEqualityOperatorParentheses) {
outputFormatter.Space(); outputFormatter.Space();
} }
break; break;
@ -2086,11 +2192,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
break; break;
case BinaryOperatorType.InEquality: case BinaryOperatorType.InEquality:
case BinaryOperatorType.ReferenceInequality: case BinaryOperatorType.ReferenceInequality:
if (prettyPrintOptions.AroundRelationalOperatorParentheses) { if (prettyPrintOptions.AroundEqualityOperatorParentheses) {
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.NotEqual); outputFormatter.PrintToken(Tokens.NotEqual);
if (prettyPrintOptions.AroundRelationalOperatorParentheses) { if (prettyPrintOptions.AroundEqualityOperatorParentheses) {
outputFormatter.Space(); outputFormatter.Space();
} }
break; break;
@ -2133,7 +2239,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) public override object TrackedVisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{ {
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinParentheses) {
outputFormatter.Space();
}
TrackVisit(parenthesizedExpression.Expression, data); TrackVisit(parenthesizedExpression.Expression, data);
if (this.prettyPrintOptions.WithinParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -2147,7 +2259,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
AppendCommaSeparatedList(invocationExpression.Arguments); AppendCommaSeparatedList(invocationExpression.Arguments);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -2287,7 +2405,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinSizeOfParentheses) {
outputFormatter.Space();
}
TrackVisit(sizeOfExpression.TypeReference, data); TrackVisit(sizeOfExpression.TypeReference, data);
if (this.prettyPrintOptions.WithinSizeOfParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -2299,7 +2423,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinTypeOfParentheses) {
outputFormatter.Space();
}
TrackVisit(typeOfExpression.TypeReference, data); TrackVisit(typeOfExpression.TypeReference, data);
if (this.prettyPrintOptions.WithinTypeOfParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -2311,7 +2441,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinTypeOfParentheses) {
outputFormatter.Space();
}
TrackVisit(defaultValueExpression.TypeReference, data); TrackVisit(defaultValueExpression.TypeReference, data);
if (this.prettyPrintOptions.WithinTypeOfParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -2338,7 +2474,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (anonymousMethodExpression.Parameters.Count > 0 || anonymousMethodExpression.HasParameterList) { if (anonymousMethodExpression.Parameters.Count > 0 || anonymousMethodExpression.HasParameterList) {
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
bool withinParentheses = this.prettyPrintOptions.WithinMethodDeclarationParentheses && anonymousMethodExpression.Parameters.Any ();
if (withinParentheses) {
outputFormatter.Space();
}
AppendCommaSeparatedList(anonymousMethodExpression.Parameters); AppendCommaSeparatedList(anonymousMethodExpression.Parameters);
if (withinParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
OutputBlockAllowInline(anonymousMethodExpression.Body, this.prettyPrintOptions.MethodBraceStyle, false); OutputBlockAllowInline(anonymousMethodExpression.Body, this.prettyPrintOptions.MethodBraceStyle, false);
@ -2352,7 +2495,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintIdentifier(lambdaExpression.Parameters[0].ParameterName); outputFormatter.PrintIdentifier(lambdaExpression.Parameters[0].ParameterName);
} else { } else {
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinParentheses) {
outputFormatter.Space();
}
AppendCommaSeparatedList(lambdaExpression.Parameters); AppendCommaSeparatedList(lambdaExpression.Parameters);
if (this.prettyPrintOptions.WithinParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
outputFormatter.Space(); outputFormatter.Space();
@ -2375,7 +2524,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinCheckedExpressionParantheses) {
outputFormatter.Space();
}
TrackVisit(checkedExpression.Expression, data); TrackVisit(checkedExpression.Expression, data);
if (this.prettyPrintOptions.WithinCheckedExpressionParantheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -2387,7 +2542,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinCheckedExpressionParantheses) {
outputFormatter.Space();
}
TrackVisit(uncheckedExpression.Expression, data); TrackVisit(uncheckedExpression.Expression, data);
if (this.prettyPrintOptions.WithinCheckedExpressionParantheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
return null; return null;
} }
@ -2420,7 +2581,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
TrackVisit(castExpression.CastTo, data); TrackVisit(castExpression.CastTo, data);
} else { } else {
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (prettyPrintOptions.WithinCastParentheses) {
outputFormatter.Space();
}
TrackVisit(castExpression.CastTo, data); TrackVisit(castExpression.CastTo, data);
if (prettyPrintOptions.WithinCastParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
if (this.prettyPrintOptions.SpacesAfterTypecast) { if (this.prettyPrintOptions.SpacesAfterTypecast) {
outputFormatter.Space(); outputFormatter.Space();
@ -2485,7 +2652,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
} }
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
AppendCommaSeparatedList(objectCreateExpression.Parameters); AppendCommaSeparatedList(objectCreateExpression.Parameters);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
if (!objectCreateExpression.ObjectInitializer.IsNull) { if (!objectCreateExpression.ObjectInitializer.IsNull) {
@ -2537,9 +2710,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (target is BinaryOperatorExpression || target is CastExpression) { if (target is BinaryOperatorExpression || target is CastExpression) {
outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.PrintToken(Tokens.OpenParenthesis);
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
} }
TrackVisit(target, data); TrackVisit(target, data);
if (target is BinaryOperatorExpression || target is CastExpression) { if (target is BinaryOperatorExpression || target is CastExpression) {
if (this.prettyPrintOptions.WithinMethodCallParentheses) {
outputFormatter.Space();
}
outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.PrintToken(Tokens.CloseParenthesis);
} }
outputFormatter.PrintToken(Tokens.Dot); outputFormatter.PrintToken(Tokens.Dot);

7
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/OutputFormatter.cs

@ -52,6 +52,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (indent) if (indent)
++IndentationLevel; ++IndentationLevel;
break; break;
case BraceStyle.EndOfLineWithoutSpace:
PrintToken(Tokens.OpenCurlyBrace);
NewLine();
if (indent)
++IndentationLevel;
break;
case BraceStyle.NextLine: case BraceStyle.NextLine:
NewLine(); NewLine();
Indent(); Indent();
@ -86,6 +92,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
BraceStyle style = (BraceStyle)braceStack.Pop(); BraceStyle style = (BraceStyle)braceStack.Pop();
switch (style) { switch (style) {
case BraceStyle.EndOfLine: case BraceStyle.EndOfLine:
case BraceStyle.EndOfLineWithoutSpace:
case BraceStyle.NextLine: case BraceStyle.NextLine:
if (indent) if (indent)
--IndentationLevel; --IndentationLevel;

171
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/PrettyPrintOptions.cs

@ -9,6 +9,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{ {
public enum BraceStyle { public enum BraceStyle {
EndOfLine, EndOfLine,
EndOfLineWithoutSpace,
NextLine, NextLine,
NextLineShifted, NextLineShifted,
NextLineShifted2 NextLineShifted2
@ -339,6 +340,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
#endregion #endregion
#region Spaces
#region Before Parentheses #region Before Parentheses
bool beforeMethodCallParentheses = false; bool beforeMethodCallParentheses = false;
bool beforeDelegateDeclarationParentheses = false; bool beforeDelegateDeclarationParentheses = false;
@ -590,6 +593,159 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
#endregion #endregion
#region WithinParentheses
bool withinCheckedExpressionParantheses = false;
public bool WithinCheckedExpressionParantheses {
get {
return withinCheckedExpressionParantheses;
}
set {
withinCheckedExpressionParantheses = value;
}
}
bool withinTypeOfParentheses = false;
public bool WithinTypeOfParentheses {
get {
return withinTypeOfParentheses;
}
set {
withinTypeOfParentheses = value;
}
}
bool withinSizeOfParentheses = false;
public bool WithinSizeOfParentheses {
get {
return withinSizeOfParentheses;
}
set {
withinSizeOfParentheses = value;
}
}
bool withinCastParentheses = false;
public bool WithinCastParentheses {
get {
return withinCastParentheses;
}
set {
withinCastParentheses = value;
}
}
bool withinUsingParentheses = false;
public bool WithinUsingParentheses {
get {
return withinUsingParentheses;
}
set {
withinUsingParentheses = value;
}
}
bool withinLockParentheses = false;
public bool WithinLockParentheses {
get {
return withinLockParentheses;
}
set {
withinLockParentheses = value;
}
}
bool withinSwitchParentheses = false;
public bool WithinSwitchParentheses {
get {
return withinSwitchParentheses;
}
set {
withinSwitchParentheses = value;
}
}
bool withinCatchParentheses = false;
public bool WithinCatchParentheses {
get {
return withinCatchParentheses;
}
set {
withinCatchParentheses = value;
}
}
bool withinForEachParentheses = false;
public bool WithinForEachParentheses {
get {
return withinForEachParentheses;
}
set {
withinForEachParentheses = value;
}
}
bool withinForParentheses = false;
public bool WithinForParentheses {
get {
return withinForParentheses;
}
set {
withinForParentheses = value;
}
}
bool withinWhileParentheses = false;
public bool WithinWhileParentheses {
get {
return withinWhileParentheses;
}
set {
withinWhileParentheses = value;
}
}
bool withinIfParentheses = false;
public bool WithinIfParentheses {
get {
return withinIfParentheses;
}
set {
withinIfParentheses = value;
}
}
bool withinMethodDeclarationParentheses = false;
public bool WithinMethodDeclarationParentheses {
get {
return withinMethodDeclarationParentheses;
}
set {
withinMethodDeclarationParentheses = value;
}
}
bool withinMethodCallParentheses = false;
public bool WithinMethodCallParentheses {
get {
return withinMethodCallParentheses;
}
set {
withinMethodCallParentheses = value;
}
}
bool withinParentheses = false;
public bool WithinParentheses {
get {
return withinParentheses;
}
set {
withinParentheses = value;
}
}
#endregion
#region SpacesInConditionalOperator #region SpacesInConditionalOperator
bool conditionalOperatorBeforeConditionSpace = true; bool conditionalOperatorBeforeConditionSpace = true;
bool conditionalOperatorAfterConditionSpace = true; bool conditionalOperatorAfterConditionSpace = true;
@ -632,12 +788,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
#endregion #endregion
#region OtherSpaces #region OtherSpaces
bool spacesWithinBrackets = false;
bool spacesAfterComma = true; bool spacesAfterComma = true;
bool spacesBeforeComma = false;
bool spacesAfterSemicolon = true;
bool spacesAfterTypecast = false;
public bool SpacesAfterComma { public bool SpacesAfterComma {
get { get {
return spacesAfterComma; return spacesAfterComma;
@ -646,6 +797,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
spacesAfterComma = value; spacesAfterComma = value;
} }
} }
bool spacesAfterSemicolon = true;
public bool SpacesAfterSemicolon { public bool SpacesAfterSemicolon {
get { get {
return spacesAfterSemicolon; return spacesAfterSemicolon;
@ -654,6 +807,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
spacesAfterSemicolon = value; spacesAfterSemicolon = value;
} }
} }
bool spacesAfterTypecast = false;
public bool SpacesAfterTypecast { public bool SpacesAfterTypecast {
get { get {
return spacesAfterTypecast; return spacesAfterTypecast;
@ -662,6 +817,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
spacesAfterTypecast = value; spacesAfterTypecast = value;
} }
} }
bool spacesBeforeComma = false;
public bool SpacesBeforeComma { public bool SpacesBeforeComma {
get { get {
return spacesBeforeComma; return spacesBeforeComma;
@ -670,6 +827,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
spacesBeforeComma = value; spacesBeforeComma = value;
} }
} }
bool spacesWithinBrackets = false;
public bool SpacesWithinBrackets { public bool SpacesWithinBrackets {
get { get {
return spacesWithinBrackets; return spacesWithinBrackets;
@ -679,6 +838,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
} }
#endregion #endregion
#endregion
} }
} }
Loading…
Cancel
Save