mirror of
https://github.com/OMGeeky/UnityCodeGenerators.git
synced 2025-12-27 23:08:04 +01:00
cleanup (not really semantic change)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user