Update data generator
This commit is contained in:
parent
fed9d27a37
commit
e8c5304f61
2
pom.xml
2
pom.xml
|
@ -169,7 +169,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>it.cavallium</groupId>
|
<groupId>it.cavallium</groupId>
|
||||||
<artifactId>data-generator-runtime</artifactId>
|
<artifactId>data-generator-runtime</artifactId>
|
||||||
<version>1.0.62</version>
|
<version>1.0.63</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
|
@ -66,6 +66,7 @@ import org.yaml.snakeyaml.Yaml;
|
||||||
public class SourcesGenerator {
|
public class SourcesGenerator {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SourcesGenerator.class);
|
private static final Logger logger = LoggerFactory.getLogger(SourcesGenerator.class);
|
||||||
|
private static final boolean OVERRIDE_ALL_NULLABLE_METHODS = false;
|
||||||
|
|
||||||
private final SourcesGeneratorConfiguration configuration;
|
private final SourcesGeneratorConfiguration configuration;
|
||||||
|
|
||||||
|
@ -913,71 +914,73 @@ public class SourcesGenerator {
|
||||||
emptyMethod.returns(nullableClassType);
|
emptyMethod.returns(nullableClassType);
|
||||||
emptyMethod.addStatement("return NULL");
|
emptyMethod.addStatement("return NULL");
|
||||||
nullableTypeClass.addMethod(emptyMethod.build());
|
nullableTypeClass.addMethod(emptyMethod.build());
|
||||||
var isEmptyMethod = MethodSpec.methodBuilder("isEmpty");
|
if (OVERRIDE_ALL_NULLABLE_METHODS) {
|
||||||
isEmptyMethod.addModifiers(Modifier.PUBLIC);
|
var isEmptyMethod = MethodSpec.methodBuilder("isEmpty");
|
||||||
isEmptyMethod.addModifiers(Modifier.FINAL);
|
isEmptyMethod.addModifiers(Modifier.PUBLIC);
|
||||||
isEmptyMethod.addAnnotation(Override.class);
|
isEmptyMethod.addModifiers(Modifier.FINAL);
|
||||||
isEmptyMethod.returns(TypeName.BOOLEAN);
|
isEmptyMethod.addAnnotation(Override.class);
|
||||||
isEmptyMethod.addStatement("return value == null");
|
isEmptyMethod.returns(TypeName.BOOLEAN);
|
||||||
nullableTypeClass.addMethod(isEmptyMethod.build());
|
isEmptyMethod.addStatement("return value == null");
|
||||||
var isPresentMethod = MethodSpec.methodBuilder("isPresent");
|
nullableTypeClass.addMethod(isEmptyMethod.build());
|
||||||
isPresentMethod.addModifiers(Modifier.PUBLIC);
|
var isPresentMethod = MethodSpec.methodBuilder("isPresent");
|
||||||
isPresentMethod.addModifiers(Modifier.FINAL);
|
isPresentMethod.addModifiers(Modifier.PUBLIC);
|
||||||
isPresentMethod.addAnnotation(Override.class);
|
isPresentMethod.addModifiers(Modifier.FINAL);
|
||||||
isPresentMethod.returns(TypeName.BOOLEAN);
|
isPresentMethod.addAnnotation(Override.class);
|
||||||
isPresentMethod.addStatement("return value != null");
|
isPresentMethod.returns(TypeName.BOOLEAN);
|
||||||
nullableTypeClass.addMethod(isPresentMethod.build());
|
isPresentMethod.addStatement("return value != null");
|
||||||
var getMethod = MethodSpec.methodBuilder("get");
|
nullableTypeClass.addMethod(isPresentMethod.build());
|
||||||
getMethod.addModifiers(Modifier.PUBLIC);
|
var getMethod = MethodSpec.methodBuilder("get");
|
||||||
getMethod.addModifiers(Modifier.FINAL);
|
getMethod.addModifiers(Modifier.PUBLIC);
|
||||||
getMethod.addException(NullPointerException.class);
|
getMethod.addModifiers(Modifier.FINAL);
|
||||||
getMethod.addAnnotation(Override.class);
|
getMethod.addException(NullPointerException.class);
|
||||||
getMethod.addAnnotation(NotNull.class);
|
getMethod.addAnnotation(Override.class);
|
||||||
getMethod.returns(typeType);
|
getMethod.addAnnotation(NotNull.class);
|
||||||
getMethod.beginControlFlow("if (value == null)");
|
getMethod.returns(typeType);
|
||||||
getMethod.addStatement("throw new $T()", NullPointerException.class);
|
getMethod.beginControlFlow("if (value == null)");
|
||||||
getMethod.nextControlFlow("else");
|
getMethod.addStatement("throw new $T()", NullPointerException.class);
|
||||||
getMethod.addStatement("return value");
|
getMethod.nextControlFlow("else");
|
||||||
getMethod.endControlFlow();
|
getMethod.addStatement("return value");
|
||||||
nullableTypeClass.addMethod(getMethod.build());
|
getMethod.endControlFlow();
|
||||||
var orElseMethod = MethodSpec.methodBuilder("orElse");
|
nullableTypeClass.addMethod(getMethod.build());
|
||||||
orElseMethod.addParameter(ParameterSpec
|
var orElseMethod = MethodSpec.methodBuilder("orElse");
|
||||||
.builder(typeType, "defaultValue")
|
orElseMethod.addParameter(ParameterSpec
|
||||||
.addAnnotation(NotNull.class)
|
.builder(typeType, "defaultValue")
|
||||||
.build());
|
.addAnnotation(NotNull.class)
|
||||||
orElseMethod.addModifiers(Modifier.PUBLIC);
|
.build());
|
||||||
orElseMethod.addModifiers(Modifier.FINAL);
|
orElseMethod.addModifiers(Modifier.PUBLIC);
|
||||||
orElseMethod.addAnnotation(Override.class);
|
orElseMethod.addModifiers(Modifier.FINAL);
|
||||||
orElseMethod.addAnnotation(NotNull.class);
|
orElseMethod.addAnnotation(Override.class);
|
||||||
orElseMethod.returns(typeType);
|
orElseMethod.addAnnotation(NotNull.class);
|
||||||
orElseMethod.beginControlFlow("if (value == null)");
|
orElseMethod.returns(typeType);
|
||||||
orElseMethod.addStatement("return defaultValue");
|
orElseMethod.beginControlFlow("if (value == null)");
|
||||||
orElseMethod.nextControlFlow("else");
|
orElseMethod.addStatement("return defaultValue");
|
||||||
orElseMethod.addStatement("return value");
|
orElseMethod.nextControlFlow("else");
|
||||||
orElseMethod.endControlFlow();
|
orElseMethod.addStatement("return value");
|
||||||
nullableTypeClass.addMethod(orElseMethod.build());
|
orElseMethod.endControlFlow();
|
||||||
var orMethodGeneric = MethodSpec.methodBuilder("or");
|
nullableTypeClass.addMethod(orElseMethod.build());
|
||||||
orMethodGeneric.addParameter(ParameterSpec
|
var orMethodGeneric = MethodSpec.methodBuilder("or");
|
||||||
.builder(ParameterizedTypeName.get(
|
orMethodGeneric.addParameter(ParameterSpec
|
||||||
ClassName.get("it.cavallium.data.generator", "NativeNullable"),
|
.builder(ParameterizedTypeName.get(
|
||||||
WildcardTypeName.subtypeOf(typeType)), "fallback")
|
ClassName.get("it.cavallium.data.generator", "NativeNullable"),
|
||||||
.addAnnotation(NotNull.class)
|
WildcardTypeName.subtypeOf(typeType)), "fallback")
|
||||||
.build());
|
.addAnnotation(NotNull.class)
|
||||||
orMethodGeneric.addModifiers(Modifier.PUBLIC);
|
.build());
|
||||||
orMethodGeneric.addModifiers(Modifier.FINAL);
|
orMethodGeneric.addModifiers(Modifier.PUBLIC);
|
||||||
orMethodGeneric.addAnnotation(Override.class);
|
orMethodGeneric.addModifiers(Modifier.FINAL);
|
||||||
orMethodGeneric.addAnnotation(NotNull.class);
|
orMethodGeneric.addAnnotation(Override.class);
|
||||||
orMethodGeneric.returns(nullableClassType);
|
orMethodGeneric.addAnnotation(NotNull.class);
|
||||||
orMethodGeneric.beginControlFlow("if (value == null)");
|
orMethodGeneric.returns(nullableClassType);
|
||||||
orMethodGeneric.beginControlFlow("if (fallback.getClass() == $T.class)", nullableClassType);
|
orMethodGeneric.beginControlFlow("if (value == null)");
|
||||||
orMethodGeneric.addStatement("return ($T) fallback", nullableClassType);
|
orMethodGeneric.beginControlFlow("if (fallback.getClass() == $T.class)", nullableClassType);
|
||||||
orMethodGeneric.nextControlFlow("else");
|
orMethodGeneric.addStatement("return ($T) fallback", nullableClassType);
|
||||||
orMethodGeneric.addStatement("return ofNullable(fallback.getNullable())");
|
orMethodGeneric.nextControlFlow("else");
|
||||||
orMethodGeneric.endControlFlow();
|
orMethodGeneric.addStatement("return ofNullable(fallback.getNullable())");
|
||||||
orMethodGeneric.nextControlFlow("else");
|
orMethodGeneric.endControlFlow();
|
||||||
orMethodGeneric.addStatement("return this");
|
orMethodGeneric.nextControlFlow("else");
|
||||||
orMethodGeneric.endControlFlow();
|
orMethodGeneric.addStatement("return this");
|
||||||
nullableTypeClass.addMethod(orMethodGeneric.build());
|
orMethodGeneric.endControlFlow();
|
||||||
|
nullableTypeClass.addMethod(orMethodGeneric.build());
|
||||||
|
}
|
||||||
var orMethodSpecific = MethodSpec.methodBuilder("or");
|
var orMethodSpecific = MethodSpec.methodBuilder("or");
|
||||||
orMethodSpecific.addParameter(ParameterSpec
|
orMethodSpecific.addParameter(ParameterSpec
|
||||||
.builder(nullableTypeType, "fallback")
|
.builder(nullableTypeType, "fallback")
|
||||||
|
@ -1001,22 +1004,24 @@ public class SourcesGenerator {
|
||||||
getNullableMethod.returns(typeType);
|
getNullableMethod.returns(typeType);
|
||||||
getNullableMethod.addStatement("return value");
|
getNullableMethod.addStatement("return value");
|
||||||
nullableTypeClass.addMethod(getNullableMethod.build());
|
nullableTypeClass.addMethod(getNullableMethod.build());
|
||||||
var getNullableParam = MethodSpec.methodBuilder("getNullable");
|
if (OVERRIDE_ALL_NULLABLE_METHODS) {
|
||||||
getNullableParam.addParameter(ParameterSpec
|
var getNullableParam = MethodSpec.methodBuilder("getNullable");
|
||||||
.builder(typeType, "defaultValue")
|
getNullableParam.addParameter(ParameterSpec
|
||||||
.addAnnotation(Nullable.class)
|
.builder(typeType, "defaultValue")
|
||||||
.build());
|
.addAnnotation(Nullable.class)
|
||||||
getNullableParam.addModifiers(Modifier.PUBLIC);
|
.build());
|
||||||
getNullableParam.addModifiers(Modifier.FINAL);
|
getNullableParam.addModifiers(Modifier.PUBLIC);
|
||||||
getNullableParam.addAnnotation(Override.class);
|
getNullableParam.addModifiers(Modifier.FINAL);
|
||||||
getNullableParam.addAnnotation(Nullable.class);
|
getNullableParam.addAnnotation(Override.class);
|
||||||
getNullableParam.returns(typeType);
|
getNullableParam.addAnnotation(Nullable.class);
|
||||||
getNullableParam.beginControlFlow("if (value == null)");
|
getNullableParam.returns(typeType);
|
||||||
getNullableParam.addStatement("return defaultValue");
|
getNullableParam.beginControlFlow("if (value == null)");
|
||||||
getNullableParam.nextControlFlow("else");
|
getNullableParam.addStatement("return defaultValue");
|
||||||
getNullableParam.addStatement("return value");
|
getNullableParam.nextControlFlow("else");
|
||||||
getNullableParam.endControlFlow();
|
getNullableParam.addStatement("return value");
|
||||||
nullableTypeClass.addMethod(getNullableParam.build());
|
getNullableParam.endControlFlow();
|
||||||
|
nullableTypeClass.addMethod(getNullableParam.build());
|
||||||
|
}
|
||||||
var getDollarNullableMethod = MethodSpec.methodBuilder("$getNullable");
|
var getDollarNullableMethod = MethodSpec.methodBuilder("$getNullable");
|
||||||
getDollarNullableMethod.addModifiers(Modifier.PUBLIC);
|
getDollarNullableMethod.addModifiers(Modifier.PUBLIC);
|
||||||
getDollarNullableMethod.addModifiers(Modifier.FINAL);
|
getDollarNullableMethod.addModifiers(Modifier.FINAL);
|
||||||
|
|
Loading…
Reference in New Issue