Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » operation return type as Tuple
operation return type as Tuple [message #754848] Fri, 04 November 2011 11:40 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 458
Registered: June 2011
Senior Member
Hi,

I want to create an ocl operation with return type as Tuple.
For example if we want Integer to be return type of operation then we do like

eOperation.setEType(EcorePackage.eINSTANCE.getEInt())

and when we want to have a class as return type then

eOperation.setEType(etypeClass);

i want to have operation's return type as tuple holding class object and integer togather.

Any idea?

Thanks!

Warmest Regards

[Updated on: Fri, 04 November 2011 11:41]

Report message to a moderator

Re: operation return type as Tuple [message #754860 is a reply to message #754848] Fri, 04 November 2011 12:44 Go to previous messageGo to next message
Axel Uhl is currently offline Axel Uhl
Messages: 40
Registered: July 2009
Member
Have you tried using org.eclipse.ocl.ecore.TupleType? It extends EClass. Its properties represent the tuple's components.

Best,
-- Axel
Re: operation return type as Tuple [message #754880 is a reply to message #754860] Fri, 04 November 2011 13:57 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3838
Registered: July 2009
Senior Member
Hi

You will probably also want values.

You may find
org.eclipse.ocl.ecore.tests.RegressionTest.test_product_126336() and
org.eclipse.ocl.ecore.tests.CollectionsTest.test_tupleWithCollectionLiteralPart_175490()
are a source of useful example usages.

Regards

Ed Willink


On 04/11/2011 17:44, Axel Uhl wrote:
> Have you tried using org.eclipse.ocl.ecore.TupleType? It extends
> EClass. Its properties represent the tuple's components.
>
> Best,
> -- Axel
Re: operation return type as Tuple [message #757780 is a reply to message #754860] Mon, 21 November 2011 11:07 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 458
Registered: June 2011
Senior Member
Hi,

Thanks for help!

I am using the following code but when i try to parse the OCL operation it gives parse exception.

EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
TupleType tt = org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createTupleType();
EAttribute eAttribute1 = EcoreFactory.eINSTANCE.createEAttribute();
EAttribute eAttribute2 = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute1.setEType(EcorePackage.eINSTANCE.getEString());
eAttribute1.setEType(EcorePackage.eINSTANCE.getEDouble());
tt.getEStructuralFeatures().add(eAttribute1);
tt.getEStructuralFeatures().add(eAttribute2);
eOperation.setEType(tt);

can you help me finding the problem?

Best Regards,

Re: operation return type as Tuple [message #757875 is a reply to message #757780] Mon, 21 November 2011 13:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3838
Registered: July 2009
Senior Member
Hi

You only provided half an example. When reporting an exception quote the
exception. I get no trouble from

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.ocl.ecore.TupleType;

public class Geek {

public void test() {
EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
TupleType tt =
org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createTupleType();
EAttribute eAttribute1 = EcoreFactory.eINSTANCE.createEAttribute();
EAttribute eAttribute2 = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute1.setEType(EcorePackage.eINSTANCE.getEString());
eAttribute1.setEType(EcorePackage.eINSTANCE.getEDouble());
tt.getEStructuralFeatures().add(eAttribute1);
tt.getEStructuralFeatures().add(eAttribute2);
eOperation.setEType(tt);

}
}

I suspect you made the wrong import decision on one of
EcorePackage/EcoreFactory/TupleType.

Regards

Ed Willink

On 21/11/2011 16:07, ModelGeek wrote:
> EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
> TupleType tt =
> org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createTupleType();
> EAttribute eAttribute1 = EcoreFactory.eINSTANCE.createEAttribute();
> EAttribute eAttribute2 = EcoreFactory.eINSTANCE.createEAttribute();
> eAttribute1.setEType(EcorePackage.eINSTANCE.getEString());
> eAttribute1.setEType(EcorePackage.eINSTANCE.getEDouble());
> tt.getEStructuralFeatures().add(eAttribute1);
> tt.getEStructuralFeatures().add(eAttribute2);
> eOperation.setEType(tt);
Re: operation return type as Tuple [message #758173 is a reply to message #757875] Tue, 22 November 2011 03:53 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 458
Registered: June 2011
Senior Member
Hi,

Here is complete code and exception:

EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eAnnotation.setSource("http://www.eclipse.org/emf/2002/Ecore/OCL");
eAnnotation.getDetails().put("body", operation.getBody());
eOperation.setName(operation.getName());
eOperation.getEAnnotations().add(eAnnotation);
TupleType tt = org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createTupleType();
EAttribute eAttribute1 = EcoreFactory.eINSTANCE.createEAttribute();
EAttribute eAttribute2 = EcoreFactory.eINSTANCE.createEAttribute();
eAttribute1.setEType(EcorePackage.eINSTANCE.getEString());
eAttribute1.setEType(EcorePackage.eINSTANCE.getEDouble());
tt.getEStructuralFeatures().add(eAttribute1);
tt.getEStructuralFeatures().add(eAttribute2);
eOperation.setEType(tt);

OCL<?, EClassifier, EOperation, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
OCLHelper<EClassifier, EOperation, ?, Constraint> helper = ocl.createOCLHelper();
OCLFunction operation = null;
helper.setOperationContext(eClass, eOperation);
try {
String body = eOperation.getEAnnotations().get(0).getDetails().get("body");
helper.createBodyCondition(body);
} catch (ParserException ex) {
ex.printStackTrace(); }

org.eclipse.ocl.ParserException
at org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLHelperImpl.java:403)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createBodyCondition(OCLHelperImpl.java:263)
at abstractmodeller.model.prm.ECoreGenerator.validateOCLOperation(ECoreGenerator.java:651)
at abstractmodeller.model.prm.Prm.parsePOClFunctionsForPrmClass(Prm.java:792)
at abstractmodeller.view.canvas.controllers.PrmClassWidgetController.parsePOCLFunctions(PrmClassWidgetController.java:338)
at abstractmodeller.view.canvas.dialogs.POCLFunctionsDialog.init(POCLFunctionsDialog.java:190)
at abstractmodeller.view.canvas.dialogs.POCLFunctionsDialog.<init>(POCLFunctionsDialog.java:92)
at abstractmodeller.view.canvas.PrmClassWidget.executePopupMenuChoice(PrmClassWidget.java:495)
at abstractmodeller.view.shared.components.PopupMenu.actionPerformed(PopupMenu.java:219)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.NullPointerException
at org.eclipse.ocl.ecore.internal.OCLFactoryImpl.createTupleType(OCLFactoryImpl.java:153)
at org.eclipse.ocl.AbstractTypeResolver.createTupleType(AbstractTypeResolver.java:403)
at org.eclipse.ocl.AbstractTypeResolver.resolveTupleType(AbstractTypeResolver.java:385)
at org.eclipse.ocl.AbstractTypeResolver$ResolveSwitch.caseTupleType(AbstractTypeResolver.java:1008)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:260)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:111)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:99)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:84)
at org.eclipse.ocl.AbstractTypeResolver.resolve(AbstractTypeResolver.java:127)
at org.eclipse.ocl.AbstractTypeResolver$ResolveSwitch.caseCollectionType(AbstractTypeResolver.java:1003)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:161)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:111)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:99)
at org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:84)
at org.eclipse.ocl.AbstractTypeResolver.resolve(AbstractTypeResolver.java:127)
at org.eclipse.ocl.util.TypeUtil.resolveType(TypeUtil.java:617)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getOCLType(AbstractOCLAnalyzer.java:4423)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.prePostOrBodyDeclCS(AbstractOCLAnalyzer.java:969)
at org.eclipse.ocl.parser.OCLAnalyzer.parsePrePostOrBodyDeclCS(OCLAnalyzer.java:290)
at org.eclipse.ocl.internal.helper.HelperUtil.parseBodyCondition(HelperUtil.java:284)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createBodyCondition(OCLHelperImpl.java:260)
... 34 more

[Updated on: Tue, 22 November 2011 03:56]

Report message to a moderator

Re: operation return type as Tuple [message #758188 is a reply to message #758173] Tue, 22 November 2011 04:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3838
Registered: July 2009
Senior Member
Hi

This is still not complete code (where are the imports?)

You have added additional Java lines which completely change the
question; previously it was a simple Java coding problem, now there is
some OCL parsing, but you do not provide the OCL or the referenced models.

The stack trace clearly shows an NPE at OCLFactoryImpl.java:153, that on
the current code base is

Environment<?, C, O, P, ?, ?, ?, ?, ?, ?, ?, ?> env =

Environment.Registry.INSTANCE.getEnvironmentFor(parts.get(0));

which looks suspiciously like Environment.Registry.INSTANCE is null,
since parts is an EMF collection that is never null. But INSTANCE has an
initializer so it too should never be null. You need to do some
debugging. Perhaps you are using older code and the line number aligns
differently. It always helps to specify a code version.

Background: Tuples and Collections are awkward because specializations
have to be created and contained somewhere. OCL provides a default
internal package for them, but if you serialize the OCL you must take
responsibility for their containment; I doubt you're serializing, so you
can ignore doing this.

Regards

Ed Willink

On 22/11/2011 08:53, ModelGeek wrote:
> Hi,
>
> Here is complete code and exception:
>
> EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
> TupleType tt =
> org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createTupleType();
> EAttribute eAttribute1 = EcoreFactory.eINSTANCE.createEAttribute();
> EAttribute eAttribute2 = EcoreFactory.eINSTANCE.createEAttribute();
> eAttribute1.setEType(EcorePackage.eINSTANCE.getEString());
> eAttribute1.setEType(EcorePackage.eINSTANCE.getEDouble());
> tt.getEStructuralFeatures().add(eAttribute1);
> tt.getEStructuralFeatures().add(eAttribute2);
> eOperation.setEType(tt);
>
> OCL<?, EClassifier, EOperation, ?, ?, ?, ?, ?, ?,
> Constraint, EClass, EObject> ocl =
> OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> OCLHelper<EClassifier, EOperation, ?, Constraint>
> helper = ocl.createOCLHelper();
> OCLFunction operation = null;
> helper.setOperationContext(eClass, eOperation);
> try {
> String body =
> eOperation.getEAnnotations().get(0).getDetails().get("body");
> helper.createBodyCondition(body);
> } catch (ParserException ex) {
> ex.printStackTrace(); }
>
> org.eclipse.ocl.ParserException
> at
> org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLHelperImpl.java:403)
> at
> org.eclipse.ocl.internal.helper.OCLHelperImpl.createBodyCondition(OCLHelperImpl.java:263)
> at
> abstractmodeller.model.prm.ECoreGenerator.validateOCLOperation(ECoreGenerator.java:651)
> at
> abstractmodeller.model.prm.Prm.parsePOClFunctionsForPrmClass(Prm.java:792)
> at
> abstractmodeller.view.canvas.controllers.PrmClassWidgetController.parsePOCLFunctions(PrmClassWidgetController.java:338)
> at
> abstractmodeller.view.canvas.dialogs.POCLFunctionsDialog.init(POCLFunctionsDialog.java:190)
> at
> abstractmodeller.view.canvas.dialogs.POCLFunctionsDialog.<init>(POCLFunctionsDialog.java:92)
> at
> abstractmodeller.view.canvas.PrmClassWidget.executePopupMenuChoice(PrmClassWidget.java:495)
> at
> abstractmodeller.view.shared.components.PopupMenu.actionPerformed(PopupMenu.java:219)
> at
> javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
> at
> javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
> at
> javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
> at
> javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
> at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
> at
> javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223)
> at
> javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
> at java.awt.Component.processMouseEvent(Component.java:6267)
> at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
> at java.awt.Component.processEvent(Component.java:6032)
> at java.awt.Container.processEvent(Container.java:2041)
> at java.awt.Component.dispatchEventImpl(Component.java:4630)
> at java.awt.Container.dispatchEventImpl(Container.java:2099)
> at java.awt.Component.dispatchEvent(Component.java:4460)
> at
> java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
> at
> java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
> at java.awt.Container.dispatchEventImpl(Container.java:2085)
> at java.awt.Window.dispatchEventImpl(Window.java:2478)
> at java.awt.Component.dispatchEvent(Component.java:4460)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
> at
> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
> at
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
> at
> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
> at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
> at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.ocl.ecore.internal.OCLFactoryImpl.createTupleType(OCLFactoryImpl.java:153)
> at
> org.eclipse.ocl.AbstractTypeResolver.createTupleType(AbstractTypeResolver.java:403)
> at
> org.eclipse.ocl.AbstractTypeResolver.resolveTupleType(AbstractTypeResolver.java:385)
> at
> org.eclipse.ocl.AbstractTypeResolver$ResolveSwitch.caseTupleType(AbstractTypeResolver.java:1008)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:260)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:111)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:99)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:84)
> at
> org.eclipse.ocl.AbstractTypeResolver.resolve(AbstractTypeResolver.java:127)
> at
> org.eclipse.ocl.AbstractTypeResolver$ResolveSwitch.caseCollectionType(AbstractTypeResolver.java:1003)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:161)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:111)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitchSuperTypes(TypesSwitch.java:116)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:99)
> at
> org.eclipse.ocl.types.util.TypesSwitch.doSwitch(TypesSwitch.java:84)
> at
> org.eclipse.ocl.AbstractTypeResolver.resolve(AbstractTypeResolver.java:127)
> at org.eclipse.ocl.util.TypeUtil.resolveType(TypeUtil.java:617)
> at
> org.eclipse.ocl.parser.AbstractOCLAnalyzer.getOCLType(AbstractOCLAnalyzer.java:4423)
> at
> org.eclipse.ocl.parser.AbstractOCLAnalyzer.prePostOrBodyDeclCS(AbstractOCLAnalyzer.java:969)
> at
> org.eclipse.ocl.parser.OCLAnalyzer.parsePrePostOrBodyDeclCS(OCLAnalyzer.java:290)
> at
> org.eclipse.ocl.internal.helper.HelperUtil.parseBodyCondition(HelperUtil.java:284)
> at
> org.eclipse.ocl.internal.helper.OCLHelperImpl.createBodyCondition(OCLHelperImpl.java:260)
> ... 34 more
Re: operation return type as Tuple [message #758211 is a reply to message #758188] Tue, 22 November 2011 06:01 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 458
Registered: June 2011
Senior Member
Hi,

I have tried to check and i have found that Environment.Registry.INSTANCE is not null but Environment.Registry.INSTANCE.getEnvironmentFor(eClass) gives null.

And i am not doing serialization.

When i try to create an ocl operation with return type not as tuple type then everything works fine, the parsing works fine as well.

Do you have any clue? what is going wrong

Thanks alot for helping

Regards,

[Updated on: Tue, 22 November 2011 06:48]

Report message to a moderator

Re: operation return type as Tuple [message #758240 is a reply to message #758211] Tue, 22 November 2011 07:26 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 458
Registered: June 2011
Senior Member
Hi,

I have solved it, i added

Environment.Registry.INSTANCE.registerEnvironment(ocl.getEnvironment());

and it operation parsed perfectly.

THanks for help!
Re: operation return type as Tuple [message #758305 is a reply to message #758240] Tue, 22 November 2011 11:49 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 3838
Registered: July 2009
Senior Member
Hi

Well done for finding a workaround/fix. It doesn't seem right to do
something to a global registry, and it doesn't seem right that you
should need to do so at all.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=364493 raised, though
since it's on the legacy code, I can't be sure if it'll be resolved.

Regards

Ed Willink

On 22/11/2011 12:26, ModelGeek wrote:
> Hi,
>
> I have solved it, i added
>
> Environment.Registry.INSTANCE.registerEnvironment(ocl.getEnvironment());
>
> and it operation parsed perfectly.
>
> THanks for help!
Previous Topic:[Announce] Eclipse OCL 4.0.0 (Juno) M3 is now available
Next Topic:How to initialize the attributes of variables in an OCL query
Goto Forum:
  


Current Time: Wed Apr 16 03:23:42 EDT 2014

Powered by FUDForum. Page generated in 0.04863 seconds