Skip to content

Commit

Permalink
Fixing issue #17
Browse files Browse the repository at this point in the history
  • Loading branch information
beakona committed Nov 30, 2023
1 parent 746ff19 commit dc35de0
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 88 deletions.
55 changes: 18 additions & 37 deletions AutoInterfaceSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,41 @@ public static void Main()
//p.Method(1, out f, ref g, "t", 1, 2, 3);

IPrintableComplex p = new Person2();
//p.Print();
p.Print();
p.PrintComplex();
}
}

interface IPrintableComplex
{
[Obsolete("ok", false)]
void Print();
void PrintComplex();

[Obsolete("12")]
int Count
{
get;
[Obsolete("ok3")]
set;
}

int Count2
{
//[Obsolete("cd2")]
get;
}

[Obsolete("cd")]
int this[int a]
{
[Obsolete("cd3")]
get;
}
}

public class SimplePrinter
public class SimplePrinter //: IPrintableComplex
{
public void Print() { Console.WriteLine("OK"); }
public void PrintComplex() { Console.WriteLine("OK2"); }

public int Count
{
get;
set;
}

public int Count2 => 10;
public int this[int a] => 10;
public void PrintComplex() { Console.WriteLine("OKC"); }
}

public partial class Person2 : IPrintableComplex
public partial class Person2 //: IPrintableComplex
{
[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = false)]
private readonly SimplePrinter aspect1 = new SimplePrinter();
//[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = true, MemberMatch = BeaKona.MemberMatchTypes.Public)]
//private readonly SimplePrinter aspect1 = new SimplePrinter();

//[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = true, MemberMatch = BeaKona.MemberMatchTypes.Explicit)]
//private readonly SimplePrinter aspect2 = new SimplePrinter();

[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = true)]
private readonly SimplePrinter aspect3 = new SimplePrinter();

//[BeaKona.AutoInterface(typeof(IPrintableComplex), AllowMissingMembers = true, MemberMatch = BeaKona.MemberMatchTypes.Any)]
//private readonly SimplePrinter aspect4 = new SimplePrinter();

//void IPrintableComplex.PrintComplex() => Console.WriteLine("OKC2");

public void PrintComplex() { Console.WriteLine("Oh, K."); }
//void IPrintableComplex.PrintComplex() { Console.WriteLine("Oh, K."); }
}


Expand Down
1 change: 1 addition & 0 deletions BeaKona.AutoInterfaceAttributes/AutoInterfaceAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public AutoInterfaceAttribute(Type type)
public string? TemplateBody { get; set; }
public string? TemplateFileName { get; set; }
public bool AllowMissingMembers { get; set; }
public MemberMatchTypes MemberMatch { get; set; }
}
8 changes: 8 additions & 0 deletions BeaKona.AutoInterfaceAttributes/MemberMatchTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BeaKona;

public enum MemberMatchTypes
{
Explicit,
Public,
Any,
}
4 changes: 3 additions & 1 deletion BeaKona.AutoInterfaceGenerator/AutoInterfaceRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace BeaKona.AutoInterfaceGenerator;

internal sealed class AutoInterfaceRecord : IMemberInfo
{
public AutoInterfaceRecord(ISymbol member, ITypeSymbol receiverType, INamedTypeSymbol interfaceType, TemplateDefinition? template, List<PartialTemplate> templateParts, bool bySignature, bool preferCoalesce, bool allowMissingMembers)
public AutoInterfaceRecord(ISymbol member, ITypeSymbol receiverType, INamedTypeSymbol interfaceType, TemplateDefinition? template, List<PartialTemplate> templateParts, bool bySignature, bool preferCoalesce, bool allowMissingMembers, MemberMatchTypes memberMatch)
{
this.Member = member;
this.ReceiverType = receiverType;
Expand All @@ -14,6 +14,7 @@ public AutoInterfaceRecord(ISymbol member, ITypeSymbol receiverType, INamedTypeS
this.BySignature = bySignature;
this.PreferCoalesce = preferCoalesce;
this.AllowMissingMembers = allowMissingMembers;
this.MemberMatch = memberMatch;
}

public ISymbol Member { get; }
Expand All @@ -24,4 +25,5 @@ public AutoInterfaceRecord(ISymbol member, ITypeSymbol receiverType, INamedTypeS
public bool BySignature { get; }
public bool PreferCoalesce { get; }
public bool AllowMissingMembers { get; }
public MemberMatchTypes MemberMatch { get; }
}
113 changes: 72 additions & 41 deletions BeaKona.AutoInterfaceGenerator/AutoInterfaceSourceGenerator.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<RepositoryUrl>https://github.com/beakona/AutoInterface</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_AddAnalyzersToOutput</TargetsForTfmSpecificContentInPackage>
<Version>1.0.30</Version>
<Version>1.0.31</Version>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions BeaKona.AutoInterfaceGenerator/ComparerBySignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public sealed class ComparerBySignature : IEqualityComparer<ISymbol>

public bool Equals(ISymbol s1, ISymbol s2)
{
//should we check s1/s2.DeclaredAccessibility to be Accessibility.Public || Accessibility.NotApplicable??

if (s1.Kind == s2.Kind)
{
if (s1.Kind == SymbolKind.Method)
Expand Down
1 change: 1 addition & 0 deletions BeaKona.AutoInterfaceGenerator/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void ReportDiagnostic(GeneratorExecutionContext context, string id
var lDescription = new LocalizableResourceString(description, AutoInterfaceResource.ResourceManager, typeof(AutoInterfaceResource));
var category = typeof(AutoInterfaceSourceGenerator).Namespace;
var link = "https://github.com/beakona/AutoInterface";

var dd = new DiagnosticDescriptor(id, lTitle, lMessage, category, severity, true, lDescription, link, WellKnownDiagnosticTags.NotConfigurable);
var d = Diagnostic.Create(dd, location, messageArgs);
context.ReportDiagnostic(d);
Expand Down
1 change: 1 addition & 0 deletions BeaKona.AutoInterfaceGenerator/IMemberInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ internal interface IMemberInfo
bool BySignature { get; }
bool PreferCoalesce { get; }
bool AllowMissingMembers { get; }
MemberMatchTypes MemberMatch { get; }
}
10 changes: 5 additions & 5 deletions BeaKona.AutoInterfaceGenerator/ITypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public static bool IsMemberImplementedExplicitly(this ITypeSymbol @this, ISymbol
};
}

public static bool IsMemberImplemented(this ITypeSymbol @this, ISymbol member)
{
ISymbol? implementation = @this.FindImplementationForInterfaceMember(member);
//public static bool IsMemberImplemented(this ITypeSymbol @this, ISymbol member)
//{
// ISymbol? implementation = @this.FindImplementationForInterfaceMember(member);

return implementation is not null && implementation.IsStatic == false && implementation.ContainingType.Equals(@this, SymbolEqualityComparer.Default);
}
// return implementation is not null && implementation.IsStatic == false && implementation.ContainingType.Equals(@this, SymbolEqualityComparer.Default);
//}

public static ISymbol? FindImplementationForInterfaceMemberBySignature(this ITypeSymbol @this, ISymbol interfaceMember)
{
Expand Down
6 changes: 3 additions & 3 deletions BeaKona.AutoInterfaceGenerator/Templates/PartialTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public PartialTemplate(AutoInterfaceTargets memberTargets, Regex? memberFilter,
{
if (ts[1].template.MemberFilter != null)
{
Helpers.ReportDiagnostic(context, "BK-AG16", nameof(AutoInterfaceResource.AG16_title), nameof(AutoInterfaceResource.AG16_message), nameof(AutoInterfaceResource.AG16_description), DiagnosticSeverity.Error, ts[0].reference,
Helpers.ReportDiagnostic(context, "BKAG16", nameof(AutoInterfaceResource.AG16_title), nameof(AutoInterfaceResource.AG16_message), nameof(AutoInterfaceResource.AG16_description), DiagnosticSeverity.Error, ts[0].reference,
name);
return null;
}
Expand All @@ -47,13 +47,13 @@ public PartialTemplate(AutoInterfaceTargets memberTargets, Regex? memberFilter,
}
else
{
Helpers.ReportDiagnostic(context, "BK-AG16", nameof(AutoInterfaceResource.AG16_title), nameof(AutoInterfaceResource.AG16_message), nameof(AutoInterfaceResource.AG16_description), DiagnosticSeverity.Error, ts[0].reference,
Helpers.ReportDiagnostic(context, "BKAG16", nameof(AutoInterfaceResource.AG16_title), nameof(AutoInterfaceResource.AG16_message), nameof(AutoInterfaceResource.AG16_description), DiagnosticSeverity.Error, ts[0].reference,
name);
return null;
}
}
default:
Helpers.ReportDiagnostic(context, "BK-AG16", nameof(AutoInterfaceResource.AG16_title), nameof(AutoInterfaceResource.AG16_message), nameof(AutoInterfaceResource.AG16_description), DiagnosticSeverity.Error, ts[0].reference,
Helpers.ReportDiagnostic(context, "BKAG16", nameof(AutoInterfaceResource.AG16_title), nameof(AutoInterfaceResource.AG16_message), nameof(AutoInterfaceResource.AG16_description), DiagnosticSeverity.Error, ts[0].reference,
name);
return null;
}
Expand Down

0 comments on commit dc35de0

Please sign in to comment.