Skip to content

Commit

Permalink
case where namespace is not generated properly
Browse files Browse the repository at this point in the history
  • Loading branch information
beakona committed Jul 29, 2021
1 parent fb4e57a commit 2611dd2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
31 changes: 24 additions & 7 deletions AutoInterfaceSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
using TestInterfaces;
//using TestInterfaces.A.B;

namespace X.C
{
namespace D
{
namespace E.F
{
namespace G
{
public interface IPrintable2
{
void Print3();
}
}
}
}
}

namespace AutoInterfaceSample
{
Expand All @@ -7,12 +24,12 @@ public class Program
public static void Main()
{
//System.Diagnostics.Debug.WriteLine(BeaKona.Output.Debug_Person.Info);
IPrintable<int> p = new Person();
TestInterfaces.A.B.IPrintable<int> p = new Person();
p.Print1();
}
}

public class PrinterV1 : IPrintable<int>, IPrintable2
public class PrinterV1 : TestInterfaces.A.B.IPrintable<int>, X.C.D.E.F.G.IPrintable2
{
public int Length => 100;
public int Count => 200;
Expand All @@ -37,18 +54,18 @@ private void LogDebug(string name)
}

//[BeaKona.AutoInterface]
[BeaKona.AutoInterface(typeof(ITestable))]
[BeaKona.AutoInterface(typeof(TestInterfaces.A.B.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();
private readonly TestInterfaces.A.B.IPrintable<int>? aspect1 = new PrinterV1();

[BeaKona.AutoInterface(typeof(IPrintable<int>), IncludeBaseInterfaces = false)]
[BeaKona.AutoInterface(typeof(IPrintable2))]
[BeaKona.AutoInterface(typeof(TestInterfaces.A.B.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))]
Expand Down
26 changes: 15 additions & 11 deletions BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BeaKona.AutoInterfaceGenerator
{
Expand Down Expand Up @@ -445,14 +444,14 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
{
IMemberInfo reference = references.First();

if (property.GetMethod is IMethodSymbol)
if (property.GetMethod is not null)
{
builder.AppendIndentation();
builder.Append("get => ");
this.WritePropertyCall(builder, reference, property, scope, SemanticFacts.IsNullable(this.Compilation, property.Type), true);
builder.AppendLine(';');
}
if (property.SetMethod is IMethodSymbol)
if (property.SetMethod is not null)
{
builder.AppendIndentation();
builder.Append("set => ");
Expand All @@ -462,7 +461,7 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
}
else
{
if (property.GetMethod is IMethodSymbol)
if (property.GetMethod is not null)
{
builder.AppendIndentation();
if (getterTemplate != null)
Expand Down Expand Up @@ -503,7 +502,7 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
builder.AppendLine(';');
}
}
if (property.SetMethod is IMethodSymbol)
if (property.SetMethod is not null)
{
builder.AppendIndentation();
builder.AppendLine("set");
Expand Down Expand Up @@ -872,6 +871,16 @@ private string GetSourceIdentifier(ISymbol symbol)
{
return "this";
}
else if (symbol is INamespaceSymbol ns)
{
return ns.Name;
//return string.Join("+", ns.ConstituentNamespaces.Select(i => i.Name));
//return $"<{@namespace.Name};{symbol}>" + this.GetSourceIdentifier(@namespace.Name);
}
else if (symbol.DeclaringSyntaxReferences.Length == 0)
{
return symbol.Name;
}
else
{
foreach (SyntaxReference syntaxReference in symbol.DeclaringSyntaxReferences)
Expand Down Expand Up @@ -941,19 +950,14 @@ private string GetSourceIdentifier(ISymbol symbol)
}
else if (syntax is NamespaceDeclarationSyntax @namespace)
{
return this.GetSourceIdentifier(@namespace.Name);
throw new NotSupportedException(syntax.GetType().ToString());
}
else
{
throw new NotSupportedException(syntax.GetType().ToString());
}
}

if (symbol.DeclaringSyntaxReferences.Length == 0)
{
return symbol.Name;
}

throw new NotSupportedException();
}
}
Expand Down
7 changes: 1 addition & 6 deletions TestInterfaces/Interfaces.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace TestInterfaces
namespace TestInterfaces.A.B
{
public interface ITestable
{
Expand All @@ -14,9 +14,4 @@ public interface IPrintable<T> : ITestable
void Print1();
void Print2();
}

public interface IPrintable2
{
void Print3();
}
}

0 comments on commit 2611dd2

Please sign in to comment.