41
41
grammar Java;
42
42
43
43
// starting point for parsing a java file
44
- /* The annotations are separated out to make parsing faster, but must be associated with
45
- a packageDeclaration or a typeDeclaration (and not an empty one). */
46
44
compilationUnit
47
- : annotations
48
- ( packageDeclaration importDeclaration* typeDeclaration*
49
- | classOrInterfaceDeclaration typeDeclaration*
50
- )
51
- EOF
52
- | packageDeclaration? importDeclaration* typeDeclaration*
53
- EOF
45
+ : packageDeclaration? importDeclaration* typeDeclaration* EOF
54
46
;
55
47
56
48
packageDeclaration
57
- : ' package' qualifiedName ' ;'
49
+ : annotation* ' package' qualifiedName ' ;'
58
50
;
59
-
51
+
60
52
importDeclaration
61
53
: ' import' ' static' ? qualifiedName (' .' ' *' )? ' ;'
62
54
;
63
55
64
56
typeDeclaration
65
- : classOrInterfaceDeclaration
57
+ : classOrInterfaceModifier* classDeclaration
58
+ | classOrInterfaceModifier* enumDeclaration
59
+ | classOrInterfaceModifier* interfaceDeclaration
60
+ | classOrInterfaceModifier* annotationTypeDeclaration
66
61
| ' ;'
67
62
;
68
63
69
- classOrInterfaceDeclaration
70
- : classOrInterfaceModifier* (classDeclaration | interfaceDeclaration)
71
- ;
72
-
73
64
classOrInterfaceModifier
74
65
: annotation // class or interface
75
66
| ( ' public' // class or interface
@@ -83,11 +74,6 @@ classOrInterfaceModifier
83
74
;
84
75
85
76
classDeclaration
86
- : normalClassDeclaration
87
- | enumDeclaration
88
- ;
89
-
90
- normalClassDeclaration
91
77
: ' class' Identifier typeParameters?
92
78
(' extends' type)?
93
79
(' implements' typeList)?
@@ -116,19 +102,14 @@ enumConstants
116
102
;
117
103
118
104
enumConstant
119
- : annotations? Identifier arguments? classBody?
105
+ : annotation* Identifier arguments? classBody?
120
106
;
121
107
122
108
enumBodyDeclarations
123
109
: ' ;' (classBodyDeclaration)*
124
110
;
125
111
126
112
interfaceDeclaration
127
- : normalInterfaceDeclaration
128
- | annotationTypeDeclaration
129
- ;
130
-
131
- normalInterfaceDeclaration
132
113
: ' interface' Identifier typeParameters? (' extends' typeList)? interfaceBody
133
114
;
134
115
@@ -156,7 +137,9 @@ memberDecl
156
137
| ' void' Identifier voidMethodDeclaratorRest
157
138
| Identifier constructorDeclaratorRest
158
139
| interfaceDeclaration
140
+ | annotationTypeDeclaration
159
141
| classDeclaration
142
+ | enumDeclaration
160
143
;
161
144
162
145
memberDeclaration
@@ -186,7 +169,9 @@ interfaceMemberDecl
186
169
| interfaceGenericMethodDecl
187
170
| ' void' Identifier voidInterfaceMethodDeclaratorRest
188
171
| interfaceDeclaration
172
+ | annotationTypeDeclaration
189
173
| classDeclaration
174
+ | enumDeclaration
190
175
;
191
176
192
177
interfaceMethodOrFieldDecl
@@ -365,10 +350,6 @@ literal
365
350
366
351
// ANNOTATIONS
367
352
368
- annotations
369
- : annotation+
370
- ;
371
-
372
353
annotation
373
354
: ' @' annotationName ( ' (' ( elementValuePairs | elementValue )? ' )' )?
374
355
;
@@ -410,8 +391,8 @@ annotationTypeElementDeclaration
410
391
411
392
annotationTypeElementRest
412
393
: type annotationMethodOrConstantRest ' ;'
413
- | normalClassDeclaration ' ;' ?
414
- | normalInterfaceDeclaration ' ;' ?
394
+ | classDeclaration ' ;' ?
395
+ | interfaceDeclaration ' ;' ?
415
396
| enumDeclaration ' ;' ?
416
397
| annotationTypeDeclaration ' ;' ?
417
398
;
@@ -441,8 +422,8 @@ block
441
422
442
423
blockStatement
443
424
: localVariableDeclarationStatement
444
- | classOrInterfaceDeclaration
445
425
| statement
426
+ | typeDeclaration
446
427
;
447
428
448
429
localVariableDeclarationStatement
0 commit comments