@ant-yasa/uast-parser-java-js 0.1.15-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.babelrc +12 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.js +38 -0
  4. package/.mocharc-integration.js +1 -0
  5. package/.mocharc.js +4 -0
  6. package/.prettierignore +1 -0
  7. package/.prettierrc +4 -0
  8. package/LEGAL.md +7 -0
  9. package/README.md +35 -0
  10. package/antlr/Java.g4 +1008 -0
  11. package/antlr/JavaLexer.g4 +241 -0
  12. package/antlr/JavaLexer_origin.g4 +241 -0
  13. package/antlr/JavaParser.g4 +765 -0
  14. package/antlr/JavaParser_origin.g4 +766 -0
  15. package/dist/package.json +73 -0
  16. package/dist/src/frontend/java/ASTBuilder.d.ts +171 -0
  17. package/dist/src/frontend/java/ASTBuilder.js +2369 -0
  18. package/dist/src/frontend/java/ASTBuilder.js.map +1 -0
  19. package/dist/src/frontend/java/ErrorListener.d.ts +9 -0
  20. package/dist/src/frontend/java/ErrorListener.js +24 -0
  21. package/dist/src/frontend/java/ErrorListener.js.map +1 -0
  22. package/dist/src/frontend/java/antlr/JavaLexer.d.ts +154 -0
  23. package/dist/src/frontend/java/antlr/JavaLexer.js +812 -0
  24. package/dist/src/frontend/java/antlr/JavaLexer.js.map +1 -0
  25. package/dist/src/frontend/java/antlr/JavaListener.d.ts +1393 -0
  26. package/dist/src/frontend/java/antlr/JavaListener.js +4 -0
  27. package/dist/src/frontend/java/antlr/JavaListener.js.map +1 -0
  28. package/dist/src/frontend/java/antlr/JavaParser.d.ts +2065 -0
  29. package/dist/src/frontend/java/antlr/JavaParser.js +15279 -0
  30. package/dist/src/frontend/java/antlr/JavaParser.js.map +1 -0
  31. package/dist/src/frontend/java/antlr/JavaVisitor.d.ts +892 -0
  32. package/dist/src/frontend/java/antlr/JavaVisitor.js +4 -0
  33. package/dist/src/frontend/java/antlr/JavaVisitor.js.map +1 -0
  34. package/dist/src/frontend/java/parser.d.ts +20 -0
  35. package/dist/src/frontend/java/parser.js +93 -0
  36. package/dist/src/frontend/java/parser.js.map +1 -0
  37. package/dist/src/frontend/java/testBuilder.d.ts +146 -0
  38. package/dist/src/frontend/java/testBuilder.js +464 -0
  39. package/dist/src/frontend/java/testBuilder.js.map +1 -0
  40. package/dist/src/frontend/java/types.d.ts +29 -0
  41. package/dist/src/frontend/java/types.js +3 -0
  42. package/dist/src/frontend/java/types.js.map +1 -0
  43. package/dist/src/frontend/javascript/parser.d.ts +8 -0
  44. package/dist/src/frontend/javascript/parser.js +1121 -0
  45. package/dist/src/frontend/javascript/parser.js.map +1 -0
  46. package/dist/src/index.d.ts +14 -0
  47. package/dist/src/index.js +76 -0
  48. package/dist/src/index.js.map +1 -0
  49. package/output.txt +3820 -0
  50. package/package.json +73 -0
  51. package/tests/benchmark/base/class.js +32 -0
  52. package/tests/benchmark/base/class.js.json +1809 -0
  53. package/tests/benchmark/base/class_test.js +13 -0
  54. package/tests/benchmark/base/class_test.js.json +435 -0
  55. package/tests/benchmark/base/comment.js +21 -0
  56. package/tests/benchmark/base/comment.js.json +1443 -0
  57. package/tests/benchmark/base/demo.ts +1060 -0
  58. package/tests/benchmark/base/empty.js +4 -0
  59. package/tests/benchmark/base/empty.js.json +202 -0
  60. package/tests/benchmark/base/export.js +36 -0
  61. package/tests/benchmark/base/export.js.json +6345 -0
  62. package/tests/benchmark/base/export1.js +2 -0
  63. package/tests/benchmark/base/export1.js.json +251 -0
  64. package/tests/benchmark/base/export2.js +35 -0
  65. package/tests/benchmark/base/export2.js.json +3297 -0
  66. package/tests/benchmark/base/expressions.js +25 -0
  67. package/tests/benchmark/base/expressions.js.json +1654 -0
  68. package/tests/benchmark/base/for.js +7 -0
  69. package/tests/benchmark/base/for.js.json +738 -0
  70. package/tests/benchmark/base/function.js +15 -0
  71. package/tests/benchmark/base/function.js.json +1458 -0
  72. package/tests/benchmark/base/import.js +3 -0
  73. package/tests/benchmark/base/import.js.json +416 -0
  74. package/tests/benchmark/base/literal.js +27 -0
  75. package/tests/benchmark/base/literal.js.json +1234 -0
  76. package/tests/benchmark/base/param.js +4 -0
  77. package/tests/benchmark/base/param.js.json +410 -0
  78. package/tests/benchmark/base/parseerror.js +1 -0
  79. package/tests/benchmark/base/parseerror.js.json +191 -0
  80. package/tests/benchmark/base/patternlike.js +24 -0
  81. package/tests/benchmark/base/patternlike.js.json +3720 -0
  82. package/tests/benchmark/base/react.js +8 -0
  83. package/tests/benchmark/base/react.js.json +211 -0
  84. package/tests/benchmark/base/switch.js +11 -0
  85. package/tests/benchmark/base/switch.js.json +741 -0
  86. package/tests/benchmark/base/taint.ts +61 -0
  87. package/tests/benchmark/base/temp.js +311 -0
  88. package/tests/benchmark/base/temp.js.json +22170 -0
  89. package/tests/benchmark/base/tmp.js +134 -0
  90. package/tests/benchmark/base/tmp.js.json +15409 -0
  91. package/tests/benchmark/base/vardecl.js +9 -0
  92. package/tests/benchmark/base/vardecl.js.json +491 -0
  93. package/tests/index.js +43 -0
  94. package/tests/index.ts +66 -0
  95. package/tests/test.d.ts +0 -0
  96. package/tests/test.js +38 -0
  97. package/tests/test.ts +60 -0
  98. package/tsconfig.json +24 -0
  99. package/tsconfig.test.json +13 -0
  100. package/webpack.config.js +21 -0
@@ -0,0 +1,766 @@
1
+ /*
2
+ [The "BSD licence"]
3
+ Copyright (c) 2013 Terence Parr, Sam Harwell
4
+ Copyright (c) 2017 Ivan Kochurkin (upgrade to Java 8)
5
+ Copyright (c) 2021 Michał Lorek (upgrade to Java 11)
6
+ Copyright (c) 2022 Michał Lorek (upgrade to Java 17)
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions
11
+ are met:
12
+ 1. Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ 2. Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+ 3. The name of the author may not be used to endorse or promote products
18
+ derived from this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ */
31
+ compilationUnit
32
+ : packageDeclaration? importDeclaration* typeDeclaration*
33
+ | moduleDeclaration EOF
34
+ ;
35
+
36
+ packageDeclaration
37
+ : annotation* PACKAGE qualifiedName ';'
38
+ ;
39
+
40
+ importDeclaration
41
+ : ';'
42
+ | IMPORT STATIC? qualifiedName ('.' '*')? ';'
43
+ ;
44
+
45
+ typeDeclaration
46
+ : classOrInterfaceModifier*
47
+ (classDeclaration | enumDeclaration | interfaceDeclaration | annotationTypeDeclaration | recordDeclaration)
48
+ | ';'
49
+ ;
50
+
51
+ modifier
52
+ : classOrInterfaceModifier
53
+ | NATIVE
54
+ | SYNCHRONIZED
55
+ | TRANSIENT
56
+ | VOLATILE
57
+ ;
58
+
59
+ classOrInterfaceModifier
60
+ : annotation
61
+ | PUBLIC
62
+ | PROTECTED
63
+ | PRIVATE
64
+ | STATIC
65
+ | ABSTRACT
66
+ | FINAL // FINAL for class only -- does not apply to interfaces
67
+ | STRICTFP
68
+ | SEALED // Java17
69
+ | NON_SEALED // Java17
70
+ ;
71
+
72
+ variableModifier
73
+ : FINAL
74
+ | annotation
75
+ ;
76
+
77
+ classDeclaration
78
+ : CLASS identifier typeParameters?
79
+ (EXTENDS typeType)?
80
+ (IMPLEMENTS typeList)?
81
+ (PERMITS typeList)? // Java17
82
+ classBody
83
+ ;
84
+
85
+ typeParameters
86
+ : '<' typeParameter (',' typeParameter)* '>'
87
+ ;
88
+
89
+ typeParameter
90
+ : annotation* identifier (EXTENDS annotation* typeBound)?
91
+ ;
92
+
93
+ typeBound
94
+ : typeType ('&' typeType)*
95
+ ;
96
+
97
+ enumDeclaration
98
+ : ENUM identifier (IMPLEMENTS typeList)? '{' enumConstants? ','? enumBodyDeclarations? '}'
99
+ ;
100
+
101
+ enumConstants
102
+ : enumConstant (',' enumConstant)*
103
+ ;
104
+
105
+ enumConstant
106
+ : annotation* identifier arguments? classBody?
107
+ ;
108
+
109
+ enumBodyDeclarations
110
+ : ';' classBodyDeclaration*
111
+ ;
112
+
113
+ interfaceDeclaration
114
+ : INTERFACE identifier typeParameters? (EXTENDS typeList)? (PERMITS typeList)? interfaceBody
115
+ ;
116
+
117
+ classBody
118
+ : '{' classBodyDeclaration* '}'
119
+ ;
120
+
121
+ interfaceBody
122
+ : '{' interfaceBodyDeclaration* '}'
123
+ ;
124
+
125
+ classBodyDeclaration
126
+ : ';'
127
+ | STATIC? block
128
+ | modifier* memberDeclaration
129
+ ;
130
+
131
+ memberDeclaration
132
+ : recordDeclaration //Java17
133
+ | methodDeclaration
134
+ | genericMethodDeclaration
135
+ | fieldDeclaration
136
+ | constructorDeclaration
137
+ | genericConstructorDeclaration
138
+ | interfaceDeclaration
139
+ | annotationTypeDeclaration
140
+ | classDeclaration
141
+ | enumDeclaration
142
+ ;
143
+
144
+ /* We use rule this even for void methods which cannot have [] after parameters.
145
+ This simplifies grammar and we can consider void to be a type, which
146
+ renders the [] matching as a context-sensitive issue or a semantic check
147
+ for invalid return type after parsing.
148
+ */
149
+ methodDeclaration
150
+ : typeTypeOrVoid identifier formalParameters ('[' ']')*
151
+ (THROWS qualifiedNameList)?
152
+ methodBody
153
+ ;
154
+
155
+ methodBody
156
+ : block
157
+ | ';'
158
+ ;
159
+
160
+ typeTypeOrVoid
161
+ : typeType
162
+ | VOID
163
+ ;
164
+
165
+ genericMethodDeclaration
166
+ : typeParameters methodDeclaration
167
+ ;
168
+
169
+ genericConstructorDeclaration
170
+ : typeParameters constructorDeclaration
171
+ ;
172
+
173
+ constructorDeclaration
174
+ : identifier formalParameters (THROWS qualifiedNameList)? constructorBody=block
175
+ ;
176
+
177
+ compactConstructorDeclaration
178
+ : modifier* identifier constructorBody=block
179
+ ;
180
+
181
+ fieldDeclaration
182
+ : typeType variableDeclarators ';'
183
+ ;
184
+
185
+ interfaceBodyDeclaration
186
+ : modifier* interfaceMemberDeclaration
187
+ | ';'
188
+ ;
189
+
190
+ interfaceMemberDeclaration
191
+ : recordDeclaration // Java17
192
+ | constDeclaration
193
+ | interfaceMethodDeclaration
194
+ | genericInterfaceMethodDeclaration
195
+ | interfaceDeclaration
196
+ | annotationTypeDeclaration
197
+ | classDeclaration
198
+ | enumDeclaration
199
+ ;
200
+
201
+ constDeclaration
202
+ : typeType constantDeclarator (',' constantDeclarator)* ';'
203
+ ;
204
+
205
+ constantDeclarator
206
+ : identifier ('[' ']')* '=' variableInitializer
207
+ ;
208
+
209
+ // Early versions of Java allows brackets after the method name, eg.
210
+ // public int[] return2DArray() [] { ... }
211
+ // is the same as
212
+ // public int[][] return2DArray() { ... }
213
+ interfaceMethodDeclaration
214
+ : interfaceMethodModifier* interfaceCommonBodyDeclaration
215
+ ;
216
+
217
+ // Java8
218
+ interfaceMethodModifier
219
+ : annotation
220
+ | PUBLIC
221
+ | ABSTRACT
222
+ | DEFAULT
223
+ | STATIC
224
+ | STRICTFP
225
+ ;
226
+
227
+ genericInterfaceMethodDeclaration
228
+ : interfaceMethodModifier* typeParameters interfaceCommonBodyDeclaration
229
+ ;
230
+
231
+ interfaceCommonBodyDeclaration
232
+ : annotation* typeTypeOrVoid identifier formalParameters ('[' ']')* (THROWS qualifiedNameList)? methodBody
233
+ ;
234
+
235
+ variableDeclarators
236
+ : variableDeclarator (',' variableDeclarator)*
237
+ ;
238
+
239
+ variableDeclarator
240
+ : variableDeclaratorId ('=' variableInitializer)?
241
+ ;
242
+
243
+ variableDeclaratorId
244
+ : identifier ('[' ']')*
245
+ ;
246
+
247
+ variableInitializer
248
+ : arrayInitializer
249
+ | expression
250
+ ;
251
+
252
+ arrayInitializer
253
+ : '{' (variableInitializer (',' variableInitializer)* (',')? )? '}'
254
+ ;
255
+
256
+ classOrInterfaceType
257
+ : (identifier typeArguments? '.')* typeIdentifier typeArguments?
258
+ ;
259
+
260
+ typeArgument
261
+ : typeType
262
+ | annotation* '?' ((EXTENDS | SUPER) typeType)?
263
+ ;
264
+
265
+ qualifiedNameList
266
+ : qualifiedName (',' qualifiedName)*
267
+ ;
268
+
269
+ formalParameters
270
+ : '(' ( receiverParameter?
271
+ | receiverParameter (',' formalParameterList)?
272
+ | formalParameterList?
273
+ ) ')'
274
+ ;
275
+
276
+ receiverParameter
277
+ : typeType (identifier '.')* THIS
278
+ ;
279
+
280
+ formalParameterList
281
+ : formalParameter (',' formalParameter)* (',' lastFormalParameter)?
282
+ | lastFormalParameter
283
+ ;
284
+
285
+ formalParameter
286
+ : variableModifier* typeType variableDeclaratorId
287
+ ;
288
+
289
+ lastFormalParameter
290
+ : variableModifier* typeType annotation* '...' variableDeclaratorId
291
+ ;
292
+
293
+ // local variable type inference
294
+ lambdaLVTIList
295
+ : lambdaLVTIParameter (',' lambdaLVTIParameter)*
296
+ ;
297
+
298
+ lambdaLVTIParameter
299
+ : variableModifier* VAR identifier
300
+ ;
301
+
302
+ qualifiedName
303
+ : identifier ('.' identifier)*
304
+ ;
305
+
306
+ literal
307
+ : integerLiteral
308
+ | floatLiteral
309
+ | CHAR_LITERAL
310
+ | STRING_LITERAL
311
+ | BOOL_LITERAL
312
+ | NULL_LITERAL
313
+ | TEXT_BLOCK // Java17
314
+ ;
315
+
316
+ integerLiteral
317
+ : DECIMAL_LITERAL
318
+ | HEX_LITERAL
319
+ | OCT_LITERAL
320
+ | BINARY_LITERAL
321
+ ;
322
+
323
+ floatLiteral
324
+ : FLOAT_LITERAL
325
+ | HEX_FLOAT_LITERAL
326
+ ;
327
+
328
+ // ANNOTATIONS
329
+ altAnnotationQualifiedName
330
+ : (identifier DOT)* '@' identifier
331
+ ;
332
+
333
+ annotation
334
+ : ('@' qualifiedName | altAnnotationQualifiedName) ('(' ( elementValuePairs | elementValue )? ')')?
335
+ ;
336
+
337
+ elementValuePairs
338
+ : elementValuePair (',' elementValuePair)*
339
+ ;
340
+
341
+ elementValuePair
342
+ : identifier '=' elementValue
343
+ ;
344
+
345
+ elementValue
346
+ : expression
347
+ | annotation
348
+ | elementValueArrayInitializer
349
+ ;
350
+
351
+ elementValueArrayInitializer
352
+ : '{' (elementValue (',' elementValue)*)? (',')? '}'
353
+ ;
354
+
355
+ annotationTypeDeclaration
356
+ : '@' INTERFACE identifier annotationTypeBody
357
+ ;
358
+
359
+ annotationTypeBody
360
+ : '{' (annotationTypeElementDeclaration)* '}'
361
+ ;
362
+
363
+ annotationTypeElementDeclaration
364
+ : modifier* annotationTypeElementRest
365
+ | ';' // this is not allowed by the grammar, but apparently allowed by the actual compiler
366
+ ;
367
+
368
+ annotationTypeElementRest
369
+ : typeType annotationMethodOrConstantRest ';'
370
+ | classDeclaration ';'?
371
+ | interfaceDeclaration ';'?
372
+ | enumDeclaration ';'?
373
+ | annotationTypeDeclaration ';'?
374
+ | recordDeclaration ';'? // Java17
375
+ ;
376
+
377
+ annotationMethodOrConstantRest
378
+ : annotationMethodRest
379
+ | annotationConstantRest
380
+ ;
381
+
382
+ annotationMethodRest
383
+ : identifier '(' ')' defaultValue?
384
+ ;
385
+
386
+ annotationConstantRest
387
+ : variableDeclarators
388
+ ;
389
+
390
+ defaultValue
391
+ : DEFAULT elementValue
392
+ ;
393
+
394
+ // MODULES - Java9
395
+
396
+ moduleDeclaration
397
+ : OPEN? MODULE qualifiedName moduleBody
398
+ ;
399
+
400
+ moduleBody
401
+ : '{' moduleDirective* '}'
402
+ ;
403
+
404
+ moduleDirective
405
+ : REQUIRES requiresModifier* qualifiedName ';'
406
+ | EXPORTS qualifiedName (TO qualifiedName)? ';'
407
+ | OPENS qualifiedName (TO qualifiedName)? ';'
408
+ | USES qualifiedName ';'
409
+ | PROVIDES qualifiedName WITH qualifiedName ';'
410
+ ;
411
+
412
+ requiresModifier
413
+ : TRANSITIVE
414
+ | STATIC
415
+ ;
416
+
417
+ // RECORDS - Java 17
418
+
419
+ recordDeclaration
420
+ : RECORD identifier typeParameters? recordHeader
421
+ (IMPLEMENTS typeList)?
422
+ recordBody
423
+ ;
424
+
425
+ recordHeader
426
+ : '(' recordComponentList? ')'
427
+ ;
428
+
429
+ recordComponentList
430
+ : recordComponent (',' recordComponent)*
431
+ ;
432
+
433
+ recordComponent
434
+ : typeType identifier
435
+ ;
436
+
437
+ recordBody
438
+ : '{' (classBodyDeclaration | compactConstructorDeclaration)* '}'
439
+ ;
440
+
441
+ // STATEMENTS / BLOCKS
442
+
443
+ block
444
+ : '{' blockStatement* '}'
445
+ ;
446
+
447
+ blockStatement
448
+ : localVariableDeclaration ';'
449
+ | localTypeDeclaration
450
+ | statement
451
+ ;
452
+
453
+ localVariableDeclaration
454
+ : variableModifier* (VAR identifier '=' expression | typeType variableDeclarators)
455
+ ;
456
+
457
+ identifier
458
+ : IDENTIFIER
459
+ | MODULE
460
+ | OPEN
461
+ | REQUIRES
462
+ | EXPORTS
463
+ | OPENS
464
+ | TO
465
+ | USES
466
+ | PROVIDES
467
+ | WITH
468
+ | TRANSITIVE
469
+ | YIELD
470
+ | SEALED
471
+ | PERMITS
472
+ | RECORD
473
+ | VAR
474
+ ;
475
+
476
+ typeIdentifier // Identifiers that are not restricted for type declarations
477
+ : IDENTIFIER
478
+ | MODULE
479
+ | OPEN
480
+ | REQUIRES
481
+ | EXPORTS
482
+ | OPENS
483
+ | TO
484
+ | USES
485
+ | PROVIDES
486
+ | WITH
487
+ | TRANSITIVE
488
+ | SEALED
489
+ | PERMITS
490
+ | RECORD
491
+ ;
492
+
493
+ localTypeDeclaration
494
+ : classOrInterfaceModifier*
495
+ (classDeclaration | interfaceDeclaration | recordDeclaration)
496
+ ;
497
+
498
+ statement
499
+ : blockLabel=block
500
+ | ASSERT expression (':' expression)? ';'
501
+ | IF parExpression statement (ELSE statement)?
502
+ | FOR '(' forControl ')' statement
503
+ | WHILE parExpression statement
504
+ | DO statement WHILE parExpression ';'
505
+ | TRY block (catchClause+ finallyBlock? | finallyBlock)
506
+ | TRY resourceSpecification block catchClause* finallyBlock?
507
+ | SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}'
508
+ | SYNCHRONIZED parExpression block
509
+ | RETURN expression? ';'
510
+ | THROW expression ';'
511
+ | BREAK identifier? ';'
512
+ | CONTINUE identifier? ';'
513
+ | YIELD expression ';' // Java17
514
+ | SEMI
515
+ | statementExpression=expression ';'
516
+ | switchExpression ';'? // Java17
517
+ | identifierLabel=identifier ':' statement
518
+ ;
519
+
520
+ catchClause
521
+ : CATCH '(' variableModifier* catchType identifier ')' block
522
+ ;
523
+
524
+ catchType
525
+ : qualifiedName ('|' qualifiedName)*
526
+ ;
527
+
528
+ finallyBlock
529
+ : FINALLY block
530
+ ;
531
+
532
+ resourceSpecification
533
+ : '(' resources ';'? ')'
534
+ ;
535
+
536
+ resources
537
+ : resource (';' resource)*
538
+ ;
539
+
540
+ resource
541
+ : variableModifier* ( classOrInterfaceType variableDeclaratorId | VAR identifier ) '=' expression
542
+ | qualifiedName
543
+ ;
544
+
545
+ /** Matches cases then statements, both of which are mandatory.
546
+ * To handle empty cases at the end, we add switchLabel* to statement.
547
+ */
548
+ switchBlockStatementGroup
549
+ : switchLabel+ blockStatement+
550
+ ;
551
+
552
+ switchLabel
553
+ : CASE (constantExpression=expression | enumConstantName=IDENTIFIER | typeType varName=identifier) ':'
554
+ | DEFAULT ':'
555
+ ;
556
+
557
+ forControl
558
+ : enhancedForControl
559
+ | forInit? ';' expression? ';' forUpdate=expressionList?
560
+ ;
561
+
562
+ forInit
563
+ : localVariableDeclaration
564
+ | expressionList
565
+ ;
566
+
567
+ enhancedForControl
568
+ : variableModifier* (typeType | VAR) variableDeclaratorId ':' expression
569
+ ;
570
+
571
+ // EXPRESSIONS
572
+
573
+ parExpression
574
+ : '(' expression ')'
575
+ ;
576
+
577
+ expressionList
578
+ : expression (',' expression)*
579
+ ;
580
+
581
+ methodCall
582
+ : identifier '(' expressionList? ')'
583
+ | THIS '(' expressionList? ')'
584
+ | SUPER '(' expressionList? ')'
585
+ ;
586
+
587
+ expression
588
+ : primary
589
+ | expression bop='.'
590
+ (
591
+ identifier
592
+ | methodCall
593
+ | THIS
594
+ | NEW nonWildcardTypeArguments? innerCreator
595
+ | SUPER superSuffix
596
+ | explicitGenericInvocation
597
+ )
598
+ | expression '[' expression ']'
599
+ | methodCall
600
+ | NEW creator
601
+ | '(' annotation* typeType ('&' typeType)* ')' expression
602
+ | lambdaExpression // Java8
603
+ | switchExpression // Java17
604
+ // Java 8 methodReference
605
+ | expression '::' typeArguments? identifier
606
+ | typeType '::' (typeArguments? identifier | NEW)
607
+ | classType '::' typeArguments? NEW
608
+ // Operators
609
+ | expression postfix=('++' | '--')
610
+ | prefix=('+'|'-'|'++'|'--') expression
611
+ | prefix=('~'|'!') expression
612
+ | expression bop=('*'|'/'|'%') expression
613
+ | expression bop=('+'|'-') expression
614
+ | expression ('<' '<' | '>' '>' '>' | '>' '>') expression
615
+ | expression bop=('<=' | '>=' | '>' | '<') expression
616
+ | expression bop=INSTANCEOF (typeType | pattern)
617
+ | expression bop=('==' | '!=') expression
618
+ | expression bop='&' expression
619
+ | expression bop='^' expression
620
+ | expression bop='|' expression
621
+ | expression bop='&&' expression
622
+ | expression bop='||' expression
623
+ | <assoc=right> expression bop='?' expression ':' expression
624
+ | <assoc=right> expression
625
+ bop=('=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '>>=' | '>>>=' | '<<=' | '%=')
626
+ expression
627
+ ;
628
+
629
+ // Java17
630
+ pattern
631
+ : variableModifier* typeType annotation* identifier
632
+ ;
633
+
634
+ // Java8
635
+ lambdaExpression
636
+ : lambdaParameters '->' lambdaBody
637
+ ;
638
+
639
+ // Java8
640
+ lambdaParameters
641
+ : identifier
642
+ | '(' formalParameterList? ')'
643
+ | '(' identifier (',' identifier)* ')'
644
+ | '(' lambdaLVTIList? ')'
645
+ ;
646
+
647
+ // Java8
648
+ lambdaBody
649
+ : expression
650
+ | block
651
+ ;
652
+
653
+ primary
654
+ : '(' expression ')'
655
+ | THIS
656
+ | SUPER
657
+ | literal
658
+ | identifier
659
+ | typeTypeOrVoid '.' CLASS
660
+ | nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments)
661
+ ;
662
+
663
+ // Java17
664
+ switchExpression
665
+ : SWITCH parExpression '{' switchLabeledRule* '}'
666
+ ;
667
+
668
+ // Java17
669
+ switchLabeledRule
670
+ : CASE (expressionList | NULL_LITERAL | guardedPattern) (ARROW | COLON) switchRuleOutcome
671
+ | DEFAULT (ARROW | COLON) switchRuleOutcome
672
+ ;
673
+
674
+ // Java17
675
+ guardedPattern
676
+ : '(' guardedPattern ')'
677
+ | variableModifier* typeType annotation* identifier ('&&' expression)*
678
+ | guardedPattern '&&' expression
679
+ ;
680
+
681
+ // Java17
682
+ switchRuleOutcome
683
+ : block
684
+ | blockStatement*
685
+ ;
686
+
687
+ classType
688
+ : (classOrInterfaceType '.')? annotation* identifier typeArguments?
689
+ ;
690
+
691
+ creator
692
+ : nonWildcardTypeArguments createdName classCreatorRest
693
+ | createdName (arrayCreatorRest | classCreatorRest)
694
+ ;
695
+
696
+ createdName
697
+ : identifier typeArgumentsOrDiamond? ('.' identifier typeArgumentsOrDiamond?)*
698
+ | primitiveType
699
+ ;
700
+
701
+ innerCreator
702
+ : identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest
703
+ ;
704
+
705
+ arrayCreatorRest
706
+ : '[' (']' ('[' ']')* arrayInitializer | expression ']' ('[' expression ']')* ('[' ']')*)
707
+ ;
708
+
709
+ classCreatorRest
710
+ : arguments classBody?
711
+ ;
712
+
713
+ explicitGenericInvocation
714
+ : nonWildcardTypeArguments explicitGenericInvocationSuffix
715
+ ;
716
+
717
+ typeArgumentsOrDiamond
718
+ : '<' '>'
719
+ | typeArguments
720
+ ;
721
+
722
+ nonWildcardTypeArgumentsOrDiamond
723
+ : '<' '>'
724
+ | nonWildcardTypeArguments
725
+ ;
726
+
727
+ nonWildcardTypeArguments
728
+ : '<' typeList '>'
729
+ ;
730
+
731
+ typeList
732
+ : typeType (',' typeType)*
733
+ ;
734
+
735
+ typeType
736
+ : annotation* (classOrInterfaceType | primitiveType) (annotation* '[' ']')*
737
+ ;
738
+
739
+ primitiveType
740
+ : BOOLEAN
741
+ | CHAR
742
+ | BYTE
743
+ | SHORT
744
+ | INT
745
+ | LONG
746
+ | FLOAT
747
+ | DOUBLE
748
+ ;
749
+
750
+ typeArguments
751
+ : '<' typeArgument (',' typeArgument)* '>'
752
+ ;
753
+
754
+ superSuffix
755
+ : arguments
756
+ | '.' typeArguments? identifier arguments?
757
+ ;
758
+
759
+ explicitGenericInvocationSuffix
760
+ : SUPER superSuffix
761
+ | identifier arguments
762
+ ;
763
+
764
+ arguments
765
+ : '(' expressionList? ')'
766
+ ;