2020-02-10 09:40:22 -08:00

2.0 KiB

title
7. Annotator

An Annotator helps highlight and annotate any code based on specific rules. This section adds annotation functionality to support the Simple language in the context of Java code.

  • bullet item {:toc}

7.1. Define an Annotator

The SimpleAnnotator subclasses Annotator. Consider a literal string that starts with "simple:" as a prefix of a Simple language key. It isn't part of the Simple language, but it is a useful convention for detecting Simple language keys embedded as string literals in other languages, like Java. Annotate the simple:key literal expression, and differentiate between a well-formed vs. an unresolved property:

{%  include /code_samples/simple_language/src/main/java/com/intellij/sdk/language/SimpleAnnotator.java %}

7.2. Register the Annotator

Using an extension point, register the Simple language annotator class with the IntelliJ Platform:

  <extensions defaultExtensionNs="com.intellij">
    <annotator language="JAVA" implementationClass="com.intellij.sdk.language.SimpleAnnotator"/>
  </extensions>

7.3. Run the Project

As a test, define the following Java file containing a Simple language prefix:value pair:

public class Test {
    public static void main(String[] args) {
        System.out.println("simple:website");
    }
}

Open this Java file in an IDE Development Instance running the simple_language plugin to check if the IDE resolves a property:

Annotator{:width="800px"}

If the property is an undefined name, the annotator will annotate the code with an error.

Unresolved property{:width="800px"}

Try changing the Simple language color settings to differentiate the annotation from the default language color settings.