Skip to content

Commit

Permalink
return: attribute target for properties is abandoned now
Browse files Browse the repository at this point in the history
  • Loading branch information
beakona committed Mar 15, 2024
1 parent 0441c4c commit 0540103
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
13 changes: 10 additions & 3 deletions AutoInterfaceSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ interface ITestInterfaceObsolete

[Obsolete]
[DisallowNull]
ResObject? TestObsoleteProperty { get; }
ResObject? TestObsoleteProperty
{
get;
}

[DisallowNull]
ResObject? TestExpandedProperty
{
[return: MaybeNull]
get;
}

}

[Obsolete]

class ResObject;

[AttributeUsage(AttributeTargets.All)]
Expand Down
26 changes: 3 additions & 23 deletions BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ private void WriteAttribute(SourceBuilder builder, AttributeData attribute, bool

private IEnumerable<AttributeData> GetParameterAttributes(IParameterSymbol parameter)
{
var attributes = parameter.GetAttributes().Where(IsPublicAccess);

foreach (var attribute in attributes)
foreach (var attribute in parameter.GetAttributes().Where(IsPublicAccess))
{
if (attribute.AttributeClass is INamedTypeSymbol attributeClass)
{
Expand All @@ -335,9 +333,7 @@ private IEnumerable<AttributeData> GetParameterAttributes(IParameterSymbol param

private IEnumerable<AttributeData> GetForwardAttributes(ISymbol symbol)
{
var attributes = symbol.GetAttributes().Where(IsPublicAccess);

foreach (var attribute in attributes)
foreach (var attribute in symbol.GetAttributes().Where(IsPublicAccess))
{
if (attribute.AttributeClass is INamedTypeSymbol attributeClass)
{
Expand All @@ -353,19 +349,9 @@ private IEnumerable<AttributeData> GetForwardAttributes(ISymbol symbol)
}
}

private IEnumerable<AttributeData> GetReturnAttributes(ISymbol symbol)
{
return this.GetReturnAttributes(symbol.GetAttributes());
}

private IEnumerable<AttributeData> GetReturnAttributes(IMethodSymbol method)
{
return this.GetReturnAttributes(method.GetReturnTypeAttributes());
}

private IEnumerable<AttributeData> GetReturnAttributes(IEnumerable<AttributeData> attributes)
{
foreach (var attribute in attributes)
foreach (var attribute in method.GetReturnTypeAttributes().Where(IsPublicAccess))
{
if (attribute.AttributeClass is INamedTypeSymbol attributeClass)
{
Expand Down Expand Up @@ -601,7 +587,6 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
PartialTemplate? setterTemplate = this.GetMatchedTemplates(references, setterTarget, property.IsIndexer ? "this" : property.Name);

this.WriteForwardAttributes(builder, property);
this.WriteReturnAttributes(builder, this.GetReturnAttributes(property));

builder.AppendIndentation();
this.WriteTypeReference(builder, property.Type, scope);
Expand Down Expand Up @@ -653,7 +638,6 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
if (property.SetMethod is not null)
{
this.WriteForwardAttributes(builder, property.SetMethod);
this.WriteReturnAttributes(builder, this.GetReturnAttributes(property.SetMethod));

builder.AppendIndentation();
builder.Append("set => ");
Expand Down Expand Up @@ -710,7 +694,6 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
if (property.SetMethod is not null)
{
this.WriteForwardAttributes(builder, property.SetMethod);
this.WriteReturnAttributes(builder, this.GetReturnAttributes(property.SetMethod));

builder.AppendIndentation();
builder.AppendLine("set");
Expand Down Expand Up @@ -770,7 +753,6 @@ public void WriteEventDefinition(SourceBuilder builder, IEventSymbol @event, Sco
PartialTemplate? removerTemplate = this.GetMatchedTemplates(references, AutoInterfaceTargets.EventRemover, @event.Name);

this.WriteForwardAttributes(builder, @event);
this.WriteReturnAttributes(builder, this.GetReturnAttributes(@event));

builder.AppendIndentation();
builder.Append("event");
Expand Down Expand Up @@ -809,7 +791,6 @@ public void WriteEventDefinition(SourceBuilder builder, IEventSymbol @event, Sco
if (@event.AddMethod != null)
{
this.WriteForwardAttributes(builder, @event.AddMethod);
this.WriteReturnAttributes(builder, this.GetReturnAttributes(@event.AddMethod));

builder.AppendIndentation();
builder.AppendLine("add");
Expand Down Expand Up @@ -854,7 +835,6 @@ public void WriteEventDefinition(SourceBuilder builder, IEventSymbol @event, Sco
if (@event.RemoveMethod != null)
{
this.WriteForwardAttributes(builder, @event.RemoveMethod);
this.WriteReturnAttributes(builder, this.GetReturnAttributes(@event.RemoveMethod));

builder.AppendIndentation();
builder.AppendLine("remove");
Expand Down

0 comments on commit 0540103

Please sign in to comment.