From 9c1b89095953e9f9f457ed8c33a11599665952e9 Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Mon, 17 Feb 2020 16:11:34 +0100 Subject: [PATCH] #16: add first implementation of tableEntry analyzer --- GBase/Diagnosis/GBaseTableEntryAnalyzer.cs | 38 ++++++++++++++++++++++ GBase/GBase.csproj | 1 + 2 files changed, 39 insertions(+) create mode 100644 GBase/Diagnosis/GBaseTableEntryAnalyzer.cs diff --git a/GBase/Diagnosis/GBaseTableEntryAnalyzer.cs b/GBase/Diagnosis/GBaseTableEntryAnalyzer.cs new file mode 100644 index 0000000..96503ca --- /dev/null +++ b/GBase/Diagnosis/GBaseTableEntryAnalyzer.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace GBase.Diagnosis +{ + [DiagnosticAnalyzer(LanguageNames.CSharp)] + public class GBaseTableEntryAnalyzer : DiagnosticAnalyzer + { + private const string DIAGNOSTIC_ID = "GBaseTableEntryAnalyzer"; + private const string CATEGORY = "GBaseTableEntryAnalyzer Category"; + + private static readonly LocalizableString _title = "Missing GBaseEntries for this GBaseTable"; + private static readonly LocalizableString _messageFormat = "Type '{0}' is marked as GBaseTable but doesn't contain any GBase entries."; + + private static readonly DiagnosticDescriptor _rule = new DiagnosticDescriptor(DIAGNOSTIC_ID, _title, _messageFormat, CATEGORY, DiagnosticSeverity.Warning, true); + + public override ImmutableArray SupportedDiagnostics { get { return ImmutableArray.Create(_rule); } } + + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); + context.EnableConcurrentExecution(); + context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.Attribute); + } + + private void AnalyzeNode(SyntaxNodeAnalysisContext context) + { + AttributeSyntax attribute = (AttributeSyntax) context.Node; + } + } +} diff --git a/GBase/GBase.csproj b/GBase/GBase.csproj index 42b1313..917f8f6 100644 --- a/GBase/GBase.csproj +++ b/GBase/GBase.csproj @@ -23,6 +23,7 @@ +