< prev index next >

test/langtools/tools/javac/parser/extend/TrialParser.java

Print this page




 158             case WHILE:
 159             case DO:
 160             case TRY:
 161             case SWITCH:
 162             case SYNCHRONIZED:
 163             case RETURN:
 164             case THROW:
 165             case BREAK:
 166             case CONTINUE:
 167             case SEMI:
 168             case ELSE:
 169             case FINALLY:
 170             case CATCH:
 171             case ASSERT:
 172                 return List.<JCTree>of(parseStatement());
 173             default:
 174                 JCModifiers mods = modifiersOpt(pmods);
 175                 if (token.kind == CLASS
 176                         || token.kind == INTERFACE
 177                         || token.kind == ENUM) {
 178                     return List.<JCTree>of(classOrInterfaceOrEnumDeclaration(mods, dc));
 179                 } else {
 180                     int pos = token.pos;
 181                     List<JCTypeParameter> typarams = typeParametersOpt();
 182                 // if there are type parameters but no modifiers, save the start
 183                     // position of the method in the modifiers.
 184                     if (typarams.nonEmpty() && mods.pos == Position.NOPOS) {
 185                         mods.pos = pos;
 186                         storeEnd(mods, pos);
 187                     }
 188                     List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION);
 189 
 190                     if (annosAfterParams.nonEmpty()) {
 191                         checkSourceLevel(annosAfterParams.head.pos, Feature.ANNOTATIONS_AFTER_TYPE_PARAMS);
 192                         mods.annotations = mods.annotations.appendList(annosAfterParams);
 193                         if (mods.pos == Position.NOPOS) {
 194                             mods.pos = mods.annotations.head.pos;
 195                         }
 196                     }
 197 
 198                     Token prevToken = token;


 203                         t = to(F.at(pos).TypeIdent(TypeTag.VOID));
 204                         nextToken();
 205                     } else {
 206                         // return type of method, declared type of variable, or an expression
 207                         t = term(EXPR | TYPE);
 208                     }
 209                     if (token.kind == COLON && t.hasTag(IDENT)) {
 210                         // labelled statement
 211                         nextToken();
 212                         JCStatement stat = parseStatement();
 213                         return List.<JCTree>of(F.at(pos).Labelled(prevToken.name(), stat));
 214                     } else if ((isVoid || (lastmode & TYPE) != 0) && LAX_IDENTIFIER.accepts(token.kind)) {
 215                         // we have "Type Ident", so we can assume it is variable or method declaration
 216                         pos = token.pos;
 217                         Name name = ident();
 218                         if (token.kind == LPAREN) {
 219                         // method declaration
 220                             //mods.flags |= Flags.STATIC;
 221                             return List.of(methodDeclaratorRest(
 222                                     pos, mods, t, name, typarams,
 223                                     false, isVoid, dc));
 224                         } else if (!isVoid && typarams.isEmpty()) {
 225                         // variable declaration
 226                             //mods.flags |= Flags.STATIC;
 227                             List<JCTree> defs
 228                                     = variableDeclaratorsRest(pos, mods, t, name, false, dc,
 229                                             new ListBuffer<JCTree>(), true).toList();
 230                             accept(SEMI);
 231                             storeEnd(defs.last(), S.prevToken().endPos);
 232                             return defs;
 233                         } else {
 234                             // malformed declaration, return error
 235                             pos = token.pos;
 236                             List<JCTree> err = isVoid
 237                                     ? List.<JCTree>of(toP(F.at(pos).MethodDef(mods, name, t, typarams,
 238                                                             List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null)))
 239                                     : null;
 240                             return List.<JCTree>of(syntaxError(token.pos, err, Errors.Expected(LPAREN)));
 241                         }
 242                     } else if (!typarams.isEmpty()) {
 243                         // type parameters on non-variable non-method -- error


 158             case WHILE:
 159             case DO:
 160             case TRY:
 161             case SWITCH:
 162             case SYNCHRONIZED:
 163             case RETURN:
 164             case THROW:
 165             case BREAK:
 166             case CONTINUE:
 167             case SEMI:
 168             case ELSE:
 169             case FINALLY:
 170             case CATCH:
 171             case ASSERT:
 172                 return List.<JCTree>of(parseStatement());
 173             default:
 174                 JCModifiers mods = modifiersOpt(pmods);
 175                 if (token.kind == CLASS
 176                         || token.kind == INTERFACE
 177                         || token.kind == ENUM) {
 178                     return List.<JCTree>of(classOrRecordOrInterfaceOrEnumDeclaration(mods, dc));
 179                 } else {
 180                     int pos = token.pos;
 181                     List<JCTypeParameter> typarams = typeParametersOpt();
 182                 // if there are type parameters but no modifiers, save the start
 183                     // position of the method in the modifiers.
 184                     if (typarams.nonEmpty() && mods.pos == Position.NOPOS) {
 185                         mods.pos = pos;
 186                         storeEnd(mods, pos);
 187                     }
 188                     List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION);
 189 
 190                     if (annosAfterParams.nonEmpty()) {
 191                         checkSourceLevel(annosAfterParams.head.pos, Feature.ANNOTATIONS_AFTER_TYPE_PARAMS);
 192                         mods.annotations = mods.annotations.appendList(annosAfterParams);
 193                         if (mods.pos == Position.NOPOS) {
 194                             mods.pos = mods.annotations.head.pos;
 195                         }
 196                     }
 197 
 198                     Token prevToken = token;


 203                         t = to(F.at(pos).TypeIdent(TypeTag.VOID));
 204                         nextToken();
 205                     } else {
 206                         // return type of method, declared type of variable, or an expression
 207                         t = term(EXPR | TYPE);
 208                     }
 209                     if (token.kind == COLON && t.hasTag(IDENT)) {
 210                         // labelled statement
 211                         nextToken();
 212                         JCStatement stat = parseStatement();
 213                         return List.<JCTree>of(F.at(pos).Labelled(prevToken.name(), stat));
 214                     } else if ((isVoid || (lastmode & TYPE) != 0) && LAX_IDENTIFIER.accepts(token.kind)) {
 215                         // we have "Type Ident", so we can assume it is variable or method declaration
 216                         pos = token.pos;
 217                         Name name = ident();
 218                         if (token.kind == LPAREN) {
 219                         // method declaration
 220                             //mods.flags |= Flags.STATIC;
 221                             return List.of(methodDeclaratorRest(
 222                                     pos, mods, t, name, typarams,
 223                                     false, isVoid, false, dc));
 224                         } else if (!isVoid && typarams.isEmpty()) {
 225                         // variable declaration
 226                             //mods.flags |= Flags.STATIC;
 227                             List<JCTree> defs
 228                                     = variableDeclaratorsRest(pos, mods, t, name, false, dc,
 229                                             new ListBuffer<JCTree>(), true).toList();
 230                             accept(SEMI);
 231                             storeEnd(defs.last(), S.prevToken().endPos);
 232                             return defs;
 233                         } else {
 234                             // malformed declaration, return error
 235                             pos = token.pos;
 236                             List<JCTree> err = isVoid
 237                                     ? List.<JCTree>of(toP(F.at(pos).MethodDef(mods, name, t, typarams,
 238                                                             List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null)))
 239                                     : null;
 240                             return List.<JCTree>of(syntaxError(token.pos, err, Errors.Expected(LPAREN)));
 241                         }
 242                     } else if (!typarams.isEmpty()) {
 243                         // type parameters on non-variable non-method -- error
< prev index next >