[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.mdt.ocl] Re: def expression?

Hi Joel

I'm not sure about your whole problem but when you mention removing variables from environments I get very uncomfortable. It is much easier
to created a nested environment for the nested scope and revert to the
outer ebvironment when you want to recover context.


I know Let and Iterate current use dynamically changing environments, but that is likely to change to nested environments in the next MDT-OCL release.

	Regards

		Ed Willink

Joel Greenyer wrote:
Hi Christian,
thanks for pointing me to the JUnit tests. However, I am still a bit lost. Or, maybe, my problem is bit more tricky than just using def-expressions.


What I am doing is the following: I have a graph matcher that matches typed nodes to eObjects. When named nodes are
bound in the matching process, I add a variable with the node's name and the bound eObject to the OCL
environment/evaluationenvironment. The graph matcher also backtracks at times, and when it does, I remove those variables corresponding to the back-tracked nodes again from the OCL environment/evaluationenvironment.


Before nodes can be bound, I check OCL constraints that are attached to them. Those constraints
may contain variables that already exist (when the corresponding nodes were bound) or not (when the corresponding nodes are not yet bound). In the latter case, I catch a parseException and try evaluating the expression again when matching the next node and so on, until I can successfully evaluate the expression. I put all successfully evaluated expressions in a map (node where evaluation was successful->expression) and upon backtracking, I put them back into a list of yet-to-be-evaluated expressions.


Now I'd like to use expressions that allow me to define reusable values (and also operations in the long term).

One general thing that confuses me is that the def-expressions define attributes of some context classifier. In
let-expressions, for example, I just define a variable that I can reuse in the in-expression. That is rather what I want. I'd just like to create a variable to reuse.


Right now I am thinking of processing the "def: <varname> : <typename> = " part of the def-expression in my own code, let the OCL-helper evaluate the subsequent expression, and define a variable in the same way I do for my nodes.
Then again I wonder whether the OCL fragmework could help me do that? Or do you have any better idea to define my variables?
Mind, that I also have to "undefine" those variables again when I backtrack past the point of where I successfully evaluated it.


Thanks for helping

Joel




Christian W. Damus wrote:
Hi, Joel,

If the SDK documentation doesn't provide examples, then your best bet is to look into the JUnit tests. Search for invocations of the OCLHelper methods in the org.eclipse.ocl.ecore.tests plug-in, for example. They should all be covered, IIRC.

HTH,

Christian


On Wed, 2009-08-05 at 15:46 +0200, Joel Greenyer wrote:
So, the def-expression is no query and createQuery(String expression) does not work. Instead, I have to use OCLHelper.defineAttribute(String defExpression), right?
The problem is that I can't find any examples of using the OCL API in the right way to handle different cases of expressions (queries and def-expression) that I have in my transformation rules.
Could anyone please provide a snippet how to do that or point me to some example that demonstrates how to do it?


Thanks a lot

Joel

Joel Greenyer wrote:
> Hi,
> I'm confused whether or how the "def:" expression is supported. My > intuition is that I e.g. type
> > def: s: String = 'Hello'
> > in the console and that I can use the variable s when evaluating > subsequent expressions. However, that doesn't seem to work.
> > What am I missing?
> > Joel