Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Define allInstances() operation for Signals
Define allInstances() operation for Signals [message #1735185] Thu, 16 June 2016 08:20 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Hi!

I need to write and parse constraints of the form:
Signal1.allInstances()->notEmpty()
where Signal1 is an instance of uml::Signal

I don't need to execute them, instead I need only an AST.

The problem is that I get the error:
Unresolved Static Operation 'test::Signal1::allInstances()'

It seems that signals doesn't have allInstances() operation. Here is a request with a test project and more details:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=496210

Is it possible to define this operation programmaticaly as a workaround? I'm trying to define the operation for all signals in the model programmaticaly:

        TreeIterator<EObject> iter = uml.eAllContents();
        while (iter.hasNext()) {
            EObject obj = iter.next();
            if (obj instanceof Signal) {
                try {
                    org.eclipse.ocl.pivot.Signal signal = ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Signal.class, obj);
                    org.eclipse.ocl.pivot.Operation asOperation = PivotFactory.eINSTANCE.createOperation();
                    org.eclipse.ocl.pivot.CollectionType returnType = PivotFactory.eINSTANCE.createSetType();
                    returnType.setElementType(signal);

                    TemplateSignature sign = PivotFactory.eINSTANCE.createTemplateSignature();
                    TemplateParameter param = PivotFactory.eINSTANCE.createTemplateParameter();
                    sign.getOwnedParameters().add(param);
                    
                    returnType.setOwnedSignature(sign);
                    returnType.setLower(0);
                    returnType.setUpper(-1);
                    returnType.setOwningPackage(umlAS);
                    
                    signal.getOwnedOperations().add(asOperation);
                    asOperation.setName("allInstances");
                    asOperation.setIsStatic(true);
                    asOperation.setType(returnType);
                } catch (ParserException e) {
                    e.printStackTrace();
                }
            }
        }


Here is a full project https://github.com/AresEkb/allInstances_test Just uncomment the operation creation code. But something is wrong:

org.eclipse.ocl.pivot.utilities.SemanticException: The 'test::Signal1' constraint is invalid: 'Signal1.allInstances()->notEmpty()'
1: java.lang.IllegalStateException
	at org.eclipse.ocl.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:144)
	at org.eclipse.ocl.pivot.internal.context.AbstractParserContext.parse(AbstractParserContext.java:154)
	at org.eclipse.ocl.pivot.internal.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:113)
	at org.eclipse.ocl.pivot.utilities.OCL.createInvariant(OCL.java:261)


Could you suggest the right way to define allInstances() programmaticaly?
Re: Define allInstances() operation for Signals [message #1735213 is a reply to message #1735185] Thu, 16 June 2016 11:08 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5580
Registered: July 2009
Senior Member
Hi

A fix is described in https://bugs.eclipse.org/bugs/show_bug.cgi?id=496210

Please add comments to the bug for any relevant part of this that is not
addressed.

-----

Modifying loaded metamodels is very dangerous since the current manually
written support almost certainly has missing code to refresh caches.

The Pivot OCL supports open classes, whereby a CompleteClass is an
overlaid merge of many partial classes. You should therefore create a
new Model/Package/Class/Operation hierarchy and install it. The easiest
way may be to load a Complete OCL document. This will certainly give you
some clues as to what you need to do and may point you at some helper
routines. Most notably, your handcrafted return type specialiization is
very deficient. It should be a shared singleton in the orphanage.

Regards

Ed Willink


On 16/06/2016 09:21, Denis Nikiforov wrote:
> Hi!
>
> I need to write and parse constraints of the form:
> Signal1.allInstances()->notEmpty()
> where Signal1 is an instance of uml::Signal
>
> I don't need to execute them, instead I need only an AST.
>
> The problem is that I get the error:
> Unresolved Static Operation 'test::Signal1::allInstances()'
>
> It seems that signals doesn't have allInstances() operation. Here is a
> request with a test project and more details:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=496210
>
> Is it possible to define this operation programmaticaly as a
> workaround? I'm trying to define the operation for all signals in the
> model programmaticaly:
>
> TreeIterator<EObject> iter = uml.eAllContents();
> while (iter.hasNext()) {
> EObject obj = iter.next();
> if (obj instanceof Signal) {
> try {
> org.eclipse.ocl.pivot.Signal signal =
> ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Signal.class,
> obj);
> org.eclipse.ocl.pivot.Operation asOperation =
> PivotFactory.eINSTANCE.createOperation();
> org.eclipse.ocl.pivot.CollectionType returnType =
> PivotFactory.eINSTANCE.createSetType();
> returnType.setElementType(signal);
>
> TemplateSignature sign =
> PivotFactory.eINSTANCE.createTemplateSignature();
> TemplateParameter param =
> PivotFactory.eINSTANCE.createTemplateParameter();
> sign.getOwnedParameters().add(param);
> returnType.setOwnedSignature(sign);
> returnType.setLower(0);
> returnType.setUpper(-1);
> returnType.setOwningPackage(umlAS);
> signal.getOwnedOperations().add(asOperation);
> asOperation.setName("allInstances");
> asOperation.setIsStatic(true);
> asOperation.setType(returnType);
> } catch (ParserException e) {
> e.printStackTrace();
> }
> }
> }
>
>
> Here is a full project https://github.com/AresEkb/allInstances_test
> Just uncomment the operation creation code. But something is wrong:
>
> org.eclipse.ocl.pivot.utilities.SemanticException: The 'test::Signal1'
> constraint is invalid: 'Signal1.allInstances()->notEmpty()'
> 1: java.lang.IllegalStateException
> at
> org.eclipse.ocl.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:144)
> at
> org.eclipse.ocl.pivot.internal.context.AbstractParserContext.parse(AbstractParserContext.java:154)
> at
> org.eclipse.ocl.pivot.internal.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:113)
> at org.eclipse.ocl.pivot.utilities.OCL.createInvariant(OCL.java:261)
>
>
> Could you suggest the right way to define allInstances() programmaticaly?
Previous Topic:[oclinecore] import statement gets rewritten
Next Topic:Announcing OCL 6.1.0 (and 6.2.0) for Neon
Goto Forum:
  


Current Time: Fri Jan 19 00:09:49 GMT 2018

Powered by FUDForum. Page generated in 0.02159 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software