Skip to content

Commit

Permalink
Fix comparing method
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Sep 2, 2024
1 parent da37fca commit fb30318
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
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;
Expand Down Expand Up @@ -557,7 +555,7 @@ private String generateMethodCallers(IDLClass idlClass, ArrayList<Pair<IDLMethod

Type type = internalMethod.getType();
boolean isVoidType = type.isVoidType();
String typeStr = getCPPType(idlMethod.returnType);
String typeStr = getCPPType(idlMethod.getCPPReturnType());

String methodCode = generateMethodID(internalMethod);

Expand All @@ -573,7 +571,7 @@ private String generateMethodCallers(IDLClass idlClass, ArrayList<Pair<IDLMethod
boolean isPrimitive = parameter.getType().isPrimitiveType();
String paramName = idlParameter.name;
String callParamName = idlParameter.name;
String paramType = idlParameter.type;
String paramType = idlParameter.getCPPReturnType();
boolean isString = paramType.equals("String");
String tag = " ";
String callParamCast = "";
Expand Down Expand Up @@ -640,7 +638,7 @@ private String getCPPType(String typeString) {

private void setupMethodGenerated(IDLMethod idlMethod, String param, ClassOrInterfaceDeclaration classDeclaration, MethodDeclaration methodDeclaration, MethodDeclaration nativeMethod) {
Type returnType = methodDeclaration.getType();
String returnTypeStr = idlMethod.getReturnType();
String returnTypeStr = idlMethod.getJavaReturnType();
String methodName = idlMethod.name;
String classTypeName = classDeclaration.getNameAsString();
IDLClass idlClass = idlMethod.idlFile.getClass(classTypeName);
Expand Down Expand Up @@ -764,7 +762,7 @@ private static String getParams(NodeList<Parameter> parameters, ArrayList<IDLPar
Parameter parameter = parameters.get(i);
IDLParameter idlParameter = idParameters.get(i);
Type type = parameter.getType();
String paramName = getParam(idlParameter.idlFile, type, idlParameter.name, idlParameter.type, idlParameter.isAny, idlParameter.isRef, idlParameter.isValue, idlParameter.isArray);
String paramName = getParam(idlParameter.idlFile, type, idlParameter.name, idlParameter.getCPPReturnType(), idlParameter.isAny, idlParameter.isRef, idlParameter.isValue, idlParameter.isArray);
if(i > 0) {
param += ", ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ else if(returnType.contains("long")) {
}
}

public String getReturnType() {
public String getCPPReturnType() {
return returnType;
}

public String getJavaReturnType() {
return returnType.replace("unsigned", "").trim();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ else if(type.equals("double[]")) {
}
}

public String getType() {
public String getCPPReturnType() {
return type;
}

public String getJavaType() {
if(isAny) {
return "long";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static ConstructorDeclaration getOrCreateConstructorDeclaration(IDLDefaul
ArrayList<IDLParameter> parameters = idlConstructor.parameters;
for(int i = 0; i < parameters.size(); i++) {
IDLParameter parameter = parameters.get(i);
String paramType = parameter.getType();
String paramType = parameter.getJavaType();
paramType = IDLHelper.convertEnumToInt(idlParser.idlReader, paramType);
JParserHelper.addMissingImportType(jParser, unit, paramType);
constructorDeclaration.addAndGetParameter(paramType, parameter.name);
Expand Down Expand Up @@ -126,7 +126,7 @@ public static ConstructorDeclaration containsConstructor(ClassOrInterfaceDeclara
String[] paramTypes = new String[parameters.size()];
for(int i = 0; i < parameters.size(); i++) {
IDLParameter parameter = parameters.get(i);
String paramType = parameter.type;
String paramType = parameter.getJavaType();
paramTypes[i] = paramType;
}
Optional<ConstructorDeclaration> constructorDeclarationOptional = classOrInterfaceDeclaration.getConstructorByParameterTypes(paramTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static MethodDeclaration generateAndAddMethodOnly(IDLDefaultCodeParser id
methodDeclaration.setStatic(idlMethod.isStaticMethod);
for(int i = 0; i < parameters.size(); i++) {
IDLParameter idlParameter = parameters.get(i);
String paramType = idlParameter.getType();
String paramType = idlParameter.getJavaType();
String paramName = idlParameter.name;
paramType = IDLHelper.convertEnumToInt(idlParser.idlReader, paramType);
Parameter parameter = methodDeclaration.addAndGetParameter(paramType, paramName);
Expand All @@ -117,7 +117,7 @@ public static MethodDeclaration generateAndAddMethodOnly(IDLDefaultCodeParser id
}

if(returnType == null) {
String returnTypeStr = IDLHelper.convertEnumToInt(idlParser.idlReader, idlMethod.getReturnType());
String returnTypeStr = IDLHelper.convertEnumToInt(idlParser.idlReader, idlMethod.getJavaReturnType());
returnType = StaticJavaParser.parseType(returnTypeStr);
}
methodDeclaration.setType(returnType);
Expand Down Expand Up @@ -403,7 +403,7 @@ private static MethodDeclaration containsMethod(IDLDefaultCodeParser idlParser,

for(int i = 0; i < parameters.size(); i++) {
IDLParameter parameter = parameters.get(i);
String paramType = parameter.type;
String paramType = parameter.getJavaType();
paramType = IDLHelper.convertEnumToInt(idlParser.idlReader, paramType);
paramTypes[i] = paramType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private static String getParams(NodeList<Parameter> parameters, ArrayList<IDLPar
IDLParameter idlParameter = idParameters.get(i);
Type type = parameter.getType();
boolean isObject = type.isClassOrInterfaceType();
String paramName = getParam(idlParameter.idlFile, isObject, idlParameter.name, idlParameter.type, idlParameter.isRef, idlParameter.isValue);
String paramName = getParam(idlParameter.idlFile, isObject, idlParameter.name, idlParameter.getJavaType(), idlParameter.isRef, idlParameter.isValue);
if(i > 0) {
param += ", ";
}
Expand Down

0 comments on commit fb30318

Please sign in to comment.