Open gavinking opened 7 years ago
This would be much more useful if we allowed qualified names as well, because otherwise it’s limited to operations implemented inside the class, which seems to counter the point that we don’t need extension methods in Ceylon because toplevel functions are just as useful.
shared class CeylonExpressionTransformer(…) … {
transformAddAssignmentOperation(AddAssignmentOperation that)
=> "AddAssignmentOperation {
``that.$target`` = ``that.target.transform(this)``;
``that.$summand`` = ``that.summand.transform(this)``;
}"; // indentation elided for clarity
…
}
shared JsonObject writeBook(Book book)
=> JsonObject {
book.$title -> book.title,
book.$authors -> JsonArray(book.authors*.name)
};
otherwise it’s limited to operations implemented inside the class
Well that's not necessarily true; you could use import
.
But sure, I guess there's nothing wrong with something like Book.$title
. It does make it something a bit more than a "string literal", however.
I propose adding a new string literal syntax, where the string must be:
$
, andExample 1:
Or:
Example 2:
Advantages
Scenarios where this would be used include:
string
implementations, as above,ceylon.json
, as above,oneToMany(mappedBy=$property)
annotation.The advantage here is that the IDE would offer, along with errors when the identifier is misspelled: