|
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision: 1965 $</version>
// </file>
using System.Collections;
using ICSharpCode.NRefactory.Parser.CSharp;
namespace ICSharpCode.NRefactory.PrettyPrinter
{
public sealed class CSharpOutputFormatter : AbstractOutputFormatter
{
PrettyPrintOptions prettyPrintOptions;
bool emitSemicolon = true;
public bool EmitSemicolon {
get {
return emitSemicolon;
}
set {
emitSemicolon = value;
}
}
public CSharpOutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
{
this.prettyPrintOptions = prettyPrintOptions;
}
public override void PrintToken(int token)
{
if (token == Tokens.Semicolon && !EmitSemicolon) {
return;
}
PrintText(Tokens.GetTokenString(token));
}
Stack braceStack = new Stack();
public void BeginBrace(BraceStyle style)
{
switch (style) {
case BraceStyle.EndOfLine:
if (!LastCharacterIsWhiteSpace) {
Space();
}
PrintToken(Tokens.OpenCurlyBrace);
NewLine();
++IndentationLevel;
break;
case BraceStyle.NextLine:
NewLine();
Indent();
PrintToken(Tokens.OpenCurlyBrace);
NewLine();
++IndentationLevel;
break;
case BraceStyle.NextLineShifted:
NewLine();
++IndentationLevel;
Indent();
PrintToken(Tokens.OpenCurlyBrace);
NewLine();
break;
case BraceStyle.NextLineShifted2:
NewLine();
++IndentationLevel;
Indent();
PrintToken(Tokens.OpenCurlyBrace);
NewLine();
++IndentationLevel;
break;
}
braceStack.Push(style);
}
public void EndBrace()
{
BraceStyle style = (BraceStyle)braceStack.Pop();
switch (style) {
case BraceStyle.EndOfLine:
case BraceStyle.NextLine:
--IndentationLevel;
Indent();
PrintToken(Tokens.CloseCurlyBrace);
NewLine();
break;
case BraceStyle.NextLineShifted:
Indent();
PrintToken(Tokens.CloseCurlyBrace);
NewLine();
--IndentationLevel;
break;
case BraceStyle.NextLineShifted2:
--IndentationLevel;
Indent();
PrintToken(Tokens.CloseCurlyBrace);
NewLine();
--IndentationLevel;
break;
}
}
public override void PrintIdentifier(string identifier)
{
if (Keywords.GetToken(identifier) >= 0)
PrintText("@");
PrintText(identifier);
}
public override void PrintComment(Comment comment, bool forceWriteInPreviousBlock)
{
switch (comment.CommentType) {
case CommentType.Block:
if (forceWriteInPreviousBlock) {
WriteInPreviousLine("/*" + comment.CommentText + "*/", forceWriteInPreviousBlock);
} else {
PrintSpecialText("/*" + comment.CommentText + "*/");
}
break;
case CommentType.Documentation:
WriteLineInPreviousLine("///" + comment.CommentText, forceWriteInPreviousBlock);
break;
default:
WriteLineInPreviousLine("//" + comment.CommentText, forceWriteInPreviousBlock);
break;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.