8227923: End position of EndElementTree is -1
Fixing end positions for DocTrees EndElementTree, EntityTree and CommentTree. Reviewed-by: jjg
This commit is contained in:
parent
8d62f19e8d
commit
03270bb92a
@ -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.Notes;
|
||||
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 @@ public class JavacTrees extends DocTrees {
|
||||
|
||||
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);
|
||||
|
||||
|
@ -930,7 +930,7 @@ public class DocCommentParser {
|
||||
skipWhitespace();
|
||||
if (ch == '>') {
|
||||
nextChar();
|
||||
return m.at(p).newEndElementTree(name);
|
||||
return m.at(p).newEndElementTree(name).setEndPos(bp);
|
||||
}
|
||||
}
|
||||
} else if (ch == '!') {
|
||||
|
@ -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 abstract class DCTree implements DocTree {
|
||||
}
|
||||
}
|
||||
|
||||
public static class DCEndElement extends DCTree implements EndElementTree {
|
||||
public static class DCEndElement extends DCEndPosTree<DCStartElement> implements EndElementTree {
|
||||
public final Name name;
|
||||
|
||||
DCEndElement(Name name) {
|
||||
|
@ -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
|
||||
|
@ -3,6 +3,8 @@ DOC_COMMENT:First sentence.
|
||||
*
|
||||
* <p>Description with {@link java.io.InputStream link}
|
||||
*
|
||||
* <em>text < < <!--some comment--> suffix</em>
|
||||
*
|
||||
* @param first description
|
||||
* @param second description
|
||||
* @return whatever
|
||||
@ -15,6 +17,18 @@ TEXT:Description with!trailing-whitespace!
|
||||
LINK:{@link java.io.InputStream link}
|
||||
REFERENCE:java.io.InputStream
|
||||
TEXT:link
|
||||
TEXT:
|
||||
*
|
||||
*!trailing-whitespace!
|
||||
START_ELEMENT:<em>
|
||||
TEXT:text!trailing-whitespace!
|
||||
ENTITY:<
|
||||
TEXT:!trailing-whitespace!
|
||||
ENTITY:<
|
||||
TEXT:!trailing-whitespace!
|
||||
COMMENT:<!--some comment-->
|
||||
TEXT: suffix
|
||||
END_ELEMENT:</em>
|
||||
PARAM:@param first description
|
||||
IDENTIFIER:first
|
||||
TEXT:description
|
||||
@ -61,7 +75,7 @@ REFERENCE:IllegalStateException
|
||||
SINCE:@since
|
||||
ERRONEOUS:@see
|
||||
withWhiteSpaces:
|
||||
DOC_COMMENT:First sentence.
|
||||
DOC_COMMENT:First sentence. <em >text <!-- some comment --> suffix</em >
|
||||
*
|
||||
* <p>Description with {@link }, {@link java.util.List#add( int )},
|
||||
* {@link java.util.List#add( int ) some text with whitespaces}, {@link
|
||||
@ -72,6 +86,14 @@ DOC_COMMENT:First sentence.
|
||||
* @throws java.lang.IllegalStateException
|
||||
* @throws java.lang.IllegalStateException some text
|
||||
TEXT:First sentence.
|
||||
START_ELEMENT:<em >
|
||||
TEXT:text!trailing-whitespace!
|
||||
COMMENT:<!-- some comment -->
|
||||
TEXT: suffix
|
||||
END_ELEMENT:</em >
|
||||
TEXT:
|
||||
*
|
||||
*!trailing-whitespace!
|
||||
START_ELEMENT:<p>
|
||||
TEXT:Description with!trailing-whitespace!
|
||||
LINK:{@link }
|
||||
@ -96,4 +118,79 @@ THROWS:@throws java.lang.IllegalStateException
|
||||
REFERENCE:java.lang.IllegalStateException
|
||||
THROWS:@throws java.lang.IllegalStateException some text
|
||||
REFERENCE:java.lang.IllegalStateException
|
||||
TEXT:some text
|
||||
TEXT:some text
|
||||
erroneous2:
|
||||
DOC_COMMENT:First sentence.
|
||||
*
|
||||
* <p>Description with {@unknownInlineTag }, {@unknownInlineTag text}, {@unknownInlineTag
|
||||
*
|
||||
* @param p1 p {@unknownInlineTag text
|
||||
* @param p2 p <
|
||||
* @param p3 p <em
|
||||
* @param p4 p <!--
|
||||
* @param p5 p <!-- --
|
||||
* @param p6 p <!-- --
|
||||
* @param p7 p &
|
||||
* @param p8 p <
|
||||
* @param p9 p <em> </
|
||||
* @param pa p <em> </em
|
||||
TEXT:First sentence.
|
||||
START_ELEMENT:<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 <em
|
||||
IDENTIFIER:p3
|
||||
TEXT:p!trailing-whitespace!
|
||||
ERRONEOUS:<
|
||||
TEXT:em
|
||||
PARAM:@param p4 p <!--
|
||||
IDENTIFIER:p4
|
||||
TEXT:p!trailing-whitespace!
|
||||
ERRONEOUS:<
|
||||
TEXT:!--
|
||||
PARAM:@param p5 p <!-- --
|
||||
IDENTIFIER:p5
|
||||
TEXT:p!trailing-whitespace!
|
||||
ERRONEOUS:<
|
||||
TEXT:!-- --
|
||||
PARAM:@param p6 p <!-- --
|
||||
IDENTIFIER:p6
|
||||
TEXT:p!trailing-whitespace!
|
||||
ERRONEOUS:<
|
||||
TEXT:!-- --
|
||||
PARAM:@param p7 p &
|
||||
IDENTIFIER:p7
|
||||
TEXT:p!trailing-whitespace!
|
||||
ERRONEOUS:&
|
||||
PARAM:@param p8 p <
|
||||
IDENTIFIER:p8
|
||||
TEXT:p!trailing-whitespace!
|
||||
ERRONEOUS:<
|
||||
PARAM:@param p9 p <em> </
|
||||
IDENTIFIER:p9
|
||||
TEXT:p!trailing-whitespace!
|
||||
START_ELEMENT:<em>
|
||||
TEXT:!trailing-whitespace!
|
||||
ERRONEOUS:<
|
||||
TEXT:/
|
||||
PARAM:@param pa p <em> </em
|
||||
IDENTIFIER:pa
|
||||
TEXT:p!trailing-whitespace!
|
||||
START_ELEMENT:<em>
|
||||
TEXT:!trailing-whitespace!
|
||||
ERRONEOUS:<
|
||||
TEXT:/em
|
||||
|
@ -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 @@ public class TestPositionSource {
|
||||
*
|
||||
* <p>Description with {@link java.io.InputStream link}
|
||||
*
|
||||
* <em>text < < <!--some comment--> suffix</em>
|
||||
*
|
||||
* @param first description
|
||||
* @param second description
|
||||
* @return whatever
|
||||
@ -54,7 +56,7 @@ public class TestPositionSource {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**First sentence.
|
||||
/**First sentence. <em >text <!-- some comment --> suffix</em >
|
||||
*
|
||||
* <p>Description with {@link }, {@link java.util.List#add( int )},
|
||||
* {@link java.util.List#add( int ) some text with whitespaces}, {@link
|
||||
@ -69,4 +71,22 @@ public class TestPositionSource {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**First sentence.
|
||||
*
|
||||
* <p>Description with {@unknownInlineTag }, {@unknownInlineTag text}, {@unknownInlineTag
|
||||
*
|
||||
* @param p1 p {@unknownInlineTag text
|
||||
* @param p2 p <
|
||||
* @param p3 p <em
|
||||
* @param p4 p <!--
|
||||
* @param p5 p <!-- --
|
||||
* @param p6 p <!-- --
|
||||
* @param p7 p &
|
||||
* @param p8 p <
|
||||
* @param p9 p <em> </
|
||||
* @param pa p <em> </em
|
||||
*/
|
||||
public void erroneous2(int p1, int p2, int p3, int p4, int p5,
|
||||
int p6, int p7, int p8, int p9, int pa) {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user