Can the copy-paste handler be inherited?

I've implemented some copy-paste handler for my abstract concept, that does some common logic (identifiers renumbering). But the handler does not apply to the child concept.
Is it a correct behavior? If so, how can I work around this?

Thanks,
Alexey
11 comments
The concerned question: what is the policy of copy-paste handlers applying? Do they apply only to node is being copied or to whole node tree starts from the copied one?

Thanks,
Alexey
0
You can extract common logic into a separate (utility) class.
0
AFAIKSee in the code :-) it is executed only on root element which was copied. This is a way to "adopt" copied/pasted node to a context, so it make sense to execute handles only for root element of copied sub-tree.
0
AFAICSee in practice :-) when there are no handler for the root node, it's just copied but handlers are applied to child nodes. I can be wrong...
0
I've already extracted it. I'll describe my problem.
I have some abstract concept, e.g. IMyStatement. It has behavior method renumerate() that should be invoked, when IMyStatement is being copied. My colleague Vasily creates a concrete concept VStatement that implements IMyStatement. Vasily is really sad because he should to specify handler for VStatement and call the method renumerate() – he even doesn't know, what is renumerate() for.
My goal is to specify handler for IMyStatement so Vasily can develop his VStatement without thinking about some technical details...
0
I see! please file a request for it.
0
Oops, this feature is already in MPS..

The logic of proper PasteWrapper lookup is: we are looking for first existing paste wrapper assigned to node's concept or one of it's super-concept. See jetbrains.mps.baselanguage.actions.wrappers root keeping a PastWrapper applicable for Expression and transforming it to a statement.

This Wrapper will be executed then you are trying to paste _ANY_ expression (Expression concept itself is abstract, so it can hardly have any reasonable instances).

So, answering your question - you can create PastWrapper for IMyStatement interface and this wrapped will be used for all sub-concepts of this interface unless you define concrete wrapper for concrete sub-copncept of IMyStatement interface.
0
I'll create a newfeature task MPS-13144.

Thanks!
0
I'll try to reproduce my problem. I remember that I have had to specify handler for each sub-concept...
0
My test project is attached. I have one rootable concept 'Collection', that contains collection of 'IdAware' elements. The technical details of IdAware – it has elementId property, that should be unique inside one Collection. Also there is a concept 'ElementA', that can be really instantiated.
I've created a node factory for IdAware, that generates a new elementId for newly created node. And it works: I can add new nodes and ids generated correctly.
Also I've created a paste handler for IdAware that creates the new elementId for just pasted node. But it does not work: elements are copied with their ids. When I've changed applicable concept for paste handler from IdAware to ElementA, it worked correct.
test.zip (12KB)

Project was created and tested on MPS2.0 M5

Thanks,
Alexey
0
Ok. I reopened your request. Will check what's the problem with it.
0

Please sign in to leave a comment.