Browse Source

* NRefactory.csproj:

* Src/PrettyPrinter/CSharp/OutputFormatter.cs:
* Src/PrettyPrinter/CSharp/PrettyPrintOptions.cs:
* Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs: Added some options.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3849 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mike Krüger 17 years ago
parent
commit
c16eaaff79
  1. 43
      src/Libraries/NRefactory/Project/NRefactory.csproj
  2. 63
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  3. 11
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/OutputFormatter.cs
  4. 127
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/PrettyPrintOptions.cs

43
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -26,18 +27,19 @@ @@ -26,18 +27,19 @@
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<Optimize>false</Optimize>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<DefineConstants>TEST;DEBUG;NET35</DefineConstants>
<OutputPath>..\..\..\..\bin\</OutputPath>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugType>none</DebugType>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<Optimize>true</Optimize>
<DefineConstants>TEST;NET35</DefineConstants>
<OutputPath>..\..\..\..\bin\</OutputPath>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugType>none</DebugType>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>Full</DebugType>
@ -77,9 +79,6 @@ @@ -77,9 +79,6 @@
<Compile Include="Src\Lexer\VBNet\Lexer.cs" />
<Compile Include="Src\Lexer\VBNet\Tokens.cs" />
<Compile Include="Src\Lexer\Special\ISpecial.cs" />
<Compile Include="..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Src\OperatorPrecedence.cs" />
<Compile Include="Src\Parser\CSharp\CSharpParser.cs" />
<Compile Include="Src\Parser\CSharp\Parser.cs" />
@ -137,26 +136,24 @@ @@ -137,26 +136,24 @@
<ItemGroup>
<Content Include="Src\Lexer\CSharp\KeywordList.txt" />
<Content Include="Src\Lexer\VBNet\KeywordList.txt" />
<Folder Include="Src\Parser" />
<Folder Include="Src\Parser\CSharp" />
<Folder Include="Src\" />
<Folder Include="Src\Parser\" />
<Content Include="Src\Parser\CSharp\cs.ATG" />
<Folder Include="Src\Parser\Frames" />
<Folder Include="Src\Parser\" />
<Content Include="Src\Parser\Frames\Parser.frame" />
<Content Include="Src\Parser\Frames\Scanner.frame" />
<Content Include="Src\Parser\Frames\SharpCoco.exe" />
<Content Include="Src\Parser\Frames\trace.txt" />
<Folder Include="Src\Parser\VBNet" />
<Folder Include="Src\Parser\" />
<Content Include="Src\Parser\VBNet\VBNET.ATG" />
<Content Include="Src\Parser\gen.bat" />
<Folder Include="Src\PrettyPrinter" />
<Folder Include="Src\PrettyPrinter\CSharp" />
<Folder Include="Src\PrettyPrinter\VBNet" />
<Folder Include="Src\Visitors" />
<Folder Include="Src\Ast" />
<Folder Include="Src\Ast\General" />
</ItemGroup>
<ItemGroup>
<Folder Include="Src\AstBuilder" />
<Folder Include="Src\" />
<Folder Include="Src\PrettyPrinter\" />
<Folder Include="Src\PrettyPrinter\" />
<Folder Include="Src\" />
<Folder Include="Src\" />
<Folder Include="Src\Ast\" />
<Folder Include="Src\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

63
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -315,11 +315,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -315,11 +315,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
outputFormatter.PrintIdentifier(namespaceDeclaration.Name);
outputFormatter.BeginBrace(this.prettyPrintOptions.NamespaceBraceStyle);
outputFormatter.BeginBrace (this.prettyPrintOptions.NamespaceBraceStyle, this.prettyPrintOptions.IndentNamespaceBody);
namespaceDeclaration.AcceptChildren(this, data);
outputFormatter.EndBrace();
outputFormatter.EndBrace(this.prettyPrintOptions.IndentNamespaceBody);
return null;
}
@ -392,16 +392,16 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -392,16 +392,16 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
switch (typeDeclaration.Type) {
case ClassType.Enum:
outputFormatter.BeginBrace(this.prettyPrintOptions.EnumBraceStyle);
outputFormatter.BeginBrace(this.prettyPrintOptions.EnumBraceStyle, this.prettyPrintOptions.IndentEnumBody);
break;
case ClassType.Interface:
outputFormatter.BeginBrace(this.prettyPrintOptions.InterfaceBraceStyle);
outputFormatter.BeginBrace(this.prettyPrintOptions.InterfaceBraceStyle, this.prettyPrintOptions.IndentInterfaceBody);
break;
case ClassType.Struct:
outputFormatter.BeginBrace(this.prettyPrintOptions.StructBraceStyle);
outputFormatter.BeginBrace(this.prettyPrintOptions.StructBraceStyle, this.prettyPrintOptions.IndentStructBody);
break;
default:
outputFormatter.BeginBrace(this.prettyPrintOptions.ClassBraceStyle);
outputFormatter.BeginBrace(this.prettyPrintOptions.ClassBraceStyle, this.prettyPrintOptions.IndentClassBody);
break;
}
@ -413,7 +413,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -413,7 +413,20 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
typeDeclaration.AcceptChildren(this, data);
}
currentType = oldType;
outputFormatter.EndBrace();
switch (typeDeclaration.Type) {
case ClassType.Enum:
outputFormatter.EndBrace(this.prettyPrintOptions.IndentEnumBody);
break;
case ClassType.Interface:
outputFormatter.EndBrace(this.prettyPrintOptions.IndentInterfaceBody);
break;
case ClassType.Struct:
outputFormatter.EndBrace(this.prettyPrintOptions.IndentStructBody);
break;
default:
outputFormatter.EndBrace(this.prettyPrintOptions.IndentCaseBody);
break;
}
return null;
}
@ -536,12 +549,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -536,12 +549,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
outputFormatter.PrintIdentifier(propertyDeclaration.Name);
outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle);
outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle, this.prettyPrintOptions.IndentPropertyBody);
TrackVisit(propertyDeclaration.GetRegion, data);
TrackVisit(propertyDeclaration.SetRegion, data);
outputFormatter.EndBrace();
outputFormatter.EndBrace(this.prettyPrintOptions.IndentPropertyBody);
return null;
}
@ -601,10 +614,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -601,10 +614,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
} else {
outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle);
outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle, this.prettyPrintOptions.IndentEventBody);
TrackVisit(eventDeclaration.AddRegion, data);
TrackVisit(eventDeclaration.RemoveRegion, data);
outputFormatter.EndBrace();
outputFormatter.EndBrace(this.prettyPrintOptions.IndentEventBody);
}
return null;
}
@ -924,7 +937,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -924,7 +937,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
} else {
outputFormatter.BeginBrace(braceStyle);
outputFormatter.BeginBrace(braceStyle, this.prettyPrintOptions.IndentBlocks);
foreach (Statement stmt in blockStatement.Children) {
outputFormatter.Indent();
if (stmt is BlockStatement) {
@ -935,7 +948,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -935,7 +948,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (!outputFormatter.LastCharacterIsNewLine)
outputFormatter.NewLine();
}
outputFormatter.EndBrace();
outputFormatter.EndBrace(this.prettyPrintOptions.IndentBlocks);
}
EndVisit(blockStatement);
}
@ -1035,7 +1048,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1035,7 +1048,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Null);
outputFormatter.PrintToken(Tokens.CloseParenthesis);
outputFormatter.BeginBrace(BraceStyle.EndOfLine);
outputFormatter.BeginBrace(BraceStyle.EndOfLine, this.prettyPrintOptions.IndentBlocks);
outputFormatter.Indent();
outputFormatter.PrintIdentifier(raiseEventStatement.EventName);
@ -1045,7 +1058,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1045,7 +1058,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
outputFormatter.EndBrace();
outputFormatter.EndBrace(this.prettyPrintOptions.IndentBlocks);
return null;
}
@ -1321,10 +1334,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1321,10 +1334,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
outputFormatter.NewLine();
if (prettyPrintOptions.IndentSwitchBody)
++outputFormatter.IndentationLevel;
foreach (SwitchSection section in switchStatement.SwitchSections) {
TrackVisit(section, data);
}
if (prettyPrintOptions.IndentSwitchBody)
--outputFormatter.IndentationLevel;
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
@ -1336,13 +1353,25 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1336,13 +1353,25 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
foreach (CaseLabel label in switchSection.SwitchLabels) {
TrackVisit(label, data);
}
int standardIndentLevel = outputFormatter.IndentationLevel;
if (prettyPrintOptions.IndentCaseBody)
++outputFormatter.IndentationLevel;
foreach (Statement stmt in switchSection.Children) {
for (int i = 0; i < switchSection.Children.Count; i++) {
Statement stmt = switchSection.Children[i] as Statement;
int oldIndent = outputFormatter.IndentationLevel;
if (i == switchSection.Children.Count - 1) {
if (prettyPrintOptions.IndentBreakStatements)
outputFormatter.IndentationLevel = standardIndentLevel + 1;
else
outputFormatter.IndentationLevel = standardIndentLevel;
}
outputFormatter.Indent();
TrackVisit(stmt, data);
outputFormatter.NewLine();
outputFormatter.IndentationLevel = oldIndent;
}
if (prettyPrintOptions.IndentCaseBody)
--outputFormatter.IndentationLevel;
return null;
}

11
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/OutputFormatter.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
Stack braceStack = new Stack();
public void BeginBrace(BraceStyle style)
public void BeginBrace(BraceStyle style, bool indent)
{
switch (style) {
case BraceStyle.EndOfLine:
@ -49,6 +49,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -49,6 +49,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
PrintToken(Tokens.OpenCurlyBrace);
NewLine();
if (indent)
++IndentationLevel;
break;
case BraceStyle.NextLine:
@ -56,10 +57,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -56,10 +57,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
Indent();
PrintToken(Tokens.OpenCurlyBrace);
NewLine();
if (indent)
++IndentationLevel;
break;
case BraceStyle.NextLineShifted:
NewLine();
if (indent)
++IndentationLevel;
Indent();
PrintToken(Tokens.OpenCurlyBrace);
@ -67,6 +70,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -67,6 +70,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
break;
case BraceStyle.NextLineShifted2:
NewLine();
if (indent)
++IndentationLevel;
Indent();
PrintToken(Tokens.OpenCurlyBrace);
@ -77,12 +81,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -77,12 +81,13 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
braceStack.Push(style);
}
public void EndBrace()
public void EndBrace(bool indent)
{
BraceStyle style = (BraceStyle)braceStack.Pop();
switch (style) {
case BraceStyle.EndOfLine:
case BraceStyle.NextLine:
if (indent)
--IndentationLevel;
Indent();
PrintToken(Tokens.CloseCurlyBrace);
@ -92,9 +97,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -92,9 +97,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
Indent();
PrintToken(Tokens.CloseCurlyBrace);
NewLine();
if (indent)
--IndentationLevel;
break;
case BraceStyle.NextLineShifted2:
if (indent)
--IndentationLevel;
Indent();
PrintToken(Tokens.CloseCurlyBrace);

127
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/PrettyPrintOptions.cs

@ -213,6 +213,132 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -213,6 +213,132 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
#endregion
#region Indentation
bool indentNamespaceBody = true;
bool indentClassBody = true;
bool indentInterfaceBody = true;
bool indentStructBody = true;
bool indentEnumBody = true;
bool indentMethodBody = true;
bool indentPropertyBody = true;
bool indentEventBody = true;
bool indentBlocks = true;
bool indentSwitchBody = true;
bool indentCaseBody = true;
bool indentBreakStatements = true;
public bool IndentBlocks {
get {
return indentBlocks;
}
set {
indentBlocks = value;
}
}
public bool IndentClassBody {
get {
return indentClassBody;
}
set {
indentClassBody = value;
}
}
public bool IndentStructBody {
get {
return indentStructBody;
}
set {
indentStructBody = value;
}
}
public bool IndentPropertyBody {
get {
return indentPropertyBody;
}
set {
indentPropertyBody = value;
}
}
public bool IndentNamespaceBody {
get {
return indentNamespaceBody;
}
set {
indentNamespaceBody = value;
}
}
public bool IndentMethodBody {
get {
return indentMethodBody;
}
set {
indentMethodBody = value;
}
}
public bool IndentInterfaceBody {
get {
return indentInterfaceBody;
}
set {
indentInterfaceBody = value;
}
}
public bool IndentEventBody {
get {
return indentEventBody;
}
set {
indentEventBody = value;
}
}
public bool IndentEnumBody {
get {
return indentEnumBody;
}
set {
indentEnumBody = value;
}
}
public bool IndentBreakStatements {
get {
return indentBreakStatements;
}
set {
indentBreakStatements = value;
}
}
public bool IndentSwitchBody {
get {
return indentSwitchBody;
}
set {
indentSwitchBody = value;
}
}
public bool IndentCaseBody {
get {
return indentCaseBody;
}
set {
indentCaseBody = value;
}
}
#endregion
#region Before Parentheses
bool beforeMethodCallParentheses = false;
bool beforeDelegateDeclarationParentheses = false;
@ -553,5 +679,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -553,5 +679,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
#endregion
}
}
Loading…
Cancel
Save