4using Microsoft.CodeAnalysis;
5using Microsoft.CodeAnalysis.Text;
20 DiagnosticSeverity severity)
22 return new DiagnosticDescriptor(
id, title, messageFormat, category, severity,
true);
30 DiagnosticSeverity severity,
31 params
object?[]? args)
34 .CreateDiagnostic(symbol, args);
39 params
object?[]? args)
41 return Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args);
45 DiagnosticDescriptor descriptor,
46 params
object?[]? args)
48 return Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args);
71 public static AttributeData?
GetAttribute(
this ISymbol symbol,
string name)
73 return symbol.GetAttributes()
74 .FirstOrDefault(x => x.AttributeClass?.ToDisplayString() == name);
79 return symbol.GetReturnTypeAttributes()
80 .FirstOrDefault(x => x.AttributeClass?.ToDisplayString() == name);
85 context.AddSource(
"BadInteropAttributes.cs",
86 SourceText.From(
@"using System;
87namespace BadScript2.Interop
89 [AttributeUsage(AttributeTargets.Class)]
90 internal sealed class BadInteropApiAttribute : Attribute
92 public string? Name { get; }
93 public bool ConstructorPrivate { get; }
94 public BadInteropApiAttribute(string? name = null, bool constructorPrivate = false)
97 ConstructorPrivate = constructorPrivate;
101 [AttributeUsage(AttributeTargets.Method)]
102 internal sealed class BadMethodAttribute : Attribute
104 public string? Name { get; }
105 public string? Description { get; }
106 public BadMethodAttribute(string? name = null, string? description = null)
109 Description = description;
113 [AttributeUsage(AttributeTargets.Parameter)]
114 internal sealed class BadParameterAttribute : Attribute
116 public string? Name { get; }
117 public string? Description { get; }
118 public string? NativeType { get; }
119 public BadParameterAttribute(string? name = null, string? description = null, string? nativeType = null)
122 Description = description;
123 NativeType = nativeType;
127 [AttributeUsage(AttributeTargets.ReturnValue)]
128 internal sealed class BadReturnAttribute : Attribute
130 public string? Description { get; }
131 public bool AllowNativeTypes { get; }
132 public BadReturnAttribute(string? description = null, bool allowNativeTypes = false)
134 Description = description;
135 AllowNativeTypes = allowNativeTypes;
139 internal abstract class BadAutoGeneratedInteropApi : BadScript2.Runtime.Interop.BadInteropApi
141 protected BadAutoGeneratedInteropApi(string apiName) : base(apiName) { }
143 protected virtual void AdditionalData(BadScript2.Runtime.Objects.BadTable target) { }
static ? AttributeData GetInteropMethodAttribute(this IMethodSymbol symbol)
static ? AttributeData GetReturnTypeAttribute(this IMethodSymbol symbol, string name)
static ? AttributeData GetParameterAttribute(this IParameterSymbol symbol)
static DiagnosticDescriptor CreateDescriptor(string id, string title, string messageFormat, string category, DiagnosticSeverity severity)
static Diagnostic CreateDiagnostic(this ISymbol symbol, DiagnosticDescriptor descriptor, params object?[]? args)
static ? AttributeData GetReturnTypeAttribute(this IMethodSymbol symbol)
static Diagnostic CreateDiagnostic(this ISymbol symbol, string id, string title, string messageFormat, string category, DiagnosticSeverity severity, params object?[]? args)
const string INTEROP_METHOD_RETURN_ATTRIBUTE
const string INTEROP_METHOD_PARAMETER_ATTRIBUTE
static void RegisterAttributeSource(IncrementalGeneratorPostInitializationContext context)
const string INTEROP_METHOD_ATTRIBUTE
static Diagnostic CreateDiagnostic(this DiagnosticDescriptor descriptor, ISymbol symbol, params object?[]? args)
const string INTEROP_API_ATTRIBUTE
static ? AttributeData GetInteropApiAttribute(this ITypeSymbol symbol)
static ? AttributeData GetAttribute(this ISymbol symbol, string name)