TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Type-safely embed DSLs directly into Java

43 点作者 mckinney超过 4 年前

6 条评论

lmilcin超过 4 年前
Except it is not really embedded in Java, only in comments.<p>I sincerely hope this dies a quick death.<p>Java with its jars and infrastructure already makes it plenty convenient to work with resources without them having to be in your face when you are editing the file. Good IDE lets you move between the resource file and the code with a single click.
评论 #24511493 未加载
评论 #24530479 未加载
评论 #24511656 未加载
评论 #24523058 未加载
marktangotango超过 4 年前
I&#x27;m curious how this works under the hood, looks like it&#x27;s added as an annotation processor, and the DSL is embedded in specially formatted comments, but not in annotations. This implies to me the annotation processor is processing the comments in a source file? I did not know annotation processors could do this! Also implies comments carry through to the compiled .class files which I did not think they did either (runtime bytedcode weaving)?
评论 #24510786 未加载
tofflos超过 4 年前
Thank you for making this.<p>Have you considered an approach based on annotations and multi-line strings? I&#x27;m not sure string constants are valid targets for annotations but maybe that could be added to the language?<p><pre><code> @Language(name=&quot;Javascript&quot;) &quot;&quot;&quot; function callBark(aBarker) { aBarker.bark(); } &quot;&quot;&quot;</code></pre>
评论 #24514537 未加载
rhacker超过 4 年前
The graphql example is not the greatest, but I would personally use GQL Code Generator to create a little strongy typed client for all your .graphql files:<p><a href="https:&#x2F;&#x2F;graphql-code-generator.com&#x2F;docs&#x2F;plugins&#x2F;java" rel="nofollow">https:&#x2F;&#x2F;graphql-code-generator.com&#x2F;docs&#x2F;plugins&#x2F;java</a><p>Not sure if there&#x27;s a strong use-case in general here. Even Groovy code, which is a popular choice for JVM DSL languages, has pretty excellent stub generation.
评论 #24510229 未加载
jnellis超过 4 年前
You can write other languages like this in Groovy using Intellij. Intellij allows you to annotate a multiline string as another language, then it will parse and syntax color, autoformat for you. The use case would be when you are templating frontend code snippets on the server side. I&#x27;m not sure if its just Groovy though, I&#x27;m betting Intellij can probably do this with other languages that have multiline strings.
评论 #24511998 未加载
qisyou超过 4 年前
This is cooool!