| 1 | using Microsoft.CodeAnalysis; |
| 2 | using Microsoft.CodeAnalysis.CSharp.Syntax; |
| 3 | |
| 4 | namespace Godot.SourceGenerators.Internal; |
| 5 | |
| 6 | internal static class Common |
| 7 | { |
| 8 | public static void ReportNonPartialUnmanagedCallbacksClass( |
| 9 | GeneratorExecutionContext context, |
| 10 | ClassDeclarationSyntax cds, INamedTypeSymbol symbol |
| 11 | ) |
| 12 | { |
| 13 | string message = |
| 14 | "Missing partial modifier on declaration of type '" + |
| 15 | $"{symbol.FullQualifiedNameOmitGlobal()}' which has attribute '{GeneratorClasses.GenerateUnmanagedCallbacksAttr}'"; |
| 16 | |
| 17 | string description = $"{message}. Classes with attribute '{GeneratorClasses.GenerateUnmanagedCallbacksAttr}' " + |
| 18 | "must be declared with the partial modifier."; |
| 19 | |
| 20 | context.ReportDiagnostic(Diagnostic.Create( |
| 21 | new DiagnosticDescriptor(id: "GODOT-INTERNAL-G0001", |
| 22 | title: message, |
| 23 | messageFormat: message, |
| 24 | category: "Usage", |
| 25 | DiagnosticSeverity.Error, |
| 26 | isEnabledByDefault: true, |
| 27 | description), |
| 28 | cds.GetLocation(), |
| 29 | cds.SyntaxTree.FilePath)); |
| 30 | } |
| 31 | |
| 32 | public static void ReportNonPartialUnmanagedCallbacksOuterClass( |
| 33 | GeneratorExecutionContext context, |
| 34 | TypeDeclarationSyntax outerTypeDeclSyntax |
| 35 | ) |
| 36 | { |
| 37 | var outerSymbol = context.Compilation |
| 38 | .GetSemanticModel(outerTypeDeclSyntax.SyntaxTree) |
| 39 | .GetDeclaredSymbol(outerTypeDeclSyntax); |
| 40 | |
| 41 | string fullQualifiedName = outerSymbol is INamedTypeSymbol namedTypeSymbol ? |
| 42 | namedTypeSymbol.FullQualifiedNameOmitGlobal() : |
| 43 | "type not found"; |
| 44 | |
| 45 | string message = |
| 46 | $"Missing partial modifier on declaration of type '{fullQualifiedName}', " + |
| 47 | $"which contains one or more subclasses with attribute " + |
| 48 | $"'{GeneratorClasses.GenerateUnmanagedCallbacksAttr}'"; |
| 49 | |
| 50 | string description = $"{message}. Classes with attribute " + |
| 51 | $"'{GeneratorClasses.GenerateUnmanagedCallbacksAttr}' and their " + |
| 52 | "containing types must be declared with the partial modifier."; |
| 53 | |
| 54 | context.ReportDiagnostic(Diagnostic.Create( |
| 55 | new DiagnosticDescriptor(id: "GODOT-INTERNAL-G0002", |
| 56 | title: message, |
| 57 | messageFormat: message, |
| 58 | category: "Usage", |
| 59 | DiagnosticSeverity.Error, |
| 60 | isEnabledByDefault: true, |
| 61 | description), |
| 62 | outerTypeDeclSyntax.GetLocation(), |
| 63 | outerTypeDeclSyntax.SyntaxTree.FilePath)); |
| 64 | } |
| 65 | } |