| Summary: | [Xtend] support for definition of constructors | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Sven Efftinge <sven.efftinge> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | eclipse.dserodio, jan, sebastian.zarnekow |
| Version: | 2.1.0 | Flags: | sven.efftinge:
juno+
|
| Target Milestone: | M4 | ||
| Hardware: | PC | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
|
Description
Sven Efftinge
The semantics will be just like in Java, the syntax is almost the same.
The single difference is that instead of repetition of the class' name you only need to write the keyword 'constructor'. This reduces redundancy and at the same time gives a nice visual anchor in the text file.
Example:
class MyClass extends AnotherClass {
constructor () {
this("MyClass")
}
constructor (String name) {
super(name)
}
}
In Xbase everything is an expression but might compile to a sequence of Java statements. Java does only allow expressions that don't call non-static methods in the constructor's arguments. We have to specify/verify what kind of Xbase expressions are allowed as arguments in Xtend's super/this calls. My idea was to allow all the expressions and as long as we can't turn it into a Java expression, we generate something like:
super(new Function0<String>() {
public String apply() {
// generated Java statements.
}
}.apply());
In addition we should add a compiler check for this context so invalid calls get marked.
Btw.: we should do the same thing for field initializers.
To be done:
Validation for super(..) call / this(..) call
Cyclic constructor invocation
Expressify the arguments that are passed to super(..) / this(..)
Compiler
Current syntax proposal:
class Z extends Something {
new(int a, int b) {
super(a + b)
}
}
Pushed working version. Remaining issues will be tracked in own tickets. Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |