Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Annotation Processor] Set default int type to BigInteger #433

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this for now till we find a better way to notify error during compilation.

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
Loading