- Michael Brunner
- 05/12/11
Hi,
I would like to generate some unique-id for a node. To do that, I want to access the parent concept in the constructor(behaviour) of a concept.
But it is null!
What to do?
I would like to generate some unique-id for a node. To do that, I want to access the parent concept in the constructor(behaviour) of a concept.
But it is null!
What to do?
- Alex Shatalin
- 05/13/11
You can try making unique-id property "derived" - create a getter for it and return proper value from there.
- Michael Brunner
- 05/15/11
Hi Alex,
already had that idea on my own.
But the problem is, that I want to save the unique id in the model, so it doesn't change.
I tried this in the getter:
But it throws an exception. Probably I'm not allowed to change the identifier here.
(Why is there nothing red in the editor then)...
Exception:
jetbrains.mps.smodel.IllegalModelChangeError : registered node can only be modified inside undoable command or in 'loading' model [textSymbols] TextSymbol <no name>[8642124865149417439] in [...].sandbox.sandbox
already had that idea on my own.
But the problem is, that I want to save the unique id in the model, so it doesn't change.
I tried this in the getter:
if (node.identifier == -1) {
node.identifier = node.generateIdentifier(node.parent as TextSymbolSet);
}
return node.identifier;
But it throws an exception. Probably I'm not allowed to change the identifier here.
(Why is there nothing red in the editor then)...
Exception:
jetbrains.mps.smodel.IllegalModelChangeError : registered node can only be modified inside undoable command or in 'loading' model [textSymbols] TextSymbol <no name>[8642124865149417439] in [...].sandbox.sandbox
- Michael Brunner
- 05/15/11
Ah, I just used the "commmand" block. And now it works as expected.
Had to import plugin-language to constraints-model.
EDIT:
Another alternative is to use a node-factory.
Had to import plugin-language to constraints-model.
EDIT:
Another alternative is to use a node-factory.
- Alex Shatalin
- 05/30/11
You right. Node Factories looks even more suitable here.
- Dmitry Ivanov
- 09/28/11
While we can use derived properties it'd much easier to have an access to the parent (or may be "probable" parent) in the behavior's constructor.
So the question is still actual, why can't we get a reference to the parent in the constructor?
So the question is still actual, why can't we get a reference to the parent in the constructor?
- Evgeny Gryaznov
- 09/28/11
What if you moved the node between parents? During refactoring for example or you just selected it and pressed Alt-Down. Node factories allows to adapt a node to the environment, but only once! Besides, it works only in an editor. When you write code to manipulate the AST you prefer to be able to create a node first, and then attach it to the parent.
Technically, we can add a "probable" parent to the constructor. But we cannot guarantee when it will be available so it doesn't make sense.
Technically, we can add a "probable" parent to the constructor. But we cannot guarantee when it will be available so it doesn't make sense.