Creating Eclipse Plugins Syntax Highlighting Yevgeniy Bangiyev 030307

Creating Eclipse Plugins: Syntax Highlighting Yevgeniy Bangiyev 03/03/07

Purpose • Syntax highlighting is the changing of font settings of tokens in an editor of a programming language to indicate type and mark certain elements or aspects of code. – Tokens are keywords, comment text, strings, integers, identifiers, operators, etc. • Eclipse provides an easy way of creating syntax highlighting for language plugins.

Adding Editor In your plugin project folder, go to the MANIFEST. MF file, then to Extensions and to Add. Click on Extension Wizards, chose Editor, and click Next. extension used Write a class name, editor name, and the file that the editor will be for.

New File Additions The main settings of the editor can be edited in the plugin. xml file. There will be a lot of Java classes created in the src/ editors section, but not all will be needed.

Adding Keyword Highlighting Create a Word. Detector. java file in the src/editors folder and copy this code to it: package plugintest. editors; import org. eclipse. jface. text. rules. IWord. Detector; import org. eclipse. jface. text. rules. Word. Rule; public class Word. Detector implements IWord. Detector { public boolean is. Word. Part(char c) { return (c>' ') && (c<='~'); } public boolean is. Word. Start(char c) { return (c>' ') && (c<='~'); } }

Color Constants File • Open the IXMLColor. Constants. java file and add a RBG constant KEYWORD with the color you want (red is set here, for RBG colors go to the 3 rd link listed on the last slide).

Scanner File Go to the XMLScanner. java file in the src/editors folder. Create a new IToken like the one that is already there but with KEYWORD in the 1 st parameter, put a comma after it, type null, and then SWT. BOLD to make the font bold. Increase the rules array by one, create a new instance of the Word. Rule class, add the keywords for your language, and then set the instance name equal to the next index of the rules array.

Adding Comments Highlighting In the XMLScanner. java file, create a new IToken with XML_ COMMENT being in the 1 st parameter. You can make it bold, Italic (with SWT. ITALIC), or leave it to be regular. Increase the rules array by one, create a new End. Of. Line. Rule for the next array index, with the set of characters that indicate the start of comments and the comment IToken as parameters. Change the font color of comments by editing the RBG color of XML_COMMENT in IXMLColor. Constants. java.

Testing • Launch test the plugin and open a file ending with the file extension you set for the editor. • Code for test. jay:

Sources 1. www. eclipse. org 2. www. cetic. be/internal. php 3? id_art icle=225 3. web. njit. edu/~kevin/rgb. txt. html
- Slides: 10