@Language annotation for JDK 13 text blocks

Brian Goetz brian.goetz at oracle.com
Sat Feb 8 00:10:32 UTC 2020


Alex has correctly pointed out that annotations on expressions are not 
currently supported (and in fact the original design never really 
considered them a serious target of opportunity, because the design 
center at the time was squarely "class, method, and field metadata").  
This would be a major investment, and frankly, I don't see the return on 
it.

Separately ...

> Another issue would be: where/how to standardize the set of 
> "languages"? The IANA registry with media types doesn't contain things 
> like SQL (let alone all its dialects), JSP, JSX, etc. And it's not 
> Java SE's job to maintain such a registry either.

Indeed it is not.  But, this is closely related to another problem which 
we care about, which is: if I am constructing (say) an SQL string, 
whether by concatenation or by some future interpolation feature 
(please, no discussion of this now, it is not on the table right now), I 
would like to use some sort of SQL-specific sanitizer on arguments to 
avoid injection attacks.

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:

   - inside the delimiter:  String s = ""{SQL}" ...SQL content starts on 
next line... """;
   - on the first line after the delimiter, which currently must be blank:
     String s = """ I AM A SQL STRING [1]
                      SELECT * from Foo""";
   - inside the string itself, using escapes: String s = 
"""\$blahSQLblah$ ... SQL content on next line... """;  [1]

and I'm sure you can think of others, equally ugly.


[1] Deliberately stupid syntax used for conceptual illustration only.

>
> Kind regards, Anthony
>
> PS: the Text Blocks JEP [1] specifies amber-dev as the mailing list 
> for discussion, so I took the liberty to change the mailing lists. As 
> I understand it, ide-support-dev is meant for IDE/tooling support when 
> working on the OpenJDK codebase itself
>
> [1] http://openjdk.java.net/jeps/368
>
> On 07/02/2020 12:58, Geertjan Wielenga wrote:
>> Hi all,
>>
>> It would be of great support for IDEs, editors, and tools of various 
>> kinds
>> if a @Language annotation would be part of the support for text 
>> blocks, so
>> that tooling would be able to determine which editor should be injected
>> within the text block.
>>
>> For example, imagine this annotation on top of a text block:
>>
>> @Language="text/html"
>>
>> That would then be used by IDEs, editors, tools, etc, to determine 
>> that the
>> text within the block is HTML and that therefore, for the tools that
>> support this (e.g., NetBeans, IntelliJ IDEA), an HTML editor would 
>> then be
>> injected within the text block, which would make HTML-oriented syntax
>> coloring, code completion, etc, available within the text block.
>>
>> If this meets with enthusiasm, what would the next steps be? An 
>> addition to
>> the text block spec or a new spec or something different?
>>
>> Thanks,
>>
>> Geertjan



More information about the amber-dev mailing list