@Language annotation for JDK 13 text blocks
Alex Buckley
alex.buckley at oracle.com
Fri Feb 7 19:15:13 UTC 2020
Anthony, thanks for the mailing list move.
Geertjan, text blocks are just expressions of type String, and
annotations on expressions (or statements) is an incredibly hard
problem. The issue is that the java.lang.reflect and javax.lang.model
APIs don't expose individual expressions and statements, such as those
within a method body or on the RHS of a field initializer. IDEs which
maintain direct access to the AST might be able to retrieve the
annotations, but frameworks which work on class files or during
annotation processing would not be able to retrieve them. This severely
dials back the case for annotatable expressions in the Java language.
That said, I recall some discussion here last year about using the space
immediately to the right of the opening delimiter to denote a control
language, governing the text to follow -- have a look for that.
Alex
On 2/7/2020 10:36 AM, Anthony Vanelverdinghe wrote:
> [moving discussion to amber-dev]
>
> Hi Geertjan
>
> Not sure if there's been public mailing list discussions about it, but
> I'm pretty sure the amber team has already considered the idea of
> attaching this kind of metadata to text blocks. I don't know of any
> related decisions, though.
>
> One issue with annotations in particular, is that text blocks can appear
> in contexts where annotations can't, such as arguments to a method call,
> or annotation element values (JPA's @NamedQuery comes to mind).
> 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.
>
> 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