Skip to content

Commit

Permalink
fixed more bugs in namespace name generation
Browse files Browse the repository at this point in the history
  • Loading branch information
beakona committed Jul 29, 2021
1 parent 26aa737 commit 6462f2a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 47 deletions.
105 changes: 65 additions & 40 deletions AutoInterfaceSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,83 @@ public interface IPrintable2
}
}

namespace AutoInterfaceSample
namespace AutoInterfaceSample.Test.TT
{
public class Program
namespace T2
{
public static void Main()
public interface ITest2
{
//System.Diagnostics.Debug.WriteLine(BeaKona.Output.Debug_Person.Info);
IPrintable<int> p = new Person();
p.Print1();
void Play();
}
}

public class PrinterV1 : IPrintable<int>, X.C.D.E.F.G.IPrintable2
namespace T3
{
public int Length => 100;
public int Count => 200;
public void Print1()
public interface ITest2
{
void Play();
}
public void Print2()
{
}
public void Print3()
{
}
public void PrintTest()
{
}
}

public partial class Person //: IPrintable//, IPrintable2
{
private void LogDebug(string name)
namespace T4.T5
{
}
public class Program
{
public static void Main()
{
//System.Diagnostics.Debug.WriteLine(BeaKona.Output.Debug_Person.Info);
IPrintable<int> p = new Person();
p.Print1();
}
}

//[BeaKona.AutoInterface]
[BeaKona.AutoInterface(typeof(ITestable))]
//[BeaKona.AutoInterface(typeof(ITestable))]
//[BeaKona.AutoInterface(typeof(IPrintable), true)]
//[BeaKona.AutoInterface(typeof(IPrintable), false)]
//[BeaKona.AutoInterface(typeof(IPrintable))]//, TemplateBody = "void TestB1() {}"
//[BeaKona.AutoInterface(typeof(IPrintable2))]//, TemplateBody = "void TestB2() {}"
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.PropertyGetter, Filter = "Length", Language = "scriban", Body = "return 1;")]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print(\\d)?", Body = "LogDebug(nameof({{interface}}.{{name}})); {{expression}};")]
private readonly IPrintable<int>? aspect1 = new PrinterV1();
public class PrinterV1 : IPrintable<int>, X.C.D.E.F.G.IPrintable2, T2.ITest2
{
public int Length => 100;
public int Count => 200;
public void Print1()
{
}
public void Print2()
{
}
public void Print3()
{
}
public void PrintTest()
{
}
public void Play()
{
}
}

[BeaKona.AutoInterface(typeof(IPrintable<int>), IncludeBaseInterfaces = false)]
[BeaKona.AutoInterface(typeof(X.C.D.E.F.G.IPrintable2))]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
//[BeaKona.AutoInterface(typeof(ITestable))]
private readonly PrinterV1? aspect2 = new PrinterV1();
public partial class Person //: IPrintable//, IPrintable2
{
private void LogDebug(string name)
{
}

//[BeaKona.AutoInterface]
[BeaKona.AutoInterface(typeof(ITestable))]
//[BeaKona.AutoInterface(typeof(ITestable))]
//[BeaKona.AutoInterface(typeof(IPrintable), true)]
//[BeaKona.AutoInterface(typeof(IPrintable), false)]
//[BeaKona.AutoInterface(typeof(IPrintable))]//, TemplateBody = "void TestB1() {}"
//[BeaKona.AutoInterface(typeof(IPrintable2))]//, TemplateBody = "void TestB2() {}"
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.PropertyGetter, Filter = "Length", Language = "scriban", Body = "return 1;")]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print(\\d)?", Body = "LogDebug(nameof({{interface}}.{{name}})); {{expression}};")]
private readonly IPrintable<int>? aspect1 = new PrinterV1();

[BeaKona.AutoInterface(typeof(IPrintable<int>), IncludeBaseInterfaces = false)]
[BeaKona.AutoInterface(typeof(X.C.D.E.F.G.IPrintable2))]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
//[BeaKona.AutoInterfaceTemplate(BeaKona.AutoInterfaceTargets.Method, Filter = "Print2", Body = "/* */")]
//[BeaKona.AutoInterface(typeof(ITestable))]
private readonly PrinterV1? aspect2 = new PrinterV1();

[BeaKona.AutoInterface(typeof(T2.ITest2))]
private readonly T2.ITest2? aspect3 = new PrinterV1();
}
}
}
}
23 changes: 16 additions & 7 deletions BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -716,13 +716,22 @@ public void WriteNamespaceBeginning(SourceBuilder builder, INamespaceSymbol @nam
{
if (@namespace != null && @namespace.ConstituentNamespaces.Length > 0)
{
builder.AppendIndentation();
builder.Append("namespace");
builder.Append(' ');
builder.AppendLine(GetSourceIdentifier(@namespace));
builder.AppendIndentation();
builder.AppendLine('{');
builder.IncrementIndentation();
List<INamespaceSymbol> containingNamespaces = new();
for (INamespaceSymbol? ct = @namespace; ct != null && ct.IsGlobalNamespace == false; ct = ct.ContainingNamespace)
{
containingNamespaces.Insert(0, ct);
}

if (containingNamespaces.Count > 0)
{
builder.AppendIndentation();
builder.Append("namespace");
builder.Append(' ');
builder.AppendLine(string.Join(".", containingNamespaces.Select(i => GetSourceIdentifier(i))));
builder.AppendIndentation();
builder.AppendLine('{');
builder.IncrementIndentation();
}
}
}

Expand Down

0 comments on commit 6462f2a

Please sign in to comment.