From 3ff5a781db1c9b5105b1890fe495c17dc382af5d Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Mon, 9 Oct 2023 17:53:57 +0000 Subject: [PATCH] 8317693: Unused parameter to Tokens.Token.comment method Reviewed-by: iris, jlahoda --- .../sun/tools/javac/parser/JavacParser.java | 29 +++++++++---------- .../com/sun/tools/javac/parser/Tokens.java | 2 +- .../share/classes/jdk/jshell/ReplParser.java | 7 ++--- .../sampleapi/generator/Documentifier.java | 4 +-- .../javac/parser/extend/TrialParser.java | 8 ++--- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index 6238daf83d4..15d648a867e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -40,7 +40,6 @@ import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Source.Feature; import com.sun.tools.javac.file.PathFileObject; import com.sun.tools.javac.parser.Tokens.*; -import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Fragments; import com.sun.tools.javac.resources.CompilerProperties.Warnings; @@ -2819,7 +2818,7 @@ public class JavacParser implements Parser { return List.of(parseSimpleStatement()); case MONKEYS_AT: case FINAL: { - dc = token.comment(CommentStyle.JAVADOC); + dc = token.docComment(); JCModifiers mods = modifiersOpt(); if (isDeclaration()) { return List.of(classOrRecordOrInterfaceOrEnumDeclaration(mods, dc)); @@ -2829,19 +2828,19 @@ public class JavacParser implements Parser { } } case ABSTRACT: case STRICTFP: { - dc = token.comment(CommentStyle.JAVADOC); + dc = token.docComment(); JCModifiers mods = modifiersOpt(); return List.of(classOrRecordOrInterfaceOrEnumDeclaration(mods, dc)); } case INTERFACE: case CLASS: - dc = token.comment(CommentStyle.JAVADOC); + dc = token.docComment(); return List.of(classOrRecordOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); case ENUM: if (!allowRecords) { log.error(DiagnosticFlag.SYNTAX, token.pos, Errors.LocalEnum); } - dc = token.comment(CommentStyle.JAVADOC); + dc = token.docComment(); return List.of(classOrRecordOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); case IDENTIFIER: if (token.name() == names.yield && allowYieldStatement) { @@ -2898,17 +2897,17 @@ public class JavacParser implements Parser { nextToken(); nextToken(); nextToken(); - return List.of(classOrRecordOrInterfaceOrEnumDeclaration(modifiersOpt(), token.comment(CommentStyle.JAVADOC))); + return List.of(classOrRecordOrInterfaceOrEnumDeclaration(modifiersOpt(), token.docComment())); } else if (isSealedClassStart(true)) { checkSourceLevel(Feature.SEALED_CLASSES); log.error(token.pos, Errors.SealedOrNonSealedLocalClassesNotAllowed); nextToken(); - return List.of(classOrRecordOrInterfaceOrEnumDeclaration(modifiersOpt(), token.comment(CommentStyle.JAVADOC))); + return List.of(classOrRecordOrInterfaceOrEnumDeclaration(modifiersOpt(), token.docComment())); } } } if (isRecordStart() && allowRecords) { - dc = token.comment(CommentStyle.JAVADOC); + dc = token.docComment(); return List.of(recordDeclaration(F.at(pos).Modifiers(0), dc)); } else { Token prevToken = token; @@ -3911,7 +3910,7 @@ public class JavacParser implements Parser { JCExpression pid = qualident(false); accept(SEMI); JCPackageDecl pd = toP(F.at(packagePos).PackageDecl(annotations, pid)); - attach(pd, firstToken.comment(CommentStyle.JAVADOC)); + attach(pd, firstToken.docComment()); consumedToplevelDoc = true; defs.append(pd); } @@ -3946,9 +3945,9 @@ public class JavacParser implements Parser { seenImport = true; defs.append(importDeclaration()); } else { - Comment docComment = token.comment(CommentStyle.JAVADOC); + Comment docComment = token.docComment(); if (firstTypeDecl && !seenImport && !seenPackage) { - docComment = firstToken.comment(CommentStyle.JAVADOC); + docComment = firstToken.docComment(); consumedToplevelDoc = true; } if (mods != null || token.kind != SEMI) @@ -4015,7 +4014,7 @@ public class JavacParser implements Parser { List topLevelDefs = isUnnamedClass ? constructUnnamedClass(defs.toList()) : defs.toList(); JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(topLevelDefs); if (!consumedToplevelDoc) - attach(toplevel, firstToken.comment(CommentStyle.JAVADOC)); + attach(toplevel, firstToken.docComment()); if (defs.isEmpty()) storeEnd(toplevel, S.prevToken().endPos); if (keepDocComments) @@ -4500,7 +4499,7 @@ public class JavacParser implements Parser { /** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ] */ JCTree enumeratorDeclaration(Name enumName) { - Comment dc = token.comment(CommentStyle.JAVADOC); + Comment dc = token.docComment(); int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM; if (token.deprecatedFlag()) { flags |= Flags.DEPRECATED; @@ -4605,7 +4604,7 @@ public class JavacParser implements Parser { nextToken(); return List.nil(); } else { - Comment dc = token.comment(CommentStyle.JAVADOC); + Comment dc = token.docComment(); int pos = token.pos; mods = modifiersOpt(mods); if (isDeclaration()) { @@ -4738,7 +4737,7 @@ public class JavacParser implements Parser { private List topLevelMethodOrFieldDeclaration(JCModifiers mods) throws AssertionError { int topPos = token.pos; int pos = token.pos; - Comment dc = token.comment(CommentStyle.JAVADOC); + Comment dc = token.docComment(); List typarams = typeParametersOpt(); // if there are type parameters but no modifiers, save the start diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java index 864696e95c9..b6be0a84b7d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java @@ -358,7 +358,7 @@ public class Tokens { * Preserve classic semantics - if multiple javadocs are found on the token * the last one is returned */ - public Comment comment(Comment.CommentStyle style) { + public Comment docComment() { List comments = getComments(Comment.CommentStyle.JAVADOC); return comments.isEmpty() ? null : diff --git a/src/jdk.jshell/share/classes/jdk/jshell/ReplParser.java b/src/jdk.jshell/share/classes/jdk/jshell/ReplParser.java index 4177e667710..2968bc3e173 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/ReplParser.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/ReplParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,6 @@ import com.sun.tools.javac.code.Source.Feature; import com.sun.tools.javac.code.TypeTag; import com.sun.tools.javac.parser.JavacParser; import com.sun.tools.javac.parser.Tokens.Comment; -import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; import com.sun.tools.javac.parser.Tokens.Token; import com.sun.tools.javac.resources.CompilerProperties.Errors; import static com.sun.tools.javac.parser.Tokens.TokenKind.CLASS; @@ -115,9 +114,9 @@ class ReplParser extends JavacParser { seenImport = true; defs.append(importDeclaration()); } else { - Comment docComment = token.comment(CommentStyle.JAVADOC); + Comment docComment = token.docComment(); if (firstTypeDecl && !seenImport && !seenPackage) { - docComment = firstToken.comment(CommentStyle.JAVADOC); + docComment = firstToken.docComment(); } List udefs = replUnit(mods, docComment); // if (def instanceof JCExpressionStatement) diff --git a/test/langtools/jdk/javadoc/tool/sampleapi/lib/sampleapi/generator/Documentifier.java b/test/langtools/jdk/javadoc/tool/sampleapi/lib/sampleapi/generator/Documentifier.java index 2f7a974bb06..d06cb6e31a5 100644 --- a/test/langtools/jdk/javadoc/tool/sampleapi/lib/sampleapi/generator/Documentifier.java +++ b/test/langtools/jdk/javadoc/tool/sampleapi/lib/sampleapi/generator/Documentifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -114,7 +114,7 @@ class Documentifier { Scanner scanner = scanners.newScanner(docComment, true); scanner.nextToken(); Token token = scanner.token(); - return token.comment(CommentStyle.JAVADOC); + return token.docComment(); } // provide package comment data ONLY diff --git a/test/langtools/tools/javac/parser/extend/TrialParser.java b/test/langtools/tools/javac/parser/extend/TrialParser.java index 3fcef968b52..539676a90fb 100644 --- a/test/langtools/tools/javac/parser/extend/TrialParser.java +++ b/test/langtools/tools/javac/parser/extend/TrialParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -95,7 +95,7 @@ class TrialParser extends JavacParser { JCExpression pid = qualident(false); accept(SEMI); JCPackageDecl pd = F.at(packagePos).PackageDecl(annotations, pid); - attach(pd, firstToken.comment(CommentStyle.JAVADOC)); + attach(pd, firstToken.docComment()); storeEnd(pd, token.pos); defs.append(pd); } @@ -114,9 +114,9 @@ class TrialParser extends JavacParser { defs.append(importDeclaration()); break; } else { - Comment docComment = token.comment(CommentStyle.JAVADOC); + Comment docComment = token.docComment(); if (firstTypeDecl && !seenImport && !seenPackage) { - docComment = firstToken.comment(CommentStyle.JAVADOC); + docComment = firstToken.docComment(); } List udefs = aUnit(mods, docComment); for (JCTree def : udefs) {