6using System.Collections.Immutable;
10 [DiagnosticAnalyzer(LanguageNames.CSharp)]
14 private static readonly DiagnosticDescriptor operationUsageRule =
15 new DiagnosticDescriptor(
16 Constants.AnalyzerIdentifiers.IsOperationAttributeUsageCorrect, EvaluateOperationAttributeUsageAnalyzerConstants.Title,
17 EvaluateOperationAttributeUsageAnalyzerConstants.Message, Constants.Categories.Usage,
18 DiagnosticSeverity.Error,
true,
19 helpLinkUri: HelpUrlBuilder.Build(
22 public override ImmutableArray<DiagnosticDescriptor>
SupportedDiagnostics => ImmutableArray.Create(operationUsageRule);
26 context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
27 context.EnableConcurrentExecution();
28 context.RegisterSyntaxNodeAction(AnalyzerAttributeDeclaration, SyntaxKind.Attribute);
31 private static void AnalyzerAttributeDeclaration(SyntaxNodeAnalysisContext context)
33 var attributeNode = (AttributeSyntax)context.Node;
34 var attributeSymbol = context.SemanticModel.GetSymbolInfo(attributeNode).Symbol.ContainingSymbol as ITypeSymbol;
36 if (attributeSymbol.IsDataPortalOperationAttribute())
38 var methodNode = attributeNode.FindParent<MethodDeclarationSyntax>();
39 var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodNode);
40 var typeSymbol = methodSymbol.ContainingType;
42 if (!typeSymbol.IsStereotype() || methodSymbol.IsStatic)
44 context.ReportDiagnostic(Diagnostic.Create(
45 operationUsageRule, attributeNode.GetLocation()));
override void Initialize(AnalysisContext context)
override ImmutableArray< DiagnosticDescriptor > SupportedDiagnostics