Skip to content

Commit

Permalink
[Annotation Processor] Set default int type to BigInteger (#433)
Browse files Browse the repository at this point in the history
* chore: Show error stack incase of error

* chore: Updated default int type to BigInteger and package name to lowercase

* chore: Remove - and _ from package name
  • Loading branch information
satran004 authored Sep 13, 2024
1 parent c0a4a87 commit 804a958
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
try {
plutusContractBlueprint = PlutusBlueprintLoader.loadBlueprint(blueprintFile);
} catch (Exception e) {
e.printStackTrace();
error(typeElement, "Error processing blueprint file %s", blueprintFile.getAbsolutePath(), e);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Modifier;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import static com.bloxbean.cardano.client.plutus.annotation.processor.util.JavaFileUtil.toPackageNameFormat;
import static com.bloxbean.cardano.client.plutus.blueprint.model.BlueprintDatatype.*;

public class DataTypeProcessUtil {
Expand All @@ -36,7 +38,7 @@ public FieldSpec processIntegerDataType(String javaDoc, BlueprintSchema schema,
if(schema.getDataType() != integer)
throw new IllegalArgumentException("Schema is not of type integer");
String title = schema.getTitle() == null ? alternativeName : schema.getTitle();
return FieldSpec.builder(int.class, title)
return FieldSpec.builder(BigInteger.class, title)
.addModifiers(Modifier.PRIVATE)
.addJavadoc(javaDoc)
.build();
Expand Down Expand Up @@ -94,7 +96,7 @@ private TypeName getInnerType(String ns, BlueprintSchema items) {
case bytes:
return TypeName.get(byte[].class);
case integer:
return TypeName.get(Integer.class);
return TypeName.get(BigInteger.class);
case string:
return TypeName.get(String.class);
case bool:
Expand Down Expand Up @@ -207,6 +209,7 @@ public FieldSpec processPlutusDataType(String javaDoc, BlueprintSchema schema, S
private String getPackage(String ns) {
String pkg = (ns != null && !ns.isEmpty())? annotation.packageName() + "." + ns + ".model"
: annotation.packageName() + ".model";
return pkg;

return toPackageNameFormat(pkg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;

import static com.bloxbean.cardano.client.plutus.annotation.processor.util.CodeGenUtil.createMethodSpecsForGetterSetters;
import static com.bloxbean.cardano.client.plutus.annotation.processor.util.JavaFileUtil.toPackageNameFormat;

@Slf4j
public class FieldSpecProcessor {
Expand Down Expand Up @@ -337,6 +338,7 @@ public List<FieldSpec> createFieldSpecForDataTypes(String ns, String javaDoc, Bl
private String getPackageName(String ns) {
String pkg = (ns != null && !ns.isEmpty()) ? annotation.packageName() + "." + ns + ".model"
: annotation.packageName() + ".model";
return pkg;

return toPackageNameFormat(pkg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import static com.bloxbean.cardano.client.plutus.annotation.processor.util.CodeGenUtil.createMethodSpecsForGetterSetters;
import static com.bloxbean.cardano.client.plutus.annotation.processor.util.Constant.GENERATED_CODE;
import static com.bloxbean.cardano.client.plutus.annotation.processor.util.JavaFileUtil.toPackageNameFormat;

public class ValidatorProcessor {

Expand Down Expand Up @@ -68,6 +69,8 @@ public void processValidator(Validator validator, PlutusVersion plutusVersion) {
if (pkgSuffix != null)
packageName = packageName + "." + pkgSuffix;

packageName = toPackageNameFormat(packageName);

String title = validatorName;
title = JavaFileUtil.toCamelCase(title);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public static String toClassNameFormat(String s) {
return firstUpperCase(toCamelCase(s));
}

public static String toPackageNameFormat(String pkg) {
if (pkg == null) {
return null;
}

return pkg.toLowerCase().replace("-", "").replace("_", "");
}


/**
* Creates a Java file from a TypeSpec with a given classname and package
*
Expand Down

0 comments on commit 804a958

Please sign in to comment.