Browse Source

Folding using declarations

pull/275/head
Artur Zgodziński 15 years ago
parent
commit
a63302a0cb
  1. 25
      ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

25
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -33,6 +33,8 @@ namespace ICSharpCode.Decompiler.Ast
readonly Stack<AstNode> nodeStack = new Stack<AstNode>(); readonly Stack<AstNode> nodeStack = new Stack<AstNode>();
int braceLevelWithinType = -1; int braceLevelWithinType = -1;
bool inDocumentationComment = false; bool inDocumentationComment = false;
bool firstUsingDeclaration;
bool lastUsingDeclaration;
public TextOutputFormatter(ITextOutput output) public TextOutputFormatter(ITextOutput output)
{ {
@ -62,6 +64,11 @@ namespace ICSharpCode.Decompiler.Ast
return; return;
} }
if (firstUsingDeclaration) {
output.MarkFoldStart(defaultCollapsed: true);
firstUsingDeclaration = false;
}
output.Write(identifier); output.Write(identifier);
} }
@ -183,6 +190,10 @@ namespace ICSharpCode.Decompiler.Ast
public void NewLine() public void NewLine()
{ {
if (lastUsingDeclaration) {
output.MarkFoldEnd();
lastUsingDeclaration = false;
}
output.WriteLine(); output.WriteLine();
} }
@ -221,6 +232,15 @@ namespace ICSharpCode.Decompiler.Ast
public void StartNode(AstNode node) public void StartNode(AstNode node)
{ {
if (nodeStack.Count == 0) {
if (IsUsingDeclaration(node)) {
firstUsingDeclaration = !IsUsingDeclaration(node.PrevSibling);
lastUsingDeclaration = !IsUsingDeclaration(node.NextSibling);
} else {
firstUsingDeclaration = false;
lastUsingDeclaration = false;
}
}
nodeStack.Push(node); nodeStack.Push(node);
startLocations.Push(output.Location); startLocations.Push(output.Location);
@ -231,6 +251,11 @@ namespace ICSharpCode.Decompiler.Ast
} }
} }
private bool IsUsingDeclaration(AstNode node)
{
return node is UsingDeclaration || node is UsingAliasDeclaration;
}
public void EndNode(AstNode node) public void EndNode(AstNode node)
{ {
if (nodeStack.Pop() != node) if (nodeStack.Pop() != node)

Loading…
Cancel
Save