Jakub Chrzanowski 4e802980f2
Webhelp migration (#347)
* [webhelp] Fixes for TXP00152, TXP00002, test build 27 Jul 22:26

* [webhelp] Fixes for Part #4 TXP00010, EXCEPT decimal numbers in section titles

* [webhelp] Fixes for Part #5 TXP00017

* [webhelp] Fixes for Part #4 TXP00010 - removed numbers from page section titles in "Custom Language Support Tutorial" and "Testing a Custom Language Plugin".

* [webhelp] Removed numbers from page section titles in rest of project *.md files.

* [new webhelp] Build #44 changes

* [new webhelp] Maintenance merge from master

* [new webhelp] Add placeholder file for webhelp import.

* [webhelp] Correct redirects for file name changes

* [webhelp] TOC not needed in webhelp

* [format] {:toc} not needed for webhelp

* add {:disable-links} to ensure demo links are not interpreted as real links.

* Put all badges on the same line to simplify composition.

* formatter.md: fix upsource link

* fix some links

* api_changes_list.md: remove note

* migrate to webhelp - initial

* fix GH edit URL

* remove sdkdocs-template setup in VCS config

* remove recently_updated.md

* restore COC/CONTRIBUTING.md

* api_changes_list.md: remove note

* useful_links.md: IPE

Co-authored-by: JohnHake <john.hake@jetbrains.com>
Co-authored-by: Yann Cébron <yann.cebron@jetbrains.com>
2021-01-14 16:07:39 +01:00

3.0 KiB

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.

Reference: Annotator

Required Project Configuration Changes

Classes defined in this step of the tutorial depend on com.intellij.psi.PsiLiteralExpression at runtime. Using PsiLiteralExpression introduces a dependency on com.intellij.modules.java. Beginning in version 2019.2 of the IntelliJ Platform these dependencies are declared in plugin.xml:

  <depends>com.intellij.modules.java</depends>

The dependency is also declared in the build.gradle file:

intellij {
  plugins = ['java']
}

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.

The use of new AnnotationHolder syntax starting 2020.2, which uses the builder format.

{type="note"}

{src="simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleAnnotator.java"}

If the above code is copied at this stage of the tutorial, then remove the line below the comment "** Tutorial step 18.3 …" The quick fix class in that line is not defined until later in the tutorial.

{type="tip"}

Register the Annotator

Using the com.intellij.annotator extension point in the plugin configuration file, register the Simple Language annotator class with the IntelliJ Platform:

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

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="800"}

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

Unresolved property{width="800"}

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