Child pages
  • Constraints
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

The Constraints aspect defines additional constraints on the structure of a language's concept instances, which can't be expressed in terms of Structure Language. This chapter considers the available constraints.

Can be child/parent

These are additional constraints determining whether instances of this concept can be parent (or child) nodes for other nodes.

Suppose you have a node A and it "can't be parent" of the node B, or B "can't be child" of A. In this case you won't be able to create B under A. Nevertheless, you can paste B into A even if these constraints are broken. In this case, places with broken constraints in your code will be underlined with red.

Can be ancestor

Return false if node is not allowed to be ancestor of nodes of specific concept.

parameter

description

operationContext

IOperationContext

scope

context (IScope)

node

ancestor node we are checking

childConcept

concept of the [grand]child node

Can be root

This constraint is available only for rootable concepts (instance can be root is true in the concept structure description). Return false if node cannot be a root in the given model.

parameter

description

operationContext

IOperationContext

scope

context (IScope)

model

model of the root

Property constraints

Generally speaking, "pure" concept properties are not properties, but only public fields. Property constraints allow you to make them real properties. Using these constraints,the behavior of concept's properties can be customized. Each constraint is applied to the corresponding property.

property - the property to which this constraint is applied.

get - this method is executed to get property value every time property is accessed.

parameter

description

node

node to get property from

scope

context (IScope)

set - this method is executed to set property value on every write to it. The property value is guaranteed to be valid.

parameter

description

node

node to set property

propertyValue

new property value

scope

context (IScope)

is valid - this method should determine whether the value of the property is valid. This method is executed every time the value changes, and if it returns false, the set() method is not executed.

parameter

description

node

node to check property

propertyValue

value to be checked

scope

context (IScope)

Referent constraints

Constraints of this type help to add behavior to links and make them more properties-like.

referent set handler - if specified, this method is executed on every set of this link.

parameter

description

referenceNode

node that contains link.

oldReferentNode

old value of the reference.

newReferentNode

new value of the reference.

scope

context: IScope interface to object that shows you models, languages and devkits you can see from the code.


search scope - defines the set of nodes to which this link can point. sequence<node<>> or ISearchScope can be returned from this method.

parameter

description

model

the model that contains node with link. This is just for convenience - it can be taken from either referenceNode or enclosingNode.

scope

IScope interface that shows what models, languages and devkits you can see from the code.

referenceNode

node that contains link, can be null when new node is being created for concept with smart reference. In this situation smart reference is used to determine what type of node to create in the context of enclosingNode, so the search scope method is called with null referenceNode.

enclosingNode

parent of node that contains link, null for root nodes. Both referenceNode and enclosingNode cannot be null at the same time.

linkTarget

concept that this link can refer to. Usually it is concept of the reference, so it is known statically. If we specialize reference in subconcept and do not define search scope for specialized reference, then linkTarget parameter can be used to determine what reference specialization is required.

If search scope is not set for the reference then default search scope from the reference concept is used. If the default search scope is also not set then "global" scope is used: all instances of referent concept from all imported models.


validator (since 1.5) - Each reference is checked against it's search scope and if reference goes out of the search scope after changes in model the MPS marks this reference with the error message. Sometimes it is not efficient to build the whole search scope just to check if the reference is there. The search scope can be big or it may be much more easier to check if the given node is in scope than to calculate what nodes are in scope. You can create quick reference check procedure here to speed up reference validation in such situations.

parameter

description

model
scope
referenceNode
enclosingNode
linkTarget

context of reference usage, the same meaning as in the search scope function. The main difference: referenceNode cannot be null here because validator is not used during node creation.

checkedNode

the node to be validated (referenceNode has a reference to checkedNode of type linkTarget)

It is possible to create validation routine only if you have created a list of nodes in corresponding search scope. If ISearchScope is returned from search scope routine, then isInScope(SNode) method of ISearchScope interface will be used for validation, you should override this method with your validation routine.
It is not possible to define validation routine without defining search scope.


presentation - how the reference will look like in editor and in completion list. Sometimes it is convenient to show reference differently depending on context. For example in Java language reference to the instance field f should be shown as this.f if it is shadowed by the local variable declaration with the same name. If presentation is not set, then the name of the reference node will be used as presentation (if it is INamedConcept).

parameter

description

model
scope
referenceNode
enclosingNode
linkTarget

context of reference usage, the same meaning as in the search scope function.

parameterNode

the node to be presented (referenceNode has a reference to parameterNode of type linkTarget)

visible

true - presentation of existing node, false - for new node (to be created after selection in completion menu)

smartReference

true - node is presented in smart reference

inEditor

true - presentation for editor, false - for completion menu

ISearchScope - TODO
resolve info - TODO

Default scope

Suppose we have a link pointing to an instance of concept C and we have no #search scope set for this link in referent constraints. When you edit this link, all instances of concept C from all imported models are visible by default. If you want to restrict set of visible instances for all links to concept C you can set default scope for the concept. As in referent constraint you can set search scope, validator and presentation methods. All the paramteres are the same.

Previous Next

  • No labels