Syntactic sugar?
Would it be possible to write a plugin that extends the Java language with new syntax? Here is an example:
Normal if statement
if (value == 0 || value == 1 || value == 7) { ... }
Enhanced if statement
if (value == 0, 1, 7) { ... }
The Java source code on disk wouldn't change. The new syntax would just provide a different view of the underlying if statement.
Possible or not?
Please sign in to leave a comment.
Yes, it's possible. See JavaFoldingBuilderBase in the Community Edition source code for an example. Note that the user will still edit the code in the real Java syntax form; the sugared form will only be shown when the caret is not in the modified code block.
So better than nothing then. I just feel it would be great to steal features from other languages without having to completely switch to that other language. Call me lazy, but I enjoy the benefits of IDEs in general and IntelliJ in particular. I haven't even tried a different JVM-language supported by IJ. But if there would be a plugin to support a syntactic construction from another language I would definitely use it. E.g we could have had lambdas long before JDK 8.