Browse Source

Comment positions inside enum are preserved (forum-6415).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1259 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
98e7ddff44
  1. 15
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  2. 2
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  3. 42
      src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs

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

@ -320,14 +320,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -320,14 +320,9 @@ 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();
}
for (int i = 0; i < typeDeclaration.Children.Count; i++) {
FieldDeclaration fieldDeclaration = (FieldDeclaration)typeDeclaration.Children[i];
nodeTracker.BeginNode(fieldDeclaration);
VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0];
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
@ -338,8 +333,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -338,8 +333,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
nodeTracker.TrackedVisit(f.Initializer, data);
}
if (i < typeDeclaration.Children.Count - 1) {
outputFormatter.PrintToken(Tokens.Comma);
}
outputFormatter.NewLine();
nodeTracker.EndNode(fieldDeclaration);
}
}
TypeDeclaration currentType = null;

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

@ -374,6 +374,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -374,6 +374,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
void OutputEnumMembers(TypeDeclaration typeDeclaration, object data)
{
foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) {
nodeTracker.BeginNode(fieldDeclaration);
VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0];
VisitAttributes(fieldDeclaration.Attributes, data);
outputFormatter.Indent();
@ -385,6 +386,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -385,6 +386,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
nodeTracker.TrackedVisit(f.Initializer, data);
}
outputFormatter.NewLine();
nodeTracker.EndNode(fieldDeclaration);
}
}

42
src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs

@ -32,6 +32,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -32,6 +32,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
parser.Dispose();
}
void TestProgramVB(string program)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(program));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(),
outputVisitor)) {
outputVisitor.Visit(parser.CompilationUnit, null);
}
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(program, outputVisitor.Text.TrimEnd().Replace("\r", ""));
parser.Dispose();
}
[Test]
public void SimpleComments()
{
@ -63,5 +78,32 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -63,5 +78,32 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"}\n" +
"#end if");
}
[Test]
public void Enum()
{
TestProgram("enum Test\n" +
"{\n" +
"\t// a\n" +
"\tm1,\n" +
"\t// b\n" +
"\tm2\n" +
"\t// c\n" +
"}\n" +
"// d");
}
[Test]
public void EnumVB()
{
TestProgramVB("Enum Test\n" +
"\t' a\n" +
"\tm1\n" +
"\t' b\n" +
"\tm2\n" +
"\t' c\n" +
"End Enum\n" +
"' d");
}
}
}

Loading…
Cancel
Save