langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java
changeset 24069 dfb8f11542fc
parent 24062 09047fd2a43e
child 25274 a06a738fc6be
equal deleted inserted replaced
24068:d8a1180faaa9 24069:dfb8f11542fc
  3079 
  3079 
  3080     /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
  3080     /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
  3081      */
  3081      */
  3082     public JCTree.JCCompilationUnit parseCompilationUnit() {
  3082     public JCTree.JCCompilationUnit parseCompilationUnit() {
  3083         Token firstToken = token;
  3083         Token firstToken = token;
  3084         JCExpression pid = null;
       
  3085         JCModifiers mods = null;
  3084         JCModifiers mods = null;
  3086         boolean consumedToplevelDoc = false;
  3085         boolean consumedToplevelDoc = false;
  3087         boolean seenImport = false;
  3086         boolean seenImport = false;
  3088         boolean seenPackage = false;
  3087         boolean seenPackage = false;
  3089         List<JCAnnotation> packageAnnotations = List.nil();
  3088         ListBuffer<JCTree> defs = new ListBuffer<>();
  3090         if (token.kind == MONKEYS_AT)
  3089         if (token.kind == MONKEYS_AT)
  3091             mods = modifiersOpt();
  3090             mods = modifiersOpt();
  3092 
  3091 
  3093         if (token.kind == PACKAGE) {
  3092         if (token.kind == PACKAGE) {
       
  3093             int packagePos = token.pos;
       
  3094             List<JCAnnotation> annotations = List.nil();
  3094             seenPackage = true;
  3095             seenPackage = true;
  3095             if (mods != null) {
  3096             if (mods != null) {
  3096                 checkNoMods(mods.flags);
  3097                 checkNoMods(mods.flags);
  3097                 packageAnnotations = mods.annotations;
  3098                 annotations = mods.annotations;
  3098                 mods = null;
  3099                 mods = null;
  3099             }
  3100             }
  3100             nextToken();
  3101             nextToken();
  3101             pid = qualident(false);
  3102             JCExpression pid = qualident(false);
  3102             accept(SEMI);
  3103             accept(SEMI);
  3103         }
  3104             JCPackageDecl pd = F.at(packagePos).PackageDecl(annotations, pid);
  3104         ListBuffer<JCTree> defs = new ListBuffer<>();
  3105             attach(pd, firstToken.comment(CommentStyle.JAVADOC));
       
  3106             consumedToplevelDoc = true;
       
  3107             storeEnd(pd, token.pos);
       
  3108             defs.append(pd);
       
  3109         }
       
  3110 
  3105         boolean checkForImports = true;
  3111         boolean checkForImports = true;
  3106         boolean firstTypeDecl = true;
  3112         boolean firstTypeDecl = true;
  3107         while (token.kind != EOF) {
  3113         while (token.kind != EOF) {
  3108             if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) {
  3114             if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) {
  3109                 // error recovery
  3115                 // error recovery
  3128                     checkForImports = false;
  3134                     checkForImports = false;
  3129                 mods = null;
  3135                 mods = null;
  3130                 firstTypeDecl = false;
  3136                 firstTypeDecl = false;
  3131             }
  3137             }
  3132         }
  3138         }
  3133         JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(packageAnnotations, pid, defs.toList());
  3139         JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(defs.toList());
  3134         if (!consumedToplevelDoc)
  3140         if (!consumedToplevelDoc)
  3135             attach(toplevel, firstToken.comment(CommentStyle.JAVADOC));
  3141             attach(toplevel, firstToken.comment(CommentStyle.JAVADOC));
  3136         if (defs.isEmpty())
  3142         if (defs.isEmpty())
  3137             storeEnd(toplevel, S.prevToken().endPos);
  3143             storeEnd(toplevel, S.prevToken().endPos);
  3138         if (keepDocComments)
  3144         if (keepDocComments)