4using Microsoft.CodeAnalysis;
5using Microsoft.CodeAnalysis.Text;
22 DiagnosticSeverity severity)
24 return new DiagnosticDescriptor(
id, title, messageFormat, category, severity,
true);
32 DiagnosticSeverity severity,
33 params
object?[]? args)
36 .CreateDiagnostic(symbol, args);
41 params
object?[]? args)
43 return Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args);
47 DiagnosticDescriptor descriptor,
48 params
object?[]? args)
50 return Diagnostic.Create(descriptor, symbol.Locations.FirstOrDefault(), args);
81 public static AttributeData?
GetAttribute(
this ISymbol symbol,
string name)
83 return symbol.GetAttributes()
84 .FirstOrDefault(x => x.AttributeClass?.ToDisplayString() == name);
89 return symbol.GetReturnTypeAttributes()
90 .FirstOrDefault(x => x.AttributeClass?.ToDisplayString() == name);
95 context.AddSource(
"BadInteropAttributes.cs",
96 SourceText.From(
@"using System;
97namespace BadScript2.Interop
99 [AttributeUsage(AttributeTargets.Class)]
100 internal sealed class BadInteropApiAttribute : Attribute
102 public string? Name { get; }
103 public bool ConstructorPrivate { get; }
104 public BadInteropApiAttribute(string? name = null, bool constructorPrivate = false)
107 ConstructorPrivate = constructorPrivate;
110 [AttributeUsage(AttributeTargets.Class)]
111 internal sealed class BadInteropObjectAttribute : Attribute
113 public string? TypeName { get; }
114 public Type? BaseType { get; }
115 public BadInteropObjectAttribute(string? typeName = null, Type? baseType = null)
122 [AttributeUsage(AttributeTargets.Method)]
123 internal sealed class BadMethodAttribute : Attribute
125 public string? Name { get; }
126 public string? Description { get; }
127 public BadMethodAttribute(string? name = null, string? description = null)
130 Description = description;
134 [AttributeUsage(AttributeTargets.Property)]
135 internal sealed class BadPropertyAttribute : Attribute
137 public string? Name { get; }
138 public string? Description { get; }
139 public bool ReadOnly { get; }
140 public bool AllowNativeTypes { get; }
141 public BadPropertyAttribute(string? name = null, string? description = null, bool readOnly = false, bool allowNativeTypes = false)
144 Description = description;
146 AllowNativeTypes = allowNativeTypes;
150 [AttributeUsage(AttributeTargets.Parameter)]
151 internal sealed class BadParameterAttribute : Attribute
153 public string? Name { get; }
154 public string? Description { get; }
155 public string? NativeType { get; }
156 public BadParameterAttribute(string? name = null, string? description = null, string? nativeType = null)
159 Description = description;
160 NativeType = nativeType;
164 [AttributeUsage(AttributeTargets.ReturnValue)]
165 internal sealed class BadReturnAttribute : Attribute
167 public string? Description { get; }
168 public bool AllowNativeTypes { get; }
169 public BadReturnAttribute(string? description = null, bool allowNativeTypes = false)
171 Description = description;
172 AllowNativeTypes = allowNativeTypes;
176 internal abstract class BadAutoGeneratedInteropApi : BadScript2.Runtime.Interop.BadInteropApi
178 protected BadAutoGeneratedInteropApi(string apiName) : base(apiName) { }
180 protected virtual void AdditionalData(BadScript2.Runtime.Objects.BadTable target) { }
static ? AttributeData GetInteropObjectAttribute(this ITypeSymbol symbol)
static ? AttributeData GetInteropMethodAttribute(this IMethodSymbol symbol)
const string INTEROP_OBJECT_ATTRIBUTE
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)
static ? AttributeData GetInteropPropertyAttribute(this IPropertySymbol symbol)
const string INTEROP_METHOD_RETURN_ATTRIBUTE
const string INTEROP_PROPERTY_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)