Java Reference
In-Depth Information
Following is an example from GMF's
xpt::EMFUtils
extensions:
String toStringLiteral(String strValue) :
JAVA
org.eclipse.gmf.internal.codegen.util.EmfUtils.toStringLiteral(
java.lang.String)
;
Xtend Examples
The first example provides the same functionality we expressed in our mindmap
model using OCL. Although the derived feature for
rootTopics
was created
and annotated with OCL to provide the value, this snippet of Xtend completes
the story by showing what otherwise we would need to do to accomplish the
same thing if we had not “pulled up” the capability into our metamodel. This is
an extension that returns the list of root Topic elements from a Map:
import
mindmap;
cached
List[mindmap::Topic] rootTopics(Map mindmap) :
let
topics = mindmap.elements.typeSelect(mindmap::Topic) :
topics.without(topics.subtopics)
;
To compare, this is the OCL we added to the metamodel after creating a
derived, transient, volatile
rootTopics
reference in our Map class:
let
topics :
Set
(mindmap::Topic) =
self
.elements
->
select
(
oclIsKindOf
(mindmap::Topic))
->
collect
(
oclAsType
(mindmap::Topic))->asSet()
in
topics->symmetricDifference(topics.subtopics->asSet())
Finally, this is the QVT we used in our transformation from mindmap root
Topic to RequirementGroup objects:
var
topics :
Set
(mindmap::Topic) := mmap.elements
->
select
(
oclIsTypeOf
(mindmap::Topic))
->
collect
(
oclAsType
(mindmap::Topic))->asSet();
var
rootTopics :
Set
(mindmap::Topic) := topics
->symmetricDifference(topics.subtopics->asSet());
As you can see, the three are similar. Because QVT OML is based on OCL,
it's understandably the same syntax as the OCL annotation. And because Xtend
Search WWH ::
Custom Search