Skip to content

Commit

Permalink
masesgroup#512 (comment): Added invocation of base methods
Browse files Browse the repository at this point in the history
  • Loading branch information
masesdevelopers committed Sep 27, 2024
1 parent 6424962 commit d0b4430
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/net/JNetReflector/InternalConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static string VersionPlaceHolder()
public const string ClassSuffix = "Class";
public const string FieldSuffix = "Field";
public const string MethodSuffix = "Method";
public const string BaseMethodSuffix = "Base";
public const string DefaultMethodSuffix = "Default";
public const string DirectMethodSuffix = "Direct";
public const string NamespaceSuffix = "Ns";
Expand Down
44 changes: 44 additions & 0 deletions src/net/JNetReflector/InternalMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,36 @@ static string AnalyzeMethods(this Class classDefinition, IEnumerable<Class> clas
string baseHandlerName = methodIndexer == 0 ? methodName : (methodIndexer == 1 ? methodName + paramCount : methodName + paramCount + $"_{methodIndexer}");
if (implementMethodAsListener)
{
if (classDefinition.IsJVMClassWithCallbacks())
{
// add base method
jDecoration.AppendLine();
jDecoration.Append(AllPackageClasses.ClassStub.MethodStub.HELP_REMARK_DEFAULT_METHOD);

string methodNameDefault = methodName + SpecialNames.BaseMethodSuffix;
template = Template.GetTemplate(Template.SingleMethodTemplate);
singleMethod = template.Replace(AllPackageClasses.ClassStub.MethodStub.DECORATION, jDecoration.ToString())
.Replace(AllPackageClasses.ClassStub.MethodStub.LISTENER_HANDLER_EXECUTION, listenerHandlerType)
.Replace(AllPackageClasses.ClassStub.MethodStub.LISTENER_HANDLER_NAME, baseHandlerName)
.Replace(AllPackageClasses.ClassStub.MethodStub.MODIFIER, modifier)
.Replace(AllPackageClasses.ClassStub.MethodStub.RETURNTYPE, returnType)
.Replace(AllPackageClasses.ClassStub.MethodStub.NAME, methodNameDefault)
.Replace(AllPackageClasses.ClassStub.MethodStub.PARAMETERS, paramsString)
.Replace(AllPackageClasses.ClassStub.MethodStub.WHERECLAUSES, genericClauses.ConvertClauses(isGeneric))
.Replace(AllPackageClasses.ClassStub.MethodStub.EXECUTION, executionStub.Replace(methodNameOrigin, methodNameOrigin + SpecialNames.BaseMethodSuffix))
.Replace(AllPackageClasses.ClassStub.MethodStub.LISTENER_EXECUTION_TYPE, executionPropertyParams)
.Replace(AllPackageClasses.ClassStub.MethodStub.LISTENER_EXECUTION, listenerExecutionParamsString)
.Replace(AllPackageClasses.ClassStub.MethodStub.HELP, method.JavadocHrefUrl(JNetReflectorCore.UseCamel));

jDecoration = new StringBuilder(jDecorationTemporary);
if (!forInterface)
{
subClassBlock.AppendLine(singleMethod);
jDecoration.AppendLine();
jDecoration.AppendFormat(AllPackageClasses.ClassStub.MethodStub.HELP_REMARK_HANDLER_WITH_DEFAULT, methodNameDefault);
}
}

if (method.IsDefault)
{
jDecoration.AppendLine();
Expand Down Expand Up @@ -2340,6 +2370,20 @@ static string AnalyzeJavaMethods(this Class classDefinition, string extendingInt

subClassBlock.AppendLine(singleMethod);

if (classDefinition.IsJVMClassWithCallbacks())
{
execStub = string.Format(isVoidMethod ? AllPackageClasses.ClassStub.MethodStub.SUPERINTERFACE_VOID_LISTENER_BASE_EXECUTION_FORMAT : AllPackageClasses.ClassStub.MethodStub.SUPERINTERFACE_TYPED_LISTENER_BASE_EXECUTION_FORMAT,
methodNameOrigin, executionParamsString.Length == 0 ? string.Empty : executionParamsString);

var singleBaseMethod = template.Replace(AllPackageClasses.ClassStub.MethodStub.RETURNTYPE, returnType)
.Replace(AllPackageClasses.ClassStub.MethodStub.NAME, methodNameOrigin + SpecialNames.BaseMethodSuffix)
.Replace(AllPackageClasses.ClassStub.MethodStub.PARAMETERS, paramsString)
.Replace(AllPackageClasses.ClassStub.MethodStub.EXTEND_EXCEPTIONS, exceptionsThrowed)
.Replace(AllPackageClasses.ClassStub.MethodStub.EXECUTION, execStub.AddTabLevel(1));

subClassBlock.AppendLine(singleBaseMethod);
}

if (method.IsDefault && isInterfaceJavaListener)
{
execStub = string.Format(isVoidMethod ? AllPackageClasses.ClassStub.MethodStub.SUPERINTERFACE_VOID_LISTENER_EXECUTION_FORMAT : AllPackageClasses.ClassStub.MethodStub.SUPERINTERFACE_TYPED_LISTENER_EXECUTION_FORMAT,
Expand Down
2 changes: 2 additions & 0 deletions src/net/JNetReflector/Templates/Templates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ public class MethodStub
public static string VOID_LISTENER_EXECUTION_FORMAT = "org.mases.jnet.developed.JNetEventResult eventDataExchange = new org.mases.jnet.developed.JNetEventResult();" + Environment.NewLine
+ "raiseEvent(\"{0}\", eventDataExchange{1}); if (!eventDataExchange.getHasOverride()) throw new UnsupportedOperationException(\"The method shall be implemented in .NET side since does not have a default implementation within the JVM\");";
public const string SUPERINTERFACE_VOID_LISTENER_EXECUTION_FORMAT = "{0}.super.{1}({2});";
public const string SUPERINTERFACE_VOID_LISTENER_BASE_EXECUTION_FORMAT = "super.{0}({1});";
public static string SUPERINTERFACE_VOID_DEFAULT_EXECUTION_FORMAT = "org.mases.jnet.developed.JNetEventResult eventDataExchange = new org.mases.jnet.developed.JNetEventResult();" + Environment.NewLine
+ "raiseEvent(\"{0}\", eventDataExchange{1}); if (!eventDataExchange.getHasOverride()) {2}.super.{3}({4});";
public static string SUPERINTERFACE_VOID_ADAPTER_EXECUTION_FORMAT = "org.mases.jnet.developed.JNetEventResult eventDataExchange = new org.mases.jnet.developed.JNetEventResult();" + Environment.NewLine
+ "raiseEvent(\"{0}\", eventDataExchange{1}); if (!eventDataExchange.getHasOverride()) super.{2}({3});";
public static string TYPED_LISTENER_EXECUTION_FORMAT = "org.mases.jnet.developed.JNetEventResult eventDataExchange = new org.mases.jnet.developed.JNetEventResult();" + Environment.NewLine
+ "raiseEvent(\"{0}\", eventDataExchange{1}); if (!eventDataExchange.getHasOverride()) throw new UnsupportedOperationException(\"The method shall be implemented in .NET side since does not have a default implementation within the JVM\"); Object retVal = eventDataExchange.getReturnData(); return ({2})retVal;";
public const string SUPERINTERFACE_TYPED_LISTENER_EXECUTION_FORMAT = "return {0}.super.{1}({2});";
public const string SUPERINTERFACE_TYPED_LISTENER_BASE_EXECUTION_FORMAT = "return super.{0}({1});";
public static string SUPERINTERFACE_TYPED_DEFAULT_EXECUTION_FORMAT = "org.mases.jnet.developed.JNetEventResult eventDataExchange = new org.mases.jnet.developed.JNetEventResult();" + Environment.NewLine
+ "raiseEvent(\"{0}\", eventDataExchange{1}); Object retVal; if (!eventDataExchange.getHasOverride()) retVal = {3}.super.{4}({5}); else retVal = eventDataExchange.getReturnData(); return ({2})retVal;";
public static string SUPERINTERFACE_TYPED_ADAPTER_EXECUTION_FORMAT = "org.mases.jnet.developed.JNetEventResult eventDataExchange = new org.mases.jnet.developed.JNetEventResult();" + Environment.NewLine
Expand Down

0 comments on commit d0b4430

Please sign in to comment.