is there a way to get the type of pregenerated methods in mps?... Follow
This is an auto-generated question from the MPS Slack community: is there a way to get the type of pregenerated methods in mps?
19 comments
Sort by
Date
Votes

Comment actions
Permalink
for example, in the following event listener,

Comment actions
Permalink
the code in 'child added' and 'child removed' should be the same

Comment actions
Permalink
but given that the methods' headers are pregenerated

Comment actions
Permalink


Comment actions
Permalink
there's no way (to my knowledge) to write a helper function that deals with the logic. This results in ugly, needles, (but unavoidable?) code duplication. Is there a way around this?

Comment actions
Permalink
You can extract the common logic into a separate class with a (static) method and call that method.

Comment actions
Permalink
but that method needs to know the type of instance

Comment actions
Permalink
as well as child

Comment actions
Permalink
So pass that info to it as parameters

Comment actions
Permalink
but what is the type of these arguments. The classes are pure java, right? but instance and child are two arguments whose type is not shown

Comment actions
Permalink
experiantially, instance is the interface child of an InterafceChunk concept

Comment actions
Permalink
try typing `instance`, selecting it and pressing Ctrl+Shift+P

Comment actions
Permalink
thanks! that worked

Comment actions
Permalink
now there's another problem. Copy pasting does not work from the listener into the class

Comment actions
Permalink
the code has to be manually type in again

Comment actions
Permalink
you need to be careful about what you are pasting. copy-pasting a list of statements should work fine

Comment actions
Permalink
copy-pasting the whole function won't work

Comment actions
Permalink
because they are different, incompatible concepts, whereas statements are compatible.

Comment actions
Permalink
This is auto-generated question from the MPS Community Slack Workspace. If you want to comment on the question, do it from the Slack workspace
Post is closed for comments.