Skip to content

Commit

Permalink
Fix one validation edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredebelen committed Sep 24, 2024
1 parent 4870eba commit 5e54629
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,15 @@ function meta::protocols::generation::java::generateValidate(base:meta::external
$c.properties->map(p|
if (!$p->functionReturnType().rawType->toOne()->instanceOf(meta::pure::metamodel::type::DataType),
| let mul = $p->functionReturnMultiplicity()->toOne();
if (
[
pair(
|!$mul->hasLowerBound() && $mul->hasUpperBound() && $mul->getUpperBound() == 1,
|j_if(j_ne(j_field(j_this($base), $p.name->toOne()),j_null()),
if (!$mul->hasUpperBound() || ($mul->hasUpperBound() && ($mul->getUpperBound() > 1)),
|let rawType = $p->functionReturnType().rawType->toOne();
let typeAndPackages = $context.conventions.typeAndPackageNameStrategy->toOne()->eval($rawType, $context.conventions);
let variable = j_parameter(javaClass([], [], $typeAndPackages.first->javaPackage(), $typeAndPackages.second), 'val');
j_for($variable, j_field(j_this($base), $p.name->toOne()),j_invoke($resultVar,'addAll',j_invoke($variable, 'validate',[], $listType)));,
|j_if(j_ne(j_field(j_this($base), $p.name->toOne()),j_null()),
j_invoke($resultVar,'addAll',j_invoke(j_field(j_this($base), $p.name->toOne()),'validate',[],$listType))
)
),
pair(
|!$mul->hasUpperBound() || ($mul->hasUpperBound() && ($mul->getUpperBound() > 1)),
|let rawType = $p->functionReturnType().rawType->toOne();
let typeAndPackages = $context.conventions.typeAndPackageNameStrategy->toOne()->eval($rawType, $context.conventions);
let variable = j_parameter(javaClass([], [], $typeAndPackages.first->javaPackage(), $typeAndPackages.second), 'val');
j_for($variable, j_field(j_this($base), $p.name->toOne()),j_invoke($resultVar,'addAll',j_invoke($variable, 'validate',[], $listType)));
)
],
|j_invoke($resultVar,'addAll',j_invoke(j_field(j_this($base), $p.name->toOne()),'validate',[],$listType))
);,
);
);,
|[]
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ function <<test.Test>> meta::protocols::generation::java::tests::validate::testV
' {\n'+
' result.addAll(val.validate());\n'+
' }\n'+
' result.addAll(this.child.validate());\n'+
' if (this.child != null)\n'+
' {\n'+
' result.addAll(this.child.validate());\n'+
' }\n'+
' if (this.potentialChild != null)\n'+
' {\n'+
' result.addAll(this.potentialChild.validate());\n'+
Expand Down

0 comments on commit 5e54629

Please sign in to comment.