summary refs log blame commit diff stats
path: root/java/vendor/Java.sublime-syntax
blob: c13c939badf1367b4f44c942a1f28c31ae0f129e (plain) (tree)
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246





























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                    
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: java-new
file_extensions:
  - java
  - bsh
scope: source.java

variables:
  primitives: (?:boolean|byte|char|short|int|float|long|double|var)
  storage_modifiers: (?:public|private|protected|static|final|native|synchronized|strictfp|abstract|transient|default|volatile)

  id: (?:[\p{L}_$][\p{L}\p{N}_$]*)
  classcase_id: (?:\p{Lu}[\p{L}\p{N}_$]*)
  lowercase_id: (?:[_$]*\p{Ll}[\p{Ll}\p{N}_$]*\b)
  uppercase_id: (?:[_$]*\p{Lu}[\p{Lu}\p{N}_$]*\b)

  # One dot is mandatory to not compete with other regexes that match an id.
  before_fqn: (?={{lowercase_id}}\s*\.)

  # utility lookaround
  lambda_lookahead: (?:\(.*\)|{{id}})\s*->

  # digits
  ddigits0: '\d[\d_]*?(_*)'
  ddigits: (?:(_*){{ddigits0}})
  hdigits: (?:(_*)\h[\h_]*?(_*))
  exponent: '[-+]?{{ddigits}}'
  eexponent: (?:[eE]{{exponent}})
  pexponent: (?:[pP]{{exponent}})

contexts:
  prototype:
    - match: (?=%>)
      pop: true
    - include: comments
    - include: illegal-keywords

  any_POP:
    - match: (?=\S)
      pop: true

  immediate_POP:
    - match: ''
      pop: true

  main:
    - include: prototype
    - include: package-statement
    - include: import-statement
    - include: module
    - include: class
    - include: annotations
    # Get modifiers defined on a different line than the class
    - include: storage-modifiers
    - include: stray-braces
    - include: code

  punctuation-accessor-dot:
    - match: \.
      scope: punctuation.accessor.dot.java

  punctuation-separator-comma:
    - match: \,
      scope: punctuation.separator.comma.java

  punctuation-terminator-semicolon:
    - match: ;
      scope: punctuation.terminator.java

  dot-separated-identifier:
    - match: '{{id}}'
    - include: punctuation-accessor-dot
    - include: immediate_POP

  package-statement:
    - match: \bpackage\b
      scope: keyword.other.package.java
      push:
        - - meta_scope: meta.package-declaration.java
          - include: immediate_POP
        - - match: '{{id}}'
            set:
              - meta_scope: meta.path.java entity.name.namespace.java
              - include: dot-separated-identifier
          - include: any_POP

  import-statement:
    - match: \bimport\b
      scope: keyword.control.import.java
      push:
        - - meta_scope: meta.import.java
          - include: immediate_POP
        - import-statement-body

  import-statement-body:
    - match: \bstatic\b
      scope: keyword.control.import.static.java
      set: static-import-statement-body
    - include: before-next-import
    - match: '{{lowercase_id}}'
      scope: meta.path.java support.type.package.java
      set:
        - meta_content_scope: meta.path.java
        - include: before-next-import
        - include: package
        - match: \*
          scope: meta.path.java keyword.operator.wildcard.asterisk.java
          pop: true
        - match: '{{classcase_id}}'
          scope: support.class.import.java
          set:
            - include: before-next-import
            - include: punctuation-accessor-dot
            - include: import-class
            - include: import-wildcard
            - include: any_POP
        - include: any_POP
    - include: any_POP

  static-import-statement-body:
    - include: before-next-import
    - match: '{{lowercase_id}}'
      scope: meta.path.java support.type.package.java
      set:
        - meta_content_scope: meta.path.java
        - include: before-next-import
        - include: package
        - match: '{{classcase_id}}'
          scope: support.class.import.java
          set:
            - include: before-next-import
            - include: punctuation-accessor-dot
            - include: import-constant
            - include: import-class
            - include: import-function
            - include: import-wildcard
            - include: any_POP
        - include: any_POP
    - include: any_POP

  before-next-import:
    # Prevent next import statement to be consumed when a current statement isn't terminated with ';'.
    - match: (?=\bimport\b)
      pop: true
    # For a case of a statement immediately before a class definition.
    - match: (?=\b(?:{{storage_modifiers}}|class|interface|enum)\b)
      pop: true

  package:
    - match: '{{lowercase_id}}'
      scope: support.type.package.java
    - include: punctuation-accessor-dot

  all-types:
    - include: primitive-types
    - include: object-types

  import-constant:
    - match: '{{uppercase_id}}'
      scope: constant.other.import.java

  import-class:
    - match: '{{classcase_id}}'
      scope: support.class.import.java

  import-function:
    - match: '{{id}}'
      scope: support.function.import.java

  import-wildcard:
    - match: \*
      scope: keyword.operator.wildcard.asterisk.java

  annotations:
    - match: \@
      scope: punctuation.definition.annotation.java
      push:
        - - meta_scope: meta.annotation.java
          - include: immediate_POP
        - annotation-parameters
        - - meta_content_scope: meta.annotation.identifier.java
          - include: immediate_POP
        - annotation-type-reference

  annotation-type-reference:
    - match: '{{before_fqn}}'
      set:
        - meta_scope: meta.path.java
        - match: '{{lowercase_id}}'
          scope: variable.annotation.package.java
        - include: punctuation-accessor-dot
        - include: annotation-type-no-fqn
    - include: annotation-type-no-fqn

  annotation-type-no-fqn:
    - match: '{{classcase_id}}'
      scope: variable.annotation.java
      set: after-annotation-type-reference
    - include: any_POP

  after-annotation-type-reference:
    - match: \.
      scope: punctuation.accessor.dot.java
      set: annotation-type-no-fqn
    - include: any_POP

  annotation-parameters:
    - match: \(
      scope: punctuation.section.parens.begin.java
      set:
        - meta_scope: meta.annotation.parameters.java
        - match: \)
          scope: punctuation.section.parens.end.java
          pop: true
        - match: ({{id}})\s*(=)
          captures:
            1: variable.parameter.java
            2: keyword.operator.assignment.java
          push:
            - match: (?=[,})])
              pop: true
            - include: annotations
            - include: code
        - include: annotation-array-initialization
        - include: annotations
        - include: code
    - include: any_POP

  annotation-array-initialization:
    - match: \{
      scope: punctuation.section.braces.begin.java
      push:
        - meta_scope: meta.braces.annotation-array-initialization.java
        - include: array-initialization-common
        - include: annotations

  anonymous-classes-and-new:
    - match: \bnew\b
      scope: keyword.other.storage.new.java
      push:
        - - meta_scope: meta.instantiation.java
          - include: immediate_POP
        - instantiation

  instantiation:
    - match: \b{{primitives}}\b
      scope: storage.type.primitive.java
      set: array-definition
    - match: '{{before_fqn}}'
      set: [after-object-type-in-instantiation, object-type-fqn]
    - include: object-type-instantiation-no-fqn

  object-type-instantiation-no-fqn:
    - match: '{{classcase_id}}'
      scope: support.class.java
      set: after-object-type-in-instantiation
    - include: any_POP

  after-object-type-in-instantiation:
    - match: (?=\[)
      set: array-definition
    - match: (?=\()
      set: object-construction
    - match: <>
      scope: punctuation.definition.generic.diamond.java
      set: object-construction
    - match: (?=<)
      set: [after-generic-in-instantiation, generic-type-invocation]
    - match: \.
      scope: punctuation.accessor.dot.java
      set: object-type-instantiation-no-fqn
    - include: any_POP

  after-generic-in-instantiation:
    - match: (?=\[)
      set: array-definition
    - include: object-construction

  object-construction:
    - match: \(
      scope: punctuation.section.parens.begin.java
      set:
        - meta_scope: meta.parens.constructor-arguments.java
        - match: \)
          scope: punctuation.section.parens.end.java
          set:
            - match: \{
              scope: punctuation.section.braces.begin.java
              set:
                - meta_scope: meta.class.body.anonymous.java
                - match: \}
                  scope: punctuation.section.braces.end.java
                  pop: true
                - include: class-body
            - include: any_POP
        - include: illegal-parens-terminators
        - include: code
    - include: any_POP

  array-definition:
    - match: \[
      scope: punctuation.section.brackets.begin.java
      set:
        - meta_scope: meta.brackets.array-initialization.java
        - match: \]
          scope: punctuation.section.brackets.end.java
          set:
            - match: (?=\[)
              set: array-definition
            - match: \{
              scope: punctuation.section.braces.begin.java
              set: array-initialization
            - include: any_POP
        - include: code
    - include: any_POP

  array-initialization:
    - meta_scope: meta.braces.array-initialization.java
    - include: array-initialization-common

  array-initialization-common:
    - match: \}
      scope: punctuation.section.braces.end.java
      pop: true
    - match: \{
      scope: punctuation.section.braces.begin.java
      push: array-initialization
    - include: code

  class:
    - match: (?=({{storage_modifiers}}\s+)*(?:class|(?:@)?interface|enum)\b)
      push: [class-meta, class-type]

  class-meta:
    - meta_scope: meta.class.java
    - include: immediate_POP

  class-type:
    - include: storage-modifiers
    - match: (?:class|(\@?)interface)\b
      scope: storage.type.java
      captures:
        1: punctuation.definition.type.java
      set:
        - class-block
        - class-extends
        - generic-type-declaration
        - class-name
    - match: enum\b
      scope: storage.type.java
      set:
        - enum-block
        - class-extends
        - generic-type-declaration
        - class-name
    - include: any_POP

  class-name:
    - meta_scope: meta.class.identifier.java
    - match: (?!extends|implements){{id}}\b
      scope: entity.name.class.java
      pop: true
    - include: any_POP

  class-extends:
    - match: extends\b
      scope: keyword.declaration.extends.java
      push:
        - - meta_scope: meta.class.extends.java
          - match: \,
            scope: punctuation.separator.comma.java
            push: inherited-object-type-reference
          - include: any_POP
        - inherited-object-type-reference
    - match: implements\b
      scope: keyword.declaration.implements.java
      push:
        - - meta_scope: meta.class.implements.java
          - match: \,
            scope: punctuation.separator.comma.java
            push: inherited-object-type-reference
          - include: any_POP
        - inherited-object-type-reference
    - include: any_POP

  class-block:
    - match: \{
      scope: punctuation.section.block.begin.java
      set:
        - meta_scope: meta.class.body.java meta.block.java
        - match: \}
          scope: punctuation.section.block.end.java
          pop: true
        - include: class-body
    - include: any_POP

  class-body:
    - include: class
    - include: annotations
    - include: fields-and-methods
    - include: constants-and-special-vars
    - include: storage-modifiers
    - include: all-types
    - include: static-code-block
    - include: punctuation-separator-comma
    - include: punctuation-terminator-semicolon
    - match: (?=<)
      push: generic-type-declaration

  enum-block:
    - match: \{
      scope: punctuation.section.block.begin.java
      set:
        - meta_scope: meta.class.body.java meta.block.java
        - match: \}
          scope: punctuation.section.block.end.java
          pop: true
        - include: enum-body
    - include: any_POP

  enum-body:
    - match: ^(?=\s*([[:upper:]_][[:upper:][:digit:]_]*|(?!{{primitives}}|{{storage_modifiers}})[[:lower:]_][[:alnum:]_]*)\s*[,;{(])
      push:
        - match: (?=[;}])
          pop: true
        - match: \w+
          scope: constant.other.enum.java
          push:
            - meta_scope: meta.enum.java
            - match: \{
              scope: punctuation.section.block.begin.java
              push:
                - meta_scope: meta.enum.body.java meta.block.java
                - match: \}
                  scope: punctuation.section.block.end.java
                  pop: true
                - include: enum-body
            - include: parens
            - include: any_POP
        - include: punctuation-separator-comma
    - include: class-body

  code:
    - include: constants-and-special-vars
    - include: assignment
    - include: lambdas
    - include: strings
    - include: anonymous-classes-and-new
    - include: keywords-control
    - include: method-invocations
    - include: uppercase-identifiers
    - include: all-types
    - include: keywords
    - include: code-block-include
    - include: parens
  code-block-include:
    - match: \{
      scope: punctuation.section.block.begin.java
      push:
        - meta_scope: meta.block.java
        - match: \}
          scope: punctuation.section.block.end.java
          pop: true
        - include: code-block
  code-block:
    - include: storage-modifiers
    - include: var-type
    - include: code
    - include: annotations
    - include: code-block-include
    - include: stray-parens
  comments:
    - match: /\*\*/
      scope: comment.block.empty.java punctuation.definition.comment.java
    - include: scope:text.html.javadoc
    - include: comments-inline
  comments-inline:
    - match: /\*
      scope: punctuation.definition.comment.java
      push:
        - meta_scope: comment.block.java
        - match: \*/
          scope: punctuation.definition.comment.java
          pop: true
    - match: //
      scope: punctuation.definition.comment.java
      push:
        - meta_scope: comment.line.double-slash.java
        - match: \n
          pop: true
        - match: (?=%>)
          pop: true

  constants-and-special-vars:
    - match: \b(true|false|null)\b
      scope: constant.language.java
    - match: \b(this|super)\b
      scope: variable.language.java
    # hexadecimal floats
    - match: |-
        \b(0[xX])(?x:
          # 0x1., 0x1.1, 0x1.1p1, 0x1.1p-1, 0x1.p1, 0x1.p-1 | 0x1p1
          {{hdigits}} (?: (\.) (?: {{hdigits}}? {{pexponent}}? \b )? | {{pexponent}} \b )
          # 0x.1, 0x.1p1, 0x.1p-1
          | (\.) {{hdigits}} {{pexponent}}? \b
        )
      scope: constant.numeric.float.hexadecimal.java
      captures:
        1: punctuation.definition.numeric.hexadecimal.java
        2: invalid.illegal.numeric.java
        3: invalid.illegal.numeric.java
        4: punctuation.separator.decimal.java
        5: invalid.illegal.numeric.java
        6: invalid.illegal.numeric.java
        7: invalid.illegal.numeric.java
        8: invalid.illegal.numeric.java
        9: invalid.illegal.numeric.java
        10: invalid.illegal.numeric.java
        11: punctuation.separator.decimal.java
        12: invalid.illegal.numeric.java
        13: invalid.illegal.numeric.java
        14: invalid.illegal.numeric.java
        15: invalid.illegal.numeric.java
    # decimal floats
    - match: |-
        (?x:
          \b{{ddigits0}}
          (?:
            # 1., 1.1, 1.1e1, 1.1e-1, 1.e1, 1.e-1, 1.d, 1.1d, 1.1e1d, 1.1e-1d, 1.e1d, 1.e-1d
            (\.) (?: {{ddigits}}? {{eexponent}}? ([dDfF])? \b )?
            # 1e1 1e1d
            | {{eexponent}} ([dDfF])? \b
            # 1d
            | ([dDfF]) \b
          )
          # .1, .1e1, .1e-1
          | (\.) {{ddigits}} {{eexponent}}? ([dDfF])? \b
        )
      scope: constant.numeric.float.decimal.java
      captures:
        1: invalid.illegal.numeric.java
        2: punctuation.separator.decimal.java
        3: invalid.illegal.numeric.java
        4: invalid.illegal.numeric.java
        5: invalid.illegal.numeric.java
        6: invalid.illegal.numeric.java
        7: storage.type.numeric.java
        8: invalid.illegal.numeric.java
        9: invalid.illegal.numeric.java
        10: storage.type.numeric.java
        11: storage.type.numeric.java
        12: punctuation.separator.decimal.java
        13: invalid.illegal.numeric.java
        14: invalid.illegal.numeric.java
        15: invalid.illegal.numeric.java
        16: invalid.illegal.numeric.java
        17: storage.type.numeric.java
    # binary integers
    - match: \b(0[bB])(_*)[01][01_]*?(_*)([lL])?\b
      scope: constant.numeric.integer.binary.java
      captures:
        1: punctuation.definition.numeric.binary.java
        2: invalid.illegal.numeric.java
        3: invalid.illegal.numeric.java
        4: storage.type.numeric.java
    # hexadecimal integers
    - match: \b(0[xX]){{hdigits}}([lL])?\b
      scope: constant.numeric.integer.hexadecimal.java
      captures:
        1: punctuation.definition.numeric.hexadecimal.java
        2: invalid.illegal.numeric.java
        3: invalid.illegal.numeric.java
        4: storage.type.numeric.java
    # octal integers
    - match: \b(0)(?:(_+)|[0-7_]+?(_*)|([\d_]+))([lL])?\b
      scope: constant.numeric.integer.octal.java
      captures:
        1: punctuation.definition.numeric.octal.java
        2: invalid.illegal.numeric.java
        3: invalid.illegal.numeric.java
        4: invalid.illegal.numeric.java
        5: storage.type.numeric.java
    # decimal integers
    - match: \b{{ddigits0}}([lL])?\b
      scope: constant.numeric.integer.decimal.java
      captures:
        1: invalid.illegal.numeric.java
        2: storage.type.numeric.java

  keywords:
    - match: '::'
      scope: punctuation.accessor.double-colon.java
      push:
        - match: '{{id}}'
          scope: variable.function.reference.java
          pop: true
        - include: any_POP
    - match: '\?|:'
      scope: keyword.operator.ternary.java
    - match: \binstanceof\b
      scope: keyword.operator.word.instanceof.java
    - match: (<<|>>>?)
      scope: keyword.operator.bitshift.java
    - match: (==|!=|<=|>=|<>|<|>)
      scope: keyword.operator.comparison.java
    - match: (\-\-|\+\+)
      scope: keyword.operator.increment-decrement.java
    - match: (\-|\+|\*|\/|%)
      scope: keyword.operator.arithmetic.java
    - match: (!|&&|\|\|)
      scope: keyword.operator.logical.java
    - match: (~|\^|&|\|)
      scope: keyword.operator.bitwise.java
    - match: (\.)(class\b)?
      captures:
        1: punctuation.accessor.dot.java
        2: variable.language.java
    - include: punctuation-separator-comma
    - include: punctuation-terminator-semicolon

  keywords-control:
    # exceptions
    - match: \bcatch\b
      scope: keyword.control.exception.catch.java
      push:
        - meta_scope: meta.catch.java
        - match: (?=\()
          set:
            - match: \(
              scope: punctuation.section.parens.begin.java
              set:
                - meta_scope: meta.catch.parameters.java meta.parens.java
                - match: \)
                  scope: punctuation.section.parens.end.java
                  pop: true
                - match: \|
                  scope: punctuation.separator.bar.java
                - include: parameters
        - include: any_POP
    - match: \bfinally\b
      scope: keyword.control.exception.finally.java
    - match: \btry\b
      scope: keyword.control.exception.try.java
      push: declaration-statement-parens
    # flow
    - match: \bassert\b
      scope: keyword.control.flow.assert.java
      push:
        - meta_scope: meta.assertion.java
        - match: (?=;)
          pop: true
        - match: ':'
          scope: punctuation.separator.expressions.java
        - include: code
    - match: \bbreak\b
      scope: keyword.control.flow.break.java
    - match: \bcontinue\b
      scope: keyword.control.flow.continue.java
    - match: \breturn\b
      scope: keyword.control.flow.return.java
    - match: \bthrow\b
      scope: keyword.control.flow.throw.java
    # conditional
    - match: \bif\b
      scope: keyword.control.conditional.if.java
    - match: \belse\b
      scope: keyword.control.conditional.else.java
    - match: \bswitch\b
      scope: keyword.control.conditional.switch.java
    - match: \bcase\b
      scope: keyword.control.conditional.case.java
    - match: \bdefault\b
      scope: keyword.control.conditional.default.java
    # loop
    - match: \bdo\b
      scope: keyword.control.loop.do-while.java
    - match: \bfor\b
      scope: keyword.control.loop.for.java
      push: declaration-statement-parens
    - match: \bwhile\b
      scope: keyword.control.loop.while.java

  illegal-keywords:
    - match: \b(goto|const)\b
      scope: invalid.illegal.keyword.java

  illegal-open-block:
    - match: \s?(?={)
      scope: invalid.illegal.stray-terminator-end
      pop: true

  illegal-semicolon:
    - match: ;
      scope: invalid.illegal.stray-terminator-end
      pop: true

  illegal-parens-terminators:
    # Pops the stack if anything matches
    - include: illegal-semicolon
    - include: illegal-open-block

  method-invocations:
    - match: (\.)\s*(?=<)
      captures:
        1: punctuation.accessor.dot.java
      push: generic-type-invocation
    - match: ({{id}})\s*(\()
      captures:
        1: variable.function.java
        2: punctuation.section.parens.begin.java
      push:
        - meta_scope: meta.function-call.java
        - match: \)
          scope: punctuation.section.parens.end.java
          pop: true
        - include: illegal-parens-terminators
        - include: code

  fields-and-methods:
    - match: \bvoid\b
      scope: storage.type.void.java
      push: method
    - match: (?={{id}}\s*\()
      push: method
    - match: '{{before_fqn}}'
      push: [field-or-method, after-object-and-array-types, object-type-fqn]
    - match: \b{{classcase_id}}
      scope: support.class.java
      push: [field-or-method, after-object-and-array-types]
    - match: \b{{primitives}}\b
      scope: storage.type.primitive.java
      push: [field-or-method, array-brackets]

  field-or-method:
    - match: (?={{id}}\s*\()
      set: method
    - match: (?=\S)
      set:
      - include: before-next-field
      - match: (?:({{uppercase_id}})|({{id}}))
        captures:
          1: entity.name.constant.java
          2: meta.field.java
        push: [static-assignment, array-brackets]
      - include: punctuation-separator-comma
      - include: any_POP

  before-next-field:
    # Prevent style from being removed from whole file when making a new expression
    - match: (?=\b(?:{{storage_modifiers}}|{{primitives}}|void)\b)
      pop: true

  method:
    - meta_scope: meta.method.java
    - match: ({{classcase_id}})\s*(?=\()
      captures:
        1: meta.method.identifier.java entity.name.function.constructor.java
    - match: ({{id}})\s*(?=\()
      captures:
        1: meta.method.identifier.java entity.name.function.java
    - match: \(
      scope: punctuation.section.parens.begin.java
      push:
        - meta_scope: meta.method.parameters.java meta.parens.java
        - match: \)
          scope: punctuation.section.parens.end.java
          pop: true
        - include: parameters
        - match: \S
          scope: invalid.illegal.missing-parameter-end
          pop: true
    - include: throws
    - include: annotation-default
    - match: \{
      scope: punctuation.section.block.begin.java
      set:
        - meta_scope: meta.method.java meta.method.body.java
        - match: \}
          scope: punctuation.section.block.end.java
          pop: true
        - include: code-block
    - include: any_POP

  throws:
    - match: \bthrows\b
      scope: keyword.declaration.throws.java
      push:
      - - meta_scope: meta.method.throws.java
        - match: \,
          scope: punctuation.separator.comma.java
          push: object-type-reference
        - include: any_POP
      - object-type-reference

  # Stand-along uppercase id, either type or constant.
  # Should be used only inside code blocks.
  uppercase-identifiers:
    # Popular JDK classes
    - match: \b(?:UUID|UR[LI])\b
      scope: support.class.java
      push: after-object-type
    # Generic type variable
    - match: \b\p{Lu}\b
      scope: support.class.java
      push: after-object-type
    # Uppercase constants
    - match: \b{{uppercase_id}}
      scope: constant.other.java

  # Stand-alone type, maybe type of the variable or class object reference.
  # Should be used only inside code blocks.
  object-types:
    # Here the match is more complex than 'before_fqn'.
    # In code block we can't simply distinguish package from variable.
    - match: (?=\b(?:{{lowercase_id}}\.)+\p{Lu})
      push: [after-object-type, object-type-fqn]
    - match: \b{{classcase_id}}\b
      scope: support.class.java
      push: after-object-type

  object-type-fqn:
    - meta_scope: meta.path.java
    - include: package
    - match: '{{classcase_id}}'
      scope: support.class.java
      pop: true
    - include: any_POP

  after-object-type:
    - match: (?=<)
      set: [array-brackets, generic-type-invocation]
    - match: \.(?!\.)
      scope: punctuation.accessor.dot.java
      set:
        - match: (?=<)
          set: generic-type-invocation
        - match: (?:(class)\b|({{uppercase_id}}))
          captures:
            1: variable.language.java
            2: constant.other.java
          pop: true
        - match: '{{classcase_id}}'
          scope: support.class.java
          set: after-object-type
        - include: any_POP
    - include: array-brackets

  # Used in 'throws' and generic bounds
  object-type-reference:
    - match: '{{before_fqn}}'
      set:
        - meta_scope: meta.path.java
        - include: package
        - include: object-type-reference-no-fqn
    - include: object-type-reference-no-fqn

  object-type-reference-no-fqn:
    - match: '{{classcase_id}}'
      scope: support.class.java
      set: after-object-type-reference
    - include: any_POP

  after-object-type-reference:
    - match: (?=<)
      set: generic-type-invocation
    - match: \.
      scope: punctuation.accessor.dot.java
      set: object-type-reference-no-fqn
    - include: any_POP

  # Used in method's and generic's parameters
  object-and-array-types:
    - match: '{{before_fqn}}'
      push:
        - meta_scope: meta.path.java
        - include: package
        - include: object-and-array-types-no-fqn
    - match: \b({{primitives}})(?=\s*\[)
      scope: storage.type.primitive.java
      push: array-brackets
    - match: \b{{classcase_id}}
      scope: support.class.java
      push: after-object-and-array-types

  object-and-array-types-no-fqn:
    - match: '{{classcase_id}}'
      scope: support.class.java
      set: after-object-and-array-types
    - include: any_POP

  after-object-and-array-types:
    - match: (?=<)
      set: [array-brackets, generic-type-invocation]
    - match: \.(?!\.)
      scope: punctuation.accessor.dot.java
      set: object-and-array-types-no-fqn
    - include: array-brackets

  # Used in class-level 'extends' and 'implements'
  inherited-object-type-reference:
    - match: '{{before_fqn}}'
      set:
        - meta_scope: meta.path.java
        - match: '{{lowercase_id}}'
          scope: entity.other.inherited-class.package.java
        - include: punctuation-accessor-dot
        - include: inherited-object-type-reference-no-fqn
    - include: inherited-object-type-reference-no-fqn

  inherited-object-type-reference-no-fqn:
    - match: (?!class|extends|implements|interface){{id}}
      scope: entity.other.inherited-class.java
      set: after-inherited-object-type-reference
    - include: any_POP

  after-inherited-object-type-reference:
    - match: (?=<)
      set: generic-type-invocation
    - match: \.
      scope: punctuation.accessor.dot.java
      set: inherited-object-type-reference-no-fqn
    - include: any_POP

  generic-type-declaration:
    - match: <
      scope: punctuation.definition.generic.begin.java
      push: generic-type-parameter
    - include: any_POP

  generic-type-terminator:
    - include: illegal-semicolon
    # These characters can't appear in a generic. If we've matched
    # them then someone forgot to close it.
    - match: (?=[{}()])
      pop: true
    - match: '>'
      scope: punctuation.definition.generic.end.java
      pop: true

  generic-type-parameter:
    - meta_scope: meta.generic.declaration.java
    - match: \b{{id}}\b
      scope: variable.parameter.type.java
      push: generic-type-bounds
    - include: generic-type-terminator

  generic-type-bounds:
    - match: (,)|(?=>)
      captures:
        1: punctuation.separator.comma.java
      pop: true
    - match: \bextends\b
      scope: keyword.declaration.extends.java
      push: [generic-type-extends-multiple-bounds, object-type-reference]
    - match: \bsuper\b
      scope: keyword.declaration.super.java
      push: object-type-reference

  generic-type-extends-multiple-bounds:
    - match: '&'
      scope: keyword.operator.multiple-bounds.java
      set: [generic-type-extends-multiple-bounds, object-type-reference]
    - include: any_POP

  generic-type-invocation:
    - match: <
      scope: punctuation.definition.generic.begin.java
      set: generic-type-argument
    - include: any_POP

  generic-type-argument:
    - meta_scope: meta.generic.java
    - match: \?
      scope: keyword.operator.wildcard.java
      push: generic-type-bounds
    - include: generic-type-terminator
    - include: object-and-array-types
    - include: punctuation-separator-comma

  annotation-default:
    - match: \bdefault\b
      scope: keyword.declaration.default.java
      push:
        - meta_scope: meta.annotation.default.java
        - match: (?=;)
          pop: true
        - include: code

  parameters:
    - match: \bfinal\b
      scope: storage.modifier.java
    - include: annotations
    - include: primitive-types
    - include: object-and-array-types
    - match: \.\.\.
      scope: keyword.operator.variadic.java
    - match: '{{id}}'
      scope: variable.parameter.java
      push: array-brackets
    - include: punctuation-separator-comma

  lambdas:
    - match: (?={{lambda_lookahead}})
      push: lambda-params

  lambda-params:
    - meta_scope: meta.function.anonymous.parameters.java
    - match: \(
      scope: punctuation.section.parens.begin.java
      set:
        - meta_scope: meta.function.anonymous.parameters.java
        - match: \)
          scope: punctuation.section.parens.end.java
          set: lambda-arrow
        - include: parameters
    - match: '{{id}}'
      scope: variable.parameter.java
      set: lambda-arrow

  lambda-arrow:
    - match: ->
      scope: storage.type.function.anonymous.java
      set:
        - meta_scope: meta.function.anonymous.body.java
        - match: (?=[)};])
          pop: true
        - include: code

  parens:
    - match: \(
      scope: punctuation.section.parens.begin.java
      push:
        - meta_scope: meta.parens.java
        - match: \)
          scope: punctuation.section.parens.end.java
          pop: true
        - include: illegal-parens-terminators
        - include: code

  declaration-statement-parens:
    - match: \(
      scope: punctuation.section.parens.begin.java
      set:
        - meta_scope: meta.parens.java
        - match: \)
          scope: punctuation.section.parens.end.java
          pop: true
        - include: illegal-open-block
        - include: code-block
    - include: any_POP

  primitive-types:
    - match: \b{{primitives}}\b
      scope: storage.type.primitive.java
      push: array-brackets

  var-type:
    - match: \bvar\b
      scope: storage.type.var.java

  array-brackets:
    - match: \[\s*\]
      scope: storage.modifier.array.java
    - include: any_POP

  static-assignment:
    - match: \=
      scope: keyword.operator.assignment.java
      set:
        - meta_scope: meta.assignment.rhs.java
        - match: (?=[,;])
          pop: true
        - include: before-next-field
        - include: code
        - include: stray-parens
    - include: any_POP

  assignment:
    - match: ([|&^*/+-]\=|\=(?!=))
      scope: keyword.operator.assignment.java
      push:
        - meta_scope: meta.assignment.rhs.java
        - match: (?=;|\)|\}|,)
          pop: true
        - include: code
  static-code-block:
    - match: \{
      scope: punctuation.section.block.begin.java
      push:
        - meta_scope: meta.static.body.java
        - match: \}
          scope: punctuation.section.block.end.java
          pop: true
        - include: code-block
  storage-modifiers:
    - match: \b{{storage_modifiers}}\b
      scope: storage.modifier.java
  stray-braces:
    - match: \}
      scope: invalid.illegal.stray-brace-end
  stray-parens:
    - match: \)
      scope: invalid.illegal.stray-parens-end

  strings:
    - match: \"
      scope: punctuation.definition.string.begin.java
      push:
        - meta_include_prototype: false
        - meta_scope: string.quoted.double.java
        - match: \"
          scope: punctuation.definition.string.end.java
          pop: true
        - include: strings-common
    - match: \'
      scope: punctuation.definition.string.begin.java
      push:
        - meta_include_prototype: false
        - meta_scope: string.quoted.single.java
        - match: \'
          scope: punctuation.definition.string.end.java
          pop: true
        - include: strings-common

  strings-common:
    - match: \n
      scope: invalid.illegal.newline.java
      pop: true
    - match: \\.
      scope: constant.character.escape.java

  module:
    - match: (?=\b(?:open\s+)?module\b)
      push:
      - - meta_scope: meta.module.java
        - include: immediate_POP
      - - match: \bopen\b
          scope: storage.modifier.java
        - match: \bmodule\b
          scope: storage.type.java
          set: [module-body, module-identifier-scope, module-identifier]

  module-identifier-scope:
    - meta_scope: meta.module.identifier.java
    - include: immediate_POP

  module-identifier:
    - match: '{{id}}'
      set:
        - - meta_scope: entity.name.module.java
          - include: immediate_POP
        - dot-separated-identifier
    - include: any_POP

  module-body:
    - match: \{
      scope: punctuation.section.braces.begin.java
      set:
        - meta_scope: meta.module.body.java
        - include: module-body-content
        - match: \}
          scope: punctuation.section.braces.end.java
          pop: true
    - include: any_POP

  module-body-content:
    - match: \bexports\b
      scope: keyword.other.module.exports.java
      push: [exports-statement-scope, exports-or-opens-statement]
    - match: \bopens\b
      scope: keyword.other.module.opens.java
      push: [opens-statement-scope, exports-or-opens-statement]
    - match: \brequires\b
      scope: keyword.other.module.requires.java
      push: requires-statement
    - match: \buses\b
      scope: keyword.other.module.uses.java
      push: [uses-statement-scope, object-type-reference]
    - match: \bprovides\b
      scope: keyword.other.module.provides.java
      push: [provides-statement-scope, provides-with-statement, object-type-reference]
    - include: punctuation-terminator-semicolon

  # Should always come before module/package patterns
  module-statement-terminator:
    - match: (?=[;\}])
      pop: true
    - match: (?=\b(?:requires|exports|uses|provides|opens)\b)
      pop: true

  support-type-module:
    - match: '{{id}}'
      push:
        - - meta_scope: support.type.module.java
          - include: immediate_POP
        - dot-separated-identifier

  exports-statement-scope:
    - meta_scope: meta.exports.java
    - include: immediate_POP

  opens-statement-scope:
    - meta_scope: meta.opens.java
    - include: immediate_POP

  exports-or-opens-statement:
    - match: \bto\b
      scope: keyword.other.module.to.java
      set:
        - include: module-statement-terminator
        - include: support-type-module
        - include: punctuation-separator-comma
    - include: module-statement-terminator
    - match: '{{id}}'
      push:
        - - meta_scope: support.type.package.java
          - include: immediate_POP
        - dot-separated-identifier

  requires-statement:
    - meta_scope: meta.requires.java
    - match: \btransitive\b
      scope: keyword.other.module.transitive.java
    - include: module-statement-terminator
    - include: support-type-module

  uses-statement-scope:
    - meta_scope: meta.uses.java
    - include: immediate_POP

  provides-statement-scope:
    - meta_scope: meta.provides.java
    - include: immediate_POP

  provides-with-statement:
    - match: \bwith\b
      scope: keyword.other.module.with.java
      set:
        - - match: \,
            scope: punctuation.separator.comma.java
            push: object-type-reference
          - include: any_POP
        - object-type-reference
    - include: any_POP