27 |
27 |
28 import java.util.*; |
28 import java.util.*; |
29 |
29 |
30 import com.sun.tools.javac.code.*; |
30 import com.sun.tools.javac.code.*; |
31 import com.sun.tools.javac.parser.Tokens.*; |
31 import com.sun.tools.javac.parser.Tokens.*; |
|
32 import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; |
32 import com.sun.tools.javac.tree.*; |
33 import com.sun.tools.javac.tree.*; |
33 import com.sun.tools.javac.tree.JCTree.*; |
34 import com.sun.tools.javac.tree.JCTree.*; |
34 import com.sun.tools.javac.util.*; |
35 import com.sun.tools.javac.util.*; |
35 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
1582 case CONTINUE: case SEMI: case ELSE: case FINALLY: case CATCH: |
1583 case CONTINUE: case SEMI: case ELSE: case FINALLY: case CATCH: |
1583 stats.append(parseStatement()); |
1584 stats.append(parseStatement()); |
1584 break; |
1585 break; |
1585 case MONKEYS_AT: |
1586 case MONKEYS_AT: |
1586 case FINAL: { |
1587 case FINAL: { |
1587 String dc = token.docComment; |
1588 String dc = token.comment(CommentStyle.JAVADOC); |
1588 JCModifiers mods = modifiersOpt(); |
1589 JCModifiers mods = modifiersOpt(); |
1589 if (token.kind == INTERFACE || |
1590 if (token.kind == INTERFACE || |
1590 token.kind == CLASS || |
1591 token.kind == CLASS || |
1591 allowEnums && token.kind == ENUM) { |
1592 allowEnums && token.kind == ENUM) { |
1592 stats.append(classOrInterfaceOrEnumDeclaration(mods, dc)); |
1593 stats.append(classOrInterfaceOrEnumDeclaration(mods, dc)); |
1599 accept(SEMI); |
1600 accept(SEMI); |
1600 } |
1601 } |
1601 break; |
1602 break; |
1602 } |
1603 } |
1603 case ABSTRACT: case STRICTFP: { |
1604 case ABSTRACT: case STRICTFP: { |
1604 String dc = token.docComment; |
1605 String dc = token.comment(CommentStyle.JAVADOC); |
1605 JCModifiers mods = modifiersOpt(); |
1606 JCModifiers mods = modifiersOpt(); |
1606 stats.append(classOrInterfaceOrEnumDeclaration(mods, dc)); |
1607 stats.append(classOrInterfaceOrEnumDeclaration(mods, dc)); |
1607 break; |
1608 break; |
1608 } |
1609 } |
1609 case INTERFACE: |
1610 case INTERFACE: |
1610 case CLASS: |
1611 case CLASS: |
1611 String dc = token.docComment; |
1612 String dc = token.comment(CommentStyle.JAVADOC); |
1612 stats.append(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); |
1613 stats.append(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); |
1613 break; |
1614 break; |
1614 case ENUM: |
1615 case ENUM: |
1615 case ASSERT: |
1616 case ASSERT: |
1616 if (allowEnums && token.kind == ENUM) { |
1617 if (allowEnums && token.kind == ENUM) { |
1617 error(token.pos, "local.enum"); |
1618 error(token.pos, "local.enum"); |
1618 dc = token.docComment; |
1619 dc = token.comment(CommentStyle.JAVADOC); |
1619 stats.append(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); |
1620 stats.append(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); |
1620 break; |
1621 break; |
1621 } else if (allowAsserts && token.kind == ASSERT) { |
1622 } else if (allowAsserts && token.kind == ASSERT) { |
1622 stats.append(parseStatement()); |
1623 stats.append(parseStatement()); |
1623 break; |
1624 break; |
2269 } |
2270 } |
2270 if (checkForImports && mods == null && token.kind == IMPORT) { |
2271 if (checkForImports && mods == null && token.kind == IMPORT) { |
2271 seenImport = true; |
2272 seenImport = true; |
2272 defs.append(importDeclaration()); |
2273 defs.append(importDeclaration()); |
2273 } else { |
2274 } else { |
2274 String docComment = token.docComment; |
2275 String docComment = token.comment(CommentStyle.JAVADOC); |
2275 if (firstTypeDecl && !seenImport && !seenPackage) { |
2276 if (firstTypeDecl && !seenImport && !seenPackage) { |
2276 docComment = firstToken.docComment; |
2277 docComment = firstToken.comment(CommentStyle.JAVADOC); |
2277 consumedToplevelDoc = true; |
2278 consumedToplevelDoc = true; |
2278 } |
2279 } |
2279 JCTree def = typeDeclaration(mods, docComment); |
2280 JCTree def = typeDeclaration(mods, docComment); |
2280 if (def instanceof JCExpressionStatement) |
2281 if (def instanceof JCExpressionStatement) |
2281 def = ((JCExpressionStatement)def).expr; |
2282 def = ((JCExpressionStatement)def).expr; |
2286 firstTypeDecl = false; |
2287 firstTypeDecl = false; |
2287 } |
2288 } |
2288 } |
2289 } |
2289 JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(packageAnnotations, pid, defs.toList()); |
2290 JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(packageAnnotations, pid, defs.toList()); |
2290 if (!consumedToplevelDoc) |
2291 if (!consumedToplevelDoc) |
2291 attach(toplevel, firstToken.docComment); |
2292 attach(toplevel, firstToken.comment(CommentStyle.JAVADOC)); |
2292 if (defs.elems.isEmpty()) |
2293 if (defs.elems.isEmpty()) |
2293 storeEnd(toplevel, S.prevToken().endPos); |
2294 storeEnd(toplevel, S.prevToken().endPos); |
2294 if (keepDocComments) |
2295 if (keepDocComments) |
2295 toplevel.docComments = docComments; |
2296 toplevel.docComments = docComments; |
2296 if (keepLineMap) |
2297 if (keepLineMap) |
2496 } |
2497 } |
2497 |
2498 |
2498 /** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ] |
2499 /** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ] |
2499 */ |
2500 */ |
2500 JCTree enumeratorDeclaration(Name enumName) { |
2501 JCTree enumeratorDeclaration(Name enumName) { |
2501 String dc = token.docComment; |
2502 String dc = token.comment(CommentStyle.JAVADOC); |
2502 int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM; |
2503 int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM; |
2503 if (token.deprecatedFlag) { |
2504 if (token.deprecatedFlag()) { |
2504 flags |= Flags.DEPRECATED; |
2505 flags |= Flags.DEPRECATED; |
2505 } |
2506 } |
2506 int pos = token.pos; |
2507 int pos = token.pos; |
2507 List<JCAnnotation> annotations = annotationsOpt(); |
2508 List<JCAnnotation> annotations = annotationsOpt(); |
2508 JCModifiers mods = F.at(annotations.isEmpty() ? Position.NOPOS : pos).Modifiers(flags, annotations); |
2509 JCModifiers mods = F.at(annotations.isEmpty() ? Position.NOPOS : pos).Modifiers(flags, annotations); |
2585 protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { |
2586 protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { |
2586 if (token.kind == SEMI) { |
2587 if (token.kind == SEMI) { |
2587 nextToken(); |
2588 nextToken(); |
2588 return List.<JCTree>nil(); |
2589 return List.<JCTree>nil(); |
2589 } else { |
2590 } else { |
2590 String dc = token.docComment; |
2591 String dc = token.comment(CommentStyle.JAVADOC); |
2591 int pos = token.pos; |
2592 int pos = token.pos; |
2592 JCModifiers mods = modifiersOpt(); |
2593 JCModifiers mods = modifiersOpt(); |
2593 if (token.kind == CLASS || |
2594 if (token.kind == CLASS || |
2594 token.kind == INTERFACE || |
2595 token.kind == INTERFACE || |
2595 allowEnums && token.kind == ENUM) { |
2596 allowEnums && token.kind == ENUM) { |