-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Should use Java Optional to implement null-safe object navigation.
Examples:
operation f1(a : Foo[0,1]) :Integer;
begin
var x : String[0,1];
x := self.attr1;
return a?.m2(!!x, 3) ?: -1;
end;
Java code:
String x = this.getAttr1();
return Optional.ofNullable(a)
.map(it ->
it.m2(Object.requireNotNull(x), 3)
)
.orElseGet(
() -> -1
);
Action breakdown:
/* AddVariableValue: x */ x :=
/* ReadSelfAction */ self
/* ReadStructuralFeatureValue: attr1 */ .attr1
;
/* AddVariableValue: _result */ return
/* ConditionalNode «DefaultValueExpression» -> Integer[1,1] */
/* Clause 0 */
/* Body */
/* ReadVariable: a -> Foo[0,1] */ a
/* CallOperation: m1 -> Integer[0,1] */ ?.m2(
/* SAN «Cast Required» -> Integer[1,1] */
/* ReadVariable: x Integer[0,1] */,
/* LiteralValueSpecification: 3 -> Integer[1,1] */ 3
/* Clause 1 */
/* Body */
/* LiteralValueSpecification: -1 -> Integer[1,1] */ -1
);
Metadata
Metadata
Assignees
Labels
No labels