2.2.1. Entity

[Tip]Description

An entity can be part of a (local) pattern body. If it is part of a precondition pattern, it binds a pattern variable to an entity in the model space during pattern matching. If it is part of a postcondition, it may prescribe the creation of model elements.

[Important]Syntax
EntityAST ::= QualifiedTypeNameAST EntityBody ContainmentConstraintOptAST	
EntityBody ::= ( PatternVariableDefRefAST ) 

An entity is identified by a pattern variable.

It can have a type ( entity type ), which is either a local name or a fully qualified name of a model element ( qualified model element name). A type identifies another entity of the model space; it can be referenced with the local name only if its namespace is imported. In the most general case, the type is entity.

The location of an entity may be restricted by a containment constraint.

[Note]Semantics

The semantics of an entity largely differs on whether this entity appears in a pattern used as a stand-alone pattern, or as a precondition or a postcondition of a GT rule definition. The semantics of the postcondition case is defined in details in GT rule definition.

In case of pattern matching (precondition part or stand-alone patterns), an entity appearing in a pattern body prescribes that the corresponding pattern variable should be bound to an entity in the model space.

Note that attribute conditions (e.g. accessing the value of an entity need to be specified as part of a check condition.

During pattern matching the referenced entity must be located in the containment hierarchy according to the containment constraint. In case of the constraint the entity must be contained directly by the entity referenced by the container, whereas in case of the constraint the containment can be transitive (to find all ancestors).

Needs to be checked.  The container needs to be a constant, an ASM function, or (most typically) a pattern variable. In the latter case, the corresponding pattern variable needs to be bound prior to pattern matching (i.e. it is an input parameter of the pattern).

If there are multiple containment constraints for an entity (for instance, from the caller ASM choose rule or forall rule), all constraints need to be satisfied for a successful match. Thus, if the constraints are contradictionary, pattern matching will fail.

In case of postcondition patterns, an entity appearing in a pattern body may prescribe that a new entity has to be created in the model space, and this new entity is then assigned to the corresponding pattern variable.

Concerning containment constraints used in postcondition patterns,

  • in case of the in constraint, the new element will be created as a direct child of the entity defined by the container entity

  • in case of the no containment constraint, the new element will be created as a direct child of the root entity

  • below constraints are only checked as a postcondition, thus they require (but do not enforce) that the new element should be located in the container entity. A runtime error is issued if this is not the case.

The container is allowed to be a constant, an ASM function, or a pattern variable. In the latter case, it is allowed to have another entity referred by the pattern variable of the container.

In case of postcondition patterns, contradicting multiple containment constraints result in a runtime error.

[Caution]Constraints

Referencing to the value of an entity is not allowed in entity definitions. The value property can be accessed in check conditions as value(E) (where pattern variable E stands for the corresponding entity).

[Warning]Warning

The vpm namespace with vpm.entity and vpm.entity.relation (which were present in previous VIATRA releases as a metamodeling core) is no longer supported. Please use simple entity instead.

Defined In:  pattern body

Used By:  create rule

See Also:  pattern body, namespace import