<?xml version="1.0" encoding="UTF-8"?>
<!--

 This file is part of GtkSourceView

 Author: Gustavo Giráldez <gustavo.giraldez@gmx.net>
 Copyright (C) 2003 Gustavo Giráldez <gustavo.giraldez@gmx.net>
 Copyright (C) 2006 Jeff Walden <jwalden@mit.edu>

 GtkSourceView is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 GtkSourceView is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with this library; if not, see <http://www.gnu.org/licenses/>.

-->
<language id="java" name="Java" version="2.0" _section="Source">
  <metadata>
    <property name="mimetypes">text/x-java</property>
    <property name="globs">*.java</property>
    <property name="line-comment-start">//</property>
    <property name="block-comment-start">/*</property>
    <property name="block-comment-end">*/</property>
    <property name="suggested-suffix">.java</property>
  </metadata>

  <styles>
    <style id="comment"           name="Comment"                   map-to="def:comment"/>
    <style id="doc-comment"       name="Documentation comment"     map-to="def:doc-comment"/>
    <style id="doc-comment-element" name="Documentation comment element" map-to="def:doc-comment-element"/>
    <style id="escaped-character" name="Escaped Character"         map-to="def:special-char"/>
    <style id="multiline-string"  name="Multiline string"      map-to="def:string"/>
    <style id="string"            name="String"                    map-to="def:string"/>
    <style id="char"              name="Character"                 map-to="def:character"/>
    <style id="external"          name="External"                  map-to="def:preprocessor"/>
    <style id="annotation"        name="Annotation"                map-to="def:preprocessor"/>
    <style id="declaration"       name="Declaration"               map-to="def:type"/>
    <style id="storage-class"     name="Storage Class"             map-to="def:type"/>
    <style id="scope-declaration" name="Scope Declaration"         map-to="def:type"/>
    <style id="keyword"           name="Keyword"                   map-to="def:keyword"/>
    <style id="null-value"        name="Null Value"                map-to="def:special-constant"/>
    <style id="boolean"           name="Boolean value"             map-to="def:boolean"/>
    <style id="floating-point"    name="Floating-point number"     map-to="def:floating-point"/>
    <style id="decimal"           name="Decimal number"            map-to="def:decimal"/>
    <style id="base-n-integer"    name="Base-N number"             map-to="def:base-n-integer"/>
    <style id="reserved"          name="Future Reserved Keywords"  map-to="def:reserved"/>
    <style id="type"              name="Data Type"                 map-to="def:type"/>
  </styles>

  <definitions>

    <define-regex id="escaped-character" extended="true">
      \\(                 # leading backslash
        [\\\"\'nrbtf] |   # escaped character
        [0-7]{1,3}    |   # latin encoded char
        u[0-9a-fA-F]{4}   # unicode char
      )
    </define-regex>

    <context id="doc-comment" style-ref="doc-comment" class-disabled="no-spell-check" class="comment">
      <start>/\*\*(?![\*/])</start>
      <end>\*/</end>
      <include>
        <context ref="def:in-comment"/>
        <context id="doc-comment-element" style-ref="doc-comment-element">
          <match>\B@\w+</match>
        </context>
      </include>
    </context>

    <context id="string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
      <start>"</start>
      <end>"</end>
      <include>
        <context id="escaped-character" style-ref="escaped-character">
          <match>\%{escaped-character}</match>
        </context>
      </include>
    </context>

    <context id="multiline-string" style-ref="multiline-string" class="string" class-disabled="no-spell-check">
      <start>"""\s*$</start>
      <end>"""</end>
      <include>
        <context style-ref="escaped-character">
          <match>\%{escaped-character}</match>
        </context>
      </include>
    </context>

    <context id="char" style-ref="char">
      <match>'((\%{escaped-character})|.)'</match>
      <include>
        <context sub-pattern="2" style-ref="escaped-character"/>
      </include>
    </context>

    <context id="annotation" style-ref="annotation">
      <match>\B@\w*</match>
    </context>

    <context id="externals" style-ref="external">
      <keyword>exports</keyword>
      <keyword>import</keyword>
      <keyword>module</keyword>
      <keyword>open</keyword>
      <keyword>opens</keyword>
      <keyword>package</keyword>
      <keyword>provides</keyword>
      <keyword>requires</keyword>
      <keyword>to</keyword>
      <keyword>transitive</keyword>
      <keyword>uses</keyword>
      <keyword>with</keyword>
    </context>

    <context id="declarations" style-ref="declaration">
      <keyword>class</keyword>
      <keyword>enum</keyword>
      <keyword>extends</keyword>
      <keyword>implements</keyword>
      <keyword>instanceof</keyword>
      <keyword>interface</keyword>
      <keyword>native</keyword>
      <keyword>non-sealed</keyword>
      <keyword>permits</keyword>
      <keyword>record</keyword>
      <keyword>sealed</keyword>
      <keyword>throws</keyword>
    </context>

    <context id="primitive-types" style-ref="type">
      <keyword>boolean</keyword>
      <keyword>byte</keyword>
      <keyword>char</keyword>
      <keyword>double</keyword>
      <keyword>float</keyword>
      <keyword>int</keyword>
      <keyword>long</keyword>
      <keyword>short</keyword>
      <keyword>var</keyword>
      <keyword>void</keyword>
    </context>

    <context id="storage-class" style-ref="storage-class">
      <keyword>abstract</keyword>
      <keyword>final</keyword>
      <keyword>static</keyword>
      <keyword>strictfp</keyword>
      <keyword>synchronized</keyword>
      <keyword>transient</keyword>
      <keyword>volatile</keyword>
    </context>

    <context id="scope-declarations" style-ref="scope-declaration">
      <keyword>private</keyword>
      <keyword>protected</keyword>
      <keyword>public</keyword>
    </context>

    <context id="flow" style-ref="keyword">
      <keyword>assert</keyword>
      <keyword>break</keyword>
      <keyword>case</keyword>
      <keyword>catch</keyword>
      <keyword>continue</keyword>
      <keyword>default</keyword>
      <keyword>do</keyword>
      <keyword>else</keyword>
      <keyword>finally</keyword>
      <keyword>for</keyword>
      <keyword>if</keyword>
      <keyword>return</keyword>
      <keyword>throw</keyword>
      <keyword>switch</keyword>
      <keyword>try</keyword>
      <keyword>while</keyword>
      <keyword>yield</keyword>
    </context>

    <context id="memory" style-ref="keyword">
      <keyword>new</keyword>
      <keyword>super</keyword>
      <keyword>this</keyword>
    </context>

    <context id="future-reserved-words" style-ref="reserved">
      <keyword>const</keyword>
      <keyword>goto</keyword>
      <keyword>_</keyword>
    </context>

    <context id="null-value" style-ref="null-value">
      <keyword>null</keyword>
    </context>

    <context id="boolean" style-ref="boolean">
      <keyword>false</keyword>
      <keyword>true</keyword>
    </context>

    <context id="floating-point" style-ref="floating-point">
      <match extended="true" case-sensitive="false">
        \b(
          \d+[fd] |
          ((\d*\.\d+|\d+\.)(e[-+]?\d+)? |
            \d+e[-+]?\d+)[fd]?
        )
      </match>
    </context>
    <context id="base-n-integer" style-ref="base-n-integer">
      <match case-sensitive="false">\b(0x[\da-f]+|0[0-7]+)l?</match>
    </context>
    <context id="decimal" style-ref="decimal">
      <match case-sensitive="false">\b([1-9]\d*|0)l?</match>
    </context>

    <context id="java" class="no-spell-check">
      <include>
        <context ref="doc-comment"/>
        <context ref="def:c-like-comment" style-ref="comment"/>
        <context ref="def:c-like-comment-multiline" style-ref="comment"/>
        <context ref="def:c-like-close-comment-outside-comment"/>
        <context ref="multiline-string"/>
        <context ref="string"/>
        <context ref="char"/>
        <context ref="annotation"/>
        <context ref="externals"/>
        <context ref="declarations"/>
        <context ref="primitive-types"/>
        <context ref="storage-class"/>
        <context ref="scope-declarations"/>
        <context ref="flow"/>
        <context ref="memory"/>
        <context ref="future-reserved-words"/>
        <context ref="null-value"/>
        <context ref="boolean"/>
        <context ref="floating-point"/>
        <context ref="base-n-integer"/>
        <context ref="decimal"/>
      </include>
    </context>

  </definitions>
</language>
