@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,765 @@
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
+ : IMPORT STATIC? qualifiedName ('.' '*')? ';'+
42
+ ;
43
+
44
+ typeDeclaration
45
+ : classOrInterfaceModifier*
46
+ (classDeclaration | enumDeclaration | interfaceDeclaration | annotationTypeDeclaration | recordDeclaration)
47
+ | ';'
48
+ ;
49
+
50
+ modifier
51
+ : classOrInterfaceModifier
52
+ | NATIVE
53
+ | SYNCHRONIZED
54
+ | TRANSIENT
55
+ | VOLATILE
56
+ ;
57
+
58
+ classOrInterfaceModifier
59
+ : annotation
60
+ | PUBLIC
61
+ | PROTECTED
62
+ | PRIVATE
63
+ | STATIC
64
+ | ABSTRACT
65
+ | FINAL // FINAL for class only -- does not apply to interfaces
66
+ | STRICTFP
67
+ | SEALED // Java17
68
+ | NON_SEALED // Java17
69
+ ;
70
+
71
+ variableModifier
72
+ : FINAL
73
+ | annotation
74
+ ;
75
+
76
+ classDeclaration
77
+ : CLASS identifier typeParameters?
78
+ (EXTENDS typeType)?
79
+ (IMPLEMENTS typeList)?
80
+ (PERMITS typeList)? // Java17
81
+ classBody
82
+ ;
83
+
84
+ typeParameters
85
+ : '<' typeParameter (',' typeParameter)* '>'
86
+ ;
87
+
88
+ typeParameter
89
+ : annotation* identifier (EXTENDS annotation* typeBound)?
90
+ ;
91
+
92
+ typeBound
93
+ : typeType ('&' typeType)*
94
+ ;
95
+
96
+ enumDeclaration
97
+ : ENUM identifier (IMPLEMENTS typeList)? '{' enumConstants? ','? enumBodyDeclarations? '}'
98
+ ;
99
+
100
+ enumConstants
101
+ : enumConstant (',' enumConstant)*
102
+ ;
103
+
104
+ enumConstant
105
+ : annotation* identifier arguments? classBody?
106
+ ;
107
+
108
+ enumBodyDeclarations
109
+ : ';' classBodyDeclaration*
110
+ ;
111
+
112
+ interfaceDeclaration
113
+ : INTERFACE identifier typeParameters? (EXTENDS typeList)? (PERMITS typeList)? interfaceBody
114
+ ;
115
+
116
+ classBody
117
+ : '{' classBodyDeclaration* '}'
118
+ ;
119
+
120
+ interfaceBody
121
+ : '{' interfaceBodyDeclaration* '}'
122
+ ;
123
+
124
+ classBodyDeclaration
125
+ : ';'
126
+ | STATIC? block
127
+ | modifier* memberDeclaration
128
+ ;
129
+
130
+ memberDeclaration
131
+ : recordDeclaration //Java17
132
+ | methodDeclaration
133
+ | genericMethodDeclaration
134
+ | fieldDeclaration
135
+ | constructorDeclaration
136
+ | genericConstructorDeclaration
137
+ | interfaceDeclaration
138
+ | annotationTypeDeclaration
139
+ | classDeclaration
140
+ | enumDeclaration
141
+ ;
142
+
143
+ /* We use rule this even for void methods which cannot have [] after parameters.
144
+ This simplifies grammar and we can consider void to be a type, which
145
+ renders the [] matching as a context-sensitive issue or a semantic check
146
+ for invalid return type after parsing.
147
+ */
148
+ methodDeclaration
149
+ : typeTypeOrVoid identifier formalParameters ('[' ']')*
150
+ (THROWS qualifiedNameList)?
151
+ methodBody
152
+ ;
153
+
154
+ methodBody
155
+ : block
156
+ | ';'
157
+ ;
158
+
159
+ typeTypeOrVoid
160
+ : typeType
161
+ | VOID
162
+ ;
163
+
164
+ genericMethodDeclaration
165
+ : typeParameters methodDeclaration
166
+ ;
167
+
168
+ genericConstructorDeclaration
169
+ : typeParameters constructorDeclaration
170
+ ;
171
+
172
+ constructorDeclaration
173
+ : identifier formalParameters (THROWS qualifiedNameList)? constructorBody=block
174
+ ;
175
+
176
+ compactConstructorDeclaration
177
+ : modifier* identifier constructorBody=block
178
+ ;
179
+
180
+ fieldDeclaration
181
+ : typeType variableDeclarators ';'
182
+ ;
183
+
184
+ interfaceBodyDeclaration
185
+ : modifier* interfaceMemberDeclaration
186
+ | ';'
187
+ ;
188
+
189
+ interfaceMemberDeclaration
190
+ : constDeclaration
191
+ | interfaceMethodDeclaration
192
+ | genericInterfaceMethodDeclaration
193
+ | interfaceDeclaration
194
+ | annotationTypeDeclaration
195
+ | classDeclaration
196
+ | enumDeclaration
197
+ | recordDeclaration // Java17
198
+ ;
199
+
200
+ constDeclaration
201
+ : typeType constantDeclarator (',' constantDeclarator)* ';'
202
+ ;
203
+
204
+ constantDeclarator
205
+ : identifier ('[' ']')* '=' variableInitializer
206
+ ;
207
+
208
+ // Early versions of Java allows brackets after the method name, eg.
209
+ // public int[] return2DArray() [] { ... }
210
+ // is the same as
211
+ // public int[][] return2DArray() { ... }
212
+ interfaceMethodDeclaration
213
+ : interfaceMethodModifier* interfaceCommonBodyDeclaration
214
+ ;
215
+
216
+ // Java8
217
+ interfaceMethodModifier
218
+ : annotation
219
+ | PUBLIC
220
+ | ABSTRACT
221
+ | DEFAULT
222
+ | STATIC
223
+ | STRICTFP
224
+ ;
225
+
226
+ genericInterfaceMethodDeclaration
227
+ : interfaceMethodModifier* typeParameters interfaceCommonBodyDeclaration
228
+ ;
229
+
230
+ interfaceCommonBodyDeclaration
231
+ : annotation* typeTypeOrVoid identifier formalParameters ('[' ']')* (THROWS qualifiedNameList)? methodBody
232
+ ;
233
+
234
+ variableDeclarators
235
+ : variableDeclarator (',' variableDeclarator)*
236
+ ;
237
+
238
+ variableDeclarator
239
+ : variableDeclaratorId ('=' variableInitializer)?
240
+ ;
241
+
242
+ variableDeclaratorId
243
+ : identifier ('[' ']')*
244
+ ;
245
+
246
+ variableInitializer
247
+ : arrayInitializer
248
+ | expression
249
+ ;
250
+
251
+ arrayInitializer
252
+ : '{' (variableInitializer (',' variableInitializer)* (',')? )? '}'
253
+ ;
254
+
255
+ classOrInterfaceType
256
+ : (identifier typeArguments? '.')* typeIdentifier typeArguments?
257
+ ;
258
+
259
+ typeArgument
260
+ : typeType
261
+ | annotation* '?' ((EXTENDS | SUPER) typeType)?
262
+ ;
263
+
264
+ qualifiedNameList
265
+ : qualifiedName (',' qualifiedName)*
266
+ ;
267
+
268
+ formalParameters
269
+ : '(' ( receiverParameter?
270
+ | receiverParameter (',' formalParameterList)?
271
+ | formalParameterList?
272
+ ) ')'
273
+ ;
274
+
275
+ receiverParameter
276
+ : typeType (identifier '.')* THIS
277
+ ;
278
+
279
+ formalParameterList
280
+ : formalParameter (',' formalParameter)* (',' lastFormalParameter)?
281
+ | lastFormalParameter
282
+ ;
283
+
284
+ formalParameter
285
+ : variableModifier* typeType variableDeclaratorId
286
+ ;
287
+
288
+ lastFormalParameter
289
+ : variableModifier* typeType annotation* '...' variableDeclaratorId
290
+ ;
291
+
292
+ // local variable type inference
293
+ lambdaLVTIList
294
+ : lambdaLVTIParameter (',' lambdaLVTIParameter)*
295
+ ;
296
+
297
+ lambdaLVTIParameter
298
+ : variableModifier* VAR identifier
299
+ ;
300
+
301
+ qualifiedName
302
+ : identifier ('.' identifier)*
303
+ ;
304
+
305
+ literal
306
+ : integerLiteral
307
+ | floatLiteral
308
+ | CHAR_LITERAL
309
+ | STRING_LITERAL
310
+ | BOOL_LITERAL
311
+ | NULL_LITERAL
312
+ | TEXT_BLOCK // Java17
313
+ ;
314
+
315
+ integerLiteral
316
+ : DECIMAL_LITERAL
317
+ | HEX_LITERAL
318
+ | OCT_LITERAL
319
+ | BINARY_LITERAL
320
+ ;
321
+
322
+ floatLiteral
323
+ : FLOAT_LITERAL
324
+ | HEX_FLOAT_LITERAL
325
+ ;
326
+
327
+ // ANNOTATIONS
328
+ altAnnotationQualifiedName
329
+ : (identifier DOT)* '@' identifier
330
+ ;
331
+
332
+ annotation
333
+ : ('@' qualifiedName | altAnnotationQualifiedName) ('(' ( elementValuePairs | elementValue )? ')')?
334
+ ;
335
+
336
+ elementValuePairs
337
+ : elementValuePair (',' elementValuePair)*
338
+ ;
339
+
340
+ elementValuePair
341
+ : identifier '=' elementValue
342
+ ;
343
+
344
+ elementValue
345
+ : expression
346
+ | annotation
347
+ | elementValueArrayInitializer
348
+ ;
349
+
350
+ elementValueArrayInitializer
351
+ : '{' (elementValue (',' elementValue)*)? (',')? '}'
352
+ ;
353
+
354
+ annotationTypeDeclaration
355
+ : '@' INTERFACE identifier annotationTypeBody
356
+ ;
357
+
358
+ annotationTypeBody
359
+ : '{' (annotationTypeElementDeclaration)* '}'
360
+ ;
361
+
362
+ annotationTypeElementDeclaration
363
+ : modifier* annotationTypeElementRest
364
+ | ';' // this is not allowed by the grammar, but apparently allowed by the actual compiler
365
+ ;
366
+
367
+ annotationTypeElementRest
368
+ : typeType annotationMethodOrConstantRest ';'
369
+ | classDeclaration ';'?
370
+ | interfaceDeclaration ';'?
371
+ | enumDeclaration ';'?
372
+ | annotationTypeDeclaration ';'?
373
+ | recordDeclaration ';'? // Java17
374
+ ;
375
+
376
+ annotationMethodOrConstantRest
377
+ : annotationMethodRest
378
+ | annotationConstantRest
379
+ ;
380
+
381
+ annotationMethodRest
382
+ : identifier '(' ')' defaultValue?
383
+ ;
384
+
385
+ annotationConstantRest
386
+ : variableDeclarators
387
+ ;
388
+
389
+ defaultValue
390
+ : DEFAULT elementValue
391
+ ;
392
+
393
+ // MODULES - Java9
394
+
395
+ moduleDeclaration
396
+ : OPEN? MODULE qualifiedName moduleBody
397
+ ;
398
+
399
+ moduleBody
400
+ : '{' moduleDirective* '}'
401
+ ;
402
+
403
+ moduleDirective
404
+ : REQUIRES requiresModifier* qualifiedName ';'
405
+ | EXPORTS qualifiedName (TO qualifiedName)? ';'
406
+ | OPENS qualifiedName (TO qualifiedName)? ';'
407
+ | USES qualifiedName ';'
408
+ | PROVIDES qualifiedName WITH qualifiedName ';'
409
+ ;
410
+
411
+ requiresModifier
412
+ : TRANSITIVE
413
+ | STATIC
414
+ ;
415
+
416
+ // RECORDS - Java 17
417
+
418
+ recordDeclaration
419
+ : RECORD identifier typeParameters? recordHeader
420
+ (IMPLEMENTS typeList)?
421
+ recordBody
422
+ ;
423
+
424
+ recordHeader
425
+ : '(' recordComponentList? ')'
426
+ ;
427
+
428
+ recordComponentList
429
+ : recordComponent (',' recordComponent)*
430
+ ;
431
+
432
+ recordComponent
433
+ : typeType identifier
434
+ ;
435
+
436
+ recordBody
437
+ : '{' (classBodyDeclaration | compactConstructorDeclaration)* '}'
438
+ ;
439
+
440
+ // STATEMENTS / BLOCKS
441
+
442
+ block
443
+ : '{' blockStatement* '}'
444
+ ;
445
+
446
+ blockStatement
447
+ : localVariableDeclaration ';'
448
+ | localTypeDeclaration
449
+ | statement
450
+ ;
451
+
452
+ localVariableDeclaration
453
+ : variableModifier* (VAR identifier '=' expression | typeType variableDeclarators)
454
+ ;
455
+
456
+ identifier
457
+ : IDENTIFIER
458
+ | MODULE
459
+ | OPEN
460
+ | REQUIRES
461
+ | EXPORTS
462
+ | OPENS
463
+ | TO
464
+ | USES
465
+ | PROVIDES
466
+ | WITH
467
+ | TRANSITIVE
468
+ | YIELD
469
+ | SEALED
470
+ | PERMITS
471
+ | RECORD
472
+ | VAR
473
+ ;
474
+
475
+ typeIdentifier // Identifiers that are not restricted for type declarations
476
+ : IDENTIFIER
477
+ | MODULE
478
+ | OPEN
479
+ | REQUIRES
480
+ | EXPORTS
481
+ | OPENS
482
+ | TO
483
+ | USES
484
+ | PROVIDES
485
+ | WITH
486
+ | TRANSITIVE
487
+ | SEALED
488
+ | PERMITS
489
+ | RECORD
490
+ ;
491
+
492
+ localTypeDeclaration
493
+ : classOrInterfaceModifier*
494
+ (classDeclaration | interfaceDeclaration | recordDeclaration)
495
+ ;
496
+
497
+ statement
498
+ : blockLabel=block
499
+ | ASSERT expression (':' expression)? ';'
500
+ | IF parExpression statement (ELSE statement)?
501
+ | FOR '(' forControl ')' statement
502
+ | WHILE parExpression statement
503
+ | DO statement WHILE parExpression ';'
504
+ | TRY block (catchClause+ finallyBlock? | finallyBlock)
505
+ | TRY resourceSpecification block catchClause* finallyBlock?
506
+ | SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}'
507
+ | SYNCHRONIZED parExpression block
508
+ | RETURN expression? ';'
509
+ | THROW expression ';'
510
+ | BREAK identifier? ';'
511
+ | CONTINUE identifier? ';'
512
+ | YIELD expression ';' // Java17
513
+ | SEMI
514
+ | statementExpression=expression ';'
515
+ | switchExpression ';'? // Java17
516
+ | identifierLabel=identifier ':' statement
517
+ ;
518
+
519
+ catchClause
520
+ : CATCH '(' variableModifier* catchType identifier ')' block
521
+ ;
522
+
523
+ catchType
524
+ : qualifiedName ('|' qualifiedName)*
525
+ ;
526
+
527
+ finallyBlock
528
+ : FINALLY block
529
+ ;
530
+
531
+ resourceSpecification
532
+ : '(' resources ';'? ')'
533
+ ;
534
+
535
+ resources
536
+ : resource (';' resource)*
537
+ ;
538
+
539
+ resource
540
+ : variableModifier* ( classOrInterfaceType variableDeclaratorId | VAR identifier ) '=' expression
541
+ | identifier
542
+ ;
543
+
544
+ /** Matches cases then statements, both of which are mandatory.
545
+ * To handle empty cases at the end, we add switchLabel* to statement.
546
+ */
547
+ switchBlockStatementGroup
548
+ : switchLabel+ blockStatement+
549
+ ;
550
+
551
+ switchLabel
552
+ : CASE (constantExpression=expression | enumConstantName=IDENTIFIER | typeType varName=identifier) ':'
553
+ | DEFAULT ':'
554
+ ;
555
+
556
+ forControl
557
+ : enhancedForControl
558
+ | forInit? ';' expression? ';' forUpdate=expressionList?
559
+ ;
560
+
561
+ forInit
562
+ : localVariableDeclaration
563
+ | expressionList
564
+ ;
565
+
566
+ enhancedForControl
567
+ : variableModifier* (typeType | VAR) variableDeclaratorId ':' expression
568
+ ;
569
+
570
+ // EXPRESSIONS
571
+
572
+ parExpression
573
+ : '(' expression ')'
574
+ ;
575
+
576
+ expressionList
577
+ : expression (',' expression)*
578
+ ;
579
+
580
+ methodCall
581
+ : identifier '(' expressionList? ')'
582
+ | THIS '(' expressionList? ')'
583
+ | SUPER '(' expressionList? ')'
584
+ ;
585
+
586
+ expression
587
+ : primary
588
+ | expression bop='.'
589
+ (
590
+ identifier
591
+ | methodCall
592
+ | THIS
593
+ | NEW nonWildcardTypeArguments? innerCreator
594
+ | SUPER superSuffix
595
+ | explicitGenericInvocation
596
+ )
597
+ | expression '[' expression ']'
598
+ | methodCall
599
+ | NEW creator
600
+ | '(' annotation* typeType ('&' typeType)* ')' expression
601
+ | expression postfix=('++' | '--')
602
+ | prefix=('+'|'-'|'++'|'--') expression
603
+ | prefix=('~'|'!') expression
604
+ | expression bop=('*'|'/'|'%') expression
605
+ | expression bop=('+'|'-') expression
606
+ | expression ('<' '<' | '>' '>' '>' | '>' '>') expression
607
+ | expression bop=('<=' | '>=' | '>' | '<') expression
608
+ | expression bop=INSTANCEOF (typeType | pattern)
609
+ | expression bop=('==' | '!=') expression
610
+ | expression bop='&' expression
611
+ | expression bop='^' expression
612
+ | expression bop='|' expression
613
+ | expression bop='&&' expression
614
+ | expression bop='||' expression
615
+ | <assoc=right> expression bop='?' expression ':' expression
616
+ | <assoc=right> expression
617
+ bop=('=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '>>=' | '>>>=' | '<<=' | '%=')
618
+ expression
619
+ | lambdaExpression // Java8
620
+ | switchExpression // Java17
621
+
622
+ // Java 8 methodReference
623
+ | expression '::' typeArguments? identifier
624
+ | typeType '::' (typeArguments? identifier | NEW)
625
+ | classType '::' typeArguments? NEW
626
+ ;
627
+
628
+ // Java17
629
+ pattern
630
+ : variableModifier* typeType annotation* identifier
631
+ ;
632
+
633
+ // Java8
634
+ lambdaExpression
635
+ : lambdaParameters '->' lambdaBody
636
+ ;
637
+
638
+ // Java8
639
+ lambdaParameters
640
+ : identifier
641
+ | '(' formalParameterList? ')'
642
+ | '(' identifier (',' identifier)* ')'
643
+ | '(' lambdaLVTIList? ')'
644
+ ;
645
+
646
+ // Java8
647
+ lambdaBody
648
+ : expression
649
+ | block
650
+ ;
651
+
652
+ primary
653
+ : '(' expression ')'
654
+ | THIS
655
+ | SUPER
656
+ | literal
657
+ | identifier
658
+ | typeTypeOrVoid '.' CLASS
659
+ | nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments)
660
+ ;
661
+
662
+ // Java17
663
+ switchExpression
664
+ : SWITCH parExpression '{' switchLabeledRule* '}'
665
+ ;
666
+
667
+ // Java17
668
+ switchLabeledRule
669
+ : CASE (expressionList | NULL_LITERAL | guardedPattern) (ARROW | COLON) switchRuleOutcome
670
+ | DEFAULT (ARROW | COLON) switchRuleOutcome
671
+ ;
672
+
673
+ // Java17
674
+ guardedPattern
675
+ : '(' guardedPattern ')'
676
+ | variableModifier* typeType annotation* identifier ('&&' expression)*
677
+ | guardedPattern '&&' expression
678
+ ;
679
+
680
+ // Java17
681
+ switchRuleOutcome
682
+ : block
683
+ | blockStatement*
684
+ ;
685
+
686
+ classType
687
+ : (classOrInterfaceType '.')? annotation* identifier typeArguments?
688
+ ;
689
+
690
+ creator
691
+ : nonWildcardTypeArguments createdName classCreatorRest
692
+ | createdName (arrayCreatorRest | classCreatorRest)
693
+ ;
694
+
695
+ createdName
696
+ : identifier typeArgumentsOrDiamond? ('.' identifier typeArgumentsOrDiamond?)*
697
+ | primitiveType
698
+ ;
699
+
700
+ innerCreator
701
+ : identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest
702
+ ;
703
+
704
+ arrayCreatorRest
705
+ : '[' (']' ('[' ']')* arrayInitializer | expression ']' ('[' expression ']')* ('[' ']')*)
706
+ ;
707
+
708
+ classCreatorRest
709
+ : arguments classBody?
710
+ ;
711
+
712
+ explicitGenericInvocation
713
+ : nonWildcardTypeArguments explicitGenericInvocationSuffix
714
+ ;
715
+
716
+ typeArgumentsOrDiamond
717
+ : '<' '>'
718
+ | typeArguments
719
+ ;
720
+
721
+ nonWildcardTypeArgumentsOrDiamond
722
+ : '<' '>'
723
+ | nonWildcardTypeArguments
724
+ ;
725
+
726
+ nonWildcardTypeArguments
727
+ : '<' typeList '>'
728
+ ;
729
+
730
+ typeList
731
+ : typeType (',' typeType)*
732
+ ;
733
+
734
+ typeType
735
+ : annotation* (classOrInterfaceType | primitiveType) (annotation* '[' ']')*
736
+ ;
737
+
738
+ primitiveType
739
+ : BOOLEAN
740
+ | CHAR
741
+ | BYTE
742
+ | SHORT
743
+ | INT
744
+ | LONG
745
+ | FLOAT
746
+ | DOUBLE
747
+ ;
748
+
749
+ typeArguments
750
+ : '<' typeArgument (',' typeArgument)* '>'
751
+ ;
752
+
753
+ superSuffix
754
+ : arguments
755
+ | '.' typeArguments? identifier arguments?
756
+ ;
757
+
758
+ explicitGenericInvocationSuffix
759
+ : SUPER superSuffix
760
+ | identifier arguments
761
+ ;
762
+
763
+ arguments
764
+ : '(' expressionList? ')'
765
+ ;