title: Eclipse IDE - Costum language syntax highlighting through generic text editor extension points
body: <p>I've been trying to write a plugin for the Eclipse IDE that does syntax highlighting and code completion for a custom generic language.</p>
  
  <p>In the oxygen project version (v4.7) change notes a supposedly new and easy way to use a generic text editor and extend it with the wanted features is announced using extension points. Even code snippets are provided:</p>
  
  <blockquote>
    <p>With this new editor it is now much easier to enrich a new generic editor so you can add support relatively easy for new languages. It is reusing the existing Eclipse editor infrastructure but with the generic editor you don't need to implement an editor to supply functionality for a new file content-type. Instead you make the generic editor smarter by extension points.
    The following example shows how to contribute features to the generic editor via extensions:</p>
  </blockquote>
  
  <pre><code>&lt;extension point="org.eclipse.ui.genericeditor.contentAssistProcessors"&gt;
     &lt;contentAssistProcessor
           class="org.eclipse.ui.genericeditor.examples.dotproject.NaturesAndProjectsContentAssistProcessor"
           contentType="org.eclipse.ui.genericeditor.examples.dotproject"&gt;
     &lt;/contentAssistProcessor&gt;
  &lt;/extension&gt;
  &lt;extension point="org.eclipse.ui.genericeditor.hoverProviders"&gt;
     &lt;hoverProvider
           class="org.eclipse.ui.genericeditor.examples.dotproject.NatureLabelHoverProvider"
           contentType="org.eclipse.ui.genericeditor.examples.dotproject"
           id="natureLabelHoverProvider"&gt;
     &lt;/hoverProvider&gt;
  &lt;/extension&gt;
  &lt;extension point="org.eclipse.ui.genericeditor.presentationReconcilers"&gt;
     &lt;presentationReconciler
           class="org.eclipse.ui.genericeditor.examples.dotproject.BlueTagsPresentationReconciler"
           contentType="org.eclipse.ui.genericeditor.examples.dotproject"&gt;
     &lt;/presentationReconciler&gt;
  &lt;/extension&gt;
  </code></pre>
  
  <blockquote>
    <p>Those new extension points receive as arguments regular Platform classes (IPresentationReconcilier, ITextHover, ICompletionProposalComputer) to add behavior to the generic editor. No new Java API is necessary.</p>
    
    <p>Here is a simple example of adding some minimal Gradle syntax highlighting support:</p>
  </blockquote>
  
  <pre><code>public class GradlePR extends PresentationReconciler {
  
      private IToken quoteToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(139, 69, 19))));
      private IToken numberToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 0, 255))));
      private IToken commentToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 100, 0))));
  
      public GradlePR() {
          RuleBasedScanner scanner = new RuleBasedScanner();
  
          IRule[] rules = new IRule[5];
          rules[0] = new SingleLineRule("'", "'", quoteToken);
          rules[1] = new SingleLineRule("\"","\"", quoteToken);
          rules[2] = new PatternRule("//", null, commentToken, (char)0, true);
          rules[3] = new NumberRule(numberToken);
  
          rules[4] = new GradleWordRule();
  
          scanner.setRules(rules);
  
          DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
          this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
          this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
      }
  
  }
  </code></pre>
  
  <p>(original source: <a href="https://www.eclipse.org/eclipse/news/4.7/M3/#generic-editor" rel="nofollow noreferrer">https://www.eclipse.org/eclipse/news/4.7/M3/#generic-editor</a>)</p>
  
  <p>I've managed to open a new Plug-in Project with the generic text editor already implemented. The automatically generated plugin.xml file already contains the first code block quoted above (i.e. the extension point definition if I'm not mistaken).</p>
  
  <p>I'm really new to Eclipse plugins and not very firm on Java neither. So I haven't been able to figure out where to put the code from the second code block so as to actually implement the changes in the editor and how to connect it with the extension points.</p>
  
  <p>Any pointers in a direction, or links to some further reading (ideally very basic) or an idiot's level tutorial is much appreciated!
  Thanks.</p>