3
votes

I am working on a project, where I need to highlight a special kind of a syntaxes in a java file and extract those parts.

public class Hello{
   public static void main(String [] args){
     <<< SOMTHING >>>
   }
}

I have looked at a tutorial from IntelliJ but I cannot quite understand defining grammar for the language. What I want to do is create an IntelliJ idea plugin and define a new language which has same syntaxes as java and some other special symbols. I suppose that I can use the existing syntax highlighting for Java in IdeaJ community source.

Please someone help me how to get the existing syntax highlighting source for Java and add them to my plugin and modify.

Thanks

2

2 Answers

0
votes

Java highlighting is on by default. If you need to extend it you can write an annotator or inspection.

0
votes

So you want to add need to add java syntax highlighting to a custom file type (as per the comment). This can be achieved very easily. Follow the section 2 (Language and File Type) of the tutorial and once that is working, add the following entries to to the extensions section of the plugin.xml file.

<extensions defaultExtensionNs="com.intellij">

    <!-- This line should be already added if you followed the section 2 of the tutorial -->
    <fileTypeFactory implementation="com.simpleplugin.SimpleFileTypeFactory"/>

    <!-- We use java parser definition for our custom langauge -->
    <lang.parserDefinition language="Simple" implementationClass="com.intellij.lang.java.JavaParserDefinition"/>

    <!-- We use java syntax highlighting for our custom langauge -->
    <lang.syntaxHighlighterFactory language="Simple" implementationClass="com.intellij.lang.java.JavaSyntaxHighlighterFactory"/>

</extensions>

Below screenshot demonstrates a .simple file which has Java syntax highlighting support.

enter image description here