OCL 2.4 RTF Avatar
  1. OMG Issue

OCL24 — Introduce selectByKind and selectByType operations

  • Key: OCL24-12
  • Legacy Issue Number: 18829
  • Status: closed  
  • Source: Model Driven Solutions ( Dr. Edward Willink)
  • Summary:

    A very common 'idiom' in OCL expressions is

    sources->select(oclIsKindOf(T))>collect(oclAsType(T))>asSet()

    to select the sub-set of type T.

    This involves four library calls and requires T to be typed twice.

    In practice

    sources->select(oclIsKindOf(T)).oclAsType(T)

    may save one operation call at the expense of the wrong collection type.

    Suggest introduce

    sources->selectByKind(T)
    sources->selectByType(T)

    to simplify this oclIsKindOf/oclIsTypeOf usage.

  • Reported: OCL 2.3.1 — Sun, 21 Jul 2013 04:00 GMT
  • Disposition: Resolved — OCL 2.4
  • Disposition Summary:

    This is clearly useful:
    Acceleo (but not MOFM2T) provides "filter".
    The Dresden OCL team in http://gres.uoc.edu/OCL2011/pubs/ocl2011_submission_3.pdf suggest "selectByType" and note that QVTo provides "collectselect"
    "filter" is nice and short but fails to fulfill the expectation that the argument should be some general predicate not an unmentioned type.
    oclIsKindOf and oclIsTypeOf are already there and so unless they are to be changed, additions should be compatible and re-inforce the "KindOf"/"TypeOf" distinction..
    There are two distinct algorithms: exact type and polymorphic type so
    selectByType and selectByKind are consistent.
    selectByType clearly can include/exclude OclVoid at will.
    selectByKind probably doesn't want to include null elements even though null conforms to everything, so QVTo's collectselect exclusion is worth emulating.
    There seems no need to introduce rejectByKind and rejectByType too, since there is no associated type conversion; reject will do.
    The correct declarations should be:
    selectByKind(TT)(type : Metaclass(TT)) : Collection(TT);
    selectByType(TT)(type : Metaclass(TT)) : Collection(TT);
    These use an operation template type TT to model the type relationship between the returned Collection element type and the metatype provided as the operation argument. Unfortunately we cannot use this until OCL '2.5' aligns with UML templates and introduces templated Metaclasses.

  • Updated: Fri, 6 Mar 2015 20:57 GMT