diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java index 69c8e9e62155..3b189799368b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java @@ -256,79 +256,16 @@ public long getEndPosition(CompilationUnitTree file, Tree tree) { @Override @DefinedBy(Api.COMPILER_TREE) public long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) { - return ((DCTree) tree).getSourcePosition((DCDocComment) comment); + DCDocComment dcComment = (DCDocComment) comment; + DCTree dcTree = (DCTree) tree; + return dcComment.getSourcePosition(dcTree.getStartPosition()); } - @Override @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough") + + @Override @DefinedBy(Api.COMPILER_TREE) public long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) { DCDocComment dcComment = (DCDocComment) comment; - if (tree instanceof DCEndPosTree dcEndPosTree) { - int endPos = dcEndPosTree.getEndPos(dcComment); - - if (endPos != Position.NOPOS) { - return endPos; - } - } - int correction = 0; - switch (tree.getKind()) { - case TEXT: - DCText text = (DCText) tree; - - return dcComment.comment.getSourcePos(text.pos + text.text.length()); - case ERRONEOUS: - DCErroneous err = (DCErroneous) tree; - - return dcComment.comment.getSourcePos(err.pos + err.body.length()); - case IDENTIFIER: - DCIdentifier ident = (DCIdentifier) tree; - - return dcComment.comment.getSourcePos(ident.pos + (ident.name != names.error ? ident.name.length() : 0)); - case PARAM: - DCParam param = (DCParam) tree; - - if (param.isTypeParameter && param.getDescription().isEmpty()) { - correction = 1; - } - case AUTHOR: case DEPRECATED: case RETURN: case SEE: - case SERIAL: case SERIAL_DATA: case SERIAL_FIELD: case SINCE: - case THROWS: case UNKNOWN_BLOCK_TAG: case VERSION: { - DocTree last = getLastChild(tree); - - if (last != null) { - return getEndPosition(file, comment, last) + correction; - } - - int pos; - String name; - if (tree.getKind() == DocTree.Kind.RETURN) { - DCTree.DCReturn dcReturn = (DCTree.DCReturn) tree; - pos = dcReturn.pos; - name = dcReturn.getTagName(); - } else { - DCBlockTag block = (DCBlockTag) tree; - pos = block.pos; - name = block.getTagName(); - } - - return dcComment.comment.getSourcePos(pos + name.length() + 1); - } - case ENTITY: { - DCEntity endEl = (DCEntity) tree; - return dcComment.comment.getSourcePos(endEl.pos + (endEl.name != names.error ? endEl.name.length() : 0) + 2); - } - case COMMENT: { - DCComment endEl = (DCComment) tree; - return dcComment.comment.getSourcePos(endEl.pos + endEl.body.length()); - } - default: - DocTree last = getLastChild(tree); - - if (last != null) { - return getEndPosition(file, comment, last); - } - break; - } - - return Position.NOPOS; + DCTree dcTree = (DCTree) tree; + return dcComment.getSourcePosition(dcTree.getEndPosition()); } }; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java index ac018124d118..5c7e10693261 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -43,6 +43,7 @@ import com.sun.tools.javac.tree.DCTree.DCText; import com.sun.tools.javac.tree.DocTreeMaker; import com.sun.tools.javac.util.DiagnosticSource; +import com.sun.tools.javac.util.JCDiagnostic; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; @@ -62,14 +63,21 @@ public class DocCommentParser { static class ParseException extends Exception { private static final long serialVersionUID = 0; + final int pos; + ParseException(String key) { + this(Position.NOPOS, key); + } + ParseException(int pos, String key) { super(key); + this.pos = pos; } } - private enum Phase {PREAMBLE, BODY, POSTAMBLE} + private enum Phase { PREAMBLE, BODY, POSTAMBLE } private final ParserFactory fac; + private final JCDiagnostic.Factory diags; private final DiagnosticSource diagSource; private final Comment comment; private final DocTreeMaker m; @@ -96,6 +104,7 @@ private enum Phase {PREAMBLE, BODY, POSTAMBLE} public DocCommentParser(ParserFactory fac, DiagnosticSource diagSource, Comment comment, boolean isFileContent) { this.fac = fac; + this.diags = fac.log.diags; this.diagSource = diagSource; this.comment = comment; names = fac.names; @@ -126,18 +135,13 @@ public DCDocComment parse() { List tags = blockTags(); List postamble = isFileContent ? blockContent(Phase.POSTAMBLE) : List.nil(); - int pos = Position.NOPOS; - if (!preamble.isEmpty()) - pos = preamble.head.pos; - else if (!body.isEmpty()) - pos = body.head.pos; - else if (!tags.isEmpty()) - pos = tags.head.pos; - else if (!postamble.isEmpty()) - pos = postamble.head.pos; - - DCDocComment dc = m.at(pos).newDocCommentTree(comment, body, tags, preamble, postamble); - return dc; + int pos = !preamble.isEmpty() ? preamble.head.pos + : !body.isEmpty() ? body.head.pos + : !tags.isEmpty() ? tags.head.pos + : !postamble.isEmpty() ? postamble.head.pos + : 0; + + return m.at(pos).newDocCommentTree(comment, body, tags, preamble, postamble); } void nextChar() { @@ -281,7 +285,7 @@ protected DCTree blockTag() { return erroneous("dc.no.tag.name", p); } catch (ParseException e) { blockContent(); - return erroneous(e.getMessage(), p); + return erroneous(e.getMessage(), p, e.pos); } } @@ -334,7 +338,7 @@ protected DCTree inlineTag() { } } } catch (ParseException e) { - return erroneous(e.getMessage(), p); + return erroneous(e.getMessage(), p, e.pos); } } @@ -471,18 +475,15 @@ protected DCReference reference(boolean allowMember) throws ParseException { ref.moduleName, ref.qualExpr, ref.member, ref.paramTypes) .setEndPos(bp); - } catch (ReferenceParser.ParseException parseException) { - throw new ParseException(parseException.getMessage()); + } catch (ReferenceParser.ParseException pe) { + throw new ParseException(pos + pe.pos, pe.getMessage()); } } /** - * Read Java identifier - * Matching pairs of { } are skipped; the text is terminated by the first - * unmatched }. It is an error if the beginning of the next tag is detected. + * Reads a Java identifier. */ - @SuppressWarnings("fallthrough") protected DCIdentifier identifier() throws ParseException { skipWhitespace(); int pos = bp; @@ -496,10 +497,9 @@ protected DCIdentifier identifier() throws ParseException { } /** - * Read a quoted string. + * Reads a quoted string. * It is an error if the beginning of the next tag is detected. */ - @SuppressWarnings("fallthrough") protected DCText quotedString() { int pos = bp; nextChar(); @@ -530,7 +530,7 @@ protected DCText quotedString() { } /** - * Read a term (that is, one word). + * Reads a term (that is, one word). * It is an error if the beginning of the next tag is detected. */ @SuppressWarnings("fallthrough") @@ -567,7 +567,7 @@ protected DCText inlineWord() { } /** - * Read general text content of an inline tag, including HTML entities and elements. + * Reads general text content of an inline tag, including HTML entities and elements. * Matching pairs of { } are skipped; the text is terminated by the first * unmatched }. It is an error if the beginning of the next tag is detected. */ @@ -656,7 +656,7 @@ protected void entity(ListBuffer list) { } /** - * Read an HTML entity. + * Reads an HTML entity. * {@literal &identifier; } or {@literal &#digits; } or {@literal &#xhex-digits; } */ protected DCTree entity() { @@ -966,7 +966,33 @@ protected void addPendingText(ListBuffer list, int textEnd) { } } + /** + * Creates an {@code ErroneousTree} node, for a range of text starting at a given position, + * ending at the last non-whitespace character before the current position, + * and with the preferred position set to the last character within that range. + * + * @param code the resource key for the error message + * @param pos the starting position + * + * @return the {@code ErroneousTree} node + */ protected DCErroneous erroneous(String code, int pos) { + return erroneous(code, pos, Position.NOPOS); + } + + /** + * Creates an {@code ErroneousTree} node, for a range of text starting at a given position, + * ending at the last non-whitespace character before the current position, + * and with a given preferred position. + * + * @param code the resource key for the error message + * @param pos the starting position + * @param pref the preferred position for the node, or {@code NOPOS} to use the default value + * as the last character of the range + * + * @return the {@code ErroneousTree} node + */ + protected DCErroneous erroneous(String code, int pos, int pref) { int i = bp - 1; loop: while (i > pos) { @@ -981,8 +1007,14 @@ protected DCErroneous erroneous(String code, int pos) { } i--; } + if (pref == Position.NOPOS) { + pref = i; + } + int end = i + 1; textStart = -1; - return m.at(pos).newErroneousTree(newString(pos, i + 1), diagSource, code); + JCDiagnostic.DiagnosticPosition dp = DCTree.createDiagnosticPosition(comment, pos, pref, end); + JCDiagnostic diag = diags.error(null, diagSource, dp, code); + return m.at(pos).newErroneousTree(newString(pos, end), diag).setPrefPos(pref); } protected boolean isIdentifierStart(char ch) { @@ -1162,7 +1194,7 @@ public DCTree parse(int pos) throws ParseException { } inlineText(WhitespaceRetentionPolicy.REMOVE_ALL); // skip unexpected content nextChar(); - throw new ParseException("dc.unexpected.content"); + throw new ParseException(pos, "dc.unexpected.content"); } }, @@ -1219,7 +1251,7 @@ public DCTree parse(int pos) throws ParseException { } inlineText(WhitespaceRetentionPolicy.REMOVE_ALL); // skip unexpected content nextChar(); - throw new ParseException("dc.unexpected.content"); + throw new ParseException(pos, "dc.unexpected.content"); } }, diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ReferenceParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ReferenceParser.java index c57b3b6eb199..65958282275f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ReferenceParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ReferenceParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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,11 +30,17 @@ import com.sun.source.util.TreeScanner; import com.sun.tools.javac.parser.Tokens.TokenKind; import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.util.DiagnosticSource; +import com.sun.tools.javac.util.JCDiagnostic; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Name; +import javax.tools.JavaFileObject; +import java.util.Locale; +import java.util.Queue; + /** * A utility class to parse a string in a doc comment containing a * reference to an API element, such as a type, field or method. @@ -71,8 +77,11 @@ public static class Reference { */ public static class ParseException extends Exception { private static final long serialVersionUID = 0; - ParseException(String message) { + final int pos; + + ParseException(int pos, String message) { super(message); + this.pos = pos; } } @@ -100,106 +109,157 @@ public Reference parse(String sig) throws ParseException { Name member; List paramTypes; - Log.DeferredDiagnosticHandler deferredDiagnosticHandler - = new Log.DeferredDiagnosticHandler(fac.log); + Log.DeferredDiagnosticHandler dh = new Log.DeferredDiagnosticHandler(fac.log); try { int slash = sig.indexOf("/"); - int hash = sig.indexOf("#", slash + 1); + int afterSlash = slash + 1; + int hash = sig.indexOf("#", afterSlash); + int afterHash = hash + 1; int lparen = sig.indexOf("(", Math.max(slash, hash) + 1); - if (slash > -1) { - moduleName = parseModule(sig.substring(0, slash)); - } else { - moduleName = null; - } - if (slash > 0 && sig.length() == slash + 1) { + int afterLparen = lparen + 1; + + moduleName = switch (slash) { + case -1 -> null; + case 0 -> throw new ParseException(0, "dc.ref.syntax.error"); + default -> parseModule(sig, 0, slash, dh); + }; + + if (slash > 0 && sig.length() == afterSlash) { qualExpr = null; member = null; } else if (hash == -1) { if (lparen == -1) { - qualExpr = parseType(sig.substring(slash + 1)); + qualExpr = parseType(sig, afterSlash, sig.length(), dh); member = null; } else { qualExpr = null; - member = parseMember(sig.substring(slash + 1, lparen)); + member = parseMember(sig, afterSlash, lparen, dh); } } else { - qualExpr = (hash == slash + 1) ? null : parseType(sig.substring(slash + 1, hash)); - if (lparen == -1) - member = parseMember(sig.substring(hash + 1)); - else - member = parseMember(sig.substring(hash + 1, lparen)); + qualExpr = (hash == afterSlash) ? null : parseType(sig, afterSlash, hash, dh); + if (lparen == -1) { + member = parseMember(sig, afterHash, sig.length(), dh); + } else { + member = parseMember(sig, afterHash, lparen, dh); + } } - if (lparen < 0) { + if (lparen == -1) { paramTypes = null; } else { int rparen = sig.indexOf(")", lparen); - if (rparen != sig.length() - 1) - throw new ParseException("dc.ref.bad.parens"); - paramTypes = parseParams(sig.substring(lparen + 1, rparen)); + if (rparen != sig.length() - 1) { + throw new ParseException(rparen, "dc.ref.bad.parens"); + } + paramTypes = parseParams(sig, afterLparen, rparen, dh); } - if (!deferredDiagnosticHandler.getDiagnostics().isEmpty()) - throw new ParseException("dc.ref.syntax.error"); + assert dh.getDiagnostics().isEmpty(); } finally { - fac.log.popDiagnosticHandler(deferredDiagnosticHandler); + fac.log.popDiagnosticHandler(dh); } return new Reference(moduleName, qualExpr, member, paramTypes); } - private JCTree.JCExpression parseModule(String s) throws ParseException { - JavacParser p = fac.newParser(s, false, false, false); - JCTree.JCExpression expr = p.qualident(false); - if (p.token().kind != TokenKind.EOF) - throw new ParseException("dc.ref.unexpected.input"); - return expr; + private JCTree.JCExpression parseModule(String sig, int beginIndex, int endIndex, Log.DeferredDiagnosticHandler dh) throws ParseException { + String s = sig.substring(beginIndex, endIndex); + JavaFileObject prev = fac.log.useSource(null); + try { + JavacParser p = fac.newParser(s, false, false, false); + JCTree.JCExpression expr = p.qualident(false); + if (p.token().kind != TokenKind.EOF) { + throw new ParseException(beginIndex + p.token().pos, "dc.ref.unexpected.input"); + } + checkDiags(dh, beginIndex); + return expr; + } finally { + fac.log.useSource(prev); + } } - private JCTree parseType(String s) throws ParseException { - JavacParser p = fac.newParser(s, false, false, false); - JCTree tree = p.parseType(); - if (p.token().kind != TokenKind.EOF) - throw new ParseException("dc.ref.unexpected.input"); - return tree; + private JCTree parseType(String sig, int beginIndex, int endIndex, Log.DeferredDiagnosticHandler dh) throws ParseException { + String s = sig.substring(beginIndex, endIndex); + JavaFileObject prev = fac.log.useSource(null); + try { + JavacParser p = fac.newParser(s, false, false, false); + JCTree tree = p.parseType(); + if (p.token().kind != TokenKind.EOF) { + throw new ParseException(beginIndex + p.token().pos, "dc.ref.unexpected.input"); + } + checkDiags(dh, beginIndex); + return tree; + } finally { + fac.log.useSource(prev); + } } - private Name parseMember(String s) throws ParseException { - JavacParser p = fac.newParser(s, false, false, false); - Name name = p.ident(); - if (p.token().kind != TokenKind.EOF) - throw new ParseException("dc.ref.unexpected.input"); - return name; + private Name parseMember(String sig, int beginIndex, int endIndex, Log.DeferredDiagnosticHandler dh) throws ParseException { + String s = sig.substring(beginIndex, endIndex); + JavaFileObject prev = fac.log.useSource(null); + try { + JavacParser p = fac.newParser(s, false, false, false); + Name name = p.ident(); + if (p.token().kind != TokenKind.EOF) { + throw new ParseException(beginIndex + p.token().pos, "dc.ref.unexpected.input"); + } + checkDiags(dh, beginIndex); + return name; + } finally { + fac.log.useSource(prev); + } } - private List parseParams(String s) throws ParseException { - if (s.trim().isEmpty()) + private List parseParams(String sig, int beginIndex, int endIndex, Log.DeferredDiagnosticHandler dh) throws ParseException { + String s = sig.substring(beginIndex, endIndex); + if (s.isBlank()) { return List.nil(); + } - JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false); - ListBuffer paramTypes = new ListBuffer<>(); - paramTypes.add(p.parseType()); - - if (p.token().kind == TokenKind.IDENTIFIER) - p.nextToken(); - - while (p.token().kind == TokenKind.COMMA) { - p.nextToken(); + JavaFileObject prev = fac.log.useSource(null); + try { + JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false); + ListBuffer paramTypes = new ListBuffer<>(); paramTypes.add(p.parseType()); - if (p.token().kind == TokenKind.IDENTIFIER) + if (p.token().kind == TokenKind.IDENTIFIER) { p.nextToken(); - } + } + + while (p.token().kind == TokenKind.COMMA) { + p.nextToken(); + paramTypes.add(p.parseType()); + + if (p.token().kind == TokenKind.IDENTIFIER) { + p.nextToken(); + } + } + + if (p.token().kind != TokenKind.EOF) { + throw new ParseException(p.token().pos, "dc.ref.unexpected.input"); + } + + Tree typeAnno = new TypeAnnotationFinder().scan(paramTypes, null); + if (typeAnno != null) { + int annoPos = ((JCTree) typeAnno).getStartPosition(); + throw new ParseException(beginIndex + annoPos, "dc.ref.annotations.not.allowed"); + } - if (p.token().kind != TokenKind.EOF) - throw new ParseException("dc.ref.unexpected.input"); + checkDiags(dh, beginIndex); - if (new TypeAnnotationFinder().scan(paramTypes, null) != null) - throw new ParseException("dc.ref.annotations.not.allowed"); + return paramTypes.toList(); + } finally { + fac.log.useSource(prev); + } + } - return paramTypes.toList(); + private void checkDiags(Log.DeferredDiagnosticHandler h, int offset) throws ParseException { + JCDiagnostic d = h.getDiagnostics().peek(); + if (d != null) { + throw new ParseException(offset + ((int) d.getPosition()), "dc.ref.syntax.error"); + } } static class TypeAnnotationFinder extends TreeScanner { @@ -213,4 +273,4 @@ public Tree reduce(Tree t1, Tree t2) { return t1 != null ? t1 : t2; } } -} \ No newline at end of file +} diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java index ec9443dc73aa..85b35c64af62 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java @@ -25,26 +25,57 @@ package com.sun.tools.javac.tree; +import java.io.IOException; +import java.io.StringWriter; +import java.util.List; + +import javax.lang.model.element.Name; +import javax.lang.model.util.Elements; import javax.tools.Diagnostic; +import javax.tools.JavaFileObject; import com.sun.source.doctree.*; +import com.sun.source.util.DocTreeScanner; + import com.sun.tools.javac.parser.Tokens.Comment; import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.DefinedBy; import com.sun.tools.javac.util.DefinedBy.Api; -import com.sun.tools.javac.util.DiagnosticSource; import com.sun.tools.javac.util.JCDiagnostic; -import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; import com.sun.tools.javac.util.Position; -import java.io.IOException; -import java.io.StringWriter; -import java.util.List; - -import javax.lang.model.element.Name; -import javax.tools.JavaFileObject; +import static com.sun.tools.javac.util.Position.NOPOS; /** + * + * Root class for abstract syntax documentation tree nodes. It provides definitions + * for specific tree nodes as subclasses nested inside. + * + * Apart from the top-level {@link DCDocComment} node, generally nodes fall into + * three groups: + *
    + *
  • Leaf nodes, such as {@link DCIdentifier}, {@link DCText} + *
  • Inline tag nodes, such as {@link DCLink}, {@link DCLiteral} + *
  • Block tag nodes, such as {@link DCParam}, {@link DCThrows} + *
+ * + * Trees are typically wide and shallow, without a significant amount of nesting. + * + * Nodes have various associated positions: + *
    + *
  • the {@link #pos position} of the first character that is unique to this node, + * and not part of any child node + *
  • the {@link #getStartPosition start} of the range of characters for this node + *
  • the "{@link #getPreferredPosition() preferred}" position in the range of characters + * for this node + *
  • the {@link #getEndPosition() end} of the range of characters for this node + *
+ * + * All values are relative to the beginning of the + * {@link Elements#getDocComment comment text} in which they appear. + * To convert a value to the position in the enclosing source text, + * use {@link DCDocComment#getSourcePosition(int)}. + * *

This is NOT part of any supported API. * If you write code that depends on this, you do so at your own risk. * This code and its internal interfaces are subject to change or @@ -53,41 +84,150 @@ public abstract class DCTree implements DocTree { /** - * The position in the comment string. - * Use {@link #getSourcePosition getSourcePosition} to convert + * The position of the first character that is unique to this node. + * It is normally set by the methods in {@link DocTreeMaker}. + * + * The value is relative to the beginning of the comment text. + * Use {@link DCDocComment#getSourcePosition(int)} to convert * it to a position in the source file. * - * TODO: why not simply translate all these values into - * source file positions? Is it useful to have string-offset - * positions as well? + * @see #getStartPosition() + * @see #getPreferredPosition() + * @see #getEndPosition() */ public int pos; /** - * {@return the source position for this tree node} + * {@return a {@code DiagnosticPosition} for this node} + * The method may be used when reporting diagnostics for this node. * - * @param dc the enclosing doc comment + * @param dc the enclosing comment, used to convert comment-based positions + * to file-based positions */ - public long getSourcePosition(DCDocComment dc) { - return dc.comment.getSourcePos(pos); + public JCDiagnostic.DiagnosticPosition pos(DCDocComment dc) { + return createDiagnosticPosition(dc.comment, getStartPosition(), getPreferredPosition(), getEndPosition()); } /** - * {@return the source position for position relative to this tree node} - * This is primarily useful for nodes that wrap a single string child. + * {@return the start position of this tree node} + * + * For most nodes, this is the position of the first character that is unique to this node. * - * @param dc the enclosing doc comment - * @param offset the offset + * The value is relative to the beginning of the comment text. + * Use {@link DCDocComment#getSourcePosition(int)} to convert + * it to a position in the source file. */ - public long getSourcePosition(DCDocComment dc, int offset) { - return dc.comment.getSourcePos(pos + offset); + public int getStartPosition() { + return pos; } - public JCDiagnostic.DiagnosticPosition pos(DCDocComment dc) { - return new SimpleDiagnosticPosition(dc.comment.getSourcePos(pos)); + /** + * {@return the "preferred" position of this tree node} + * + * It is typically the position of the first character that is unique to this node. + * It is the position that is used for the caret in "line and caret" diagnostic messages. + * + * The value is relative to the beginning of the comment text. + * Use {@link DCDocComment#getSourcePosition(int)} to convert + * it to a position in the source file. + */ + public int getPreferredPosition() { + return pos; } - /** Convert a tree to a pretty-printed string. */ + /** + * {@return the end position of the tree node} + * + * The value is typically derived in one of three ways: + *

    + *
  • computed from the start and length of "leaf" nodes, such as {@link TextTree}, + *
  • computed recursively from the end of the last child node, such as for most {@link DCBlockTag block tags}, or + *
  • provided explicitly, such as for subtypes of {@link DCEndPosTree} + *
+ * + * The value is relative to the beginning of the comment text. + * Use {@link DCDocComment#getSourcePosition(int)} to convert + * it to a position in the source file. + */ + public int getEndPosition() { + if (this instanceof DCEndPosTree dcEndPosTree) { + int endPos = dcEndPosTree.getEndPos(); + + if (endPos != NOPOS) { + return endPos; + } + } + + switch (getKind()) { + case TEXT -> { + DCText text = (DCText) this; + return text.pos + text.text.length(); + } + + case ERRONEOUS -> { + DCErroneous err = (DCErroneous) this; + return err.pos + err.body.length(); + } + + case IDENTIFIER -> { + DCIdentifier ident = (DCIdentifier) this; + return ident.pos + ident.name.length(); + } + + case AUTHOR, DEPRECATED, HIDDEN, PARAM, PROVIDES, RETURN, SEE, SERIAL, SERIAL_DATA, SERIAL_FIELD, SINCE, + THROWS, UNKNOWN_BLOCK_TAG, USES, VERSION -> { + DCTree last = getLastChild(); + + if (last != null) { + int correction = (this instanceof DCParam p && p.isTypeParameter && p.getDescription().isEmpty()) ? 1 : 0; + return last.getEndPosition() + correction; + } + + String name = ((BlockTagTree) this).getTagName(); + return this.pos + name.length() + 1; + } + + case ENTITY -> { + DCEntity endEl = (DCEntity) this; + return endEl.pos + endEl.name.length() + 2; + } + + case COMMENT -> { + DCComment endEl = (DCComment) this; + return endEl.pos + endEl.body.length(); + } + + case ATTRIBUTE -> { + DCAttribute attr = (DCAttribute) this; + if (attr.vkind == AttributeTree.ValueKind.EMPTY) { + return attr.pos + attr.name.length(); + } + DCTree last = getLastChild(); + if (last != null) { + return last.getEndPosition() + (attr.vkind == AttributeTree.ValueKind.UNQUOTED ? 0 : 1); + } + } + + case DOC_COMMENT -> { + DCDocComment dc = (DCDocComment) this; + DCTree last = getLastChild(); + return last == null ? dc.pos : last.getEndPosition(); + } + + default -> { + DCTree last = getLastChild(); + if (last != null) { + return last.getEndPosition(); + } + } + } + + return NOPOS; + } + + /** + * Convert a tree to a pretty-printed string. + */ @Override public String toString() { StringWriter s = new StringWriter(); @@ -102,12 +242,64 @@ public String toString() { return s.toString(); } + /** + * {@return the last (right-most) child of this node} + */ + private DCTree getLastChild() { + final DCTree[] last = new DCTree[] {null}; + + accept(new DocTreeScanner() { + @Override @DefinedBy(Api.COMPILER_TREE) + public Void scan(DocTree node, Void p) { + if (node instanceof DCTree dcTree) last[0] = dcTree; + return null; + } + }, null); + + return last[0]; + } + + /** + * {@return a diagnostic position based on the positions in a comment} + * + * The positions are lazily converted to file-based positions, as needed. + * + * @param comment the enclosing comment + * @param start the start position in the comment + * @param pref the preferred position in the comment + * @param end the end position in the comment + */ + public static JCDiagnostic.DiagnosticPosition createDiagnosticPosition(Comment comment, int start, int pref, int end) { + return new JCDiagnostic.DiagnosticPosition() { + + @Override + public JCTree getTree() { + return null; + } + + @Override + public int getStartPosition() { + return comment.getSourcePos(start); + } + + @Override + public int getPreferredPosition() { + return comment.getSourcePos(pref); + } + + @Override + public int getEndPosition(EndPosTable endPosTable) { + return comment.getSourcePos(end); + } + }; + } + public static abstract class DCEndPosTree> extends DCTree { - private int endPos = Position.NOPOS; + private int endPos = NOPOS; - public int getEndPos(DCDocComment dc) { - return dc.comment.getSourcePos(endPos); + public int getEndPos() { + return endPos; } @SuppressWarnings("unchecked") @@ -183,6 +375,10 @@ public List getPreamble() { public List getPostamble() { return postamble; } + + public int getSourcePosition(int index) { + return comment.getSourcePos(index); + } } public static abstract class DCBlockTag extends DCTree implements BlockTagTree { @@ -388,14 +584,11 @@ public Name getName() { } } - public static class DCErroneous extends DCTree implements ErroneousTree, JCDiagnostic.DiagnosticPosition { + public static class DCErroneous extends DCTree implements ErroneousTree { public final String body; public final JCDiagnostic diag; - DCErroneous(String body, JCDiagnostic.Factory diags, DiagnosticSource diagSource, String code, Object... args) { - this.body = body; - this.diag = diags.error(null, diagSource, this, code, args); - } + private int prefPos = NOPOS; DCErroneous(String body, JCDiagnostic diag) { this.body = body; @@ -422,11 +615,6 @@ public Diagnostic getDiagnostic() { return diag; } - @Override - public JCTree getTree() { - return null; - } - @Override public int getStartPosition() { return pos; @@ -434,14 +622,19 @@ public int getStartPosition() { @Override public int getPreferredPosition() { - return pos + body.length() - 1; + return prefPos == NOPOS ? pos + body.length() - 1 : prefPos; } @Override - public int getEndPosition(EndPosTable endPosTable) { + public int getEndPosition() { return pos + body.length(); } + public DCErroneous setPrefPos(int prefPos) { + this.prefPos = prefPos; + return this; + } + } public static class DCHidden extends DCBlockTag implements HiddenTree { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocTreeMaker.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocTreeMaker.java index f8d843ee93c1..b8e5294bbdb2 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocTreeMaker.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocTreeMaker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, 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 @@ -126,9 +126,6 @@ public static DocTreeMaker instance(Context context) { */ public int pos = Position.NOPOS; - /** Access to diag factory for ErroneousTrees. */ - private final JCDiagnostic.Factory diags; - private final JavacTrees trees; /** Utility class to parse reference signatures. */ @@ -138,7 +135,6 @@ public static DocTreeMaker instance(Context context) { */ protected DocTreeMaker(Context context) { context.put(treeMakerKey, this); - diags = JCDiagnostic.Factory.instance(context); this.pos = Position.NOPOS; trees = JavacTrees.instance(context); referenceParser = new ReferenceParser(ParserFactory.instance(context)); @@ -153,13 +149,6 @@ public DocTreeMaker at(int pos) { return this; } - /** Reassign current position. - */ - public DocTreeMaker at(DiagnosticPosition pos) { - this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); - return this; - } - @Override @DefinedBy(Api.COMPILER_TREE) public DCAttribute newAttributeTree(Name name, ValueKind vkind, List value) { DCAttribute tree = new DCAttribute(name, vkind, cast(value)); @@ -289,12 +278,6 @@ public DCErroneous newErroneousTree(String text, Diagnostic diag return tree; } - public DCErroneous newErroneousTree(String text, DiagnosticSource diagSource, String code, Object... args) { - DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args); - tree.pos = pos; - return tree; - } - @Override @DefinedBy(Api.COMPILER_TREE) public DCThrows newExceptionTree(ReferenceTree name, List description) { // TODO: verify the reference is just to a type (not a field or method) @@ -713,7 +696,7 @@ private boolean isSentenceBreak(DocTree dt, boolean isFirstDocTree) { } /* - * Returns the position of the the first non-white space + * Returns the position of the first non-whitespace character. */ private int skipWhiteSpace(String s, int start) { for (int i = start; i < s.length(); i++) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java index 6bdefeda9ba9..d303b5f710f0 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2021, 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 @@ -50,7 +50,7 @@ public abstract class AbstractLog { /** Factory for diagnostics */ - protected JCDiagnostic.Factory diags; + public final JCDiagnostic.Factory diags; /** The file that's currently being translated. */ diff --git a/src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java b/src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java index f23224de5e8f..08ee400aebd1 100644 --- a/src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java +++ b/src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java @@ -495,7 +495,7 @@ public Void scan(DocTree tree, Void p) { //if there is a newline immediately behind this tree, insert behind //the newline: long endPos = sp.getEndPosition(null, dcTree, tree); - if (endPos >= 0) { + if (endPos >= offset) { if (endPos - offset + 1 < docComment.length() && docComment.charAt((int) (endPos - offset + 1)) == '\n') { endPos++; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/DocLint.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/DocLint.java index 5ef7c1ada2b9..9f1a290ba202 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/DocLint.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/DocLint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -287,7 +287,6 @@ public void init(JavacTask task, String[] args, boolean addTaskListener) { void visitDecl(Tree tree, Name name) { TreePath p = getCurrentPath(); DocCommentTree dc = env.trees.getDocCommentTree(p); - checker.scan(dc, p); } }; diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocLog.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocLog.java index 92b7115e1fcc..8409169968b0 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocLog.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocLog.java @@ -45,13 +45,15 @@ import javax.tools.ForwardingFileObject; import javax.tools.JavaFileObject; +import jdk.javadoc.doclet.Reporter; + import com.sun.source.doctree.CommentTree; import com.sun.source.doctree.DocTree; import com.sun.source.doctree.DocTypeTree; import com.sun.source.doctree.ReferenceTree; import com.sun.source.doctree.TextTree; +import com.sun.tools.javac.tree.DCTree.DCDocComment; import com.sun.tools.javac.tree.DCTree; -import jdk.javadoc.doclet.Reporter; import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.util.Context.Factory; @@ -278,12 +280,13 @@ public void print(Diagnostic.Kind kind, DocTreePath path, int start, int pos, in DiagnosticSource ds = getDiagnosticSource(path); DCTree.DCDocComment docComment = (DCTree.DCDocComment) path.getDocComment(); - DCTree tree = (DCTree) path.getLeaf(); + DCTree docTree = (DCTree) path.getLeaf(); // note: it is important to evaluate the offsets in the context of the position // within the comment text, and not in the context of the overall source text - int sStart = (int) tree.getSourcePosition(docComment, start); - int sPos = (int) tree.getSourcePosition(docComment, pos); - int sEnd = (int) tree.getSourcePosition(docComment, end); + int dtStart = docTree.getStartPosition(); + int sStart = docComment.getSourcePosition(dtStart + start); + int sPos = docComment.getSourcePosition(dtStart + pos); + int sEnd = docComment.getSourcePosition(dtStart + end); DiagnosticPosition dp = createDiagnosticPosition(null, sStart, sPos, sEnd); report(dt, flags, ds, dp, message); @@ -292,7 +295,7 @@ public void print(Diagnostic.Kind kind, DocTreePath path, int start, int pos, in private int getSourcePos(DocTreePath path, int offset) { DCTree.DCDocComment docComment = (DCTree.DCDocComment) path.getDocComment(); DCTree tree = (DCTree) path.getLeaf(); - return (int) tree.getSourcePosition(docComment, offset); + return docComment.getSourcePosition(tree.getStartPosition() + offset); } @Override // Reporter @@ -566,11 +569,9 @@ private void report(DiagnosticType dt, Set flags, DiagnosticSour * @return the diagnostic position */ private DiagnosticPosition getDiagnosticPosition(DocTreePath path) { - DocSourcePositions posns = getSourcePositions(); - CompilationUnitTree compUnit = path.getTreePath().getCompilationUnit(); - int start = (int) posns.getStartPosition(compUnit, path.getDocComment(), path.getLeaf()); - int end = (int) posns.getEndPosition(compUnit, path.getDocComment(), path.getLeaf()); - return createDiagnosticPosition(null, start, start, end); + DCDocComment dc = (DCDocComment) path.getDocComment(); + DCTree dcTree = (DCTree) path.getLeaf(); + return dcTree.pos(dc); } /** @@ -657,7 +658,7 @@ private Set getDiagnosticFlags(Diagnostic.Kind kind) { } /** - * Returns the diagnostic source for an documentation tree node. + * Returns the diagnostic source for a documentation tree node. * * @param path the path for the documentation tree node * @return the diagnostic source diff --git a/test/langtools/tools/doclint/CrashInAnnotateTest.out b/test/langtools/tools/doclint/CrashInAnnotateTest.out index 74cffab6173d..0275032554e7 100644 --- a/test/langtools/tools/doclint/CrashInAnnotateTest.out +++ b/test/langtools/tools/doclint/CrashInAnnotateTest.out @@ -1,7 +1,7 @@ -CrashInAnnotateTest.java:10:5: compiler.err.proc.messager: annotations not allowed -CrashInAnnotateTest.java:11:5: compiler.err.proc.messager: syntax error in reference -CrashInAnnotateTest.java:16:5: compiler.err.proc.messager: annotations not allowed -CrashInAnnotateTest.java:21:5: compiler.err.proc.messager: syntax error in reference -CrashInAnnotateTest.java:24:5: compiler.err.proc.messager: syntax error in reference -CrashInAnnotateTest.java:25:5: compiler.err.proc.messager: syntax error in reference +CrashInAnnotateTest.java:10:20: compiler.err.proc.messager: annotations not allowed +CrashInAnnotateTest.java:11:37: compiler.err.proc.messager: syntax error in reference +CrashInAnnotateTest.java:16:39: compiler.err.proc.messager: annotations not allowed +CrashInAnnotateTest.java:21:23: compiler.err.proc.messager: syntax error in reference +CrashInAnnotateTest.java:24:54: compiler.err.proc.messager: syntax error in reference +CrashInAnnotateTest.java:25:37: compiler.err.proc.messager: syntax error in reference 6 errors \ No newline at end of file diff --git a/test/langtools/tools/doclint/EndWithIdentifierTest.out b/test/langtools/tools/doclint/EndWithIdentifierTest.out index 41f15e40653a..48b473414d8b 100644 --- a/test/langtools/tools/doclint/EndWithIdentifierTest.out +++ b/test/langtools/tools/doclint/EndWithIdentifierTest.out @@ -1,12 +1,12 @@ EndWithIdentifierTest.java:17: error: syntax error in reference /**{@link*/ - ^ + ^ EndWithIdentifierTest.java:22: error: reference not found * @see List*/ ^ EndWithIdentifierTest.java:25: error: semicolon missing /**&*/ - ^ + ^ EndWithIdentifierTest.java:28: error: malformed HTML /** files = new ArrayList<>(); + try (DirectoryStream ds = Files.newDirectoryStream(src, this::isDocCommentTesterTest)) { + for (Path p : ds) { + files.add(fm.getJavaFileObjects(p).iterator().next()); + } + } + + JavacTask task = (JavacTask) compiler.getTask(null, null, null, null, null, files); + + DocTrees trees = DocTrees.instance(task); + Map counts = new TreeMap<>(); + DocTreeScanner dtScanner = new DocTreeScanner() { + @Override + public Object scan(DocTree node, Object o) { + if (node != null) { + DocTree.Kind k = node.getKind(); + counts.put(k, counts.computeIfAbsent(k, k_ -> 0) + 1); + } + return super.scan(node, o); + } + }; + + TreePathScanner declScanner = new DeclScanner() { + @Override + void visitDecl(Tree tree, Name name) { + TreePath path = getCurrentPath(); + DocCommentTree dc = trees.getDocCommentTree(path); + dtScanner.scan(dc, null); + } + }; + + + task.addTaskListener(new TaskListener() { + @Override + public void finished(TaskEvent e) { + if (e.getKind() == TaskEvent.Kind.PARSE) { + declScanner.scan(e.getCompilationUnit(), null); + } + } + }); + + task.parse(); + + counts.forEach((k, v) -> System.err.printf("%20s: %5d%n", k, v)); + + // Note: DOC_TYPE cannot appear in any doc comment in a *.java file, + // and OTHER is a special value that never appears in any standard DocTree node. + List notFound = Stream.of(DocTree.Kind.values()) + .filter(k -> switch (k) { case DOC_TYPE, OTHER -> false; default -> true; }) + .filter(k -> !counts.containsKey(k)) + .toList(); + + if (!notFound.isEmpty()) { + System.err.println(); + System.err.println("ERROR: The following kinds were not found: " + notFound.stream() + .map(DocTree.Kind::name) + .collect(Collectors.joining(", "))); + System.err.println(); + throw new Exception("Not Found: " + notFound); + } + } + + boolean isDocCommentTesterTest(Path p) throws IOException { + if (!p.getFileName().toString().endsWith(".java")) { + return false; + } + + String marker = " * @run main DocCommentTester " + p.getFileName(); + for (String line : Files.readAllLines(p)) { + if (line.equals(marker)) { + return true; + } else if (line.contains("{")) { + return false; + } + } + return false; + } + + static abstract class DeclScanner extends TreePathScanner { + abstract void visitDecl(Tree tree, Name name); + + @Override + public Void visitClass(ClassTree tree, Void ignore) { + super.visitClass(tree, ignore); + visitDecl(tree, tree.getSimpleName()); + return null; + } + + @Override + public Void visitMethod(MethodTree tree, Void ignore) { + super.visitMethod(tree, ignore); + visitDecl(tree, tree.getName()); + return null; + } + + @Override + public Void visitVariable(VariableTree tree, Void ignore) { + super.visitVariable(tree, ignore); + visitDecl(tree, tree.getName()); + return null; + } + } +} diff --git a/test/langtools/tools/javac/doctree/DeprecatedTest.java b/test/langtools/tools/javac/doctree/DeprecatedTest.java index 8d9a59e565ff..ac5923afa191 100644 --- a/test/langtools/tools/javac/doctree/DeprecatedTest.java +++ b/test/langtools/tools/javac/doctree/DeprecatedTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/DocCommentTester.java b/test/langtools/tools/javac/doctree/DocCommentTester.java index 95c4586758ac..7594a5f8d008 100644 --- a/test/langtools/tools/javac/doctree/DocCommentTester.java +++ b/test/langtools/tools/javac/doctree/DocCommentTester.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -37,6 +37,7 @@ import java.util.stream.Collectors; import javax.lang.model.element.Name; +import javax.tools.Diagnostic; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; @@ -57,14 +58,16 @@ import com.sun.tools.javac.tree.DCTree.DCErroneous; import com.sun.tools.javac.tree.DocPretty; +/** + * A class to test doc comment trees. + * It is normally executed by calling {@code main}, providing a source file to be analyzed. + * The file is scanned for top-level declarations, and the comment for any such declarations + * is analyzed with a series of "checkers". + * + * @see DocCommentTester.ASTChecker#main(String... args) + */ public class DocCommentTester { - public static final String BI_MARKER = "BREAK_ITERATOR"; - public final boolean useBreakIterator; - - public DocCommentTester(boolean useBreakIterator) { - this.useBreakIterator = useBreakIterator; - } public static void main(String... args) throws Exception { ArrayList list = new ArrayList<>(Arrays.asList(args)); if (!list.isEmpty() && "-useBreakIterator".equals(list.get(0))) { @@ -75,6 +78,13 @@ public static void main(String... args) throws Exception { } } + public static final String BI_MARKER = "BREAK_ITERATOR"; + public final boolean useBreakIterator; + + public DocCommentTester(boolean useBreakIterator) { + this.useBreakIterator = useBreakIterator; + } + public void run(List args) throws Exception { String testSrc = System.getProperty("test.src"); @@ -98,7 +108,9 @@ public void run(List args) throws Exception { final Checker[] checkers = { new ASTChecker(this, trees), new PosChecker(this, trees), - new PrettyChecker(this, trees) + new PrettyChecker(this, trees), + new RangeChecker(this, trees), + new StartEndPosChecker(this, trees) }; DeclScanner d = new DeclScanner() { @@ -194,7 +206,7 @@ void error(String msg) { int errors; /** - * Verify the structure of the DocTree AST by comparing it against golden text. + * Verifies the structure of the DocTree AST by comparing it against golden text. */ static class ASTChecker extends Checker { static final String NEWLINE = System.getProperty("line.separator"); @@ -280,7 +292,7 @@ else if (arg.startsWith("-")) final DocTrees trees = DocTrees.instance(t); DeclScanner d = new DeclScanner() { - Printer p = new Printer(); + final Printer p = new Printer(); String source; @Override @@ -784,7 +796,7 @@ else if (s.contains("'") || s.contains(" ")) } /** - * Verify the reported tree positions by comparing the characters found + * Verifies the reported tree positions by comparing the characters found * at and after the reported position with the beginning of the pretty- * printed text. */ @@ -799,16 +811,16 @@ void check(TreePath path, Name name) throws Exception { final CharSequence cs = fo.getCharContent(true); final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path); - DCTree t = (DCTree) trees.getDocCommentTree(path); DocTreeScanner scanner = new DocTreeScanner<>() { @Override public Void scan(DocTree node, Void ignore) { if (node != null) { try { + DCTree dcTree = (DCTree) node; String expect = getExpectText(node); - long pos = ((DCTree) node).getSourcePosition(dc); - String found = getFoundText(cs, (int) pos, expect.length()); + long startPos = dc.getSourcePosition(dcTree.getStartPosition()); + String found = getFoundText(cs, (int) startPos, expect.length()); if (!found.equals(expect)) { System.err.println("expect: " + expect); System.err.println("found: " + found); @@ -816,7 +828,7 @@ public Void scan(DocTree node, Void ignore) { } } catch (StringIndexOutOfBoundsException e) { - error(node.getClass() + ": " + e.toString()); + error(node.getClass() + ": " + e); e.printStackTrace(); } } @@ -824,7 +836,7 @@ public Void scan(DocTree node, Void ignore) { } }; - scanner.scan(t, null); + scanner.scan(dc, null); } String getExpectText(DocTree t) { @@ -845,7 +857,7 @@ String getFoundText(CharSequence cs, int pos, int len) { } /** - * Verify the pretty printed text against a normalized form of the + * Verifies the pretty printed text against a normalized form of the * original doc comment. */ static class PrettyChecker extends Checker { @@ -893,9 +905,9 @@ String normalize(String s) { } String normalizeFragment(String s) { - return s.replaceAll("\\{@docRoot\\s+\\}", "{@docRoot}") - .replaceAll("\\{@inheritDoc\\s+\\}", "{@inheritDoc}") - .replaceAll("(\\{@value\\s+[^}]+)\\s+(\\})", "$1$2") + return s.replaceAll("\\{@docRoot\\s+}", "{@docRoot}") + .replaceAll("\\{@inheritDoc\\s+}", "{@inheritDoc}") + .replaceAll("(\\{@value\\s+[^}]+)\\s+(})", "$1$2") .replaceAll("\n[ \t]+@", "\n@"); } @@ -907,21 +919,166 @@ int copyLiteral(String s, int start, StringBuilder sb) { sb.append(' '); } switch (ch) { - case '{': + case '{' -> depth++; - break; - case '}': + + case '}' -> { depth--; if (depth < 0) { sb.append(ch); return i + 1; } - break; + } } sb.append(ch); } return s.length(); } } + + + /** + * Verifies the general "left to right" constraints for the positions of + * nodes in the DocTree AST. + */ + static class RangeChecker extends Checker { + int cursor = 0; + + RangeChecker(DocCommentTester test, DocTrees docTrees) { + test.super(docTrees); + } + + @Override + void check(TreePath path, Name name) throws Exception { + final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path); + + DocTreeScanner scanner = new DocTreeScanner<>() { + @Override + public Void scan(DocTree node, Void ignore) { + if (node instanceof DCTree dcTree) { + int start = dcTree.getStartPosition(); + int pref = dcTree.getPreferredPosition(); + int end = dcTree.getEndPosition(); + + // check within the node, start <= pref <= end + check("start:pref", dcTree, start, pref); + check("pref:end", dcTree, pref, end); + + // check cursor <= start + check("cursor:start", dcTree, cursor, start); + cursor = start; + + // recursively scan any children, updating the cursor + super.scan(node, ignore); + + // check cursor <= end + check("cursor:end", dcTree, cursor, end); + cursor = end; + } + return null; + } + }; + + cursor = 0; + scanner.scan(dc, null); + + } + + void check(String name, DCTree tree, int first, int second) { + if (!(first <= second)) { + error(name, tree, first, second); + } + } + + private void error(String name, DCTree tree, int first, int second) { + String t = tree.toString().replaceAll("\\s+", " "); + if (t.length() > 32) { + t = t.substring(0, 15) + "..." + t.substring(t.length() - 15); + } + error("Checking " + name + " for " + tree.getKind() + " `" + t + "`; first:" + first + ", second:" + second); + + } + } + + /** + * Verifies that the start and end positions of all nodes in a DocCommentTree point to the + * expected characters in the source code. + * + * The expected characters are derived from the beginning and end of the DocPretty output + * for each node. Note that while the whitespace within the DocPretty output may not exactly + * match the original source code, the first and last characters should match. + */ + static class StartEndPosChecker extends Checker { + + StartEndPosChecker(DocCommentTester test, DocTrees docTrees) { + test.super(docTrees); + } + + @Override + void check(TreePath path, Name name) throws Exception { + final DCDocComment dc = (DCDocComment) trees.getDocCommentTree(path); + JavaFileObject jfo = path.getCompilationUnit().getSourceFile(); + CharSequence content = jfo.getCharContent(true); + + DocTreeScanner scanner = new DocTreeScanner<>() { + @Override + public Void scan(DocTree node, Void ignore) { + if (node instanceof DCTree dcTree) { + int start = dc.getSourcePosition(dc.getStartPosition()); + int end = dc.getSourcePosition(dcTree.getEndPosition()); + + try { + StringWriter out = new StringWriter(); + DocPretty dp = new DocPretty(out); + dp.print(trees.getDocCommentTree(path)); + String pretty = out.toString(); + + if (pretty.isEmpty()) { + if (start != end) { + error("Error: expected content is empty, but actual content is not: " + + dcTree.getKind() + " [" + start + "," + end + ")" + + ": \"" + content.subSequence(start, end) + "\"" ); + } + } else { + check(dcTree, "start", content, start, pretty, 0); + check(dcTree, "end", content, end - 1, pretty, pretty.length() - 1); + } + + } catch (IOException e) { + error("Error generating DocPretty for tree at position " + start + "; " + e); + } + } + return null; + } + }; + + scanner.scan(dc, null); + } + + void check(DCTree tree, String label, CharSequence content, int contentIndex, String pretty, int prettyIndex) { + if (contentIndex == Diagnostic.NOPOS) { + error("NOPOS for content " + label + ": " + tree.getKind() + " >>" + abbrev(pretty, MAX) + "<<"); + } + + char contentChar = content.charAt(contentIndex); + char prettyChar = pretty.charAt(prettyIndex); + if (contentChar != prettyChar) { + error ("Mismatch for content " + label + ": " + + "expect: '" + prettyChar + "', found: '" + contentChar + "' at position " + contentIndex + ": " + + tree.getKind() + " >>" + abbrev(pretty, MAX) + "<<"); + } + } + + static final int MAX = 64; + + static String abbrev(String s, int max) { + s = s.replaceAll("\\s+", " "); + if (s.length() > max) { + s = s.substring(0, max / 2 - 2) + " ... " + s.substring(max / 2 + 2); + } + return s; + } + + } } diff --git a/test/langtools/tools/javac/doctree/DocRootTest.java b/test/langtools/tools/javac/doctree/DocRootTest.java index c48b4b74789b..674e81851829 100644 --- a/test/langtools/tools/javac/doctree/DocRootTest.java +++ b/test/langtools/tools/javac/doctree/DocRootTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/ElementTest.java b/test/langtools/tools/javac/doctree/ElementTest.java index c2346b20a7d4..911814c5880f 100644 --- a/test/langtools/tools/javac/doctree/ElementTest.java +++ b/test/langtools/tools/javac/doctree/ElementTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 8078320 8247788 + * @bug 7021614 8078320 8247788 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/EntityTest.java b/test/langtools/tools/javac/doctree/EntityTest.java index 3e7517d27159..4e75a733b30d 100644 --- a/test/langtools/tools/javac/doctree/EntityTest.java +++ b/test/langtools/tools/javac/doctree/EntityTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/ExceptionTest.java b/test/langtools/tools/javac/doctree/ExceptionTest.java index 98a2ac285f53..600b428b4cf7 100644 --- a/test/langtools/tools/javac/doctree/ExceptionTest.java +++ b/test/langtools/tools/javac/doctree/ExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/FirstSentenceTest.java b/test/langtools/tools/javac/doctree/FirstSentenceTest.java index a93726a891c2..3a973d87bd23 100644 --- a/test/langtools/tools/javac/doctree/FirstSentenceTest.java +++ b/test/langtools/tools/javac/doctree/FirstSentenceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 8078320 8132096 + * @bug 7021614 8078320 8132096 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file @@ -38,7 +38,7 @@ class FirstSentenceTest { /** */ void empty() { } /* -DocComment[DOC_COMMENT, pos:-1 +DocComment[DOC_COMMENT, pos:0 firstSentence: empty body: empty block tags: empty @@ -46,7 +46,7 @@ void empty() { } */ /* BREAK_ITERATOR -DocComment[DOC_COMMENT, pos:-1 +DocComment[DOC_COMMENT, pos:0 firstSentence: empty body: empty block tags: empty diff --git a/test/langtools/tools/javac/doctree/HiddenTest.java b/test/langtools/tools/javac/doctree/HiddenTest.java index 9a8c19b27d8c..7ed981780e34 100644 --- a/test/langtools/tools/javac/doctree/HiddenTest.java +++ b/test/langtools/tools/javac/doctree/HiddenTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8073100 + * @bug 8073100 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/InPreTest.java b/test/langtools/tools/javac/doctree/InPreTest.java index 78730a4d1080..1929c221bc77 100644 --- a/test/langtools/tools/javac/doctree/InPreTest.java +++ b/test/langtools/tools/javac/doctree/InPreTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8078320 + * @bug 8078320 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/IndexTest.java b/test/langtools/tools/javac/doctree/IndexTest.java index 0cbd079a13cb..f41477a72c8f 100644 --- a/test/langtools/tools/javac/doctree/IndexTest.java +++ b/test/langtools/tools/javac/doctree/IndexTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8144287 + * @bug 8144287 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/InheritDocTest.java b/test/langtools/tools/javac/doctree/InheritDocTest.java index 403441e1d284..3034f7848936 100644 --- a/test/langtools/tools/javac/doctree/InheritDocTest.java +++ b/test/langtools/tools/javac/doctree/InheritDocTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/LinkPlainTest.java b/test/langtools/tools/javac/doctree/LinkPlainTest.java index 695640684bd3..04ac81ffe7cf 100644 --- a/test/langtools/tools/javac/doctree/LinkPlainTest.java +++ b/test/langtools/tools/javac/doctree/LinkPlainTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/LinkTest.java b/test/langtools/tools/javac/doctree/LinkTest.java index 6d3a8897de86..79e2a9d43d1f 100644 --- a/test/langtools/tools/javac/doctree/LinkTest.java +++ b/test/langtools/tools/javac/doctree/LinkTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/LiteralTest.java b/test/langtools/tools/javac/doctree/LiteralTest.java index 2b68ed23c94d..38592ab9e4ff 100644 --- a/test/langtools/tools/javac/doctree/LiteralTest.java +++ b/test/langtools/tools/javac/doctree/LiteralTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 8241780 + * @bug 7021614 8241780 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/ParamTest.java b/test/langtools/tools/javac/doctree/ParamTest.java index f8bc76ba4912..676f201b4a2b 100644 --- a/test/langtools/tools/javac/doctree/ParamTest.java +++ b/test/langtools/tools/javac/doctree/ParamTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/ProvidesTest.java b/test/langtools/tools/javac/doctree/ProvidesTest.java index 6c1e67459288..132a29982b12 100644 --- a/test/langtools/tools/javac/doctree/ProvidesTest.java +++ b/test/langtools/tools/javac/doctree/ProvidesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8160196 + * @bug 8160196 8273244 * @summary Module summary page should display information based on "api" or "detail" mode. * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/ReturnTest.java b/test/langtools/tools/javac/doctree/ReturnTest.java index 5b6dfa3a18b0..3db7651dd9ae 100644 --- a/test/langtools/tools/javac/doctree/ReturnTest.java +++ b/test/langtools/tools/javac/doctree/ReturnTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/SeeTest.java b/test/langtools/tools/javac/doctree/SeeTest.java index 8ded81aab943..24d5f85036ed 100644 --- a/test/langtools/tools/javac/doctree/SeeTest.java +++ b/test/langtools/tools/javac/doctree/SeeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 8031212 + * @bug 7021614 8031212 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/SerialDataTest.java b/test/langtools/tools/javac/doctree/SerialDataTest.java index b73d011b9715..f46af82eec46 100644 --- a/test/langtools/tools/javac/doctree/SerialDataTest.java +++ b/test/langtools/tools/javac/doctree/SerialDataTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/SerialFieldTest.java b/test/langtools/tools/javac/doctree/SerialFieldTest.java index ac389af8ec84..c9a369155024 100644 --- a/test/langtools/tools/javac/doctree/SerialFieldTest.java +++ b/test/langtools/tools/javac/doctree/SerialFieldTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/SerialTest.java b/test/langtools/tools/javac/doctree/SerialTest.java index 9760a0b71560..d45e7173e4f4 100644 --- a/test/langtools/tools/javac/doctree/SerialTest.java +++ b/test/langtools/tools/javac/doctree/SerialTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/SinceTest.java b/test/langtools/tools/javac/doctree/SinceTest.java index d89e5597e0a2..9325efc4cac3 100644 --- a/test/langtools/tools/javac/doctree/SinceTest.java +++ b/test/langtools/tools/javac/doctree/SinceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/SummaryTest.java b/test/langtools/tools/javac/doctree/SummaryTest.java index 11231bae122f..d2dfa334b669 100644 --- a/test/langtools/tools/javac/doctree/SummaryTest.java +++ b/test/langtools/tools/javac/doctree/SummaryTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8173425 + * @bug 8173425 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/SystemPropertyTest.java b/test/langtools/tools/javac/doctree/SystemPropertyTest.java index a7f56f0c00f0..de3c6994d2fd 100644 --- a/test/langtools/tools/javac/doctree/SystemPropertyTest.java +++ b/test/langtools/tools/javac/doctree/SystemPropertyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 5076751 + * @bug 5076751 8273244 * @summary System properties documentation needed in javadocs * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/TagTest.java b/test/langtools/tools/javac/doctree/TagTest.java index f23a9d6a07af..298ac8e7f0d6 100644 --- a/test/langtools/tools/javac/doctree/TagTest.java +++ b/test/langtools/tools/javac/doctree/TagTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 8078320 + * @bug 7021614 8078320 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/ThrowableTest.java b/test/langtools/tools/javac/doctree/ThrowableTest.java index 3f3360afb06c..e8a9dec0a779 100644 --- a/test/langtools/tools/javac/doctree/ThrowableTest.java +++ b/test/langtools/tools/javac/doctree/ThrowableTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/UsesTest.java b/test/langtools/tools/javac/doctree/UsesTest.java index 3d24ed065d65..bb4b7aecb989 100644 --- a/test/langtools/tools/javac/doctree/UsesTest.java +++ b/test/langtools/tools/javac/doctree/UsesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8160196 + * @bug 8160196 8273244 * @summary Module summary page should display information based on "api" or "detail" mode. * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/ValueTest.java b/test/langtools/tools/javac/doctree/ValueTest.java index 941b2ae6abce..6c0a634f5c7d 100644 --- a/test/langtools/tools/javac/doctree/ValueTest.java +++ b/test/langtools/tools/javac/doctree/ValueTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/VersionTest.java b/test/langtools/tools/javac/doctree/VersionTest.java index 9fa6ac7bbc3f..ce6fba6ccec8 100644 --- a/test/langtools/tools/javac/doctree/VersionTest.java +++ b/test/langtools/tools/javac/doctree/VersionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8273244 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file diff --git a/test/langtools/tools/javac/doctree/positions/TestPosition.java b/test/langtools/tools/javac/doctree/positions/TestPosition.java index 9d527ad366ea..6d66a84d83ba 100644 --- a/test/langtools/tools/javac/doctree/positions/TestPosition.java +++ b/test/langtools/tools/javac/doctree/positions/TestPosition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021, 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 @@ -77,7 +77,7 @@ public boolean process(Set annotations, RoundEnvironment new DocTreeScanner() { @Override public Void scan(DocTree node, Void p) { if (node != null) { - DocSourcePositions sp = (DocSourcePositions) trees.getSourcePositions(); //XXX: the cast??? + DocSourcePositions sp = trees.getSourcePositions(); int start = (int) sp.getStartPosition(testElement.getCompilationUnit(), docCommentTree, node); int end = (int) sp.getEndPosition(testElement.getCompilationUnit(), docCommentTree, node); String snippet = code.substring(start, end).replace(" \n", "!trailing-whitespace!\n"); diff --git a/test/langtools/tools/javac/tree/AbstractTreeScannerTest.java b/test/langtools/tools/javac/tree/AbstractTreeScannerTest.java index 8f7508d70349..ab870a72a4e4 100644 --- a/test/langtools/tools/javac/tree/AbstractTreeScannerTest.java +++ b/test/langtools/tools/javac/tree/AbstractTreeScannerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021, 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 @@ -200,10 +200,11 @@ void error(JavaFileObject file, String msg) { } /** - * Report an error for a specific tree node. - * @param file the source file for the tree - * @param t the tree node - * @param label an indication of the error + * Report an error for a specific tree node. + * + * @param file the source file for the tree + * @param tree the tree node + * @param msg an indication of the error */ void error(JavaFileObject file, Tree tree, String msg) { JCTree t = (JCTree) tree; @@ -211,15 +212,17 @@ void error(JavaFileObject file, Tree tree, String msg) { } /** - * Report an error for a specific tree node. - * @param file the source file for the tree - * @param t the tree node - * @param label an indication of the error + * Report an error for a specific tree node. + * + * @param file the source file for the tree + * @param comment the top level doc tree node + * @param tree the tree node + * @param msg an indication of the error */ void error(JavaFileObject file, DocCommentTree comment, DocTree tree, String msg) { DCDocComment dc = (DCDocComment) comment; DCTree t = (DCTree) tree; - error(file.getName() + ":" + getLine(file, t.getSourcePosition(dc)) + ": " + msg + " " + trim(t, 64)); + error(file.getName() + ":" + getLine(file, dc.getSourcePosition(t.pos)) + ": " + msg + " " + trim(t, 64)); } /**