@Language annotation for JDK 13 text blocks

John Rose john.r.rose at oracle.com
Sat Feb 8 00:23:28 UTC 2020


On Feb 7, 2020, at 4:10 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
> As Alex mentions, in addition to nonexistent annotations on expressions, there are a few places where we can stash additional metadata, all of them ugly:

And if you pull some more on this “string”, you can make the following
additional moves:

* The annotated thingy is no longer a string but an AnnotatedString
with at least two properties:  String value()  and String annotation().
So we are no longer doing String literals.

* But annotations are classes, so the annotation should be a class name,
and then you get String value()  and Class annotation().  And the annotation
in the syntax is revealed as a class name, to be resolved and access checked.

* The annotated thingy should have a stronger type, such as SQLString.
In that case, you want the class name to be at the head of the syntax,
not tucked away inside.  It’ more like a constructor call.  At this point
you can dip into Java’s current repertoire of syntaxes and just say that
we are going to call a factory method SQLString.of(String), which
returns whatever.

* But wait, that’s not my nice bespoke syntax, that’s just an old-school
method call!  Well, OK, this is a place where we might want to add new
syntax, but it’s probably a syntax that starts with a class name and
continues with a string literal.  Like C++ programmable string literals.

* But wait, why do strings get all the fun?  Where we end up is with
some sort of programmable literal syntax which starts with a class
name and continues with something that looks like a literal for a
string, a list, a map, etc.

For now, I think the sweet spot is List.of, Map.of, SQLString.of.

— John


More information about the amber-dev mailing list