Browse Source

Fixed some C# output visitor bugs.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@716 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
951b9bf716
  1. 102
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  2. 11
      src/Libraries/NRefactory/Project/Src/Output/CSharp/PrettyPrintOptions.cs
  3. 30
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  4. 12
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs
  5. 12
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

102
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -461,14 +461,27 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -461,14 +461,27 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(FieldDeclaration fieldDeclaration, object data)
{
// TODO: use FieldDeclaration.GetTypeForField and VB.NET fields aren't that easy....
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(fieldDeclaration.Modifier);
nodeTracker.TrackedVisit(fieldDeclaration.TypeReference, data);
outputFormatter.Space();
AppendCommaSeparatedList(fieldDeclaration.Fields);
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
if (!fieldDeclaration.TypeReference.IsNull) {
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(fieldDeclaration.Modifier);
nodeTracker.TrackedVisit(fieldDeclaration.TypeReference, data);
outputFormatter.Space();
AppendCommaSeparatedList(fieldDeclaration.Fields);
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
} else {
foreach (VariableDeclaration varDecl in fieldDeclaration.Fields) {
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
OutputModifier(fieldDeclaration.Modifier);
nodeTracker.TrackedVisit(varDecl.TypeReference, data);
outputFormatter.Space();
nodeTracker.TrackedVisit(varDecl, data);
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
}
}
return null;
}
@ -831,7 +844,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -831,7 +844,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(BlockStatement blockStatement, object data)
{
OutputBlock(blockStatement, BraceStyle.NextLine);
if (data is BraceStyle)
OutputBlock(blockStatement, (BraceStyle)data);
else
OutputBlock(blockStatement, BraceStyle.NextLine);
return null;
}
@ -1020,11 +1036,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1020,11 +1036,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.OpenParenthesis);
nodeTracker.TrackedVisit(elseIfSection.Condition, data);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
nodeTracker.TrackedVisit(elseIfSection.EmbeddedStatement, data);
outputFormatter.NewLine();
--outputFormatter.IndentationLevel;
WriteEmbeddedStatement(elseIfSection.EmbeddedStatement);
return null;
}
@ -1074,16 +1088,23 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1074,16 +1088,23 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.EmitSemicolon = true;
outputFormatter.DoNewLine = true;
outputFormatter.DoIndent = true;
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
if (forStatement.EmbeddedStatement is BlockStatement) {
nodeTracker.TrackedVisit(forStatement.EmbeddedStatement, false);
WriteEmbeddedStatement(forStatement.EmbeddedStatement);
return null;
}
void WriteEmbeddedStatement(Statement statement)
{
if (statement is BlockStatement) {
nodeTracker.TrackedVisit(statement, prettyPrintOptions.StatementBraceStyle);
} else {
nodeTracker.TrackedVisit(forStatement.EmbeddedStatement, data);
++outputFormatter.IndentationLevel;
outputFormatter.NewLine();
nodeTracker.TrackedVisit(statement, null);
outputFormatter.NewLine();
--outputFormatter.IndentationLevel;
}
outputFormatter.NewLine();
--outputFormatter.IndentationLevel;
return null;
}
public object Visit(LabelStatement labelStatement, object data)
@ -1248,11 +1269,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1248,11 +1269,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
++outputFormatter.IndentationLevel;
if (doLoopStatement.EmbeddedStatement is BlockStatement) {
nodeTracker.TrackedVisit(doLoopStatement.EmbeddedStatement, false);
} else {
nodeTracker.TrackedVisit(doLoopStatement.EmbeddedStatement, data);
}
WriteEmbeddedStatement(doLoopStatement.EmbeddedStatement);
--outputFormatter.IndentationLevel;
if (doLoopStatement.ConditionPosition == ConditionPosition.End) {
@ -1279,14 +1296,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1279,14 +1296,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
nodeTracker.TrackedVisit(foreachStatement.Expression, data);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
if (foreachStatement.EmbeddedStatement is BlockStatement) {
nodeTracker.TrackedVisit(foreachStatement.EmbeddedStatement, false);
} else {
nodeTracker.TrackedVisit(foreachStatement.EmbeddedStatement, data);
}
--outputFormatter.IndentationLevel;
WriteEmbeddedStatement(foreachStatement.EmbeddedStatement);
return null;
}
@ -1299,15 +1311,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1299,15 +1311,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.OpenParenthesis);
nodeTracker.TrackedVisit(lockStatement.LockExpression, data);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
nodeTracker.TrackedVisit(lockStatement.EmbeddedStatement, data);
--outputFormatter.IndentationLevel;
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
WriteEmbeddedStatement(lockStatement.EmbeddedStatement);
return null;
}
@ -1328,15 +1334,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1328,15 +1334,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.EmitSemicolon = true;
outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
nodeTracker.TrackedVisit(usingStatement.EmbeddedStatement, data);
--outputFormatter.IndentationLevel;
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
WriteEmbeddedStatement(usingStatement.EmbeddedStatement);
return null;
}

11
src/Libraries/NRefactory/Project/Src/Output/CSharp/PrettyPrintOptions.cs

@ -44,6 +44,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -44,6 +44,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
BraceStyle eventAddBraceStyle = BraceStyle.EndOfLine;
BraceStyle eventRemoveBraceStyle = BraceStyle.EndOfLine;
BraceStyle statementBraceStyle = BraceStyle.EndOfLine;
public BraceStyle StatementBraceStyle {
get {
return statementBraceStyle;
}
set {
statementBraceStyle = value;
}
}
public BraceStyle NameSpaceBraceStyle {
get {
return nameSpaceBraceStyle;

30
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -1066,10 +1066,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1066,10 +1066,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (localVariableDeclaration.Modifier != Modifier.None) {
OutputModifier(localVariableDeclaration.Modifier);
}
if ((localVariableDeclaration.Modifier & Modifier.Const) == 0) {
outputFormatter.PrintToken(Tokens.Dim);
if (!isUsingResourceAcquisition) {
if ((localVariableDeclaration.Modifier & Modifier.Const) == 0) {
outputFormatter.PrintToken(Tokens.Dim);
}
outputFormatter.Space();
}
outputFormatter.Space();
currentVariableType = localVariableDeclaration.TypeReference;
AppendCommaSeparatedList(localVariableDeclaration.Variables);
@ -1450,16 +1452,34 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1450,16 +1452,34 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(LockStatement lockStatement, object data)
{
errors.Error(-1, -1, String.Format("LockStatement is unsupported"));
outputFormatter.PrintToken(Tokens.SyncLock);
outputFormatter.Space();
nodeTracker.TrackedVisit(lockStatement.LockExpression, data);
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
nodeTracker.TrackedVisit(lockStatement.EmbeddedStatement, data);
--outputFormatter.IndentationLevel;
outputFormatter.NewLine();
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.End);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.SyncLock);
outputFormatter.NewLine();
return null;
}
bool isUsingResourceAcquisition;
public object Visit(UsingStatement usingStatement, object data)
{
outputFormatter.PrintToken(Tokens.Using);
outputFormatter.Space();
isUsingResourceAcquisition = true;
nodeTracker.TrackedVisit(usingStatement.ResourceAcquisition, data);
isUsingResourceAcquisition = false;
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
@ -1471,7 +1491,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1471,7 +1491,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.End);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Using);
outputFormatter.Space();
outputFormatter.NewLine();
return null;
@ -1489,7 +1508,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1489,7 +1508,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.End);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.With);
outputFormatter.Space();
outputFormatter.NewLine();
return null;
}

12
src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

@ -174,5 +174,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -174,5 +174,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("enum MyTest { Red = 1, Green = 2, Blue = 4, Yellow = 8 }");
}
[Test]
public void SyncLock()
{
TestStatement("lock (a) { Work(); }");
}
[Test]
public void Using()
{
TestStatement("using (A a = new A()) { a.Work(); }");
}
}
}

12
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -137,5 +137,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -137,5 +137,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("Enum MyTest\nRed = 1\n Green = 2\n Blue = 4\n Yellow = 8\n End Enum");
}
[Test]
public void SyncLock()
{
TestStatement("SyncLock a\nWork()\nEnd SyncLock");
}
[Test]
public void Using()
{
TestStatement("Using a As A = New A()\na.Work()\nEnd Using");
}
}
}

Loading…
Cancel
Save