From d9da28f455eaf73c49464fdf39f258a5cfec0c33 Mon Sep 17 00:00:00 2001 From: Mikael Lindemann Date: Sun, 16 Aug 2020 17:52:04 +0200 Subject: [PATCH] Reimplemented SingleFieldComplexRegionAnalyzer to avoid call to Compilation.GetSemanticModel() --- ...InvalidSingleFieldComplexRegionAnalyzer.cs | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/Piranha.Analyzers/InvalidSingleFieldComplexRegionAnalyzer.cs b/src/Piranha.Analyzers/InvalidSingleFieldComplexRegionAnalyzer.cs index a84f4e2..7c03028 100644 --- a/src/Piranha.Analyzers/InvalidSingleFieldComplexRegionAnalyzer.cs +++ b/src/Piranha.Analyzers/InvalidSingleFieldComplexRegionAnalyzer.cs @@ -68,36 +68,16 @@ namespace Piranha.Analyzers return; } - var references = context.SemanticModel.GetTypeInfo(property.Type).Type.DeclaringSyntaxReferences; + var members = context.SemanticModel.GetTypeInfo(property.Type).Type.GetMembers(); - if (references.IsEmpty) + if (members.IsEmpty) { return; } - var fieldCount = 0; - var fieldAttributeType = context.Compilation.GetTypeByMetadataName(Constants.Types.PiranhaExtendFieldAttribute); + var propCount = members.Count(m => m is IPropertySymbol); - foreach (var reference in references) - { - var node = reference.GetSyntax(context.CancellationToken); - - if (!(node is ClassDeclarationSyntax @class)) - { - return; - } - - var referenceSemanticModel = context.Compilation.GetSemanticModel(node.SyntaxTree); - - // Counts properties marked with FieldAttribute. - fieldCount += @class.Members - .OfType() - .Count(p => p.AttributeLists - .Any(al => al.Attributes - .Any(a => fieldAttributeType.Equals(referenceSemanticModel.GetTypeInfo(a, context.CancellationToken).Type, SymbolEqualityComparer.IncludeNullability)))); - } - - if (fieldCount == 1) + if (propCount == 1) { context.ReportDiagnostic(Diagnostic.Create(Rule, property.GetLocation())); }