|
|
|
Re: Defining OCL-Constraints on user EDataTypes [message #548799 is a reply to message #548769] |
Fri, 23 July 2010 06:33 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi Olli
I've no idea how you think this works.
a) self.oclIsUndefined() is always false for EDataType since by
definition it exists, unless you've overridden it, which is not
necessarily permitted in OCL at present (<= 2.2) and not supported in
MDT/OCL 3.0.0.
b) the java.lang.String is not visible to OCL, so there is no
self.size() operation.
As well as leading uppercase camelcase it is good to be readable for
polarity, so LessThanThirtyCharacters or NotTooLong or LengthOk would be
better.
If you use the OCLinEcore editor
(http://wiki.eclipse.org/MDT/OCLinEcore) you don't have to worry about
the EAnnotation scaffolding and you get OCL syntax validation:
package Example : ex = 'http://example'
{
datatype ThirtyCharString : 'java.lang.String'
{
invariant MaxLengthConstraint: oclIsUndefined() or self.size() <= 30;
}
}
Unfortunately, while checking your example I discovered that,
https://bugs.eclipse.org/bugs/show_bug.cgi?id=320689, the editor does
not currently consider OclAny methods for DataTypes or Enums, so you
will get an erroneous red squiggle on oclIsUndefined() and a correct red
squiggle on size().
Regards
Ed Willink
On 22/07/2010 23:40, Oliver wrote:
> Thanks Ed!
> I've found out "???" have to replaced by "self" so a valid EDataType is:
> EDataType {
> name := ThirtyCharString
> instanceTypeName := java.lang.String
> serializable := true
> eAnnotations += EAnnotation {
> source := http://www.eclipse.org/emf/2002/Ecore
> details += EStringToStringMapEntry {
> key := constraints
> value := MaxLengthConstraint
> }
> }
> eAnnotations += EAnnotation {
> source := http://www.eclipse.org/emf/2002/Ecore/OCL
> details += EStringToStringMapEntry {
> key := MaxLengthConstraint
> value := self.oclIsUndefined() or self.size() <= 30
> }
> }
> }
>
> I had never expected that this is possible, but it works :)
>
> Ciao Olli
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03494 seconds