mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8338833: Error on reference not found for a snippet target
Reviewed-by: prappo
This commit is contained in:
parent
21c1282207
commit
254713ab59
@ -136,7 +136,7 @@ public class SnippetTaglet extends BaseTaglet {
|
||||
if (styles.isEmpty()) {
|
||||
code.add(text);
|
||||
} else {
|
||||
Element e = null;
|
||||
Element ref = null;
|
||||
String linkTarget = null;
|
||||
boolean markupEncountered = false;
|
||||
Set<String> classes = new HashSet<>();
|
||||
@ -152,9 +152,11 @@ public class SnippetTaglet extends BaseTaglet {
|
||||
content.asCharSequence().toString().trim());
|
||||
}
|
||||
linkTarget = l.target();
|
||||
e = getLinkedElement(element, linkTarget);
|
||||
if (e == null) {
|
||||
// TODO: diagnostic output
|
||||
ref = getLinkedElement(element, linkTarget);
|
||||
if (ref == null) {
|
||||
messages.error(utils.getCommentHelper(element).getDocTreePath(tag),
|
||||
"doclet.link.see.reference_not_found",
|
||||
linkTarget);
|
||||
}
|
||||
}
|
||||
case Style.Markup m -> markupEncountered = true;
|
||||
@ -164,7 +166,6 @@ public class SnippetTaglet extends BaseTaglet {
|
||||
if (markupEncountered) {
|
||||
return;
|
||||
} else if (linkTarget != null) {
|
||||
assert e != null;
|
||||
//disable preview tagging inside the snippets:
|
||||
Utils.PreviewFlagProvider prevPreviewProvider = utils.setPreviewFlagProvider(el -> false);
|
||||
try {
|
||||
@ -172,10 +173,10 @@ public class SnippetTaglet extends BaseTaglet {
|
||||
c = lt.linkSeeReferenceOutput(element,
|
||||
null,
|
||||
linkTarget,
|
||||
e,
|
||||
ref,
|
||||
false, // TODO: for now
|
||||
Text.of(sequence.toString()),
|
||||
(key, args) -> { /* TODO: report diagnostic */ },
|
||||
(key, args) -> { /* Error has already been reported above */ },
|
||||
tagletWriter);
|
||||
} finally {
|
||||
utils.setPreviewFlagProvider(prevPreviewProvider);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2025, 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 8266666 8281969 8319339
|
||||
* @bug 8266666 8281969 8319339 8338833
|
||||
* @summary Implementation for snippets
|
||||
* @library /tools/lib ../../lib
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
@ -206,6 +206,50 @@ public class TestSnippetMarkup extends SnippetTester {
|
||||
testPositive(base, testCases);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure an error is generated for links with invalid reference.
|
||||
*/
|
||||
@Test
|
||||
public void testLinkReferenceNotFound(Path base) throws Exception {
|
||||
Path srcDir = base.resolve("src");
|
||||
Path outDir = base.resolve("out");
|
||||
|
||||
new ClassBuilder(tb, "pkg.A")
|
||||
.setModifiers("public", "class")
|
||||
.addMembers(
|
||||
ClassBuilder.MethodBuilder
|
||||
.parse("public void inline() { }")
|
||||
.setComments("""
|
||||
First sentence.
|
||||
{@snippet :
|
||||
First line // @link substring="First" target="String"
|
||||
Second line // @link substring="Second" target="StringReader"
|
||||
}
|
||||
"""))
|
||||
.write(srcDir);
|
||||
|
||||
javadoc("-d", outDir.toString(),
|
||||
"-sourcepath", srcDir.toString(),
|
||||
"pkg");
|
||||
|
||||
checkExit(Exit.ERROR);
|
||||
checkOutput(Output.OUT, false,
|
||||
"""
|
||||
error: reference not found: String
|
||||
""");
|
||||
checkOutput(Output.OUT, true,
|
||||
"""
|
||||
A.java:5: error: reference not found: StringReader
|
||||
""");
|
||||
checkOutput("pkg/A.html", true,
|
||||
"""
|
||||
<details class="invalid-tag">
|
||||
<summary>invalid reference</summary>
|
||||
<pre><code>Second</code></pre>
|
||||
</details>""");
|
||||
checkNoCrashes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCornerCases(Path base) throws Exception {
|
||||
var testCases = List.of(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user