[furcas-discussion] PS foreach/when

Uhl, Axel axel.uhl at sap.com
Wed Feb 16 14:41:14 CET 2011


One more thought. The Class.tcs case

                        ownedTypeDefinition = foreach("OCL:self.getSignature().output",  
                                when="OCL:self.getSignature().output.isMany() and self.calledBlock.getType().isMany()", mode="functionCallExpression", as=NestedTypeDefinition,
                                when="OCL:self.getSignature().output.oclIsKindOf(ClassTypeDefinition)", mode="functionCallExpression", as=ClassTypeDefinition, 
                                when="OCL:self.getSignature().output.oclIsKindOf(FunctionSignatureTypeDefinition)", mode="functionCallExpression", as=FunctionSignatureTypeDefinition,
                                when="OCL:self.getSignature().output.oclIsKindOf(NestedTypeDefinition)", mode="functionCallExpressionNoFurtherNesting", as=NestedTypeDefinition)

could be solved if we separated the following aspects more clearly:

 - number of elements to produce
 - type/mode of each of the elements to produce

With the current implementation of foreach there is an implicit coupling between number and type because by default both are taken from the result of the foreach expression. That's why self.getSignature().output is so convenient.

Were we able to provide an optional expression that separately defines the type based on either the template's element or the individual result element of the foreach expression then we could, in the example above, just use "self" as the foreach expression because we want to produce a single element, then use the when-clauses as specified in the example (using the template's element as their self-context) and additionally specifying some new property, e.g.,

	defaultTypeLike="self.getSignature().output"

which defines the default type to use in case no when/as is matched to be the same as the result type of the expression (self.getSignature().output).

We could still say that if no defaultTypeLike-expression is specified then the default type is taken to be the type of the current result object of the foreach expression.

For advanced use cases we may even contemplate differentiating between defaultTypeLike, which uses the template's element as its self-context, and a variant, e.g., defaultForeachTypeLike, which then uses the individual foreach result object as the self context.

Thoughts?

-- Axel


More information about the Furcas-discussion mailing list