Marcin Ziąbek 2 месяцев назад
Родитель
Сommit
21b037fded

+ 0 - 2
Source/QuestPDF.Interop.Generators/QuestPDF.Interop.Generators/ContainerSourceGenerator.cs

@@ -1,7 +1,5 @@
-using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Runtime.InteropServices;
 using Microsoft.CodeAnalysis;
 
 namespace QuestPDF.Interop.Generators;

+ 0 - 1
Source/QuestPDF.Interop.Generators/QuestPDF.Interop.Generators/DescriptorSourceGenerator.cs

@@ -1,4 +1,3 @@
-using System;
 using System.Collections.Generic;
 using System.Linq;
 using Microsoft.CodeAnalysis;

+ 26 - 8
Source/QuestPDF.Interop.Generators/QuestPDF.Interop.Generators/Helpers.cs

@@ -21,6 +21,28 @@ internal static partial class Helpers
 
         return result.ToLowerInvariant();
     }
+
+    public static string ToCamelCase(this string input)
+    {
+        if (string.IsNullOrEmpty(input))
+            return input;
+
+        return char.ToLowerInvariant(input[0]) + input.Substring(1);
+    }
+
+    /// <summary>
+    /// Extracts the unique hash suffix from a native entry point name.
+    /// Native entry points end with a hash like "__a1b2c3d4".
+    /// </summary>
+    public static string ExtractNativeMethodHash(this string nativeEntryPoint)
+    {
+        var lastUnderscore = nativeEntryPoint.LastIndexOf("__");
+        if (lastUnderscore >= 0 && lastUnderscore < nativeEntryPoint.Length - 2)
+        {
+            return nativeEntryPoint.Substring(lastUnderscore + 2);
+        }
+        return nativeEntryPoint.GetHashCode().ToString("x8");
+    }
     
     public static string GetNativeMethodName(this IMethodSymbol methodSymbol, string targetTypeName)
     {
@@ -289,13 +311,6 @@ internal static partial class Helpers
             foreach (var valueTuple in results)
                 yield return valueTuple;
         }
-        
-        // var callbackTypes = methods
-        //     .SelectMany(m => m.Parameters)
-        //     .Where(p => p.Type.IsAction() || p.Type.IsFunc())
-        //     .Select(p => p.Type);
-        //
-        // return callbackTypes.Select(t => (t.GetCallbackTypedefName(), t.GetCallbackTypedefDefinition()));
     }
 
     public static string GetCHeaderDefinition(this IMethodSymbol methodSymbol, string targetTypeName)
@@ -433,7 +448,10 @@ internal static partial class Helpers
         }
     }
     
-    // IEnumearable apply
+    /// <summary>
+    /// Applies a filter function to the method collection.
+    /// Useful for building fluent filter chains.
+    /// </summary>
     public static IEnumerable<IMethodSymbol> Apply(this IEnumerable<IMethodSymbol> methodSymbols, Func<IEnumerable<IMethodSymbol>, IEnumerable<IMethodSymbol>> filter)
     {
         return filter(methodSymbols);

+ 4 - 22
Source/QuestPDF.Interop.Generators/QuestPDF.Interop.Generators/Languages/KotlinLanguageProvider.cs

@@ -43,24 +43,16 @@ public class KotlinLanguageProvider : ILanguageProvider
     {
         return context switch
         {
-            NameContext.Method => ToCamelCase(csharpName),
-            NameContext.Parameter => ToCamelCase(csharpName),
+            NameContext.Method => csharpName.ToCamelCase(),
+            NameContext.Parameter => csharpName.ToCamelCase(),
             NameContext.EnumValue => csharpName, // UpperCamelCase (PascalCase)
-            NameContext.Property => ToCamelCase(csharpName),
+            NameContext.Property => csharpName.ToCamelCase(),
             NameContext.Constant => csharpName.ToSnakeCase().ToUpperInvariant(),
             NameContext.Class => csharpName, // Keep PascalCase
             _ => csharpName
         };
     }
 
-    private static string ToCamelCase(string pascalCase)
-    {
-        if (string.IsNullOrEmpty(pascalCase))
-            return pascalCase;
-
-        return char.ToLowerInvariant(pascalCase[0]) + pascalCase.Substring(1);
-    }
-
     public string GetTargetType(InteropTypeModel type)
     {
         return type.Kind switch
@@ -266,7 +258,7 @@ public class KotlinLanguageProvider : ILanguageProvider
         var returnClassName = kotlinReturnType != "Unit" ? kotlinReturnType : null;
 
         // Extract unique ID from native entry point
-        var uniqueId = ExtractUniqueId(method.NativeEntryPoint);
+        var uniqueId = method.NativeEntryPoint.ExtractNativeMethodHash();
 
         // Use disambiguated name for overloads
         var methodName = method.IsOverload
@@ -310,16 +302,6 @@ public class KotlinLanguageProvider : ILanguageProvider
         };
     }
 
-    private static string ExtractUniqueId(string nativeEntryPoint)
-    {
-        var lastUnderscore = nativeEntryPoint.LastIndexOf("__");
-        if (lastUnderscore >= 0 && lastUnderscore < nativeEntryPoint.Length - 2)
-        {
-            return nativeEntryPoint.Substring(lastUnderscore + 2);
-        }
-        return nativeEntryPoint.GetHashCode().ToString("x8");
-    }
-
     private string GetReturnTypeName(InteropMethodModel method)
     {
         if (method.ReturnType.Kind == InteropTypeKind.Void)

+ 0 - 5
Source/QuestPDF.Interop.Generators/QuestPDF.Interop.Generators/Languages/LanguageProviderRegistry.cs

@@ -20,11 +20,6 @@ public static class LanguageProviderRegistry
     /// </summary>
     public static ILanguageProvider Python => Providers["Python"];
 
-    /// <summary>
-    /// Gets the Java language provider.
-    /// </summary>
-    public static ILanguageProvider Java => Providers["Java"];
-
     /// <summary>
     /// Gets the TypeScript language provider.
     /// </summary>

+ 4 - 23
Source/QuestPDF.Interop.Generators/QuestPDF.Interop.Generators/Languages/TypeScriptLanguageProvider.cs

@@ -23,24 +23,16 @@ public class TypeScriptLanguageProvider : ILanguageProvider
     {
         return context switch
         {
-            NameContext.Method => ToCamelCase(csharpName),
-            NameContext.Parameter => ToCamelCase(csharpName),
+            NameContext.Method => csharpName.ToCamelCase(),
+            NameContext.Parameter => csharpName.ToCamelCase(),
             NameContext.EnumValue => csharpName, // Keep PascalCase for enum values in TypeScript
-            NameContext.Property => ToCamelCase(csharpName),
+            NameContext.Property => csharpName.ToCamelCase(),
             NameContext.Constant => csharpName.ToSnakeCase().ToUpperInvariant(),
             NameContext.Class => csharpName, // Keep PascalCase
             _ => csharpName
         };
     }
 
-    private static string ToCamelCase(string pascalCase)
-    {
-        if (string.IsNullOrEmpty(pascalCase))
-            return pascalCase;
-
-        return char.ToLowerInvariant(pascalCase[0]) + pascalCase.Substring(1);
-    }
-
     public string GetTargetType(InteropTypeModel type)
     {
         return type.Kind switch
@@ -212,7 +204,7 @@ public class TypeScriptLanguageProvider : ILanguageProvider
         var returnClassName = tsReturnType != "void" ? tsReturnType : null;
 
         // Extract unique ID from native entry point (the hash at the end)
-        var uniqueId = ExtractUniqueId(method.NativeEntryPoint);
+        var uniqueId = method.NativeEntryPoint.ExtractNativeMethodHash();
 
         // Use disambiguated name for overloads (makes them private with _prefix)
         var methodName = method.IsOverload
@@ -240,17 +232,6 @@ public class TypeScriptLanguageProvider : ILanguageProvider
         };
     }
 
-    private static string ExtractUniqueId(string nativeEntryPoint)
-    {
-        // Native entry points end with a hash like "__a1b2c3d4"
-        var lastUnderscore = nativeEntryPoint.LastIndexOf("__");
-        if (lastUnderscore >= 0 && lastUnderscore < nativeEntryPoint.Length - 2)
-        {
-            return nativeEntryPoint.Substring(lastUnderscore + 2);
-        }
-        return nativeEntryPoint.GetHashCode().ToString("x8");
-    }
-
     private string GetReturnTypeName(InteropMethodModel method)
     {
         if (method.ReturnType.Kind == InteropTypeKind.Void)

+ 2 - 2
Source/QuestPDF.Interop.Generators/QuestPDF.Interop.Generators/Models/InteropModelBuilder.cs

@@ -70,11 +70,11 @@ internal static class InteropModelBuilder
             }
             else
             {
-                // Multiple methods with same name - mark as overloads
+                // Multiple methods with same name - mark as overloads and generate suffixes
                 foreach (var method in groupMethods)
                 {
                     method.IsOverload = true;
-                   // method.OverloadSuffix = index.ToString();
+                    method.OverloadSuffix = GenerateOverloadSuffix(method);
                     method.DisambiguatedName = method.OriginalName + method.OverloadSuffix;
                 }
 

+ 0 - 2
Source/QuestPDF.Interop.Generators/QuestPDF.Interop.Generators/ObjectSourceGeneratorBase.cs

@@ -1,7 +1,5 @@
-using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Runtime.InteropServices;
 using Microsoft.CodeAnalysis;
 using QuestPDF.Interop.Generators.Languages;
 using QuestPDF.Interop.Generators.Models;