src/share/classes/com/sun/tools/javac/parser/JavacParser.java

changeset 2372
7daae506441f
parent 2355
4f7d19235357
child 2417
28e204e63063
equal deleted inserted replaced
2371:972f74339e06 2372:7daae506441f
3404 * ";" 3404 * ";"
3405 * | [STATIC] Block 3405 * | [STATIC] Block
3406 * | ModifiersOpt 3406 * | ModifiersOpt
3407 * ( Type Ident 3407 * ( Type Ident
3408 * ( VariableDeclaratorsRest ";" | MethodDeclaratorRest ) 3408 * ( VariableDeclaratorsRest ";" | MethodDeclaratorRest )
3409 * | VOID Ident MethodDeclaratorRest 3409 * | VOID Ident VoidMethodDeclaratorRest
3410 * | TypeParameters (Type | VOID) Ident MethodDeclaratorRest 3410 * | TypeParameters [Annotations]
3411 * ( Type Ident MethodDeclaratorRest
3412 * | VOID Ident VoidMethodDeclaratorRest
3413 * )
3411 * | Ident ConstructorDeclaratorRest 3414 * | Ident ConstructorDeclaratorRest
3412 * | TypeParameters Ident ConstructorDeclaratorRest 3415 * | TypeParameters Ident ConstructorDeclaratorRest
3413 * | ClassOrInterfaceOrEnumDeclaration 3416 * | ClassOrInterfaceOrEnumDeclaration
3414 * ) 3417 * )
3415 * InterfaceBodyDeclaration = 3418 * InterfaceBodyDeclaration =
3416 * ";" 3419 * ";"
3417 * | ModifiersOpt Type Ident 3420 * | ModifiersOpt
3418 * ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" ) 3421 * ( Type Ident
3422 * ( ConstantDeclaratorsRest ";" | MethodDeclaratorRest )
3423 * | VOID Ident MethodDeclaratorRest
3424 * | TypeParameters [Annotations]
3425 * ( Type Ident MethodDeclaratorRest
3426 * | VOID Ident VoidMethodDeclaratorRest
3427 * )
3428 * | ClassOrInterfaceOrEnumDeclaration
3429 * )
3430 *
3419 */ 3431 */
3420 protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { 3432 protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) {
3421 if (token.kind == SEMI) { 3433 if (token.kind == SEMI) {
3422 nextToken(); 3434 nextToken();
3423 return List.<JCTree>nil(); 3435 return List.<JCTree>nil();
3442 mods.pos = pos; 3454 mods.pos = pos;
3443 storeEnd(mods, pos); 3455 storeEnd(mods, pos);
3444 } 3456 }
3445 List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION); 3457 List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION);
3446 3458
3459 if (annosAfterParams.nonEmpty()) {
3460 checkAnnotationsAfterTypeParams(annosAfterParams.head.pos);
3461 mods.annotations = mods.annotations.appendList(annosAfterParams);
3462 if (mods.pos == Position.NOPOS)
3463 mods.pos = mods.annotations.head.pos;
3464 }
3465
3447 Token tk = token; 3466 Token tk = token;
3448 pos = token.pos; 3467 pos = token.pos;
3449 JCExpression type; 3468 JCExpression type;
3450 boolean isVoid = token.kind == VOID; 3469 boolean isVoid = token.kind == VOID;
3451 if (isVoid) { 3470 if (isVoid) {
3452 if (annosAfterParams.nonEmpty())
3453 illegal(annosAfterParams.head.pos);
3454 type = to(F.at(pos).TypeIdent(TypeTag.VOID)); 3471 type = to(F.at(pos).TypeIdent(TypeTag.VOID));
3455 nextToken(); 3472 nextToken();
3456 } else { 3473 } else {
3457 if (annosAfterParams.nonEmpty()) {
3458 checkAnnotationsAfterTypeParams(annosAfterParams.head.pos);
3459 mods.annotations = mods.annotations.appendList(annosAfterParams);
3460 if (mods.pos == Position.NOPOS)
3461 mods.pos = mods.annotations.head.pos;
3462 }
3463 // method returns types are un-annotated types 3474 // method returns types are un-annotated types
3464 type = unannotatedType(); 3475 type = unannotatedType();
3465 } 3476 }
3466 if (token.kind == LPAREN && !isInterface && type.hasTag(IDENT)) { 3477 if (token.kind == LPAREN && !isInterface && type.hasTag(IDENT)) {
3467 if (isInterface || tk.name() != className) 3478 if (isInterface || tk.name() != className)
3468 error(pos, "invalid.meth.decl.ret.type.req"); 3479 error(pos, "invalid.meth.decl.ret.type.req");
3480 else if (annosAfterParams.nonEmpty())
3481 illegal(annosAfterParams.head.pos);
3469 return List.of(methodDeclaratorRest( 3482 return List.of(methodDeclaratorRest(
3470 pos, mods, null, names.init, typarams, 3483 pos, mods, null, names.init, typarams,
3471 isInterface, true, dc)); 3484 isInterface, true, dc));
3472 } else { 3485 } else {
3473 pos = token.pos; 3486 pos = token.pos;
3495 } 3508 }
3496 } 3509 }
3497 } 3510 }
3498 3511
3499 /** MethodDeclaratorRest = 3512 /** MethodDeclaratorRest =
3500 * FormalParameters BracketsOpt [Throws TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";") 3513 * FormalParameters BracketsOpt [THROWS TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";")
3501 * VoidMethodDeclaratorRest = 3514 * VoidMethodDeclaratorRest =
3502 * FormalParameters [Throws TypeList] ( MethodBody | ";") 3515 * FormalParameters [THROWS TypeList] ( MethodBody | ";")
3503 * InterfaceMethodDeclaratorRest =
3504 * FormalParameters BracketsOpt [THROWS TypeList] ";"
3505 * VoidInterfaceMethodDeclaratorRest =
3506 * FormalParameters [THROWS TypeList] ";"
3507 * ConstructorDeclaratorRest = 3516 * ConstructorDeclaratorRest =
3508 * "(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody 3517 * "(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody
3509 */ 3518 */
3510 protected JCTree methodDeclaratorRest(int pos, 3519 protected JCTree methodDeclaratorRest(int pos,
3511 JCModifiers mods, 3520 JCModifiers mods,

mercurial