Bug 576360 - Feature Request: Textblock Annotations to specify editor for code inside java code
Summary: Feature Request: Textblock Annotations to specify editor for code inside java...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.22   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-30 10:50 EDT by Robert Murphy CLA
Modified: 2021-10-07 13:29 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Murphy CLA 2021-09-30 10:50:24 EDT
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.
Comment 1 Robert Murphy CLA 2021-09-30 11:54:55 EDT
@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";
}
Comment 2 Robert Murphy CLA 2021-10-07 13:29:18 EDT
@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);