|
|
|
|
Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1707024 is a reply to message #1707014] |
Tue, 01 September 2015 14:50 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
It should work, but rather more simply than you have suggested. OCL has
no mutation, so no constructors. The prototyped behavior is just direct
initialization with explicit/default values.
class TupleIntInt
{
property m : Integer;
property n : Integer;
}
let aTII = TupleIntInt{m = 1, n = 2} in aTII.m * aTII.n
The current prototype is inaccurate wrt to the shadow semantics that
requires shared copies, so
TupleIntInt{m = 1, n = 2} = TupleIntInt{m = 1, n = 2}
should be unequivocably true. It is false when executed using the OCL
interpreter. It is perhaps true if the code generator is given an
opportunity to do common subexpression elimination. Fixed on a WIP branch.
Regards
Ed Willink
On 01/09/2015 14:51, Keith Ó Dúlaigh wrote:
> Hi,
>
> Related to this question. Suppose I have created a class TupleIntInt
> similar to the following code. Then can I use OCL to construct a new
> instance of TupleIntInt?
>
> class TupleIntInt
> {
> property m : Integer;
> property n : Integer;
>
> operation create() : TupleIntInt[1]
> {
> body: TupleIntInt{m = 1, n = 2};
> }
> }
>
>
> Constructing a new object always returns "invalid" when I attempt to
> construct a new object.
>
> I note in an earlier post there is a link to a bug report that says
> "...pivot now has a prototype of type constructors."
>
>
> Thanks,
> Keith
>
> =====================================
> Earlier related post:
>
> https://www.eclipse.org/forums/index.php/t/543504/
|
|
|
Re: OCLinEclipse Discarding Tuple Type Information on Operations [message #1707035 is a reply to message #1707024] |
Tue, 01 September 2015 15:48 |
Keith Ó Dúlaigh Messages: 5 Registered: September 2014 |
Junior Member |
|
|
Thanks Ed, maybe my Java code is the problem because I still have "invalid" being returned.
My full OCL looks like this...
package example : web = 'URL REMOVED BECAUSE I'VE < 5 POSTS'
{
class TupleIntInt
{
operation test() : Integer
{
body: let ai = TupleIntInt{m= 5, n = 1}
in ai.m * ai.n;
}
operation test2() : Integer
{
body: 5;
}
operation test3() : TupleIntInt[1]
{
body: TupleIntInt{m= 5, n = 1};
}
attribute m : Integer[?];
attribute n : Integer[?];
}
}
...and my Java like this:
package main;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EParameter;
import org.eclipse.ocl.OCL;
import org.eclipse.ocl.ParserException;
import org.eclipse.ocl.Query;
import org.eclipse.ocl.ecore.Constraint;
import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
import org.eclipse.ocl.expressions.OCLExpression;
import org.eclipse.ocl.helper.OCLHelper;
import example.ExampleFactory;
public class Application {
public static void main(String... args) {
ExampleFactory.eINSTANCE.eClass();
Object o = runOcl("test2()");
System.out.println(o);
o = runOcl("test()");
System.out.println(o);
o = runOcl("test3()");
System.out.println(o);
}
private static Object runOcl(String queryText) {
OCL<?, EClassifier, ?, ?, ?, EParameter, ?, ?, ?, Constraint, EClass, EObject> ocl = OCL
.newInstance(EcoreEnvironmentFactory.INSTANCE);
OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl.createOCLHelper();
helper.setContext(ExampleFactory.eINSTANCE.createTupleIntInt().eClass());
Query<EClassifier, EClass, EObject> query = null;
try {
OCLExpression<EClassifier> expression = helper.createQuery(queryText);
query = ocl.createQuery(expression);
} catch (ParserException error) {
throw new RuntimeException(error);
}
return query.evaluate(ExampleFactory.eINSTANCE);
}
}
Running the Java code yields:
[Updated on: Tue, 01 September 2015 15:49] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02648 seconds