Skip to content

Commit 804a958

Browse files
authored
[Annotation Processor] Set default int type to BigInteger (#433)
* 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
1 parent c0a4a87 commit 804a958

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

annotation-processor/src/main/java/com/bloxbean/cardano/client/plutus/annotation/processor/blueprint/BlueprintAnnotationProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
8181
try {
8282
plutusContractBlueprint = PlutusBlueprintLoader.loadBlueprint(blueprintFile);
8383
} catch (Exception e) {
84+
e.printStackTrace();
8485
error(typeElement, "Error processing blueprint file %s", blueprintFile.getAbsolutePath(), e);
8586
return false;
8687
}

annotation-processor/src/main/java/com/bloxbean/cardano/client/plutus/annotation/processor/blueprint/DataTypeProcessUtil.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
import javax.annotation.processing.ProcessingEnvironment;
1111
import javax.lang.model.element.Modifier;
12+
import java.math.BigInteger;
1213
import java.util.ArrayList;
1314
import java.util.List;
1415

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

1719
public class DataTypeProcessUtil {
@@ -36,7 +38,7 @@ public FieldSpec processIntegerDataType(String javaDoc, BlueprintSchema schema,
3638
if(schema.getDataType() != integer)
3739
throw new IllegalArgumentException("Schema is not of type integer");
3840
String title = schema.getTitle() == null ? alternativeName : schema.getTitle();
39-
return FieldSpec.builder(int.class, title)
41+
return FieldSpec.builder(BigInteger.class, title)
4042
.addModifiers(Modifier.PRIVATE)
4143
.addJavadoc(javaDoc)
4244
.build();
@@ -94,7 +96,7 @@ private TypeName getInnerType(String ns, BlueprintSchema items) {
9496
case bytes:
9597
return TypeName.get(byte[].class);
9698
case integer:
97-
return TypeName.get(Integer.class);
99+
return TypeName.get(BigInteger.class);
98100
case string:
99101
return TypeName.get(String.class);
100102
case bool:
@@ -207,6 +209,7 @@ public FieldSpec processPlutusDataType(String javaDoc, BlueprintSchema schema, S
207209
private String getPackage(String ns) {
208210
String pkg = (ns != null && !ns.isEmpty())? annotation.packageName() + "." + ns + ".model"
209211
: annotation.packageName() + ".model";
210-
return pkg;
212+
213+
return toPackageNameFormat(pkg);
211214
}
212215
}

annotation-processor/src/main/java/com/bloxbean/cardano/client/plutus/annotation/processor/blueprint/FieldSpecProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

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

2021
@Slf4j
2122
public class FieldSpecProcessor {
@@ -337,6 +338,7 @@ public List<FieldSpec> createFieldSpecForDataTypes(String ns, String javaDoc, Bl
337338
private String getPackageName(String ns) {
338339
String pkg = (ns != null && !ns.isEmpty()) ? annotation.packageName() + "." + ns + ".model"
339340
: annotation.packageName() + ".model";
340-
return pkg;
341+
342+
return toPackageNameFormat(pkg);
341343
}
342344
}

annotation-processor/src/main/java/com/bloxbean/cardano/client/plutus/annotation/processor/blueprint/ValidatorProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import static com.bloxbean.cardano.client.plutus.annotation.processor.util.CodeGenUtil.createMethodSpecsForGetterSetters;
3232
import static com.bloxbean.cardano.client.plutus.annotation.processor.util.Constant.GENERATED_CODE;
33+
import static com.bloxbean.cardano.client.plutus.annotation.processor.util.JavaFileUtil.toPackageNameFormat;
3334

3435
public class ValidatorProcessor {
3536

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

72+
packageName = toPackageNameFormat(packageName);
73+
7174
String title = validatorName;
7275
title = JavaFileUtil.toCamelCase(title);
7376

annotation-processor/src/main/java/com/bloxbean/cardano/client/plutus/annotation/processor/util/JavaFileUtil.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public static String toClassNameFormat(String s) {
5656
return firstUpperCase(toCamelCase(s));
5757
}
5858

59+
public static String toPackageNameFormat(String pkg) {
60+
if (pkg == null) {
61+
return null;
62+
}
63+
64+
return pkg.toLowerCase().replace("-", "").replace("_", "");
65+
}
66+
67+
5968
/**
6069
* Creates a Java file from a TypeSpec with a given classname and package
6170
*

0 commit comments

Comments
 (0)