5using System.Collections.Generic;
6using System.Collections.Immutable;
12 [DiagnosticAnalyzer(LanguageNames.CSharp)]
16 private static readonly DiagnosticDescriptor makeNonPublicRule =
17 new DiagnosticDescriptor(
18 Constants.AnalyzerIdentifiers.IsOperationMethodPublic, IsOperationMethodPublicAnalyzerConstants.Title,
19 IsOperationMethodPublicAnalyzerConstants.Message, Constants.Categories.Design,
20 DiagnosticSeverity.Warning,
true,
21 helpLinkUri: HelpUrlBuilder.Build(
24 private static readonly DiagnosticDescriptor makeNonPublicForInterfaceRule =
25 new DiagnosticDescriptor(
26 Constants.AnalyzerIdentifiers.IsOperationMethodPublicForInterface, IsOperationMethodPublicAnalyzerConstants.Title,
27 IsOperationMethodPublicAnalyzerConstants.Message, Constants.Categories.Design,
28 DiagnosticSeverity.Warning,
true,
29 helpLinkUri: HelpUrlBuilder.Build(
33 ImmutableArray.Create(makeNonPublicRule, makeNonPublicForInterfaceRule);
37 context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
38 context.EnableConcurrentExecution();
39 context.RegisterSyntaxNodeAction(AnalyzeMethodDeclaration, SyntaxKind.MethodDeclaration);
42 private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context)
44 var methodNode = (MethodDeclarationSyntax)context.Node;
45 var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodNode);
46 var typeSymbol = methodSymbol.ContainingType;
48 if (typeSymbol.IsStereotype() && methodSymbol.IsDataPortalOperation() &&
49 methodSymbol.DeclaredAccessibility == Accessibility.Public)
51 if(typeSymbol.TypeKind == TypeKind.Interface)
53 context.ReportDiagnostic(Diagnostic.Create(
54 makeNonPublicForInterfaceRule, methodNode.Identifier.GetLocation()));
58 var properties =
new Dictionary<string, string>()
60 [IsOperationMethodPublicAnalyzerConstants.IsSealed] = typeSymbol.IsSealed.ToString()
61 }.ToImmutableDictionary();
63 context.ReportDiagnostic(Diagnostic.Create(makeNonPublicRule,
64 methodNode.Identifier.GetLocation(), properties));
override ImmutableArray< DiagnosticDescriptor > SupportedDiagnostics
override void Initialize(AnalysisContext context)