Browse Source

Fixed SD2-928: Code generation options are ignored

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2198 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
773461f3fb
  1. 13
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  2. 3
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/IOutputAstVisitor.cs
  3. 13
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  4. 32
      src/Main/Base/Project/Src/Services/AmbienceService/AmbienceService.cs
  5. 1
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj
  6. 17
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs
  7. 28
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGeneratorOptions.cs
  8. 37
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryCodeGenerator.cs

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

@ -39,13 +39,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
} }
public object Options { AbstractPrettyPrintOptions IOutputAstVisitor.Options {
get { get { return prettyPrintOptions; }
return prettyPrintOptions; }
}
set { public PrettyPrintOptions Options {
prettyPrintOptions = value as PrettyPrintOptions; get { return prettyPrintOptions; }
}
} }
public IOutputFormatter OutputFormatter { public IOutputFormatter OutputFormatter {

3
src/Libraries/NRefactory/Project/Src/PrettyPrinter/IOutputAstVisitor.cs

@ -27,9 +27,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
get; get;
} }
object Options { AbstractPrettyPrintOptions Options {
get; get;
set;
} }
IOutputFormatter OutputFormatter { IOutputFormatter OutputFormatter {
get; get;

13
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -41,13 +41,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
} }
public object Options { AbstractPrettyPrintOptions IOutputAstVisitor.Options {
get { get { return prettyPrintOptions; }
return prettyPrintOptions; }
}
set { public VBNetPrettyPrintOptions Options {
prettyPrintOptions = value as VBNetPrettyPrintOptions; get { return prettyPrintOptions; }
}
} }
public NodeTracker NodeTracker { public NodeTracker NodeTracker {

32
src/Main/Base/Project/Src/Services/AmbienceService/AmbienceService.cs

@ -8,13 +8,22 @@
using System; using System;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.NRefactory.PrettyPrinter;
namespace ICSharpCode.SharpDevelop namespace ICSharpCode.SharpDevelop
{ {
public static class AmbienceService public static class AmbienceService
{ {
static readonly string ambienceProperty = "SharpDevelop.UI.CurrentAmbience"; const string ambienceProperty = "SharpDevelop.UI.CurrentAmbience";
static readonly string codeGenerationProperty = "SharpDevelop.UI.CodeGenerationOptions"; const string codeGenerationProperty = "SharpDevelop.UI.CodeGenerationOptions";
const string textEditorProperty = "ICSharpCode.TextEditor.Document.Document.DefaultDocumentAggregatorProperties";
static AmbienceService()
{
PropertyService.PropertyChanged += new PropertyChangedEventHandler(PropertyChanged);
ApplyCodeGenerationPropertiesToNRefactory();
}
public static Properties CodeGenerationProperties { public static Properties CodeGenerationProperties {
get { get {
@ -22,6 +31,16 @@ namespace ICSharpCode.SharpDevelop
} }
} }
static void ApplyCodeGenerationPropertiesToNRefactory()
{
Properties p = CodeGenerationProperties;
LanguageProperties.CSharp.CodeGenerator.Options.EmptyLinesBetweenMembers = p.Get("BlankLinesBetweenMembers", true);
LanguageProperties.CSharp.CodeGenerator.Options.BracesOnSameLine = p.Get("StartBlockOnSameLine", true);
System.CodeDom.Compiler.CodeGeneratorOptions cdo = new CodeDOMGeneratorUtility().CreateCodeGeneratorOptions;
LanguageProperties.CSharp.CodeGenerator.Options.IndentString = cdo.IndentString;
}
public static bool GenerateDocumentComments { public static bool GenerateDocumentComments {
get { get {
return CodeGenerationProperties.Get("GenerateDocumentComments", true); return CodeGenerationProperties.Get("GenerateDocumentComments", true);
@ -90,14 +109,11 @@ namespace ICSharpCode.SharpDevelop
defaultAmbience = null; defaultAmbience = null;
OnAmbienceChanged(EventArgs.Empty); OnAmbienceChanged(EventArgs.Empty);
} }
if (e.Key == codeGenerationProperty || e.Key == textEditorProperty) {
ApplyCodeGenerationPropertiesToNRefactory();
}
} }
static AmbienceService()
{
PropertyService.PropertyChanged += new PropertyChangedEventHandler(PropertyChanged);
}
static void OnAmbienceChanged(EventArgs e) static void OnAmbienceChanged(EventArgs e)
{ {
if (AmbienceChanged != null) { if (AmbienceChanged != null) {

1
src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj

@ -88,6 +88,7 @@
<Compile Include="Src\NRefactoryResolver\NRefactoryInformationProvider.cs" /> <Compile Include="Src\NRefactoryResolver\NRefactoryInformationProvider.cs" />
<Compile Include="Src\NRefactoryResolver\NRefactoryResolver.cs" /> <Compile Include="Src\NRefactoryResolver\NRefactoryResolver.cs" />
<Compile Include="Src\NRefactoryResolver\TypeVisitor.cs" /> <Compile Include="Src\NRefactoryResolver\TypeVisitor.cs" />
<Compile Include="Src\Refactoring\CodeGeneratorOptions.cs" />
<Compile Include="Src\ReflectionLayer\DomPersistence.cs" /> <Compile Include="Src\ReflectionLayer\DomPersistence.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionClass.cs" /> <Compile Include="Src\ReflectionLayer\ReflectionClass.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionEvent.cs" /> <Compile Include="Src\ReflectionLayer\ReflectionEvent.cs" />

17
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGenerator.cs

@ -243,6 +243,12 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
} }
#endregion #endregion
readonly CodeGeneratorOptions options = new CodeGeneratorOptions();
public CodeGeneratorOptions Options {
get { return options; }
}
#region Code generation / insertion #region Code generation / insertion
public virtual void InsertCodeAfter(IMember member, IDocument document, params AbstractNode[] nodes) public virtual void InsertCodeAfter(IMember member, IDocument document, params AbstractNode[] nodes)
{ {
@ -258,13 +264,13 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
public virtual void InsertCodeAtEnd(DomRegion region, IDocument document, params AbstractNode[] nodes) public virtual void InsertCodeAtEnd(DomRegion region, IDocument document, params AbstractNode[] nodes)
{ {
InsertCodeAfter(region.EndLine - 1, document, InsertCodeAfter(region.EndLine - 1, document,
GetIndentation(document, region.BeginLine) + '\t', nodes); GetIndentation(document, region.BeginLine) + options.IndentString, nodes);
} }
public virtual void InsertCodeInClass(IClass c, IDocument document, int targetLine, params AbstractNode[] nodes) public virtual void InsertCodeInClass(IClass c, IDocument document, int targetLine, params AbstractNode[] nodes)
{ {
InsertCodeAfter(targetLine, document, InsertCodeAfter(targetLine, document,
GetIndentation(document, c.Region.BeginLine) + '\t', false, nodes); GetIndentation(document, c.Region.BeginLine) + options.IndentString, false, nodes);
} }
protected string GetIndentation(IDocument document, int line) protected string GetIndentation(IDocument document, int line)
@ -291,8 +297,11 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
IDocumentLine lineSegment = document.GetLine(insertLine + 1); IDocumentLine lineSegment = document.GetLine(insertLine + 1);
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
for (int i = 0; i < nodes.Length; i++) { for (int i = 0; i < nodes.Length; i++) {
if (startWithEmptyLine || i > 0) if (options.EmptyLinesBetweenMembers) {
b.AppendLine(indentation); if (startWithEmptyLine || i > 0) {
b.AppendLine(indentation);
}
}
b.Append(GenerateCode(nodes[i], indentation)); b.Append(GenerateCode(nodes[i], indentation));
} }
document.Insert(lineSegment.Offset, b.ToString()); document.Insert(lineSegment.Offset, b.ToString());

28
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/CodeGeneratorOptions.cs

@ -0,0 +1,28 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.SharpDevelop.Dom.Refactoring
{
public class CodeGeneratorOptions
{
public bool BracesOnSameLine = true;
public bool EmptyLinesBetweenMembers = true;
string indentString;
public string IndentString {
get { return indentString; }
set {
if (string.IsNullOrEmpty(value)) {
throw new ArgumentNullException("value");
}
indentString = value;
}
}
}
}

37
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryCodeGenerator.cs

@ -38,11 +38,31 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
public class CSharpCodeGenerator : NRefactoryCodeGenerator public class CSharpCodeGenerator : NRefactoryCodeGenerator
{ {
public static readonly CSharpCodeGenerator Instance = new CSharpCodeGenerator(); internal static readonly CSharpCodeGenerator Instance = new CSharpCodeGenerator();
public override IOutputAstVisitor CreateOutputVisitor() public override IOutputAstVisitor CreateOutputVisitor()
{ {
return new CSharpOutputVisitor(); CSharpOutputVisitor v = new CSharpOutputVisitor();
PrettyPrintOptions pOpt = v.Options;
BraceStyle braceStyle;
if (this.Options.BracesOnSameLine) {
braceStyle = BraceStyle.EndOfLine;
} else {
braceStyle = BraceStyle.NextLine;
}
pOpt.StatementBraceStyle = braceStyle;
pOpt.EventAddBraceStyle = braceStyle;
pOpt.EventRemoveBraceStyle = braceStyle;
pOpt.PropertyBraceStyle = braceStyle;
pOpt.PropertyGetBraceStyle = braceStyle;
pOpt.PropertySetBraceStyle = braceStyle;
pOpt.IndentationChar = this.Options.IndentString[0];
pOpt.IndentSize = this.Options.IndentString.Length;
pOpt.TabSize = this.Options.IndentString.Length;
return v;
} }
/// <summary> /// <summary>
@ -100,17 +120,24 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
} }
} }
} }
InsertCodeAfter(insertionLine, document, beginLineIndentation + '\t', nodes); InsertCodeAfter(insertionLine, document, beginLineIndentation + this.Options.IndentString, nodes);
} }
} }
public class VBNetCodeGenerator : NRefactoryCodeGenerator public class VBNetCodeGenerator : NRefactoryCodeGenerator
{ {
public static readonly VBNetCodeGenerator Instance = new VBNetCodeGenerator(); internal static readonly VBNetCodeGenerator Instance = new VBNetCodeGenerator();
public override IOutputAstVisitor CreateOutputVisitor() public override IOutputAstVisitor CreateOutputVisitor()
{ {
return new VBNetOutputVisitor(); VBNetOutputVisitor v = new VBNetOutputVisitor();
VBNetPrettyPrintOptions pOpt = v.Options;
pOpt.IndentationChar = this.Options.IndentString[0];
pOpt.IndentSize = this.Options.IndentString.Length;
pOpt.TabSize = this.Options.IndentString.Length;
return v;
} }
public override PropertyDeclaration CreateProperty(IField field, bool createGetter, bool createSetter) public override PropertyDeclaration CreateProperty(IField field, bool createGetter, bool createSetter)

Loading…
Cancel
Save