Don't generate 'this' for static operations

Issue #429 resolved
Matthias Schoettle created an issue

Consider the operation getInstance of Singleton, which is defined as follows (in pseudocode):

if (instance == null) then
    instance = create new instance
end if

return instance

However, the code generator generates the following, which doesn't compile:

static WorkflowUtility getWorkflowUtility() {
        if (this.instance == null) {
            this.instance = new WorkflowUtility();
        }
        return this.instance;
}

Since this cannot be used in a static context, it should never be generated automatically.

However, we have to ensure that something like the following still works (which is the reason that this is always added):

class Foo {
    int foo;

    static setFoo(int foo) {
        foo = foo;
    }
}

Comments (3)

  1. Matthias Schoettle reporter

    References #429: Removes generation of this for static fields.

    Adds the class name in front of static fields to avoid ambiguous calls.

    → <<cset f6e8f9204007>>

  2. Log in to comment