cleanup (not really semantic change)

This commit is contained in:
OMGeeky
2024-06-09 18:39:29 +02:00
parent 72c9f8feb1
commit f5b2c6c5f6
2 changed files with 52 additions and 49 deletions

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis;
@@ -66,7 +65,7 @@ internal class {Helpers.UiElementAttribute} : Attribute
INamedTypeSymbol uiElementAttributeSymbol = context.Compilation.GetTypeByMetadataName( Helpers.UiElementAttribute );
foreach ( IGrouping<INamedTypeSymbol , ISymbol> group in receiver.Fields
.GroupBy<ISymbol , INamedTypeSymbol>( f => f.ContainingType
, SymbolEqualityComparer.Default ) )
, SymbolEqualityComparer.Default ) )
{
var classSource = ProcessClass( group.Key , group , uiElementAttributeSymbol );
if ( classSource == null )
@@ -85,7 +84,7 @@ internal class {Helpers.UiElementAttribute} : Attribute
return null;
List<ISymbol> elementFields = fieldsList.Where( f => GetUiElementAttributeData( f , uiElementAttributeSymbol ) != null ).ToList();
var source = new StringBuilder( $@"// <auto-generated/>
using UnityEngine.UIElements;
@@ -109,7 +108,6 @@ public partial class {classSymbol.Name}
}}
" );
return source.ToString();
}
@@ -188,31 +186,34 @@ public partial class {classSymbol.Name}
public void OnVisitSyntaxNode( GeneratorSyntaxContext context )
{
if ( context.Node is FieldDeclarationSyntax fieldDeclarationSyntax && fieldDeclarationSyntax.AttributeLists.Count > 0 )
switch ( context.Node )
{
foreach ( VariableDeclaratorSyntax variable in fieldDeclarationSyntax.Declaration.Variables )
{
ISymbol symbol = context.SemanticModel.GetDeclaredSymbol( variable ) as IFieldSymbol;
if ( Helpers.IsDerivedFrom( symbol?.ContainingType.BaseType , "AtVisualElement" )
&& symbol.GetAttributes()
.Any( ad => ad.AttributeClass?.ToDisplayString() == Helpers.UiElementAttribute ) )
case FieldDeclarationSyntax fieldDeclarationSyntax when fieldDeclarationSyntax.AttributeLists.Count > 0:
{
Fields.Add( symbol );
foreach ( VariableDeclaratorSyntax variable in fieldDeclarationSyntax.Declaration.Variables )
{
if ( context.SemanticModel.GetDeclaredSymbol( variable ) is IFieldSymbol symbol
&& Helpers.IsDerivedFrom( symbol.ContainingType.BaseType , "AtVisualElement" )
&& symbol.GetAttributes()
.Any( ad => ad.AttributeClass?.ToDisplayString() == Helpers.UiElementAttribute ) )
{
Fields.Add( symbol );
}
}
break;
}
}
}
if ( context.Node is PropertyDeclarationSyntax propertyDeclarationSyntax && propertyDeclarationSyntax.AttributeLists.Count > 0 )
{
ISymbol symbol = context.SemanticModel.GetDeclaredSymbol( propertyDeclarationSyntax ) as IPropertySymbol;
if ( Helpers.IsDerivedFrom( symbol?.ContainingType.BaseType , "AtVisualElement" )
&& symbol.GetAttributes()
.Any( ad => ad.AttributeClass?.ToDisplayString() == Helpers.UiElementAttribute ) )
{
Fields.Add( symbol );
}
case PropertyDeclarationSyntax propertyDeclarationSyntax when propertyDeclarationSyntax.AttributeLists.Count > 0:
{
if ( context.SemanticModel.GetDeclaredSymbol( propertyDeclarationSyntax ) is IPropertySymbol symbol
&& Helpers.IsDerivedFrom( symbol.ContainingType.BaseType , "AtVisualElement" )
&& symbol.GetAttributes()
.Any( ad => ad.AttributeClass?.ToDisplayString() == Helpers.UiElementAttribute ) )
{
Fields.Add( symbol );
}
break;
}
}
}