8301813: Bad caret position in error message

Reviewed-by: iris
This commit is contained in:
Jonathan Gibbons 2023-02-06 18:41:04 +00:00
parent 8c01b6e66b
commit d53ade12a8
5 changed files with 142 additions and 14 deletions

View File

@ -280,9 +280,10 @@ public class DocCommentParser {
}
}
}
int prefPos = bp;
blockContent();
return erroneous("dc.no.tag.name", p);
return erroneous("dc.no.tag.name", p, prefPos);
} catch (ParseException e) {
blockContent();
return erroneous(e.getMessage(), p, e.pos);
@ -315,7 +316,7 @@ public class DocCommentParser {
try {
nextChar();
if (!isIdentifierStart(ch)) {
return erroneous("dc.no.tag.name", p);
return erroneous("dc.no.tag.name", p, bp);
}
Name name = readTagName();
TagParser tp = tagParsers.get(name);

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8301813
* @summary Bad caret position in error message
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main TestNoTagName
*/
import java.nio.file.Path;
import javadoc.tester.JavadocTester;
import toolbox.ToolBox;
public class TestNoTagName extends JavadocTester {
public static void main(String... args) throws Exception {
var test = new TestNoTagName();
test.runTests();
}
private ToolBox tb = new ToolBox();
@Test
public void test_inline_missing(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
/**
* abc {@ } def
*/
public class C { private C() { } }
"""
);
javadoc("-d", base.resolve("api").toString(),
src.resolve("C.java").toString()
);
checkExit(Exit.ERROR);
checkOutput(Output.OUT, true, """
C.java:2: error: no tag name after '@'
* abc {@ } def
^
""");
}
@Test
public void test_inline_bad(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
/**
* abc {@/ } def
*/
public class C { private C() { } }
"""
);
javadoc("-d", base.resolve("api").toString(),
src.resolve("C.java").toString()
);
checkExit(Exit.ERROR);
checkOutput(Output.OUT, true, """
C.java:2: error: no tag name after '@'
* abc {@/ } def
^
""");
}
@Test
public void test_block_missing(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
/**
* abc.
* @ def
*/
public class C { private C() { } }
"""
);
javadoc("-d", base.resolve("api").toString(),
src.resolve("C.java").toString()
);
checkExit(Exit.ERROR);
checkOutput(Output.OUT, true, """
C.java:3: error: no tag name after '@'
* @ def
^
""");
}
@Test
public void test_block_bad(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
/**
* abc.
* @/ def
*/
public class C { private C() { } }
"""
);
javadoc("-d", base.resolve("api").toString(),
src.resolve("C.java").toString()
);
checkExit(Exit.ERROR);
checkOutput(Output.OUT, true, """
C.java:3: error: no tag name after '@'
* @/ def
^
""");
}
}

View File

@ -9,6 +9,6 @@
/**
* abc.
* @@@
* @!#
*/
package p;

View File

@ -2,13 +2,7 @@ BadPackageCommentTest.java:14: warning: documentation comment not expected here
package p;
^
BadPackageCommentTest.java:12: error: no tag name after '@'
* @@@
^
BadPackageCommentTest.java:12: error: no tag name after '@'
* @@@
* @!#
^
BadPackageCommentTest.java:12: error: no tag name after '@'
* @@@
^
3 errors
1 error
1 warning

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 7021614 8078320 8273244 8284908 8301201
* @bug 7021614 8078320 8273244 8284908 8301201 8301813
* @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
@ -93,7 +93,7 @@ DocComment[DOC_COMMENT, pos:1
firstSentence: empty
body: empty
block tags: 1
Erroneous[ERRONEOUS, pos:1, prefPos:5
Erroneous[ERRONEOUS, pos:1, prefPos:2
code: compiler.err.dc.no.tag.name
body: @_abc
]
@ -141,7 +141,7 @@ DocComment[DOC_COMMENT, pos:1
/*
DocComment[DOC_COMMENT, pos:1
firstSentence: 2
Erroneous[ERRONEOUS, pos:1, prefPos:2
Erroneous[ERRONEOUS, pos:1, prefPos:3
code: compiler.err.dc.no.tag.name
body: {@
]