Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Assigning rule generated target model elements to a contained reference
Assigning rule generated target model elements to a contained reference [message #632337] Tue, 12 October 2010 15:36 Go to next message
James Sharp is currently offline James Sharp
Messages: 20
Registered: September 2010
Junior Member
Hi Chaps,

I have been toying around with rules and the usage of equivalent and equivalents.

I have the following rule:

rule DefinedType2NameType
transform definedType : vhdl!DefinedType
to nameType : csp!NameType {
guard : not (definedType.containsItem.exists(typeItem : vhdl!TypeItem | typeItem.name <>"'1'" and typeItem.name<>"'0'"))
nameType.name := definedType.name.toUpperCase();
nameType.definesNameTypeItems := new csp!NameTypeList;
nameType.definesNameTypeItems.containsDataTypeItem.equivalen ts();

var temp := definedType.containsItem.equivalents();
//nameType.definesNameTypeItems.containsDataTypeItem.addAll( temp);
temp.println();
}

This rule triggering the creation of the equivalent CSP values using a lazy rule (not shown here), however when I uncomment the line:
nameType.definesNameTypeItems.containsDataTypeItem.addAll(te mp);
I get the error message:
Internal error: java.lang.ArrayStoreException

How would I go about assigning the collection of tranformed TypeItems to the target model location specified by the commented line?

Many Thanks,

James
Re: Assigning rule generated target model elements to a contained reference [message #632514 is a reply to message #632337] Wed, 13 October 2010 09:39 Go to previous messageGo to next message
James Sharp is currently offline James Sharp
Messages: 20
Registered: September 2010
Junior Member
Hi chaps,

This is an error on my account. I should be using equivalent() not equivalents().

Please could you elaborate if possible on what equivalents() does as the manual is not clear.

Many Thanks,

James
Re: Assigning rule generated target model elements to a contained reference [message #632539 is a reply to message #632514] Wed, 13 October 2010 10:36 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios Kolovos
Messages: 1776
Registered: July 2009
Senior Member
Hi James,

x.equivalents() returns a collection that contains all the elements
produced from x.

x.equivalent() is the same as x.equivalents().first()

Cheers,
Dimitris

James Sharp wrote:
> Hi chaps,
> This is an error on my account. I should be using equivalent() not
> equivalents().
>
> Please could you elaborate if possible on what equivalents() does as the
> manual is not clear.
>
> Many Thanks,
>
> James
Re: Assigning rule generated target model elements to a contained reference [message #632589 is a reply to message #632539] Wed, 13 October 2010 14:12 Go to previous messageGo to next message
James Sharp is currently offline James Sharp
Messages: 20
Registered: September 2010
Junior Member
Hi Dimitris,

When performing .equivalent() I am receiving a bag in return as .equivalents() was returning a Bag of Sequences. Hence my assumption to move to equivalent() rather than equivalents().

How is this so?

Many Thanks,

James
Re: Assigning rule generated target model elements to a contained reference [message #632598 is a reply to message #632539] Wed, 13 October 2010 14:43 Go to previous messageGo to next message
James Sharp is currently offline James Sharp
Messages: 20
Registered: September 2010
Junior Member
Hi Dimitris,

My results when using equivalent() and equivalents() does not follow this pattern, (or maybe I have just not understood how to assign the values properly)

I have the line:

cProc.processStatement.letHaskellStatements.addAll(vProc.pro cessStatements.equivalent());

which returns:
Bag {HaskellStatement []} <- just one element as you say:

However if I use:
cProc.processStatement.letHaskellStatements.addAll(vProc.pro cessStatements.equivalents());

this returns:
Bag {Sequence {HaskellStatement []}, Sequence {}}

And I get the error message:
Internal error: java.lang.ArrayStoreException
at org.eclipse.emf.common.util.BasicEList.assign[BasicEList.jav a:124]

If I remove the @lazy from the rule I get 2 HaskellStatements generated within my model (albeit not assigned to the correct object).

Should I be getting back both HaskellStatements? Should they be wrapped as Sequence like this for equivalents()?


The Lazy rule producing them is:
@lazy
rule Assignment2HaskellStatement
transform vAssignment : vhdl!Assignment
to hStatement : csp!HaskellStatement {

hStatement.assignsValueTo := csp!TypeItem.select
(item|vAssignment.assignValueTo.usesElement.name.isSubstring Of(item.name)).first();

}

Sorry but totally lost why this is the result I am getting here, any help would be greatly appreciated.

Many Thanks,

James
Re: Assigning rule generated target model elements to a contained reference [message #632614 is a reply to message #632598] Wed, 13 October 2010 15:16 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios Kolovos
Messages: 1776
Registered: July 2009
Senior Member
Hi James,

equivalent() and equivalents() return different results depending on
whether they are invoked on objects or collections. For an object "o"
and a collection "c":

o.equivalent() -> returns one object
o.equivalents() -> returns a collection of objects
c.equivalent() -> returns a collection of objects
c.equivalents() -> returns a collection of collections

Therefore, the fact that

vProc.processStatements.equivalents() -> Bag {Sequence {HaskellStatement
[]}, Sequence {}}

means that processStatements is a collection which contains 2 objects,
the first of which has generated 1 HaskellStatement object and the
second has generated nothing.

Does this help?

Cheers,
Dimitris

James Sharp wrote:
> Hi Dimitris,
>
> My results when using equivalent() and equivalents() does not follow
> this pattern, (or maybe I have just not understood how to assign the
> values properly)
>
> I have the line:
>
> cProc.processStatement.letHaskellStatements.addAll(vProc.pro
> cessStatements.equivalent());
>
> which returns:
> Bag {HaskellStatement []} <- just one element as you say:
>
> However if I use:
> cProc.processStatement.letHaskellStatements.addAll(vProc.pro
> cessStatements.equivalents());
>
> this returns:
> Bag {Sequence {HaskellStatement []}, Sequence {}}
>
> And I get the error message:
> Internal error: java.lang.ArrayStoreException
> at org.eclipse.emf.common.util.BasicEList.assign[BasicEList.jav a:124]
>
> If I remove the @lazy from the rule I get 2 HaskellStatements generated
> within my model (albeit not assigned to the correct object).
>
> Should I be getting back both HaskellStatements? Should they be wrapped
> as Sequence like this for equivalents()?
>
>
> The Lazy rule producing them is:
> @lazy
> rule Assignment2HaskellStatement
> transform vAssignment : vhdl!Assignment
> to hStatement : csp!HaskellStatement {
>
> hStatement.assignsValueTo := csp!TypeItem.select
>
> (item|vAssignment.assignValueTo.usesElement.name.isSubstring
> Of(item.name)).first();
>
> }
>
> Sorry but totally lost why this is the result I am getting here, any
> help would be greatly appreciated.
>
> Many Thanks,
>
> James
Re: Assigning rule generated target model elements to a contained reference [message #632623 is a reply to message #632614] Wed, 13 October 2010 15:47 Go to previous message
James Sharp is currently offline James Sharp
Messages: 20
Registered: September 2010
Junior Member
Hi Dimitris,

Thanks, makes perfect sense. Didn't think about what it was operating on..... whoops.

Cheers,

James
Previous Topic:Calling Operations from within Operations
Next Topic:re-execute rule to duplicate object generation
Goto Forum:
  


Current Time: Thu Oct 23 03:12:03 GMT 2014

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

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