Browse Source

NRefactory output visitors: allow inserting specials between attributes and the attributed node.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2615 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
5602eff9e7
  1. 16
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/SpecialNodesInserter.cs
  2. 13
      src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs

16
src/Libraries/NRefactory/Project/Src/PrettyPrinter/SpecialNodesInserter.cs

@ -71,13 +71,23 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -71,13 +71,23 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
available = enumerator.MoveNext();
}
AttributedNode currentAttributedNode;
/// <summary>
/// Writes all specials up to the start position of the node.
/// </summary>
public void AcceptNodeStart(INode node)
{
if (node is AttributedNode) {
currentAttributedNode = node as AttributedNode;
if (currentAttributedNode.Attributes.Count == 0) {
AcceptPoint(node.StartLocation);
currentAttributedNode = null;
}
} else {
AcceptPoint(node.StartLocation);
}
}
/// <summary>
/// Writes all specials up to the end position of the node.
@ -87,6 +97,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -87,6 +97,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
visitor.ForceWriteInPreviousLine = true;
AcceptPoint(node.EndLocation);
visitor.ForceWriteInPreviousLine = false;
if (currentAttributedNode != null) {
if (node == currentAttributedNode.Attributes[currentAttributedNode.Attributes.Count - 1]) {
AcceptPoint(currentAttributedNode.StartLocation);
currentAttributedNode = null;
}
}
}
/// <summary>

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

@ -205,5 +205,18 @@ End Class"); @@ -205,5 +205,18 @@ End Class");
"\tEnd Sub\n" +
"End Class");
}
[Test]
public void ConditionalAttribute()
{
TestProgram("class A\n" +
"{\n" +
"\t#if TEST\n" +
"\t[MyAttribute()]\n" +
"\t#endif\n" +
"\tpublic int Field;\n" +
"}\n" +
"#end if");
}
}
}

Loading…
Cancel
Save