Assigning rule generated target model elements to a contained reference [message #632337] |
Tue, 12 October 2010 11:36  |
Eclipse User |
|
|
|
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 #632614 is a reply to message #632598] |
Wed, 13 October 2010 11:16   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.24755 seconds