Skip to content

Commit

Permalink
Added management of signature in method invocation (#375)
Browse files Browse the repository at this point in the history
* Added management of signature in method invocation

* Update JNetReflector usage

* Upgrade configuration

* Upgrade test program
  • Loading branch information
masesdevelopers committed Feb 29, 2024
1 parent 2fbc220 commit 12dc650
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/README.md
Expand Up @@ -15,6 +15,7 @@ The configuration is:
"RelativeDestinationCSharpClassPath": "net\\JNet\\Generated",
"RelativeDestinationJavaListenerPath": "jvm\\jnet\\src\\main\\java",
"JavaListenerBasePackage": "org.mases.jnet.generated",
"PreferMethodWithSignature": true,
"OnlyPropertiesForGetterSetter": true,
"ModulesToParse": [
"org.*",
Expand Down
1 change: 1 addition & 0 deletions src/configuration.json
Expand Up @@ -2,6 +2,7 @@
"RelativeDestinationCSharpClassPath": "net\\JNet\\Generated",
"RelativeDestinationJavaListenerPath": "jvm\\jnet\\src\\main\\java",
"JavaListenerBasePackage": "org.mases.jnet.generated",
"PreferMethodWithSignature": true,
"OnlyPropertiesForGetterSetter": true,
"ModulesToParse": [
"org.*",
Expand Down
3 changes: 3 additions & 0 deletions src/documentation/articles/usageReflector.md
Expand Up @@ -26,6 +26,7 @@ jnetreflector -OriginRootPath C:\\myJars -OriginJavadocUrl \"https://thehost/jav
_jnr_ accepts the following command-line switch:

* **ConfigurationFile**: The path where is stored a JSON file containing the tool configuration properties; the JSON items shall be written using the same command-line property names
* **JavaPLocationPath**: The path where the tool will locate javap, default is to use system available
* **OriginRootPath**: The origin path where Jars to be analyzed, and dependencies, are stored
* **OriginJavadocUrl**: The base URL of the Javadoc to be associated to the classes
* **JavadocVersion**: The version of the Javadoc to be associated to the classes, it means the Javadoc tool version used
Expand All @@ -47,6 +48,7 @@ _jnr_ accepts the following command-line switch:
* **ClassesToAvoidJavaListener**: A CSV list of class names to be avoided during generation of Java listener classes
* **NamespacesInConflict**: A CSV list of namespaces in conflict with class name: to this one will be added an "Ns" at the end
* **ClassesInConflict**: A CSV list of classes in conflict with namespace name: to this one will be added an "Class" at the end
* **PreferMethodWithSignature**: The option forces the tool to identify and use signature when available
* **OnlyPropertiesForGetterSetter**: The option forces the tool to convert into properties only getter/setter
* **ReflectDeprecated**: The option forces the tool to write any constructor, method or field marked as deprecated, default is to avoid deprecated
* **AvoidCSharpGenericDefinition**: The option forces the tool to reflect generics without create the C# generic definition
Expand Down Expand Up @@ -79,6 +81,7 @@ The options used are:
"RelativeDestinationCSharpClassPath": "net\\JNet\\Generated",
"RelativeDestinationJavaListenerPath": "jvm\\jnet\\src\\main\\java",
"JavaListenerBasePackage": "org.mases.jnet.generated",
"PreferMethodWithSignature": true,
"OnlyPropertiesForGetterSetter": true,
"ModulesToParse": [
"org.*",
Expand Down
6 changes: 5 additions & 1 deletion src/net/JNet/JNetCoreBase.cs
Expand Up @@ -213,7 +213,11 @@ protected override string[] ProcessCommandLine()

string classPath = string.Empty;
/// <see href="https://www.jcobridge.com/api-clr/html/P_MASES_JCOBridge_C2JBridge_SetupJVMWrapper_ClassPath.htm"/>
#if JNETREFLECTOR
public override string ClassPath => buildClassPath();
#else
public sealed override string ClassPath => buildClassPath();
#endif
/// <summary>
/// A list of paths to be used in initialization of JVM ClassPath
/// </summary>
Expand All @@ -238,7 +242,7 @@ string buildClassPath()
return classPath;
}

#endregion
#endregion

#region Auxiliary Methods
/// <inheritdoc cref="Parser.HelpInfo(int?)"/>
Expand Down
3 changes: 3 additions & 0 deletions src/net/JNetReflector/InternalConst.cs
Expand Up @@ -28,6 +28,7 @@ class CLIParam : MASES.JNet.CLIParam
{
// ReflectorArgs
public const string ConfigurationFile = "ConfigurationFile";
public const string JavaPLocationPath = "JavaPLocationPath";
public const string OriginRootPath = "OriginRootPath";
public const string OriginJavadocUrl = "OriginJavadocUrl";
public const string JavadocVersion = "JavadocVersion";
Expand All @@ -49,6 +50,7 @@ class CLIParam : MASES.JNet.CLIParam
public const string NamespacesToAvoid = "NamespacesToAvoid";
public const string ClassesToAvoid = "ClassesToAvoid";
public const string ClassesToAvoidInGenerics = "ClassesToAvoidInGenerics";
public const string PreferMethodWithSignature = "PreferMethodWithSignature";
public const string OnlyPropertiesForGetterSetter = "OnlyPropertiesForGetterSetter";
public const string ReflectDeprecated = "ReflectDeprecated";
public const string AvoidCSharpGenericDefinition = "AvoidCSharpGenericDefinition";
Expand Down Expand Up @@ -84,6 +86,7 @@ public static string VersionPlaceHolder()
public const string EndGenericDeclaration = ">";
public const string NetObject = "object";
public const string JavaLangAnyType = "?";
public const string JavaLangThrows = "throws";
public const string JavaLangClass = "Java.Lang.Class";
public const string JavaLangVoid = "Java.Lang.Void";
public const string JavaLangObject = "java.lang.Object";
Expand Down
34 changes: 34 additions & 0 deletions src/net/JNetReflector/InternalExtensions.cs
Expand Up @@ -25,6 +25,7 @@
using Java.Lang.Reflect;
using System.Text;
using MASES.JNetReflector.Templates;
using System.Runtime.CompilerServices;

namespace MASES.JNetReflector
{
Expand Down Expand Up @@ -285,6 +286,39 @@ public static string ConvertToJavadoc(this string result)
return result.Replace(SpecialNames.BeginGenericDeclaration, "{").Replace(SpecialNames.EndGenericDeclaration, "}");
}

public static string RemoveThrowsAndCleanupSignature(this string methodSignature)
{
if (methodSignature.Contains(SpecialNames.JavaLangThrows))
{
methodSignature = methodSignature.Substring(0, methodSignature.IndexOf(SpecialNames.JavaLangThrows));
return methodSignature.TrimEnd();
}
else if (methodSignature.EndsWith(';'))
{
return methodSignature.Substring(0, methodSignature.Length - 1);
}
return methodSignature;
}

public static string AddClassNameToSignature(this string methodSignature, string className)
{
int index = methodSignature.IndexOf('(');
if (index == -1) return methodSignature; // not a method

int index2 = methodSignature.Substring(0, index).LastIndexOf(' ');
methodSignature = methodSignature.Insert(index2 + 1, className + ".");

return methodSignature;
}

public static string SignatureFromGenericString(this IReadOnlyDictionary<string, string> methodSignatures, string genString)
{
var filteredGenString = genString.RemoveThrowsAndCleanupSignature();
string signature = null;
methodSignatures.TryGetValue(filteredGenString, out signature);
return signature;
}

#endregion

#region ZipArchiveEntry extension
Expand Down

0 comments on commit 12dc650

Please sign in to comment.