General (#1) - CollectionTemplateExp? (#12) - Message List

Hello

I understand that the CollectionTemplateExp is currently not implemented. I hate to ask those questions but this expression is pretty important to me so do you have a time horizon when integration will take place ?

Jens

  • Message #26

    Dear Jens,

    There are 2 things about the collection template expression. 1) The standard is not really clear for this feature. 2) We have so far no case found where we needed collection templates.

    So, if you can provide an example, which can only be by expressed via collection templates, we are going to implement it. Otherwise, we are fine with our QVT engine as it is.

    Best regards,

    Hajo

    • Message #27

      Given the following metamodel and instance of a library:

      Library:
      -name : String
      -alternativeNames : Set<String>
      Instance of Library
      -name : "City Library"
      -alternativeNames : "City Lib","CL","Goethe Library"
      

      and this template matching expressions

      LibraryTemplate : ObjectTemplateExp
      -referredClass = Library
      -part = PropertyTemplateItem1/2
      -bindsTo = "freevar0"
      // singlevalued property with object and collection templates
      PropertyTemplateItem1 : PropertyTemplateItem
      -referredProperty = name
      -value = NameTemplate1/3
      // multivalued property with object and collection templates
      PropertyTemplateItem1 : PropertyTemplateItem
      -referredProperty = alternativeName
      -value = NameTemplate2/4
      freevar[s] : String
      NameTemplate1 : ObjectTemplateExp
      -referredClass = String
      -bindsTo = "freevar1"
      -where = length > 2 // Library name must be longer than 2, to match
      NameTemplate2 : ObjectTemplateExp
      -referredClass = String
      -bindsTo = "freevar2"
      -where = length > 2
      NameTemplate3 : CollectionTemplateExp
      -referredCollectionType = Set
      -referredClass = String
      -bindsTo = "freevar3"
      -where = length > 2
      NameTemplate4 : CollectionTemplateExp
      -referredCollectionType = Set
      -referredClass = String
      -bindsTo = "freevar4"
      -where = length > 2
      

      Matching would result in

      NameTemplate1 matches Library.name="City Library" > 2
      NameTemplate2 matches Library.alternativeNames."Goethe Library" > 2 // existence quantor for collection
      NameTemplate3 matches Library.name="City Library" > 2 // according to spec, name is taken as a Singleton Collection
      NameTemplate4 fails as Library.alternativeNames."CL" fails the condition // all quantor for a collection
      

      Given this example, is it possible to express it only with ObjectTemplateExpressions? Maybe I'm missing something? I have yet another thing I'm not sure about: Is there any possibility to match for the collection itself, i.e. a List to have only a maximum of 5 elements. ?

      • Message #28

        You can match a collection itself by declaring a free variable a set type of the type of interest and binding this variable to the property.

            relation ..{
               varItems=Set(Something);
               enforce domain .. {
                     items=varItems
               }
               when {
                     varItems.size()<=5
               }
            }
        

        To your other questions: Maybe is it possible that you say what you want to achieve, instead of given us a (cryptic) AST description ?

        • Message #74

          It took me some time to give a reasonable example but here it is: Suppose you want to match an EClass with EAnnotations. You want to match those EClasses that contain the EAnnotation A1 AND A2.

          relation .. {
             enforce domain source var1 : EClass {
                 eAnnotations = var2 : OrderedSet(EAnnotation) {
                      match1 : EAnnotation { name = A1 }
                      match2 : EAnnotation { name = A2 }
                 }
          }
          

          Doesn't this kind of match require CollectionTemplateExpressions? ?

          • Message #75

            This can be done by the following construction:

            relation .. {
               enforce domain source var1 : EClass {
                   eAnnotations = match1 : EAnnotation { name = A1 },
                   eAnnotations = match2 : EAnnotation { name = A2 }
               }
            }
            

            There is only the disadvantage that, if A1 or A2 is contained multiple times in the eAnnotations list, the source domain matches multiple times so that the where clauses are also executed multiple times. However such cases can be excluded by using a marker relation, which is queried to be not set in the when clauses and which is actually set in the where clauses (so that it will not match again in the when clauses)

            • Message #76

              So just to understand this correctly, this construct implicitly uses collection semantics and for example this would match sequences:

              relation .. {
                 enforce domain source var1 : EClass {
                     eAnnotations = match1 : EAnnotation { name = A1 },
                     eAnnotations = match2 : EAnnotation { name = A2 }
                     eAnnotations = match3 : EAnnotation { name = A1 },
                 }
              }
              

              Your example matches a Bag against a Set and this matches multiple times.

              I'm still not sure if all cases of collection matching are covered by this construct.

              • Message #79

                Please let us now if there is a case which cannot be expressed without using collection templates.

Attachments

No attachments created.