# HG changeset patch # User jlahoda # Date 1563790878 -7200 # Node ID d48ffad997b15b3f8a1b3a0e95d7cd0544133870 # Parent 6e97fcd96aee3fb303e166073d5a25f08a5b7f86 8227923: End position of EndElementTree is -1 Summary: Fixing end positions for DocTrees EndElementTree, EntityTree and CommentTree. Reviewed-by: jjg diff -r 6e97fcd96aee -r d48ffad997b1 src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java Mon Jul 22 14:31:04 2019 +0800 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java Mon Jul 22 12:21:18 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2019, 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 @@ -109,8 +109,10 @@ import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.DCTree; import com.sun.tools.javac.tree.DCTree.DCBlockTag; +import com.sun.tools.javac.tree.DCTree.DCComment; import com.sun.tools.javac.tree.DCTree.DCDocComment; import com.sun.tools.javac.tree.DCTree.DCEndPosTree; +import com.sun.tools.javac.tree.DCTree.DCEntity; import com.sun.tools.javac.tree.DCTree.DCErroneous; import com.sun.tools.javac.tree.DCTree.DCIdentifier; import com.sun.tools.javac.tree.DCTree.DCParam; @@ -302,6 +304,14 @@ return dcComment.comment.getSourcePos(block.pos + block.getTagName().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); diff -r 6e97fcd96aee -r d48ffad997b1 src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Mon Jul 22 14:31:04 2019 +0800 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Mon Jul 22 12:21:18 2019 +0200 @@ -930,7 +930,7 @@ skipWhitespace(); if (ch == '>') { nextChar(); - return m.at(p).newEndElementTree(name); + return m.at(p).newEndElementTree(name).setEndPos(bp); } } } else if (ch == '!') { diff -r 6e97fcd96aee -r d48ffad997b1 src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java Mon Jul 22 14:31:04 2019 +0800 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java Mon Jul 22 12:21:18 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2019, 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 @@ -326,7 +326,7 @@ } } - public static class DCEndElement extends DCTree implements EndElementTree { + public static class DCEndElement extends DCEndPosTree implements EndElementTree { public final Name name; DCEndElement(Name name) { diff -r 6e97fcd96aee -r d48ffad997b1 test/langtools/tools/javac/doctree/positions/TestPosition.java --- a/test/langtools/tools/javac/doctree/positions/TestPosition.java Mon Jul 22 14:31:04 2019 +0800 +++ b/test/langtools/tools/javac/doctree/positions/TestPosition.java Mon Jul 22 12:21:18 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2019, 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 8008174 + * @bug 8008174 8227923 * @summary proper source positions for doc comments * @modules jdk.compiler * @build TestPosition diff -r 6e97fcd96aee -r d48ffad997b1 test/langtools/tools/javac/doctree/positions/TestPosition.out --- a/test/langtools/tools/javac/doctree/positions/TestPosition.out Mon Jul 22 14:31:04 2019 +0800 +++ b/test/langtools/tools/javac/doctree/positions/TestPosition.out Mon Jul 22 12:21:18 2019 +0200 @@ -3,6 +3,8 @@ * *

Description with {@link java.io.InputStream link} * + * text < < suffix + * * @param first description * @param second description * @return whatever @@ -15,6 +17,18 @@ LINK:{@link java.io.InputStream link} REFERENCE:java.io.InputStream TEXT:link +TEXT: + * + *!trailing-whitespace! +START_ELEMENT: +TEXT:text!trailing-whitespace! +ENTITY:< +TEXT:!trailing-whitespace! +ENTITY:< +TEXT:!trailing-whitespace! +COMMENT: +TEXT: suffix +END_ELEMENT: PARAM:@param first description IDENTIFIER:first TEXT:description @@ -61,7 +75,7 @@ SINCE:@since ERRONEOUS:@see withWhiteSpaces: -DOC_COMMENT:First sentence. +DOC_COMMENT:First sentence. text suffix * *

Description with {@link }, {@link java.util.List#add( int )}, * {@link java.util.List#add( int ) some text with whitespaces}, {@link @@ -72,6 +86,14 @@ * @throws java.lang.IllegalStateException * @throws java.lang.IllegalStateException some text TEXT:First sentence. +START_ELEMENT: +TEXT:text!trailing-whitespace! +COMMENT: +TEXT: suffix +END_ELEMENT: +TEXT: + * + *!trailing-whitespace! START_ELEMENT:

TEXT:Description with!trailing-whitespace! LINK:{@link } @@ -96,4 +118,79 @@ REFERENCE:java.lang.IllegalStateException THROWS:@throws java.lang.IllegalStateException some text REFERENCE:java.lang.IllegalStateException -TEXT:some text \ No newline at end of file +TEXT:some text +erroneous2: +DOC_COMMENT:First sentence. + * + *

Description with {@unknownInlineTag }, {@unknownInlineTag text}, {@unknownInlineTag + * + * @param p1 p {@unknownInlineTag text + * @param p2 p < + * @param p3 p +TEXT:Description with!trailing-whitespace! +UNKNOWN_INLINE_TAG:{@unknownInlineTag } +TEXT: +TEXT:,!trailing-whitespace! +UNKNOWN_INLINE_TAG:{@unknownInlineTag text} +TEXT:text +TEXT:,!trailing-whitespace! +ERRONEOUS:{@unknownInlineTag +PARAM:@param p1 p {@unknownInlineTag text +IDENTIFIER:p1 +TEXT:p!trailing-whitespace! +ERRONEOUS:{@unknownInlineTag text +PARAM:@param p2 p < +IDENTIFIER:p2 +TEXT:p!trailing-whitespace! +ERRONEOUS:< +PARAM:@param p3 p +TEXT:!trailing-whitespace! +ERRONEOUS:< +TEXT:/ +PARAM:@param pa p +TEXT:!trailing-whitespace! +ERRONEOUS:< +TEXT:/em diff -r 6e97fcd96aee -r d48ffad997b1 test/langtools/tools/javac/doctree/positions/TestPositionSource.java --- a/test/langtools/tools/javac/doctree/positions/TestPositionSource.java Mon Jul 22 14:31:04 2019 +0800 +++ b/test/langtools/tools/javac/doctree/positions/TestPositionSource.java Mon Jul 22 12:21:18 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2019, 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 @@ -27,6 +27,8 @@ * *

Description with {@link java.io.InputStream link} * + * text < < suffix + * * @param first description * @param second description * @return whatever @@ -54,7 +56,7 @@ return true; } - /**First sentence. + /**First sentence. text suffix * *

Description with {@link }, {@link java.util.List#add( int )}, * {@link java.util.List#add( int ) some text with whitespaces}, {@link @@ -69,4 +71,22 @@ return true; } + /**First sentence. + * + *

Description with {@unknownInlineTag }, {@unknownInlineTag text}, {@unknownInlineTag + * + * @param p1 p {@unknownInlineTag text + * @param p2 p < + * @param p3 p