[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[qvto-dev] Bad Examples in 8.1.10
|
Hi
In Issue 15376 http://solitaire.omg.org/browse/QVT13-16, I complain
that the examples in 8.1.10 are problematic.
The second example contains
"if result then return;"
which has a non-boolean condition _expression_ and a
missing endif.
In the first example, it is not clear that the revisit
adds rather than overwrites.
In the third and fourth examples it is not clear why the
second pass reuses the context for the first rather than
creates new objects.
5 years later this comes back to haunt me. With a slightly better
understanding of QVTo, my complaints seem rather understated, the
examples are quite terrible.
The attached ZIP file contains a project with launch configurations
that represent my best attempt at making the examples work.
----
I cannot get the second example to work:
transformation JClass2JPackage(inout javamodel:JAVA);
main () {
javamodel->objectsOfType(JClass)->jclass2jpackage();}
mapping Class::jclass2jpackage() : JPackage () {
init {
result := resolveIn(jclass2jpackage,true)
->select(p|self.package=p.name)->first();
if result then return;
}
name := self.package;
}
when changed to (JClass2JPackage.qvto):
modeltype JAVA uses 'http://www.omg.org/qvt/examples/javamodel';
transformation JClass2JPackage(inout javamodel:JAVA);
main () { javamodel.objectsOfType(JClass)->jclass2jpackage();}
mapping JClass::jclass2jpackage() : JPackage /*()*/{
init {
result := resolveIn(JClass::jclass2jpackage,JPackage)
->select(p|self.packageName=p.name)->first();
--if (result <> null) return;
}
name := self.packageName;
}
I am defeated by the "if result then return" line.
It seems that we must use () to force the imperative rather than
declarative if.
Presumably we need "<> null" to ensure a Boolean condition,
but Eclipse QVTo doesn't complain about this, perhaps other bugs
occlude this warning.
A value-less return is diagnosed as an error so I tried "return
result", so that:
The premature return is diagnosed as not supported by Eclipse QVTo.
Iff the premature return is really needed, then the missing support
in Eclipse QVTo is bad.
But I don't understand the resolveIn at all, the second argument
seems optional and undocumented. Is it an optional predicate on the
return value?
The semantics of the init look very important and suspect.
Presumably the resolveIn target is created before/as the init
executes but even if it does, surely, JPackage::name is
uninitialized so that ->first() must always return invalid since
the name match fails and no successful mapping ever executes?
------
Third example using late resolve seems fine apart from typos.
------
I cannot make the fourth two-pass variant work. After changing
(UML2JavaTwoPass.qvto)
transformation Uml2Java(in uml:UML,out java:JAVA)
main() : JAVA::Interface {
uml->objectsOfType(Class)->map transformClass();
uml->objectsOfType(Class)->map transformClassInheritance();
}
mapping UML::transformClass() : JAVA::Interface {
name := "Ifce".concat(self.name);
}
mapping UML::transformClassInheritance() : JAVA:Interface {
base :=
self.superClass->resolveIn(transformClass,JAVA::Interface);
}
to
modeltype JAVA uses 'http://www.omg.org/qvt/examples/javamodel';
modeltype UML uses 'http://www.omg.org/qvt/examples/umlmodel';
transformation Uml2Java(in uml:UML,out java:JAVA);
main() /*: JAVA::Interface*/ {
uml.objectsOfType(Class)->map transformClass();
uml.objectsOfType(Class)->map transformClassInheritance();
}
mapping UML::Class::transformClass() : JAVA::Interface {
name := "Ifce".concat(self.name);
}
mapping UML::Class::transformClassInheritance() : JAVA::Interface
{
init{
result :=
resolveIn(UML::Class::transformClass,JAVA::Interface)->first();
}
result.base :=
self.superClass.resolveIn(UML::Class::transformClass,JAVA::Interface);
}
I am unable to persuade the second pass to re-use the first.
Can anyone help? Is it an Eclipse QVTo bug?
Regards
Ed Willink
|
Attachment:
QVTExamples.zip
Description: Zip compressed data