Code Snippet Injection for Message View

Issue #173 invalid
Calem Bendell created an issue

Possible New Feature (I might begin working on this since I might need it)

I just inputted some exacting messages in the message view of an object, which is a fairly painful process if you're injecting loops.

For loop functionality is still being added, but it would be interesting if code snippets could be loaded and parameterised. By parameterised I mean make it so that they can be used like a concern (with the left bar on the object? still learning the terminology here!) and injected into the code at code generation as if the snippet was in the message view.

So if I wrote something like the below code snippet, it's actually very simple code but it takes a while to input into the message view and takes a while to debug if there's a typo.

How hard would something like this be to do? How would I go about starting it? It's also important that I get familiar with the codebase so I can be more productive and contributive, and this seems like a very good start :-)

Perhaps this could be parameterised with something like:

{
  "function": "+ int drawLines()",
  "locals": "MinuetoWindow window,boolean flash",
  "snippet": "models/snippets/drawlines.java"
}

drawlines.java:

    window.setVisible(true);
    boolean switchColour = true;
    while (true) {

        try {
            window.clear();
            int i = 0;
            while (i < this.lineCount) {
                if (switchColour) {
                    window.drawLine(MinuetoColor.BLUE, 5 + (i * 60), 5, 5 + (i * 60), 405);
                    window.drawLine(MinuetoColor.GREEN, 5, 5 + (i * 40), 605, 5 + (i * 40));
                } else {
                    window.drawLine(MinuetoColor.GREEN, 5 + (i * 60), 5, 5 + (i * 60), 405);
                    window.drawLine(MinuetoColor.BLUE, 5, 5 + (i * 40), 605, 5 + (i * 40));
                }
                i++;
            }
            if (this.flash) {
                switchColour = !switchColour;
            }
            Thread.sleep(1000);
            window.render();
        } catch (InterruptedException ex) {
        }
    }

Comments (4)

  1. Matthias Schoettle

    Well, there is a research group in Chile who created a DSL for RAM, which provides a textual editor with completion. It saves directly into a RAM model, so no need to do any transformation.

    I think it would be best to use something like that if you prefer that. I am not sure how far the message view stuff is or how up-to-date they are with our metamodel, but I can find out if you are interested in this.

  2. Calem Bendell reporter

    That sounds perfect! I'll try the updated message view first and then check that out.

  3. Matthias Schoettle

    Unless we want to support to "include" code that is provided somewhere else (and not using Implementation Classes), this doesn't seem to be necessary right now.

  4. Log in to comment