diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ba9d456ec42..08dd42868fb 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -151,8 +151,8 @@ jobs: ExecuteOnMoreOSes: ${{ inputs.ExecuteOnMoreOSes || github.event_name == 'schedule' }} ExecuteOnLargerJDKSet: ${{ inputs.ExecuteOnLargerJDKSet || github.ref_name == 'master' || github.event_name == 'schedule' }} EnableLinuxTests: true - EnableWindowsTests: ${{ inputs.ExecuteOnWindows || github.ref_name == 'master' || github.event_name == 'schedule' }} - EnableMacOSTests: ${{ inputs.ExecuteOnMacOS || github.event_name == 'schedule' }} + EnableWindowsTests: ${{ inputs.EnableWindowsTests || github.ref_name == 'master' || github.event_name == 'schedule' }} + EnableMacOSTests: ${{ inputs.EnableMacOSTests || github.event_name == 'schedule' }} ForceContinueOnError: ${{ inputs.ForceContinueOnError || false }} EnableProcessDump: ${{ inputs.EnableProcessDump || '0' }} ProcessDumpType: ${{ inputs.ProcessDumpType || '3' }} @@ -160,4 +160,4 @@ jobs: secrets: actor: ${{ github.actor }} GITHUB_TOKEN_INHERITED: ${{ secrets.GITHUB_TOKEN }} - JCOBRIDGE_ENCODED: ${{ secrets.JCOBRIDGE_ENCODED_2_6_6 }} + JCOBRIDGE_ENCODED: ${{ secrets.JCOBRIDGE_ENCODED_2_6_7 }} diff --git a/.github/workflows/generateclasses.yaml b/.github/workflows/generateclasses.yaml index c7ecbc7a3b6..cde3f69ab0f 100644 --- a/.github/workflows/generateclasses.yaml +++ b/.github/workflows/generateclasses.yaml @@ -25,7 +25,7 @@ jobs: DOTNET_CreateDumpDiagnostics: 1 DOTNET_CreateDumpVerboseDiagnostics: 1 DOTNET_EnableCrashReport: 1 - JCOBRIDGE_LicensePath: ${{ secrets.JCOBRIDGE_ENCODED_2_6_6 }} + JCOBRIDGE_LicensePath: ${{ secrets.JCOBRIDGE_ENCODED_2_6_7 }} # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -54,10 +54,10 @@ jobs: run: mvn "-DbinFolderName=binReflector" --file ./src/jvm/jnetreflector/pom.xml --no-transfer-progress package - name: Clear C# generated files - run: Remove-Item .\src\net\JNet\Generated\* -Recurse -Force -Exclude README.md + run: Remove-Item .\src\net\JNet\Generated\* -Recurse -Force -Exclude README.md,.editorconfig - name: Clear Java generated files - run: Remove-Item .\src\jvm\jnet\src\main\java\org\mases\jnet\generated\* -Recurse -Force -Exclude README.md,.editorconfig + run: Remove-Item .\src\jvm\jnet\src\main\java\org\mases\jnet\generated\* -Recurse -Force -Exclude README.md - run: dotnet build --no-incremental --configuration Release src\net\JNetReflector\JNetReflector.csproj diff --git a/src/net/JNet/Developed/.editorconfig b/src/net/JNet/Developed/.editorconfig new file mode 100644 index 00000000000..cba3cf97dc9 --- /dev/null +++ b/src/net/JNet/Developed/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] +generated_code = true +dotnet_analyzer_diagnostic.severity = none +dotnet_diagnostic.CS0108.severity = none diff --git a/src/net/JNet/JNet.csproj b/src/net/JNet/JNet.csproj index 0fdaecf3501..84cefba520a 100644 --- a/src/net/JNet/JNet.csproj +++ b/src/net/JNet/JNet.csproj @@ -50,7 +50,7 @@ - + All None diff --git a/src/net/JNet/Specific/AsyncEnumerable.cs b/src/net/JNet/Specific/AsyncEnumerable.cs index acd5ead247a..b4baba2711d 100644 --- a/src/net/JNet/Specific/AsyncEnumerable.cs +++ b/src/net/JNet/Specific/AsyncEnumerable.cs @@ -82,7 +82,7 @@ public ValueTask MoveNextAsync() /// The class implementing /// The type of objects to enumerate implementing public abstract class JNetAsyncEnumerable : JVMBridgeBaseEnumerable, IAsyncEnumerable - where TClass : JVMBridgeBase + where TClass : class, IJVMBridgeBase { /// /// Create an instance of diff --git a/src/net/JNetReflector/InternalExtensions.cs b/src/net/JNetReflector/InternalExtensions.cs index 8215dbffbd4..2522ff546b4 100644 --- a/src/net/JNetReflector/InternalExtensions.cs +++ b/src/net/JNetReflector/InternalExtensions.cs @@ -1421,7 +1421,7 @@ public static bool HasJVMBaseClassName(this Class entry, bool usedInGenerics, bo } } - public static string JVMBaseClassName(this Class entry, bool usedInGenerics, bool isListener, bool camel, out bool baseClassIsJVMBridgeBase) + public static string JVMBaseClassName(this Class entry, bool isClassCloseable, bool usedInGenerics, bool isListener, bool camel, out bool baseClassIsJVMBridgeBase) { baseClassIsJVMBridgeBase = false; if (isListener) @@ -1436,7 +1436,8 @@ public static string JVMBaseClassName(this Class entry, bool usedInGenerics, boo { baseClassIsJVMBridgeBase = true; string className = entry.JVMClassName(null, usedInGenerics, false); - return string.Format("MASES.JCOBridge.C2JBridge.JVMBridgeBase<{0}>", className); + return isClassCloseable ? $"MASES.JCOBridge.C2JBridge.JVMBridgeBase<{className}>" + : $"MASES.JCOBridge.C2JBridge.JVMBridgeBaseCore<{className}>"; } try { @@ -1513,7 +1514,8 @@ public static string JVMBaseClassName(this Class entry, bool usedInGenerics, boo { baseClassIsJVMBridgeBase = true; string innerName = entry.JVMClassName(null, usedInGenerics, false); - return string.Format("MASES.JCOBridge.C2JBridge.JVMBridgeBase<{0}>", innerName); + return isClassCloseable ? $"MASES.JCOBridge.C2JBridge.JVMBridgeBase<{innerName}>" + : $"MASES.JCOBridge.C2JBridge.JVMBridgeBaseCore<{innerName}>"; } } else if ((usedInGenerics || !entry.IsJVMGenericClass()) && superCls.IsJVMGenericClass()) @@ -1526,15 +1528,16 @@ public static string JVMBaseClassName(this Class entry, bool usedInGenerics, boo { baseClassIsJVMBridgeBase = true; string className = entry.JVMClassName(null, usedInGenerics, false); - return string.Format("MASES.JCOBridge.C2JBridge.JVMBridgeBase<{0}>", className); + return isClassCloseable ? $"MASES.JCOBridge.C2JBridge.JVMBridgeBase<{className}>" + : $"MASES.JCOBridge.C2JBridge.JVMBridgeBaseCore<{className}>"; } } - public static string JVMBaseInterfaceName(this Class entry, bool usedInGenerics, bool isListener, bool camel) + public static string JVMBaseInterfaceName(this Class entry, bool isClassCloseable, bool usedInGenerics, bool isListener, bool camel) { if (!entry.HasJVMBaseClassName(usedInGenerics, isListener, camel)) return string.Empty; - var fName = entry.JVMBaseClassName(usedInGenerics, isListener, camel, out _); + var fName = entry.JVMBaseClassName(isClassCloseable, usedInGenerics, isListener, camel, out _); return ToFullQualifiedInterfaceName(fName, camel); } diff --git a/src/net/JNetReflector/InternalMethods.cs b/src/net/JNetReflector/InternalMethods.cs index 114df1f4fdf..1b8a773146a 100644 --- a/src/net/JNetReflector/InternalMethods.cs +++ b/src/net/JNetReflector/InternalMethods.cs @@ -766,7 +766,7 @@ static void PrepareSingleClass(this Class jClass, IEnumerable classDefini .Replace(AllPackageClasses.ClassStub.SIMPLECLASS, jClass.JVMClassName(null, false, false)) .Replace(AllPackageClasses.ClassStub.CLASS, jClass.JVMClassName(null, isGeneric, false)) .Replace(AllPackageClasses.ClassStub.HELP, jClass.JavadocHrefUrl(JNetReflectorCore.UseCamel)) - .Replace(AllPackageClasses.ClassStub.BASECLASS, jClass.JVMBaseClassName(isGeneric, false, JNetReflectorCore.UseCamel, out _)) + .Replace(AllPackageClasses.ClassStub.BASECLASS, jClass.JVMBaseClassName(isClassCloseable, isGeneric, false, JNetReflectorCore.UseCamel, out _)) .Replace(AllPackageClasses.ClassStub.WHERECLAUSES, string.Empty); } else @@ -779,7 +779,7 @@ static void PrepareSingleClass(this Class jClass, IEnumerable classDefini .Replace(AllPackageClasses.ClassStub.CLASS, jClass.JVMClassName(new List>(), isGeneric, false)) .Replace(AllPackageClasses.ClassStub.CLASS_DIRECT, jClass.JVMClassName(new List>(), isGeneric, true)) .Replace(AllPackageClasses.ClassStub.HELP, jClass.JavadocHrefUrl(JNetReflectorCore.UseCamel)) - .Replace(AllPackageClasses.ClassStub.BASECLASS, jClass.JVMBaseClassName(isGeneric, jClassIsListener, JNetReflectorCore.UseCamel, out bool baseClassIsJVMBridgeBase) + (isMainClass ? SpecialNames.MainClassPlaceHolder : string.Empty)) + .Replace(AllPackageClasses.ClassStub.BASECLASS, jClass.JVMBaseClassName(isClassCloseable, isGeneric, jClassIsListener, JNetReflectorCore.UseCamel, out bool baseClassIsJVMBridgeBase) + (isMainClass ? SpecialNames.MainClassPlaceHolder : string.Empty)) .Replace(AllPackageClasses.ClassStub.WHERECLAUSES, jClass.WhereClauses(isGeneric, JNetReflectorCore.UseCamel)) .Replace(AllPackageClasses.ClassStub.ISABSTRACT, isClassAbstract ? "true" : "false") .Replace(AllPackageClasses.ClassStub.ISCLOSEABLE, isClassCloseable ? "true" : "false") @@ -796,6 +796,7 @@ static void PrepareSingleClass(this Class jClass, IEnumerable classDefini } else { + constructorClassBlock = jClass.AnalyzeConstructors(classDefinitions, isGeneric, true, baseClassIsJVMBridgeBase).AddTabLevel(1); if (jClass.IsJVMClassWithCallbacks()) { operatorClassBlock = jClass.AnalyzeOperators(classDefinitions, isGeneric, true).AddTabLevel(1); @@ -818,7 +819,7 @@ static void PrepareSingleClass(this Class jClass, IEnumerable classDefini singleInterfaceStr = string.Empty; if (createInterfaceData) { - string baseInterface = jClass.JVMBaseInterfaceName(isGeneric, jClassIsListener, JNetReflectorCore.UseCamel); + string baseInterface = jClass.JVMBaseInterfaceName(isClassCloseable, isGeneric, jClassIsListener, JNetReflectorCore.UseCamel); if (!string.IsNullOrWhiteSpace(baseInterface)) { baseInterface = " : " + baseInterface; @@ -949,7 +950,6 @@ static string AnalyzeConstructors(this Class classDefinition, IEnumerable var paramCount = constructor.ParameterCount; var methodNameOrigin = constructor.Name; - if (paramCount == 0) continue; // default constructor managed from AllClasses template as default for any JCOBridge reflected class bool isDeprecated = constructor.IsDeprecated(); if (!JNetReflectorCore.ReflectDeprecated && isDeprecated) { diff --git a/src/net/JNetReflector/JNetReflector.csproj b/src/net/JNetReflector/JNetReflector.csproj index e82663377a2..2faaa8b2b94 100644 --- a/src/net/JNetReflector/JNetReflector.csproj +++ b/src/net/JNetReflector/JNetReflector.csproj @@ -116,7 +116,7 @@ - + All None diff --git a/src/net/JNetReflector/Templates/AllPackageClassesStubClass.template b/src/net/JNetReflector/Templates/AllPackageClassesStubClass.template index 3fcd612542c..d1881f3f20f 100644 --- a/src/net/JNetReflector/Templates/AllPackageClassesStubClass.template +++ b/src/net/JNetReflector/Templates/AllPackageClassesStubClass.template @@ -4,10 +4,6 @@ public partial class ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER : ALLPACKAGE_CLAS { const string _bridgeClassName = "ALLPACKAGE_CLASSES_STUB_JAVACLASS_PLACEHOLDER"; /// - /// Default constructor: even if the corresponding Java class does not have one, it is mandatory for JCOBridge - /// - public ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDER() { } - /// /// Internal constructor: used internally from JCOBridge /// [global::System.Obsolete("This public initializer is needed for JCOBridge internal use, other uses can produce unidentible behaviors.")] @@ -18,7 +14,7 @@ public partial class ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER : ALLPACKAGE_CLAS public ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDER(params object[] args) : base(args) { } private static readonly global::System.Exception _LocalBridgeClazzException = null; - private static readonly MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType _LocalBridgeClazz = JVMBridgeBase.ClazzOf(_bridgeClassName, out _LocalBridgeClazzException, false); + private static readonly MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType _LocalBridgeClazz = JVMBridgeBaseCore.ClazzOf(_bridgeClassName, out _LocalBridgeClazzException, false); private static MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType LocalBridgeClazz => _LocalBridgeClazz ?? throw _LocalBridgeClazzException ?? new global::System.InvalidOperationException($"Class {_bridgeClassName} was not found."); /// diff --git a/src/net/JNetReflector/Templates/AllPackageClassesStubClassInterfaceOrAbstract.template b/src/net/JNetReflector/Templates/AllPackageClassesStubClassInterfaceOrAbstract.template index 9ca285705ca..10a13ca363d 100644 --- a/src/net/JNetReflector/Templates/AllPackageClassesStubClassInterfaceOrAbstract.template +++ b/src/net/JNetReflector/Templates/AllPackageClassesStubClassInterfaceOrAbstract.template @@ -4,11 +4,6 @@ public partial class ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER : ALLPACKAGE_CLAS { const string _bridgeClassName = "ALLPACKAGE_CLASSES_STUB_JAVACLASS_PLACEHOLDER"; /// - /// Default constructor: even if the corresponding Java class does not have one, it is mandatory for JCOBridge - /// - [global::System.Obsolete("ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDER class represents, in .NET, an instance of a JVM interface or abstract class. This public initializer is needed for JCOBridge internal use, other uses can produce unidentible behaviors.")] - public ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDER() { } - /// /// Internal constructor: used internally from JCOBridge /// [global::System.Obsolete("This public initializer is needed for JCOBridge internal use, other uses can produce unidentible behaviors.")] @@ -20,7 +15,7 @@ public partial class ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER : ALLPACKAGE_CLAS public ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDER(params object[] args) : base(args) { } private static readonly global::System.Exception _LocalBridgeClazzException = null; - private static readonly MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType _LocalBridgeClazz = JVMBridgeBase.ClazzOf(_bridgeClassName, out _LocalBridgeClazzException, false); + private static readonly MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType _LocalBridgeClazz = JVMBridgeBaseCore.ClazzOf(_bridgeClassName, out _LocalBridgeClazzException, false); private static MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType LocalBridgeClazz => _LocalBridgeClazz ?? throw _LocalBridgeClazzException ?? new global::System.InvalidOperationException($"Class {_bridgeClassName} was not found."); /// diff --git a/src/net/JNetReflector/Templates/AllPackageClassesStubClassListener.template b/src/net/JNetReflector/Templates/AllPackageClassesStubClassListener.template index db4f42d67f5..d8a85ef0338 100644 --- a/src/net/JNetReflector/Templates/AllPackageClassesStubClassListener.template +++ b/src/net/JNetReflector/Templates/AllPackageClassesStubClassListener.template @@ -2,10 +2,6 @@ ALLPACKAGE_CLASSES_STUB_CLASS_DECORATION_PLACEHOLDER public partial class ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER : ALLPACKAGE_CLASSES_STUB_BASECLASS_PLACEHOLDER { - /// - /// Default constructor: even if the corresponding Java class does not have one, it is mandatory for JCOBridge - /// - public ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDER() { InitializeHandlers(); } /// /// Internal constructor: used internally from JCOBridge /// @@ -28,15 +24,15 @@ ALLPACKAGE_CLASSES_STUB_LISTENER_CLASS_PLACEHOLDER /// public partial class ALLPACKAGE_CLASSES_STUB_CLASS_DIRECT_PLACEHOLDER : ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER { - /// - /// Default constructor: even if the corresponding Java class does not have one, it is mandatory for JCOBridge - /// - public ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDERDirect() { } /// /// Internal constructor: used internally from JCOBridge /// [global::System.Obsolete("This public initializer is needed for JCOBridge internal use, other uses can produce unidentible behaviors.")] public ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDERDirect(IJVMBridgeBaseInitializer initializer) : base(initializer) { } + /// + /// Generic constructor: it is useful for JCOBridge when there is a derived class which needs to pass arguments to the highest JVMBridgeBase class + /// + public ALLPACKAGE_CLASSES_STUB_SIMPLECLASS_PLACEHOLDERDirect(params object[] args) : base(args) { } /// public override bool AutoInit => false; @@ -46,7 +42,7 @@ public partial class ALLPACKAGE_CLASSES_STUB_CLASS_DIRECT_PLACEHOLDER : ALLPACKA const string _bridgeClassName = "ALLPACKAGE_CLASSES_STUB_JAVACLASS_DIRECT_PLACEHOLDER"; private static readonly global::System.Exception _LocalBridgeClazzException = null; - private static readonly MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType _LocalBridgeClazz = JVMBridgeBase.ClazzOf(_bridgeClassName, out _LocalBridgeClazzException, false); + private static readonly MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType _LocalBridgeClazz = JVMBridgeBaseCore.ClazzOf(_bridgeClassName, out _LocalBridgeClazzException, false); private static MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType LocalBridgeClazz => _LocalBridgeClazz ?? throw _LocalBridgeClazzException ?? new global::System.InvalidOperationException($"Class {_bridgeClassName} was not found."); /// diff --git a/src/net/JNetReflector/Templates/AllPackageClassesStubClassMainClass.template b/src/net/JNetReflector/Templates/AllPackageClassesStubClassMainClass.template index 5749ca90021..d61d9679d8f 100644 --- a/src/net/JNetReflector/Templates/AllPackageClassesStubClassMainClass.template +++ b/src/net/JNetReflector/Templates/AllPackageClassesStubClassMainClass.template @@ -6,14 +6,14 @@ public partial class ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER : MASES.JCOBridge { const string _bridgeClassName = "ALLPACKAGE_CLASSES_STUB_JAVACLASS_PLACEHOLDER"; /// - /// Initialize a new - /// - public ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER() { } - /// /// Internal constructor: used internally from JCOBridge /// [global::System.Obsolete("This public initializer is needed for JCOBridge internal use, other uses can produce unidentible behaviors.")] public ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER(IJVMBridgeBaseInitializer initializer) : base(initializer) { } + /// + /// Initialize a new + /// + public ALLPACKAGE_CLASSES_STUB_CLASS_PLACEHOLDER(params object[] args) : base(args) { } /// public override string BridgeClassName => _bridgeClassName; diff --git a/src/net/JNetReflector/Templates/Templates.cs b/src/net/JNetReflector/Templates/Templates.cs index 2970eff4f57..44fe9701535 100644 --- a/src/net/JNetReflector/Templates/Templates.cs +++ b/src/net/JNetReflector/Templates/Templates.cs @@ -160,7 +160,7 @@ public class ClassStub public static string LISTENER_CLASS_BLOCK = " const string _bridgeClassName = \"ALLPACKAGE_CLASSES_STUB_JAVACLASS_PLACEHOLDER\";" + Environment.NewLine + " private static readonly global::System.Exception _LocalBridgeClazzException = null;" + Environment.NewLine - + " private static readonly MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType _LocalBridgeClazz = JVMBridgeBase.ClazzOf(_bridgeClassName, out _LocalBridgeClazzException, false);" + Environment.NewLine + + " private static readonly MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType _LocalBridgeClazz = JVMBridgeBaseCore.ClazzOf(_bridgeClassName, out _LocalBridgeClazzException, false);" + Environment.NewLine + " private static MASES.JCOBridge.C2JBridge.JVMInterop.IJavaType LocalBridgeClazz => _LocalBridgeClazz ?? throw _LocalBridgeClazzException ?? new global::System.InvalidOperationException($\"Class {_bridgeClassName} was not found.\");" + Environment.NewLine + " " + Environment.NewLine + " /// " + Environment.NewLine