A database based on .net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.1 KiB

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using GBase.Attributes;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace GBase.Diagnosis
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class GBaseTableColumnAnalyzer : DiagnosticAnalyzer
{
private const string DIAGNOSTIC_ID = "GBaseTableColumnAnalyzer";
private const string CATEGORY = "GBaseTableColumnAnalyzer Category";
private static readonly LocalizableString _title = "Missing GBaseColumns for this GBaseTable";
private static readonly LocalizableString _messageFormat = "Type '{0}' is marked as GBaseTable but doesn't contain any GBase columns.";
private static readonly DiagnosticDescriptor _rule = new DiagnosticDescriptor(DIAGNOSTIC_ID, _title, _messageFormat, CATEGORY, DiagnosticSeverity.Warning, true);
private bool _nodeAnalyzed;
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(_rule);
private List<ClassDeclarationSyntax> TableClasses { get; }
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeClass, SyntaxKind.ClassDeclaration);
context.RegisterSyntaxNodeAction(AnalyzeMethod, SyntaxKind.MethodDeclaration);
}
private void AnalyzeClass(SyntaxNodeAnalysisContext context)
{
ClassDeclarationSyntax classDeclaration = (ClassDeclarationSyntax) context.Node;
if (!classDeclaration.AttributeLists.SelectMany(l => l.Attributes).Any(a => a.Name.ToString().Equals(nameof(GBaseTableAttribute))))
return;
_nodeAnalyzed = true;
}
private void AnalyzeMethod(SyntaxNodeAnalysisContext context)
{
}
}
}