Skip to content

Commit

Permalink
Fix return type
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Jul 11, 2023
1 parent 0c5d67a commit 2fb2dd7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions example/example-build/jni/cpp/src/NormalClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ NormalClass::NormalClass()

int NormalClass::addIntValue(int a, int b)
{
// return (a + b) * hiddenInt * hiddenParentInt;
return a + b;
return (a + b) * hiddenInt * hiddenParentInt;
}
6 changes: 2 additions & 4 deletions example/example-build/jni/cpp/src/ParentClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ ParentClass::ParentClass()

float ParentClass::addFloatValue(float a, float b)
{
// return (a + b) * hiddenParentInt;
return (a + b);
return (a + b) * hiddenParentInt;
}

bool ParentClass::invertBoolean(bool value)
{
// return !(bool)(value * hiddenParentInt);
return !value;
return !(bool)(value * hiddenParentInt);
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public void addNativeCode(MethodDeclaration methodDeclaration, String content) {
String packageName = compilationUnit.getPackageDeclaration().get().getNameAsString();
String className = classDeclaration.getNameAsString();
String packageNameCPP = packageName.replace(".", "_");
String returnTypeStr = methodDeclaration.getType().toString();
JavaMethodParser.ArgumentType returnType = getType(returnTypeStr);

String params = "(JNIEnv* env, jclass clazz";

Expand All @@ -122,7 +124,7 @@ public void addNativeCode(MethodDeclaration methodDeclaration, String content) {

params += ")";

print("JNIEXPORT jint JNICALL Java_" + packageNameCPP + "_" + className + "_" + methodName + params + " {");
print("JNIEXPORT " + returnType.getJniType() + " JNICALL Java_" + packageNameCPP + "_" + className + "_" + methodName + params + " {");
content = "\t" + content.replace("\n", "\n\t");
print(content);
print("}");
Expand Down Expand Up @@ -158,6 +160,10 @@ public void generate(JParser jParser) {
private JavaMethodParser.ArgumentType getArgumentType(Parameter parameter) {
String[] typeTokens = parameter.getType().toString().split("\\.");
String type = typeTokens[typeTokens.length - 1];
return getType(type);
}

private JavaMethodParser.ArgumentType getType(String type) {
int arrayDim = 0;
for(int i = 0; i < type.length(); i++) {
if(type.charAt(i) == '[') arrayDim++;
Expand Down

0 comments on commit 2fb2dd7

Please sign in to comment.