Browse Source

Fixed SD2-554: Enum members in output visitor

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@710 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
0cd63b78df
  1. 2
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs
  2. 10
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  3. 23
      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

2
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs

@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
// <version>$Revision$</version>
// </file>
using DebuggerLibrary;
using Debugger;
using Microsoft.CSharp;
using NUnit.Framework;
using System;

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

@ -312,7 +312,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -312,7 +312,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
void OutputEnumMembers(TypeDeclaration typeDeclaration, object data)
{
bool first = true;
foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) {
if (first) {
first = false;
} else {
outputFormatter.PrintToken(Tokens.Comma);
outputFormatter.NewLine();
}
VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0];
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
@ -323,9 +330,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -323,9 +330,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
nodeTracker.TrackedVisit(f.Initializer, data);
}
outputFormatter.PrintToken(Tokens.Comma);
outputFormatter.NewLine();
}
outputFormatter.NewLine();
}
TypeDeclaration currentType = null;

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

@ -341,7 +341,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -341,7 +341,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
TypeDeclaration oldType = currentType;
currentType = typeDeclaration;
nodeTracker.TrackedVisitChildren(typeDeclaration, data);
if (typeDeclaration.Type == ClassType.Enum) {
OutputEnumMembers(typeDeclaration, data);
} else {
nodeTracker.TrackedVisitChildren(typeDeclaration, data);
}
currentType = oldType;
--outputFormatter.IndentationLevel;
@ -355,6 +359,23 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -355,6 +359,23 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
void OutputEnumMembers(TypeDeclaration typeDeclaration, object data)
{
foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) {
VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0];
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
outputFormatter.PrintIdentifier(f.Name);
if (f.Initializer != null && !f.Initializer.IsNull) {
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.Space();
nodeTracker.TrackedVisit(f.Initializer, data);
}
outputFormatter.NewLine();
}
}
public object Visit(TemplateDefinition templateDefinition, object data)
{
outputFormatter.PrintIdentifier(templateDefinition.Name);

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

@ -162,5 +162,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -162,5 +162,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("public delegate void Predicate<T>(T item) where T : IDisposable, ICloneable;");
}
[Test]
public void Enum()
{
TestProgram("enum MyTest { Red, Green, Blue, Yellow }");
}
[Test]
public void EnumWithInitializers()
{
TestProgram("enum MyTest { Red = 1, Green = 2, Blue = 4, Yellow = 8 }");
}
}
}

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

@ -125,5 +125,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -125,5 +125,17 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("Public Delegate Function Predicate(Of T)(ByVal item As T) As String");
}
[Test]
public void Enum()
{
TestProgram("Enum MyTest\nRed\n Green\n Blue\nYellow\n End Enum");
}
[Test]
public void EnumWithInitializers()
{
TestProgram("Enum MyTest\nRed = 1\n Green = 2\n Blue = 4\n Yellow = 8\n End Enum");
}
}
}

Loading…
Cancel
Save