Uniqueness constraint on ref

hello,
I'm trying to put a constraint over a reference concept in my project.
I will explain the context :
    - There is a concept A which contain a child ID.
    - And a concept B containing a ref to A through ID, the cardinality of the ref is 1..n.
Concept B can reference seraval A.

What I want to do with my constraint is to make sure that a reference between an element of type B and A is unique.


What I've done for now is to start implementing a constraint for the concept IDref
and concept A implements ScopeProvider to override getScope() method.
In the method getScope(), I know I just have to check which ref already exists in the AST and remove it from the scope, but I dont know how to do this ...
Can you tell me if it's the right way to do this ?
And if I'm right which kind of mechanism I have to implement in getScope() to reduce end-user's possibility for the uniqueness reference (thanks to auto-completion).

Thanks,

Robin 'Ska'
5 comments
Robin, you are on the right track. You may check the languagePatterns sample (MPS3.2) for more inspiration. The "declaration-reference" part of it covers cases that are very close to what you're trying to achieve.

Vaclav
0
Ok, It's exactly what I want to do. I'm working on it.
Is there a way to debug constraints code?
0
Perfect, I'm done with this constraint.Thanks Vaclav !
I just have one more question : Can you explain me the difference between "Dependencies" and "Used Languages" in the module properties tab ? (Did I need to create an other thread for this question ?)
0
You may think of "Dependencies" as Java imports, for example - visible libraries that your code can use. "Used languages" specify the syntaxes that your code may use, which is something that has no equivalent in Java. More is to be found at https://confluence.jetbrains.com/display/MPSD32/Getting+the+dependencies+right
0

Please sign in to leave a comment.