From e83190ba520314e6e08c0879c10ab5f76bb7ac84 Mon Sep 17 00:00:00 2001 From: Natan Date: Thu, 29 Aug 2024 21:57:11 -0300 Subject: [PATCH] Parse cpp callbacks --- .../xpenatan/jparser/example/app/AppTest.java | 2 +- .../xpenatan/jparser/example/app/TestLib.java | 165 ++++++++++++- .../lib/lib-build/src/main/cpp/TestLib.idl | 50 ++-- .../src/main/cpp/source/TestLib/src/TestLib.h | 26 +- .../xpenatan/jparser/core/JParserHelper.java | 4 + .../xpenatan/jparser/cpp/CppCodeParser.java | 227 +++++++++++++++++- .../jparser/cpp/JNITypeSignature.java | 31 +++ .../xpenatan/jparser/idl/IDLMethod.java | 18 +- .../xpenatan/jparser/idl/IDLParameter.java | 25 +- .../jparser/idl/parser/IDLCallbackParser.java | 94 +++++++- .../idl/parser/IDLConstructorParser.java | 2 +- .../idl/parser/IDLDeConstructorParser.java | 2 +- .../idl/parser/IDLDefaultCodeParser.java | 5 +- .../jparser/idl/parser/IDLMethodParser.java | 36 ++- .../jparser/teavm/TeaVMCodeParser.java | 2 +- 15 files changed, 617 insertions(+), 72 deletions(-) create mode 100644 jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/JNITypeSignature.java diff --git a/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/AppTest.java b/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/AppTest.java index 5fb26613..6b2f6121 100644 --- a/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/AppTest.java +++ b/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/AppTest.java @@ -39,7 +39,7 @@ public void render() { if(init) { init = false; testPass = TestLib.test(); - color = testPass ? Color.GREEN : Color.RED; + color = testPass ? Color.LIME : Color.RED; return; } diff --git a/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/TestLib.java b/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/TestLib.java index cfef0fe3..352dd02f 100644 --- a/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/TestLib.java +++ b/example/app/core/src/main/java/com/github/xpenatan/jparser/example/app/TestLib.java @@ -1,5 +1,6 @@ package com.github.xpenatan.jparser.example.app; +import com.github.xpenatan.jparser.example.testlib.CallbackClass; import com.github.xpenatan.jparser.example.testlib.CallbackClassManual; import com.github.xpenatan.jparser.example.testlib.TestCallbackClass; import com.github.xpenatan.jparser.example.testlib.TestConstructorClass; @@ -254,6 +255,160 @@ private static boolean testStaticMethodClass() { } private static boolean testCallbackClass() { + { + TestCallbackClass test = new TestCallbackClass(); + try { + boolean[] internal_onVoidCallback = { false }; + CallbackClass callback = new CallbackClass() { + @Override + public void onVoidCallback(TestObjectClass refData, TestObjectClass pointerData) { + internal_onVoidCallback[0] = true; + } + }; + test.callVoidCallback(callback); + if(!(internal_onVoidCallback[0] == true)) { + throw new RuntimeException("internal_onVoidCallback[0] == true"); + } + } catch(Throwable e) { + e.printStackTrace(); + test.dispose(); + return false; + } + test.dispose(); + } + { + TestCallbackClass test = new TestCallbackClass(); + try { + boolean[] internal_onIntCallback = { false }; + CallbackClass callback = new CallbackClass() { + @Override + public int onIntCallback(int intValue01, int intValue02) { + internal_onIntCallback[0] = true; + return 0; + } + }; + test.callIntCallback(callback); + if(!(internal_onIntCallback[0] == true)) { + throw new RuntimeException("internal_onIntCallback[0] == true"); + } + } catch(Throwable e) { + e.printStackTrace(); + test.dispose(); + return false; + } + test.dispose(); + } + { + TestCallbackClass test = new TestCallbackClass(); + try { + boolean[] internal_onFloatCallback = { false }; + CallbackClass callback = new CallbackClass() { + @Override + public float onFloatCallback(float floatValue01, float floatValue02) { + internal_onFloatCallback[0] = true; + return 0; + } + }; + test.callFloatCallback(callback); + if(!(internal_onFloatCallback[0] == true)) { + throw new RuntimeException("internal_onFloatCallback[0] == true"); + } + } catch(Throwable e) { + e.printStackTrace(); + test.dispose(); + return false; + } + test.dispose(); + } + { + TestCallbackClass test = new TestCallbackClass(); + try { + boolean[] internal_onBoolCallback = { false }; + CallbackClass callback = new CallbackClass() { + @Override + public boolean onBoolCallback(boolean boolValue01) { + internal_onBoolCallback[0] = true; + return false; + } + }; + test.callBoolCallback(callback); + if(!(internal_onBoolCallback[0] == true)) { + throw new RuntimeException("internal_onBoolCallback[0] == true"); + } + } catch(Throwable e) { + e.printStackTrace(); + test.dispose(); + return false; + } + test.dispose(); + } + { + TestCallbackClass test = new TestCallbackClass(); + try { + String text = "HELLO_WORLD"; + test.get_strValue01().append(text); + final String[] internal_onStringCallback = new String[1]; + CallbackClass callback = new CallbackClass() { + @Override + public void onStringCallback(String strValue01) { + internal_onStringCallback[0] = strValue01; + } + }; + test.callStringCallback(callback); + if(!(text.equals(internal_onStringCallback[0]) == true)) { + throw new RuntimeException("text.equals(internal_onStringCallback[0]) == true"); + } + } catch(Throwable e) { + e.printStackTrace(); + test.dispose(); + return false; + } + test.dispose(); + } + { + TestCallbackClass test = new TestCallbackClass(); + try { + int[] onUnsignedIntCallback = { 0 }; + CallbackClass callback = new CallbackClass() { + @Override + public int onUnsignedIntCallback(int unsignedInt) { + onUnsignedIntCallback[0] = unsignedInt; + return 2; + } + }; + int i = test.callUnsignedIntCallback(callback); + if(!(onUnsignedIntCallback[0] == 13 && i == 2)) { + throw new RuntimeException("onUnsignedIntCallback[0] == 13 && i == 2"); + } + } catch(Throwable e) { + e.printStackTrace(); + test.dispose(); + return false; + } + test.dispose(); + } + { + TestCallbackClass test = new TestCallbackClass(); + try { + short[] onUnsignedShortCallback = { 0 }; + CallbackClass callback = new CallbackClass() { + @Override + public short onUnsignedShortCallback(short unsignedShort) { + onUnsignedShortCallback[0] = unsignedShort; + return 3; + } + }; + short i = test.callUnsignedShortCallback(callback); + if(!(onUnsignedShortCallback[0] == 12 && i == 3)) { + throw new RuntimeException("onUnsignedShortCallback[0] == 12 && i == 3"); + } + } catch(Throwable e) { + e.printStackTrace(); + test.dispose(); + return false; + } + test.dispose(); + } return true; } @@ -269,7 +424,7 @@ public void internal_onVoidCallback(long refData, long pointerData) { internal_onVoidCallback[0] = true; } }; - test.callVoidCallback(callback); + test.callManualVoidCallback(callback); if(!(internal_onVoidCallback[0] == true)) { throw new RuntimeException("internal_onVoidCallback[0] == true"); } @@ -291,7 +446,7 @@ public int internal_onIntCallback(int intValue01, int intValue02) { return 0; } }; - test.callIntCallback(callback); + test.callManualIntCallback(callback); if(!(internal_onIntCallback[0] == true)) { throw new RuntimeException("internal_onIntCallback[0] == true"); } @@ -313,7 +468,7 @@ public float internal_onFloatCallback(float floatValue01, float floatValue02) { return 0; } }; - test.callFloatCallback(callback); + test.callManualFloatCallback(callback); if(!(internal_onFloatCallback[0] == true)) { throw new RuntimeException("internal_onFloatCallback[0] == true"); } @@ -335,7 +490,7 @@ public boolean internal_onBoolCallback(boolean boolValue01) { return false; } }; - test.callBoolCallback(callback); + test.callManualBoolCallback(callback); if(!(internal_onBoolCallback[0] == true)) { throw new RuntimeException("internal_onBoolCallback[0] == true"); } @@ -358,7 +513,7 @@ public void internal_onStringCallback(String strValue01) { internal_onStringCallback[0] = strValue01; } }; - test.callStringCallback(callback); + test.callManualStringCallback(callback); if(!(text.equals(internal_onStringCallback[0]) == true)) { throw new RuntimeException("text.equals(internal_onStringCallback[0]) == true"); } diff --git a/example/lib/lib-build/src/main/cpp/TestLib.idl b/example/lib/lib-build/src/main/cpp/TestLib.idl index 8e939160..190a69fd 100644 --- a/example/lib/lib-build/src/main/cpp/TestLib.idl +++ b/example/lib/lib-build/src/main/cpp/TestLib.idl @@ -138,17 +138,19 @@ interface CallbackClassManual { long addInt(long a, long b); }; -//[JSImplementation="CallbackClass"] -//interface CallbackClassImpl { -// void CallbackClassImpl(); -// -// [Const] void onVoidCallback([Ref] TestObjectClass refData, TestObjectClass pointerData); -// [Const] long onIntCallback(long intValue01, long intValue02); -// [Const] float onFloatCallback(float floatValue01, float floatValue02); -// [Const] boolean onBoolCallback(boolean boolValue01); -// [Const] void onStringCallback([Const] DOMString strValue01); -//}; -//CallbackClassImpl implements CallbackClass; +[JSImplementation="CallbackClass"] +interface CallbackClassImpl { + void CallbackClassImpl(); + + [Const] void onVoidCallback([Ref] TestObjectClass refData, TestObjectClass pointerData); + [Const] long onIntCallback(long intValue01, long intValue02); + [Const] float onFloatCallback(float floatValue01, float floatValue02); + [Const] boolean onBoolCallback(boolean boolValue01); + [Const] void onStringCallback([Const] DOMString strValue01); + unsigned long onUnsignedIntCallback(unsigned long unsignedInt); + [Const] unsigned short onUnsignedShortCallback(unsigned short unsignedShort); +}; +CallbackClassImpl implements CallbackClass; [JSImplementation="CallbackClassManual"] interface CallbackClassManualImpl { @@ -162,10 +164,10 @@ interface CallbackClassManualImpl { }; CallbackClassManualImpl implements CallbackClassManual; -interface DefaultCallbackClass { - void DefaultCallbackClass(); -}; -DefaultCallbackClass implements CallbackClass; +//interface DefaultCallbackClass { +// void DefaultCallbackClass(); +//}; +//DefaultCallbackClass implements CallbackClass; //[JSImplementation="DefaultCallbackClass"] //interface DefaultCallbackClassImpl { @@ -187,11 +189,19 @@ interface TestCallbackClass { [Value] attribute TestObjectClass valueObject; attribute TestObjectClass pointerObject; - void callVoidCallback(CallbackClassManual callback); - long callIntCallback(CallbackClassManual callback); - float callFloatCallback(CallbackClassManual callback); - boolean callBoolCallback(CallbackClassManual callback); - void callStringCallback(CallbackClassManual callback); + void callVoidCallback(CallbackClass callback); + long callIntCallback(CallbackClass callback); + float callFloatCallback(CallbackClass callback); + boolean callBoolCallback(CallbackClass callback); + void callStringCallback(CallbackClass callback); + unsigned long callUnsignedIntCallback(CallbackClass callback); + unsigned short callUnsignedShortCallback(CallbackClass callback); + + void callManualVoidCallback(CallbackClassManual callback); + long callManualIntCallback(CallbackClassManual callback); + float callManualFloatCallback(CallbackClassManual callback); + boolean callManualBoolCallback(CallbackClassManual callback); + void callManualStringCallback(CallbackClassManual callback); }; enum TestEnumWithinClass { diff --git a/example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h b/example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h index bf9f147f..89964d17 100644 --- a/example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h +++ b/example/lib/lib-build/src/main/cpp/source/TestLib/src/TestLib.h @@ -263,6 +263,8 @@ class CallbackClass virtual float onFloatCallback(float floatValue01, float Value02) const = 0; virtual bool onBoolCallback(bool boolValue01) const = 0; virtual void onStringCallback(const char* strValue01) const = 0; + virtual unsigned int onUnsignedIntCallback(unsigned int unsignedInt) = 0; + virtual unsigned short onUnsignedShortCallback(unsigned short unsignedShort) const = 0; int addInt(int a, int b) { @@ -310,6 +312,12 @@ class DefaultCallbackClass : public CallbackClass } virtual void onStringCallback(const char* strValue01) const { } + virtual unsigned int onUnsignedIntCallback(unsigned int unsignedInt) { + return 10; + } + virtual unsigned short onUnsignedShortCallback(unsigned short unsignedShort) const { + return 20; + } }; class TestCallbackClass { @@ -340,20 +348,28 @@ class TestCallbackClass { const char* text = strValue01.c_str(); callback->onStringCallback(text); }; + unsigned int callUnsignedIntCallback(CallbackClass* callback) { + unsigned int value = 13; + return callback->onUnsignedIntCallback(value); + }; + unsigned short callUnsignedShortCallback(CallbackClass* callback) { + unsigned short value = 12; + return callback->onUnsignedShortCallback(value); + }; - void callVoidCallback(CallbackClassManual* callback) { + void callManualVoidCallback(CallbackClassManual* callback) { callback->onVoidCallback(valueObject, pointerObject); }; - int callIntCallback(CallbackClassManual* callback) { + int callManualIntCallback(CallbackClassManual* callback) { return callback->onIntCallback(intValue01, intValue02); }; - float callFloatCallback(CallbackClassManual* callback) { + float callManualFloatCallback(CallbackClassManual* callback) { return callback->onFloatCallback(floatValue01, floatValue02); }; - bool callBoolCallback(CallbackClassManual* callback) { + bool callManualBoolCallback(CallbackClassManual* callback) { return callback->onBoolCallback(boolValue01); }; - void callStringCallback(CallbackClassManual* callback) { + void callManualStringCallback(CallbackClassManual* callback) { const char* text = strValue01.c_str(); callback->onStringCallback(text); }; diff --git a/jParser/core/src/main/java/com/github/xpenatan/jparser/core/JParserHelper.java b/jParser/core/src/main/java/com/github/xpenatan/jparser/core/JParserHelper.java index 80887c29..7d17a3df 100644 --- a/jParser/core/src/main/java/com/github/xpenatan/jparser/core/JParserHelper.java +++ b/jParser/core/src/main/java/com/github/xpenatan/jparser/core/JParserHelper.java @@ -41,6 +41,10 @@ public static boolean isInt(Type type) { return JParserHelper.isType(type, "int"); } + public static boolean isShort(Type type) { + return JParserHelper.isType(type, "short"); + } + public static boolean isFloat(Type type) { return JParserHelper.isType(type, "float"); } diff --git a/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/CppCodeParser.java b/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/CppCodeParser.java index 9641a7df..0bbf2f15 100644 --- a/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/CppCodeParser.java +++ b/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/CppCodeParser.java @@ -1,6 +1,7 @@ package com.github.xpenatan.jparser.cpp; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -8,8 +9,14 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.comments.BlockComment; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.type.PrimitiveType; import com.github.javaparser.ast.type.Type; +import com.github.javaparser.utils.Pair; import com.github.xpenatan.jparser.core.JParser; +import com.github.xpenatan.jparser.core.JParserHelper; import com.github.xpenatan.jparser.core.JParserItem; import com.github.xpenatan.jparser.idl.IDLAttribute; import com.github.xpenatan.jparser.idl.IDLConstructor; @@ -23,6 +30,7 @@ import com.github.xpenatan.jparser.idl.IDLParameter; import com.github.xpenatan.jparser.idl.IDLReader; import com.github.xpenatan.jparser.idl.parser.IDLMethodOperation; +import com.github.xpenatan.jparser.idl.parser.IDLMethodParser; import java.util.ArrayList; public class CppCodeParser extends IDLDefaultCodeParser { @@ -386,9 +394,226 @@ public void onIDLEnumMethodGenerated(JParser jParser, IDLEnum idlEnum, ClassOrIn nativeMethodDeclaration.setBlockComment(blockComment); } + @Override + public void onIDLCallbackGenerated(JParser jParser, IDLClass idlClass, ClassOrInterfaceDeclaration classDeclaration, MethodDeclaration callbackDeclaration, ArrayList>> methods) { + NodeList methodParameters = callbackDeclaration.getParameters(); + IDLClass idlCallbackClass = idlClass.callback; + Type methodReturnType = callbackDeclaration.getType(); + MethodDeclaration nativeMethodDeclaration = IDLMethodParser.generateNativeMethod(callbackDeclaration.getNameAsString(), methodParameters, methodReturnType, false); + if(!JParserHelper.containsMethod(classDeclaration, nativeMethodDeclaration)) { + nativeMethodDeclaration.removeModifier(Modifier.Keyword.STATIC); + + // Call setupMethod + classDeclaration.getMembers().add(nativeMethodDeclaration); + MethodCallExpr caller = IDLMethodParser.createCaller(nativeMethodDeclaration); + caller.addArgument(IDLDefaultCodeParser.CPOINTER_METHOD); + BlockStmt blockStmt = callbackDeclaration.getBody().get(); + blockStmt.addStatement(caller); + String method = callbackDeclaration.getNameAsString() + "(env, object)"; + String content = METHOD_CALL_VOID_TEMPLATE.replace(TEMPLATE_TAG_METHOD, method).replace(TEMPLATE_TAG_TYPE, idlCallbackClass.name); + String header = "[-" + HEADER_CMD + ";" + CMD_NATIVE + "]"; + String blockComment = header + content; + nativeMethodDeclaration.setBlockComment(blockComment); + + + generateCPPClass(idlClass, classDeclaration, callbackDeclaration, methods); + } + } + + + private void generateCPPClass(IDLClass idlClass, ClassOrInterfaceDeclaration classDeclaration, MethodDeclaration callbackDeclaration, ArrayList>> methods) { + IDLClass callback = idlClass.callback; + String cppClass = ""; + + String callbackCode = generateSetupCallbackMethod(idlClass, callbackDeclaration, methods); + String methodsCode = generateMethodCallers(idlClass, methods); + cppClass += "" + + "class " + callback.name + " : public " + idlClass.name + " {\n" + + "private:\n" + + "\tJNIEnv* env;\n" + + "\tjobject obj;\n" + + "public:\n"; + cppClass += callbackCode; + cppClass += methodsCode; + cppClass += "};\n"; + + String header = "[-" + HEADER_CMD + ";" + CMD_NATIVE + "]\n"; + String code = header + cppClass; + + classDeclaration.getConstructors().get(0).setBlockComment(code); + + System.out.println(); + } + + private String generateSetupCallbackMethod(IDLClass idlClass, MethodDeclaration callbackDeclaration, ArrayList>> methods) { + String contentTemplate = "" + + "\tinline static jclass jClassID = 0;\n" + + "[VARIABLES]\n" + + "void [METHOD](JNIEnv* env, jobject obj) {\n" + + "\tthis->env = env;\n" + + "\tthis->obj = env->NewGlobalRef(obj);\n" + + "\tif([CLASS_NAME]::jClassID == 0) {\n" + + "\t\t[CLASS_NAME]::jClassID = (jclass)env->NewGlobalRef(env->GetObjectClass(obj));\n" + + "[METHOD_IDS]" + + "\t}\n" + + "}\n"; + String variableTemplate = "\tinline static jmethodID [METHOD]_ID = 0;\n"; + String methodIdTemplate = "\t\t[CLASS_NAME]::[METHOD]_ID = env->GetMethodID(jClassID, \"[INTERNAL_METHOD]\", \"[PARAM_CODE]\");\n"; + + IDLClass callbackClass = idlClass.callback; + String className = callbackClass.name; + + String staticVariables = ""; + String methodIds = ""; + String methodName = callbackDeclaration.getNameAsString(); + + for(int i = 0; i < methods.size(); i++) { + Pair> pair = methods.get(i); + IDLMethod idlMethod = pair.a; + Pair methodPair = pair.b; + MethodDeclaration internalMethod = methodPair.a; + MethodDeclaration publicMethod = methodPair.b; + String internalMethodName = internalMethod.getNameAsString(); + String paramCode = ""; + + Type returnType = internalMethod.getType(); + String returnTypeStr = returnType.asString(); + + NodeList parameters = internalMethod.getParameters(); + for(int i1 = 0; i1 < parameters.size(); i1++) { + Parameter parameter = parameters.get(i1); + Type type = parameter.getType(); + String typeStr = type.asString(); + if(type.isPrimitiveType()) { + String jniType = JNITypeSignature.getJNIType(typeStr); + paramCode += jniType; + } + else if(type.isClassOrInterfaceType()) { + if(typeStr.equals("String")) { + paramCode += JNITypeSignature.String.getJNIType(); + } + } + } + + paramCode = "(" + paramCode + ")" + JNITypeSignature.getJNIType(returnTypeStr); + + String variable = variableTemplate.replace("[METHOD]", idlMethod.name); + String methodId = methodIdTemplate.replace("[METHOD]", idlMethod.name) + .replace("[CLASS_NAME]", className) + .replace("[INTERNAL_METHOD]", internalMethodName) + .replace("[PARAM_CODE]", paramCode); + staticVariables += variable; + methodIds += methodId; + } + + String content = contentTemplate.replace("[VARIABLES]", staticVariables) + .replace("[METHOD]", methodName) + .replace("[CLASS_NAME]", className) + .replace("[METHOD_IDS]", methodIds); + + return content; + } + + private String generateMethodCallers(IDLClass idlClass, ArrayList>> methods) { + IDLClass callback = idlClass.callback; + String cppMethods = ""; + String cppClassName = callback.name; + + String methodTemplate = "" + + "virtual [RETURN_TYPE] [METHOD]([PARAMS])[CONST] {\n" + + " [RETURN]env->[CALL_METHOD](obj, [CPP_CLASS]::[METHOD]_ID[CALL_PARAMS]);\n" + + "}\n"; + + for(int i = 0; i < methods.size(); i++) { + Pair> pair = methods.get(i); + IDLMethod idlMethod = pair.a; + Pair methodPair = pair.b; + MethodDeclaration internalMethod = methodPair.a; + MethodDeclaration publicMethod = methodPair.b; + + Type type = internalMethod.getType(); + boolean isVoidType = type.isVoidType(); + String typeStr = getCPPType(idlMethod.returnType); + + String methodName = idlMethod.name; + String methodParams = ""; + String callParams = ""; + String constStr = idlMethod.isReturnConst ? " const" : ""; + + NodeList publicMethodParameters = publicMethod.getParameters(); + for(int i1 = 0; i1 < idlMethod.parameters.size(); i1++) { + IDLParameter idlParameter = idlMethod.parameters.get(i1); + Parameter parameter = publicMethodParameters.get(i1); + boolean isPrimitive = parameter.getType().isPrimitiveType(); + String paramName = idlParameter.name; + String callParamName = idlParameter.name; + String paramType = idlParameter.type; + boolean isString = paramType.equals("String"); + String tag = " "; + String callParamCast = ""; + + if(!isString) { + if(idlParameter.isRef) { + tag = "& "; + callParamCast = "(jlong)&"; + } + else if(!isPrimitive && !idlParameter.isValue) { + tag = "* "; + callParamCast = "(jlong)"; + } + } + else { + callParamName = "env->NewStringUTF(" + paramName + ")"; + } + paramType = getCPPType(paramType); + if(idlParameter.isConst) { + paramType = "const " + paramType; + } + callParams += ", "; + callParams += callParamCast + callParamName; + + methodParams += paramType + tag + paramName; + if(i1 < idlMethod.parameters.size() - 1) { + methodParams += ", "; + } + } + + String returnStr = ""; + if(!isVoidType) { + returnStr = "return "; + } + + if(typeStr.contains("unsigned")) { + returnStr += "(" + typeStr + ")"; + } + String callMethod = getCPPCallMethod(type); + String methodStr = methodTemplate.replace("[CALL_METHOD]", callMethod).replace("[CPP_CLASS]", cppClassName).replace("[METHOD]", methodName).replace("[CALL_PARAMS]", callParams).replace("[RETURN]", returnStr); + methodStr = methodStr.replace("[RETURN_TYPE]", typeStr).replace("[METHOD]", methodName).replace("[PARAMS]", methodParams).replace("[CONST]", constStr); + + cppMethods += methodStr; + } + return cppMethods; + } + + private String getCPPCallMethod(Type type) { + String typeString = type.asString(); + typeString = typeString.substring(0, 1).toUpperCase() + typeString.substring(1); + return "Call" + typeString + "Method"; + } + + private String getCPPType(String typeString) { + if(typeString.equals("boolean")) { + return "bool"; + } + if(typeString.equals("String")) { + return "char*"; + } + return typeString; + } + private void setupMethodGenerated(IDLMethod idlMethod, String param, ClassOrInterfaceDeclaration classDeclaration, MethodDeclaration methodDeclaration, MethodDeclaration nativeMethod) { Type returnType = methodDeclaration.getType(); - String returnTypeStr = idlMethod.returnType; + String returnTypeStr = idlMethod.getReturnType(); String methodName = idlMethod.name; String classTypeName = classDeclaration.getNameAsString(); IDLClass idlClass = idlMethod.idlFile.getClass(classTypeName); diff --git a/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/JNITypeSignature.java b/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/JNITypeSignature.java new file mode 100644 index 00000000..d9a983c8 --- /dev/null +++ b/jParser/cpp/src/main/java/com/github/xpenatan/jparser/cpp/JNITypeSignature.java @@ -0,0 +1,31 @@ +package com.github.xpenatan.jparser.cpp; + +public enum JNITypeSignature { + Void("V"), Boolean("Z"), Byte("B"), Char("C"), Short("S"), Int("I"), Long("J"), Float("F"), Double("D"), String("Ljava/lang/String;"); + + private final String jniType; + + JNITypeSignature(String type) { + jniType = type; + } + + String getJNIType() { + return jniType; + } + + static String getJNIType(String type) { + JNITypeSignature[] values = JNITypeSignature.values(); + for(int i = 0; i < values.length; i++) { + JNITypeSignature value = values[i]; + if(value.name().toLowerCase().equals(type)) { + return value.getJNIType(); + } + } + return null; + } + + static String getJNIObject(String classpath) { + classpath = classpath.replace(".", "/"); + return "L"+ classpath + ";"; + } +} \ No newline at end of file diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLMethod.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLMethod.java index 87968ce7..ebd6d874 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLMethod.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLMethod.java @@ -34,13 +34,14 @@ public void initMethod(String line) { paramsLine = IDLMethod.setParameters(idlFile, line, parameters); int index = line.indexOf("("); String leftSide = line.substring(0, index).trim(); + leftSide = IDLHelper.removeMultipleSpaces(leftSide.trim()); String tagsStr = IDLHelper.getTags(leftSide); if(!tagsStr.isEmpty()) { isReturnRef = tagsStr.contains("Ref"); isReturnValue = tagsStr.contains("Value"); isReturnConst = tagsStr.contains("Const"); - leftSide = leftSide.replace(tagsStr, ""); + leftSide = leftSide.replace(tagsStr, "").trim(); tagsStr = tagsStr.substring(1, tagsStr.length()-1); for(String s : tagsStr.split(",")) { @@ -53,21 +54,22 @@ public void initMethod(String line) { } if(leftSide.contains("[]")) { - leftSide = leftSide.replace("[]", ""); + leftSide = leftSide.replace("[]", "").trim(); isReturnArray = true; } - leftSide = IDLHelper.removeMultipleSpaces(leftSide.trim()); if(leftSide.contains("static")) { + leftSide = leftSide.replace("static", "").trim(); isStaticMethod = true; } String[] s = leftSide.split(" "); name = s[s.length-1]; - returnType = s[s.length-2]; + leftSide = leftSide.replace(name, "").trim(); + returnType = leftSide; - if(returnType.equals("long")) { - returnType = "int"; + if(returnType.contains("long")) { + returnType = returnType.replace("long", "int"); } if(returnType.equals("DOMString")) { returnType = "String"; @@ -79,6 +81,10 @@ public void initMethod(String line) { } } + public String getReturnType() { + return returnType.replace("unsigned", "").trim(); + } + public int getTotalOptionalParams() { int count = 0; for(int i = 0; i < parameters.size(); i++) { diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLParameter.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLParameter.java index 5c62de24..2e7871b1 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLParameter.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/IDLParameter.java @@ -31,11 +31,13 @@ public void initParameter(String line) { optional = line.contains("optional"); isArray = line.contains("[]"); + tmpLine = tmpLine.replace("optional", "").trim(); + tmpLine = tmpLine.replace("[]", "").trim(); - int startIndex = line.indexOf("["); - int endIndex = line.indexOf("]"); + int startIndex = tmpLine.indexOf("["); + int endIndex = tmpLine.indexOf("]"); if(startIndex != -1 && endIndex != -1 && startIndex + 2 < endIndex) { - String tagsStr = line.substring(startIndex, endIndex + 1); + String tagsStr = tmpLine.substring(startIndex, endIndex + 1); isRef = tagsStr.contains("Ref"); isConst = tagsStr.contains("Const"); isValue = tagsStr.contains("Value"); @@ -53,15 +55,18 @@ public void initParameter(String line) { } String[] s1 = tmpLine.split(" "); - type = s1[s1.length - 2]; + name = s1[s1.length - 1]; + tmpLine = tmpLine.replace(name, "").trim(); + + type = tmpLine; if(isArray) { type = type + "[]"; } - if(type.equals("long")) { + if(type.contains("long")) { // long in webidl means int - type = "int"; + type = type.replace("long", "int"); } if(type.equals("any") || type.equals("VoidPtr")) { @@ -69,9 +74,6 @@ public void initParameter(String line) { isAny = true; } - if(type.equals("long[]")) { - type = "int[]"; - } if(type.equals("DOMString")) { type = "String"; } @@ -95,10 +97,13 @@ else if(type.equals("boolean[]")) { else if(type.equals("double[]")) { type = "IDLDoubleArray"; } + } - name = s1[s1.length - 1]; + public String getType() { + return type.replace("unsigned", "").trim(); } + public IDLParameter clone() { IDLParameter clonedParam = new IDLParameter(idlFile); clonedParam.line = line; diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLCallbackParser.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLCallbackParser.java index 49d185e4..5f443048 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLCallbackParser.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLCallbackParser.java @@ -1,27 +1,109 @@ package com.github.xpenatan.jparser.idl.parser; +import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.ConstructorDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; +import com.github.javaparser.ast.type.PrimitiveType; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.utils.Pair; import com.github.xpenatan.jparser.core.JParser; import com.github.xpenatan.jparser.idl.IDLClass; import com.github.xpenatan.jparser.idl.IDLConstructor; +import com.github.xpenatan.jparser.idl.IDLMethod; import java.util.ArrayList; public class IDLCallbackParser { - public static void generateCallback(IDLDefaultCodeParser idlParser, JParser jParser, CompilationUnit unit, ClassOrInterfaceDeclaration classOrInterfaceDeclaration, IDLClass idlClass) { + private final static String callbackMethodName = "setupCallback"; + + public static void generateCallback(IDLDefaultCodeParser idlParser, JParser jParser, CompilationUnit unit, ClassOrInterfaceDeclaration classDeclaration, IDLClass idlClass) { + ArrayList constructors = idlClass.callback.constructors; - for(int i = 0; i < constructors.size(); i++) { - IDLConstructor idlConstructor = constructors.get(i); - ConstructorDeclaration constructorDeclaration = IDLConstructorParser.getOrCreateConstructorDeclaration(idlParser, jParser, unit, classOrInterfaceDeclaration, idlConstructor); + if(constructors.size() == 1) { + IDLConstructor idlConstructor = constructors.get(0); + ConstructorDeclaration constructorDeclaration = IDLConstructorParser.getOrCreateConstructorDeclaration(idlParser, jParser, unit, classDeclaration, idlConstructor); if(constructorDeclaration.getBody().isEmpty()) { - MethodDeclaration nativeMethod = IDLConstructorParser.setupConstructor(idlConstructor, classOrInterfaceDeclaration, constructorDeclaration); - idlParser.onIDLConstructorGenerated(jParser, idlConstructor, classOrInterfaceDeclaration, constructorDeclaration, nativeMethod); + MethodDeclaration callbackSetupDeclaration = classDeclaration.addMethod(callbackMethodName, Modifier.Keyword.PRIVATE); + ArrayList>> methods = createCallbackMethods(idlParser, jParser, unit, classDeclaration, idlClass); + MethodDeclaration nativeMethod = IDLConstructorParser.setupConstructor(idlConstructor, classDeclaration, constructorDeclaration); + idlParser.onIDLConstructorGenerated(jParser, idlConstructor, classDeclaration, constructorDeclaration, nativeMethod); + MethodCallExpr caller = IDLMethodParser.createCaller(callbackSetupDeclaration); + constructorDeclaration.getBody().addStatement(caller); + idlParser.onIDLCallbackGenerated(jParser, idlClass, classDeclaration, callbackSetupDeclaration, methods); + } + } + else { + throw new RuntimeException("Callback need to have 1 constructor"); + } + } + + + private static ArrayList>> createCallbackMethods(IDLDefaultCodeParser idlParser, JParser jParser, CompilationUnit unit, ClassOrInterfaceDeclaration classDeclaration, IDLClass idlClass) { + ArrayList>> methods = new ArrayList<>(); + IDLClass callbackClass = idlClass.callback; + + for(IDLMethod method : callbackClass.methods) { + MethodDeclaration methodDeclaration = IDLMethodParser.generateAndAddMethodOnly(idlParser, jParser, unit, classDeclaration, method); + MethodDeclaration internalMethod = methodDeclaration.clone(); + + internalMethod.removeModifier(Modifier.Keyword.PUBLIC); + internalMethod.addModifier(Modifier.Keyword.PRIVATE); + + NodeList parameters = internalMethod.getParameters(); + + MethodCallExpr caller = IDLMethodParser.createCaller(methodDeclaration); + + String createFieldObjectCode = ""; + for(int i = 0; i < parameters.size(); i++) { + Parameter parameter = parameters.get(i); + String paramName = parameter.getNameAsString(); + Type type = parameter.getType(); + String typeStr = type.asString(); + String fieldName = paramName; + + if(type.isClassOrInterfaceType() && !typeStr.equals("String")) { + parameter.setType(PrimitiveType.longType()); + fieldName = IDLMethodParser.generateFieldName(classDeclaration, typeStr, true); + String newBody = IDLMethodParser.CALLBACK_PARAM_TEMPLATE + .replace(IDLMethodParser.TEMPLATE_TEMP_FIELD, fieldName) + .replace(IDLMethodParser.TEMPLATE_TAG_TYPE, typeStr) + .replace(IDLMethodParser.TEMPLATE_TAG_PARAM, paramName); + + createFieldObjectCode += newBody; + } + caller.addArgument(fieldName); } + createFieldObjectCode = "{\n" + createFieldObjectCode + "}"; + BlockStmt blockStmt = StaticJavaParser.parseBlock(createFieldObjectCode); + + if(internalMethod.getType().isVoidType()) { + blockStmt.addStatement(caller); + } + else { + ReturnStmt returnStmt = new ReturnStmt(); + returnStmt.setExpression(caller); + blockStmt.addStatement(returnStmt); + } + String internName = internalMethod.getNameAsString(); + internalMethod.setName("internal_" + internName); + internalMethod.setBody(blockStmt); + classDeclaration.addMember(internalMethod); + + Pair methodDeclarationPair = new Pair<>(internalMethod, methodDeclaration); + + Pair> methodPair = new Pair<>(method, methodDeclarationPair); + methods.add(methodPair); } + return methods; } } \ No newline at end of file diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLConstructorParser.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLConstructorParser.java index 92b83b6b..49dfed34 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLConstructorParser.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLConstructorParser.java @@ -96,7 +96,7 @@ public static MethodDeclaration setupConstructor(IDLConstructor idlConstructor, Type type = StaticJavaParser.parseType(classDeclaration.getNameAsString()); boolean isStatic = true; - MethodDeclaration nativeMethod = IDLMethodParser.generateNativeMethod(false, "create", parameters, type, isStatic); + MethodDeclaration nativeMethod = IDLMethodParser.generateNativeMethod("create", parameters, type, isStatic); if(!JParserHelper.containsMethod(classDeclaration, nativeMethod)) { //Add native method if it does not exist diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLDeConstructorParser.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLDeConstructorParser.java index ed0c976a..4209202e 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLDeConstructorParser.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLDeConstructorParser.java @@ -40,7 +40,7 @@ else if(size == 0) { if(deleteMethod != null) { NodeList parameters = deleteMethod.getParameters(); Type type = deleteMethod.getType(); - MethodDeclaration nativeMethod = IDLMethodParser.generateNativeMethod(false, DELETE_NATIVE, parameters, type, false); + MethodDeclaration nativeMethod = IDLMethodParser.generateNativeMethod(DELETE_NATIVE, parameters, type, false); if(!JParserHelper.containsMethod(classOrInterfaceDeclaration, nativeMethod)) { classOrInterfaceDeclaration.getMembers().add(nativeMethod); diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLDefaultCodeParser.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLDefaultCodeParser.java index 6e7bb29c..d735293b 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLDefaultCodeParser.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLDefaultCodeParser.java @@ -12,6 +12,7 @@ import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.type.Type; +import com.github.javaparser.utils.Pair; import com.github.xpenatan.jparser.core.JParser; import com.github.xpenatan.jparser.core.JParserHelper; import com.github.xpenatan.jparser.core.codeparser.CodeParserItem; @@ -128,7 +129,7 @@ public static void setDefaultReturnValues(JParser jParser, CompilationUnit unit, BlockStmt blockStmt = idlMethodDeclaration.getBody().get(); ReturnStmt returnStmt = new ReturnStmt(); if(returnType.isPrimitiveType()) { - if(JParserHelper.isLong(returnType) || JParserHelper.isInt(returnType) || JParserHelper.isFloat(returnType) || JParserHelper.isDouble(returnType)) { + if(JParserHelper.isLong(returnType) || JParserHelper.isInt(returnType) || JParserHelper.isFloat(returnType) || JParserHelper.isDouble(returnType) || JParserHelper.isShort(returnType)) { NameExpr returnNameExpr = new NameExpr(); returnNameExpr.setName("0"); returnStmt.setExpression(returnNameExpr); @@ -164,7 +165,7 @@ public void onIDLAttributeGenerated(JParser jParser, IDLAttribute idlAttribute, public void onIDLEnumMethodGenerated(JParser jParser, IDLEnum idlEnum, ClassOrInterfaceDeclaration classDeclaration, String enumStr, FieldDeclaration fieldDeclaration, MethodDeclaration nativeMethodDeclaration) { } - public void onIDLCallbackGenerated(JParser jParser, IDLClass idlClass, ClassOrInterfaceDeclaration classDeclaration) { + public void onIDLCallbackGenerated(JParser jParser, IDLClass idlClass, ClassOrInterfaceDeclaration classDeclaration, MethodDeclaration callbackDeclaration, ArrayList>> methods) { } public String getIDLMethodName(String name) { diff --git a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLMethodParser.java b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLMethodParser.java index 220f5f8b..838afe77 100644 --- a/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLMethodParser.java +++ b/jParser/idl/src/main/java/com/github/xpenatan/jparser/idl/parser/IDLMethodParser.java @@ -47,6 +47,10 @@ public class IDLMethodParser { " return [TYPE]_TEMP_GEN_[NUM];\n" + "}"; + static final String CALLBACK_PARAM_TEMPLATE = + "if([TYPE]_TEMP_GEN_[NUM] == null) [TYPE]_TEMP_GEN_[NUM] = new [TYPE]((byte)1, (char)1);\n" + + "[TYPE]_TEMP_GEN_[NUM].setCPointer([PARAM]);\n"; + static final String GET_TEMP_OBJECT_TEMPLATE = "{\n" + " [METHOD];\n" + @@ -64,25 +68,34 @@ public class IDLMethodParser { static final String TEMPLATE_TAG_METHOD = "[METHOD]"; + static final String TEMPLATE_TAG_PARAM = "[PARAM]"; + static final String TEMPLATE_TAG_TYPE = "[TYPE]"; static final String TEMPLATE_TAG_NUM = "[NUM]"; public static void generateMethod(IDLDefaultCodeParser idlParser, JParser jParser, CompilationUnit unit, ClassOrInterfaceDeclaration classOrInterfaceDeclaration, IDLClass idlClass, IDLMethod idlMethod) { + MethodDeclaration methodDeclaration = generateAndAddMethodOnly(idlParser, jParser, unit, classOrInterfaceDeclaration, idlMethod); + if(methodDeclaration != null && idlParser.generateClass) { + setupMethod(idlParser, jParser, idlMethod, classOrInterfaceDeclaration, methodDeclaration); + } + } + + public static MethodDeclaration generateAndAddMethodOnly(IDLDefaultCodeParser idlParser, JParser jParser, CompilationUnit unit, ClassOrInterfaceDeclaration classDeclaration, IDLMethod idlMethod) { if(idlMethod.skip) { - return; + return null; } String methodName = idlMethod.name; Type returnType = null; - MethodDeclaration containsMethod = containsMethod(idlParser, classOrInterfaceDeclaration, idlMethod); + MethodDeclaration containsMethod = containsMethod(idlParser, classDeclaration, idlMethod); if(containsMethod != null) { if(canGenerateMethod(containsMethod)) { returnType = containsMethod.getType(); } else { - return; + return null; } } @@ -91,11 +104,11 @@ public static void generateMethod(IDLDefaultCodeParser idlParser, JParser jParse String updatedMethodName = idlParser.getIDLMethodName(fixedMethodName); ArrayList parameters = idlMethod.parameters; - MethodDeclaration methodDeclaration = classOrInterfaceDeclaration.addMethod(updatedMethodName, Modifier.Keyword.PUBLIC); + MethodDeclaration methodDeclaration = classDeclaration.addMethod(updatedMethodName, Modifier.Keyword.PUBLIC); methodDeclaration.setStatic(idlMethod.isStaticMethod); for(int i = 0; i < parameters.size(); i++) { IDLParameter idlParameter = parameters.get(i); - String paramType = idlParameter.type; + String paramType = idlParameter.getType(); String paramName = idlParameter.name; paramType = IDLHelper.convertEnumToInt(idlParser.idlReader, paramType); Parameter parameter = methodDeclaration.addAndGetParameter(paramType, paramName); @@ -104,15 +117,12 @@ public static void generateMethod(IDLDefaultCodeParser idlParser, JParser jParse } if(returnType == null) { - String returnTypeStr = IDLHelper.convertEnumToInt(idlParser.idlReader, idlMethod.returnType); + String returnTypeStr = IDLHelper.convertEnumToInt(idlParser.idlReader, idlMethod.getReturnType()); returnType = StaticJavaParser.parseType(returnTypeStr); } methodDeclaration.setType(returnType); IDLDefaultCodeParser.setDefaultReturnValues(jParser, unit, returnType, methodDeclaration); - - if(idlParser.generateClass) { - setupMethod(idlParser, jParser, idlMethod, classOrInterfaceDeclaration, methodDeclaration); - } + return methodDeclaration; } public static boolean canGenerateMethod(MethodDeclaration containsMethod) { @@ -160,7 +170,7 @@ private static void setupMethod(IDLDefaultCodeParser idlParser, JParser jParser, public static MethodDeclaration prepareNativeMethod(boolean isStatic, boolean isReturnValue, ClassOrInterfaceDeclaration classDeclaration, MethodDeclaration methodDeclaration, String methodName, String operator, ArrayList idlParameters) { NodeList methodParameters = methodDeclaration.getParameters(); Type methodReturnType = methodDeclaration.getType(); - MethodDeclaration nativeMethodDeclaration = generateNativeMethod(isReturnValue, methodName, methodParameters, methodReturnType, methodDeclaration.isStatic()); + MethodDeclaration nativeMethodDeclaration = generateNativeMethod(methodName, methodParameters, methodReturnType, methodDeclaration.isStatic()); if(!JParserHelper.containsMethod(classDeclaration, nativeMethodDeclaration)) { //Add native method if it does not exist classDeclaration.getMembers().add(nativeMethodDeclaration); @@ -283,7 +293,7 @@ private static BlockStmt generateTempObjects(boolean isReturnValue, ClassOrInter return body; } - private static String generateFieldName(ClassOrInterfaceDeclaration classDeclaration, String fieldType, boolean isStatic) { + public static String generateFieldName(ClassOrInterfaceDeclaration classDeclaration, String fieldType, boolean isStatic) { // Will return a temp object. // Java variable will be created by checking its class, name and number. // if the temp object already exist it will increment variable number and create it. @@ -336,7 +346,7 @@ private static String getFieldName(String type, int number, boolean isStatic) { } } - public static MethodDeclaration generateNativeMethod(boolean isReturnValue, String methodName, NodeList methodParameters, Type methodReturnType, boolean isStatic) { + public static MethodDeclaration generateNativeMethod(String methodName, NodeList methodParameters, Type methodReturnType, boolean isStatic) { boolean isClassOrInterfaceType = methodReturnType.isClassOrInterfaceType(); // Clone some generated idl method settings diff --git a/jParser/teavm/src/main/java/com/github/xpenatan/jparser/teavm/TeaVMCodeParser.java b/jParser/teavm/src/main/java/com/github/xpenatan/jparser/teavm/TeaVMCodeParser.java index bf413995..4fd2a304 100644 --- a/jParser/teavm/src/main/java/com/github/xpenatan/jparser/teavm/TeaVMCodeParser.java +++ b/jParser/teavm/src/main/java/com/github/xpenatan/jparser/teavm/TeaVMCodeParser.java @@ -778,7 +778,7 @@ else if(expression.isLambdaExpr()) { resolvedType = expression.calculateResolvedType(); } catch(Throwable t) { - t.printStackTrace(); +// t.printStackTrace(); continue; } String type = null;