Community
Participate
Working Groups
I would like Eclipse to create a standard method of specifying language for syntax highlighting in textblocks (apologies if this has already been done). For example @JavaScript could be created as follows: package org.eclipse.textblock.editor.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.SOURCE) @Target(ElementType.LOCAL_VARIABLE) public @interface JavaScript { public String version() default "ES2015"; public String editor() default "org.eclipse.wst.jsdt"; } and then used as follows: @JavaScript String code = """ /** * A useless example of javascript * @param {string} adjective - nothing useful */ function thisIsJavaScript(adjective) { console.log(`This doesn't do anything ${adjective}.`); } """; and then Eclipse would know to use JS Editor (I don't know if the package in my example is the correct package for JS Editor and I don't know if editor() should be a fully qualified package or class) for the contents of the textblock that the variable code is being set to. Eclipse would ship with a set: @JavaScript, @SQL, @CSS, @HTML, @XML, etc but then the Eclipse users could create their own and as long as they specify an installed editor then it would just work.
@Retention(RetentionPolicy.SOURCE) @Target(value = {ElementType.FIELD,ElementType.LOCAL_VARIABLE}) public @interface JavaScript { public String version() default "ES2015"; public String editor() default "org.eclipse.wst.jsdt"; }
@Retention(RetentionPolicy.SOURCE) @Target(value = {ElementType.FIELD,ElementType.LOCAL_VARIABLE,ElementType.PARAMETER}) public @interface JavaScript { public String version() default "ES2015"; public String editor() default "org.eclipse.wst.jsdt"; } An addition feature related to this: Given: ... public void addScript(@JavaScript String script) { ... } ... String js = """ ... <- Eclipse would use JavaScript syntax highlighting here because later this local variable is used as a method parameter and that method signature has that parameter @JavaScript annotated """; addScript(js);