-
Notifications
You must be signed in to change notification settings - Fork 2
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
No #foreach/#context in when-clause of foreach property ini (#93) #104
Labels
Comments
Stephan Erb ([email protected]) wrote on 2010-12-22 10:27:44 I am not quite sure if I understand the intention of this bug. However, this may be due to my partial understand of the foreach construct, which I regard to be a combination of a for-loop with a nested switch-case. template MyTemplate : {{ mySpecialFeautres = foreach("OCL:self.features", when="#foreach.isSpecial", as=SpecialTemplate when="#foreach.isVerySpecial", as=VerySpecialTemplate ) }} ; Using this foreach I intend to print just the "special" and "very special" features and ignore all the others, thus letting foreach act as a filter. How could thus a use case be realized without #foreach within the when-clauses? |
Axel Uhl ([email protected]) wrote on 2010-12-22 10:45:01 (In reply to comment #1) > I am not quite sure if I understand the intention of this bug. However, this > may be due to my partial understand of the foreach construct, which I regard to > be a combination of a for-loop with a nested switch-case. > > template MyTemplate > : {{ > mySpecialFeautres = foreach("OCL:self.features", > when="#foreach.isSpecial", > as=SpecialTemplate > when="#foreach.isVerySpecial", > as=VerySpecialTemplate > ) > }} > ; > > Using this foreach I intend to print just the "special" and "very special" > features and ignore all the others, thus letting foreach act as a filter. How > could thus a use case be realized without #foreach within the when-clauses? Stephan, you would use "self" instead of "#foreach" in the when-clauses. Using #foreach the way you do in the above example would try to resolve it against any enclosing template's foreach(...) property init which is most definitely not what you want. |
Stephan Erb ([email protected]) wrote on 2010-12-27 13:51:01 Ok, letting refer "self" to the current foreach-element makes sense to me. I thus also agree with denying #context and #foreach in when clauses. However, within the Class.tcs I found several examples that imply "self" within when clauses binds to the corresponding model element of template. What is going on there? > operatorTemplate FunctionCallExpression(operators = lparen, source = 'calledBlock') > : parameters{separator=","} ")" > {{ > ownedTypeDefinition = foreach("OCL:self.getSignature().output", > when="OCL:self.getSignature().output.isMany() and self.calledBlock.getType().isMany()", mode=..., as=..., > when="OCL:self.getSignature().output.oclIsKindOf(ClassTypeDefinition)", mode=..., as=..., > when="OCL:self.getSignature().output.oclIsKindOf(FunctionSignatureTypeDefinition)", ..., > when="OCL:self.getSignature().output.oclIsKindOf(NestedTypeDefinition)", ... ) > }} > ; |
Axel Uhl ([email protected]) wrote on 2010-12-29 00:52:30 (In reply to comment #3) > Ok, letting refer "self" to the current foreach-element makes sense to me. I > thus also agree with denying #context and #foreach in when clauses. > > However, within the Class.tcs I found several examples that imply "self" within > when clauses binds to the corresponding model element of template. What is > going on there? Good point. It seems that the MOIN implementation of FURCAS must have interpreted these when-clauses in the context of the owning template, not the result of the foreach expression. I suggest we take this opportunity to change that. |
Stephan Erb ([email protected]) wrote on 2011-01-06 13:18:52 Any objections to defer this until we can embed an OCL syntax into our TCS syntax? (Then we don't have to do it now and then rethink / refactor it within a few weeks...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently it is possible to use #context and #foreach in an OCL expression forming the "when" clause of a "foreach" property init. Not only makes this little sense as the when-clause should typically filter the elements produced by the foreach base OCL expression, but also is this difficult to handle in the impact analysis-based model updater.
We should introduce an OCL constraint on the TCS metamodel on class PredicateSemantic that forbids the use of #context and #foreach in any when-clause.
The text was updated successfully, but these errors were encountered: