Skip to content

Commit c62fb62

Browse files
committed
NativeAnnotationAttribute is generated when not included in config's name exclusion list.
1 parent 3c06eba commit c62fb62

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public sealed partial class PInvokeGenerator : IDisposable
6565
private readonly HashSet<string> _usedRemappings;
6666
private readonly string _placeholderMacroType;
6767

68-
private bool _hasAnnotateAttr;
69-
7068
private string _filePath;
7169
private string[] _clangCommandLineArgs;
7270
private CXTranslationUnit_Flags _translationFlags;
@@ -800,16 +798,18 @@ static void GenerateNativeTypeNameAttribute(PInvokeGenerator generator, Stream?
800798

801799
static void GenerateNativeAnnotationAttribute(PInvokeGenerator generator, Stream? stream, bool leaveStreamOpen)
802800
{
801+
const string AttributeName = "NativeAnnotationAttribute";
803802
var config = generator.Config;
804803

805-
if (!generator._hasAnnotateAttr)
804+
var ns = generator.GetNamespace(AttributeName);
805+
if (config.ExcludedNames.Contains(AttributeName) || config.ExcludedNames.Contains($"{ns}.{AttributeName}"))
806806
{
807807
return;
808808
}
809809

810810
if (stream is null)
811811
{
812-
var outputPath = Path.Combine(config.OutputLocation, "NativeAnnotationAttribute.cs");
812+
var outputPath = Path.Combine(config.OutputLocation, $"{AttributeName}.cs");
813813
stream = generator._outputStreamFactory(outputPath);
814814
}
815815

@@ -828,7 +828,7 @@ static void GenerateNativeAnnotationAttribute(PInvokeGenerator generator, Stream
828828
sw.WriteLine();
829829

830830
sw.Write("namespace ");
831-
sw.Write(generator.GetNamespace("NativeAnnotationAttribute"));
831+
sw.Write(ns);
832832

833833
if (generator.Config.GenerateFileScopedNamespaces)
834834
{
@@ -849,18 +849,18 @@ static void GenerateNativeAnnotationAttribute(PInvokeGenerator generator, Stream
849849
sw.Write(indentString);
850850
sw.WriteLine("[Conditional(\"DEBUG\")]");
851851
sw.Write(indentString);
852-
sw.WriteLine("internal sealed partial class NativeAnnotationAttribute : Attribute");
852+
sw.WriteLine($"internal sealed partial class {AttributeName} : Attribute");
853853
sw.Write(indentString);
854854
sw.WriteLine('{');
855855
sw.Write(indentString);
856856
sw.WriteLine(" private readonly string _annotation;");
857857
sw.WriteLine();
858858
sw.Write(indentString);
859-
sw.WriteLine(" /// <summary>Initializes a new instance of the <see cref=\"NativeAnnotationAttribute\" /> class.</summary>");
859+
sw.WriteLine($" /// <summary>Initializes a new instance of the <see cref=\"{AttributeName}\" /> class.</summary>");
860860
sw.Write(indentString);
861861
sw.WriteLine(" /// <param name=\"annotation\">The annotation that was used in the native declaration.</param>");
862862
sw.Write(indentString);
863-
sw.WriteLine(" public NativeAnnotationAttribute(string annotation)");
863+
sw.WriteLine($" public {AttributeName}(string annotation)");
864864
sw.Write(indentString);
865865
sw.WriteLine(" {");
866866
sw.Write(indentString);
@@ -6817,7 +6817,6 @@ private void WithAttributes(NamedDecl namedDecl, bool onlySupportedOSPlatform =
68176817

68186818
case CX_AttrKind_Annotate:
68196819
{
6820-
_hasAnnotateAttr = true;
68216820
var annotationText = attr.Spelling;
68226821
outputBuilder.WriteCustomAttribute($"""NativeAnnotation("{annotationText}")""");
68236822
break;

0 commit comments

Comments
 (0)