Skip to content

Commit b6906f0

Browse files
committed
refactor methodDeclaration
1 parent d7fb99f commit b6906f0

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

java/Java.g4

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,17 @@ memberDeclaration
143143
| enumDeclaration
144144
;
145145

146+
/* We use rule this even for void methods which cannot have [] after parameters.
147+
This simplifies grammar and we can consider void to be a type, which
148+
renders the [] matching as a context-sensitive issue or a semantic check
149+
for invalid return type after parsing.
150+
*/
146151
methodDeclaration
147-
: type Identifier methodDeclaratorRest
148-
| 'void' Identifier voidMethodDeclaratorRest
152+
: (type|'void') Identifier formalParameters ('[' ']')*
153+
('throws' qualifiedNameList)?
154+
( methodBody
155+
| ';'
156+
)
149157
;
150158

151159
genericMethodDeclaration
@@ -189,6 +197,11 @@ interfaceMethodOrFieldRest
189197
| interfaceMethodDeclaratorRest
190198
;
191199

200+
/** We use this even for void methods which cannot have [] after parameters.
201+
This simplifies grammar and we can consider void to be a type, which
202+
renders the [] matching as a context-sensitive issue or a semantic check
203+
for invalid return type after parsing.
204+
*/
192205
methodDeclaratorRest
193206
: formalParameters ('[' ']')*
194207
('throws' qualifiedNameList)?
@@ -197,13 +210,6 @@ methodDeclaratorRest
197210
)
198211
;
199212

200-
voidMethodDeclaratorRest
201-
: formalParameters ('throws' qualifiedNameList)?
202-
( methodBody
203-
| ';'
204-
)
205-
;
206-
207213
interfaceMethodDeclaratorRest
208214
: formalParameters ('[' ']')* ('throws' qualifiedNameList)? ';'
209215
;

0 commit comments

Comments
 (0)