Here is an example I am using to experiment with inner classes.
Inner Class Scoping Example.
The following xbase example uses our usual grammar and jvmModelInferrer files. It uses default validation and scoping handling (no files other than those generated automatically).
As you can see from the diagram of the model generated, the inner class (MyTestInnerClass), is contained in the outer class (MyTestClass). The contents of methods are an XBlockExpression and so are handled automatically by xbase. |
In the inferrer code the 'toClass' method for the inner class is called on the model element of the outer class. I have tried various combinations for the qualified name passed to this 'toClass' method, such as:
- pck.inner
- pck.outer.inner
- pck.outer$inner
In all of these cases, as we can see from the screenshot, there are problems with referring to outer function from inner function.
When I commented out the lines with errors, then the code was generated correctly, except for the third case where the inner class name was called HelloWorld5$inner which is not necessary in java source code.