mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-20 21:03:18 +00:00
8250766: javadoc adds redundant spaces when @see program element is wrapped
Reviewed-by: prappo
This commit is contained in:
parent
61bb6eca3e
commit
f07bb2f4b9
@ -35,6 +35,7 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -1024,7 +1025,6 @@ public class HtmlDocletWriter {
|
||||
case REFERENCE -> {
|
||||
// @see reference label...
|
||||
label = ref.subList(1, ref.size());
|
||||
break;
|
||||
}
|
||||
default ->
|
||||
throw new IllegalStateException(ref.get(0).getKind().toString());
|
||||
@ -1039,8 +1039,9 @@ public class HtmlDocletWriter {
|
||||
Content labelContent = plainOrCode(isLinkPlain,
|
||||
commentTagsToContent(see, element, label, context));
|
||||
|
||||
//The text from the @see tag. We will output this text when a label is not specified.
|
||||
Content text = plainOrCode(kind == LINK_PLAIN, Text.of(removeTrailingSlash(seeText)));
|
||||
// The signature from the @see tag. We will output this text when a label is not specified.
|
||||
Content text = plainOrCode(isLinkPlain,
|
||||
Text.of(Objects.requireNonNullElse(ch.getReferencedSignature(see), "")));
|
||||
|
||||
TypeElement refClass = ch.getReferencedClass(see);
|
||||
Element refMem = ch.getReferencedMember(see);
|
||||
@ -1149,10 +1150,10 @@ public class HtmlDocletWriter {
|
||||
}
|
||||
}
|
||||
|
||||
text = plainOrCode(kind == LINK_PLAIN, Text.of(refMemName));
|
||||
|
||||
return getDocLink(HtmlLinkInfo.Kind.SEE_TAG, containing,
|
||||
refMem, (labelContent.isEmpty() ? text: labelContent), null, false);
|
||||
refMem, (labelContent.isEmpty()
|
||||
? plainOrCode(isLinkPlain, Text.of(refMemName))
|
||||
: labelContent), null, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -489,7 +489,7 @@ public class SerializedFormBuilder extends AbstractBuilder {
|
||||
// TODO: Print the signature directly, if it is an array, the
|
||||
// current DocTree APIs makes it very hard to distinguish
|
||||
// an as these are returned back as "Array" a DeclaredType.
|
||||
if (refSignature.endsWith("[]")) {
|
||||
if (refSignature != null && refSignature.endsWith("[]")) {
|
||||
te = null;
|
||||
fieldType = refSignature;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2020, 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
|
||||
@ -461,11 +461,63 @@ public class CommentHelper {
|
||||
return new ReferenceDocTreeVisitor<String>() {
|
||||
@Override
|
||||
public String visitReference(ReferenceTree node, Void p) {
|
||||
return node.getSignature();
|
||||
return normalizeSignature(node.getSignature());
|
||||
}
|
||||
}.visit(dtree, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
private static String normalizeSignature(String sig) {
|
||||
if (sig == null
|
||||
|| (!sig.contains(" ") && !sig.contains("\n")
|
||||
&& !sig.contains("\r") && !sig.endsWith("/"))) {
|
||||
return sig;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
char lastChar = 0;
|
||||
for (int i = 0; i < sig.length(); i++) {
|
||||
char ch = sig.charAt(i);
|
||||
switch (ch) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\f':
|
||||
case '\t':
|
||||
case ' ':
|
||||
// Add at most one space char, or none if it isn't needed
|
||||
switch (lastChar) {
|
||||
case 0:
|
||||
case'(':
|
||||
case'<':
|
||||
case ' ':
|
||||
case '.':
|
||||
break;
|
||||
default:
|
||||
sb.append(' ');
|
||||
lastChar = ' ';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
case '>':
|
||||
case ')':
|
||||
case '.':
|
||||
// Remove preceding space character
|
||||
if (lastChar == ' ') {
|
||||
sb.setLength(sb.length() - 1);
|
||||
}
|
||||
// fallthrough
|
||||
default:
|
||||
sb.append(ch);
|
||||
lastChar = ch;
|
||||
}
|
||||
}
|
||||
// Delete trailing slash
|
||||
if (lastChar == '/') {
|
||||
sb.setLength(sb.length() - 1);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static class ReferenceDocTreeVisitor<R> extends SimpleDocTreeVisitor<R, Void> {
|
||||
@Override
|
||||
public R visitSee(SeeTree node, Void p) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 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 8017191 8182765 8200432 8239804
|
||||
* @bug 8017191 8182765 8200432 8239804 8250766
|
||||
* @summary Javadoc is confused by at-link to imported classes outside of the set of generated packages
|
||||
* @library ../../lib
|
||||
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
||||
@ -43,6 +43,7 @@ public class TestSeeTag extends JavadocTester {
|
||||
@Test
|
||||
public void test() {
|
||||
javadoc("-d", "out",
|
||||
"--no-platform-links",
|
||||
"-sourcepath", testSrc,
|
||||
"pkg");
|
||||
checkExit(Exit.OK);
|
||||
@ -55,7 +56,9 @@ public class TestSeeTag extends JavadocTester {
|
||||
<dd><a href="Test.InnerOne.html#foo()"><code>Test.InnerOne.foo()</code></a>,\s
|
||||
<a href="Test.InnerOne.html#bar(java.lang.Object)"><code>Test.InnerOne.bar(Object)</code></a>,\s
|
||||
<a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#see">Javadoc</a>,\s
|
||||
<a href="Test.InnerOne.html#baz(float)"><code>something</code></a></dd>
|
||||
<a href="Test.InnerOne.html#baz(float)"><code>something</code></a>,\s
|
||||
<a href="Test.InnerOne.html#format(java.lang.String,java.lang.Object...)"><code>Test\
|
||||
.InnerOne.format(java.lang.String, java.lang.Object...)</code></a></dd>
|
||||
</dl>""");
|
||||
|
||||
checkOutput("pkg/Test.html", false,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 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
|
||||
@ -28,11 +28,14 @@ import java.util.List;
|
||||
public class Test {
|
||||
|
||||
/**
|
||||
* Testing different combos of see tags.
|
||||
* Testing different combos of see tags, including some weird formatting.
|
||||
* @see InnerOne#foo()
|
||||
* @see InnerOne#bar(Object)
|
||||
* @see InnerOne#bar(
|
||||
* Object
|
||||
* )
|
||||
* @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#see">Javadoc</a>
|
||||
* @see InnerOne#baz(float priority) something
|
||||
* @see InnerOne#format( java .lang.String , java. lang.Object ... )
|
||||
*/
|
||||
public void foo() {}
|
||||
|
||||
@ -54,6 +57,13 @@ public class Test {
|
||||
* @param GravitationalConstant
|
||||
*/
|
||||
public void baz(float GravitationalConstant) {}
|
||||
|
||||
/**
|
||||
* Test for multiple args and varargs.
|
||||
*/
|
||||
public static String format(String s, Object... args) {
|
||||
return String.format(s, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user