Skip to content
Permalink
Browse files

8232438: Remove ?is-external=true from external links

Reviewed-by: prappo
  • Loading branch information
hns committed Feb 24, 2020
1 parent ccdde49 commit bb7344d9190b6ec120db2e47e153cb01e2cdd153
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, 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
@@ -26,11 +26,10 @@
package jdk.javadoc.internal.doclets.toolkit.util;

/**
* Abstraction for simple relative URIs, consisting of a path,
* an optional query, and an optional fragment. DocLink objects can
* be created by the constructors below or from a DocPath using the
* convenience methods, {@link DocPath#fragment fragment} and
* {@link DocPath#query query}.
* Abstraction for simple relative URIs, consisting of a path and an
* optional fragment. DocLink objects can be created by the constructors
* below or from a DocPath using the convenience
* {@link DocPath#fragment fragment} method.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
@@ -40,7 +39,6 @@
*/
public class DocLink {
final DocPath path;
final String query;
final String fragment;

/**
@@ -49,39 +47,36 @@
* @return the DocLink
*/
public static DocLink fragment(String fragment) {
return new DocLink((DocPath) null, (String) null, fragment);
return new DocLink((DocPath) null, fragment);
}

/**
* Creates a DocLink representing the URI {@code path}.
* @param path the path
*/
public DocLink(DocPath path) {
this(path, null, null);
this(path, null);
}

/**
* Creates a DocLink representing the URI {@code path?query#fragment}.
* Creates a DocLink representing the URI {@code path#fragment}.
* Any of the component parts may be null.
* @param path the path
* @param query the query
* @param fragment the fragment
*/
public DocLink(DocPath path, String query, String fragment) {
public DocLink(DocPath path, String fragment) {
this.path = path;
this.query = query;
this.fragment = fragment;
}

/**
* Creates a DocLink representing the URI {@code path?query#fragment}.
* Creates a DocLink representing the URI {@code path#fragment}.
* Any of the component parts may be null.
* @param path the path
* @param query the query
* @param fragment the fragment
*/
public DocLink(String path, String query, String fragment) {
this(DocPath.create(path), query, fragment);
public DocLink(String path, String fragment) {
this(DocPath.create(path), fragment);
}

/**
@@ -101,10 +96,10 @@ public DocLink relativizeAgainst(DocPath base) {

DocPath newPath = base.relativize(path);
// avoid generating an empty link by using the basename of the path if necessary
if (newPath.isEmpty() && isEmpty(query) && isEmpty(fragment)) {
if (newPath.isEmpty() && isEmpty(fragment)) {
newPath = path.basename();
}
return new DocLink(newPath, query, fragment);
return new DocLink(newPath, fragment);
}

// return true if the path begins <letters>://
@@ -121,21 +116,19 @@ private boolean isAbsoluteURL(DocPath path) {
}

/**
* Returns the link in the form "path?query#fragment", omitting any empty
* Returns the link in the form "path#fragment", omitting any empty
* components.
* @return the string
*/
@Override
public String toString() {
// common fast path
if (path != null && isEmpty(query) && isEmpty(fragment))
if (path != null && isEmpty(fragment))
return path.getPath();

StringBuilder sb = new StringBuilder();
if (path != null)
sb.append(path.getPath());
if (!isEmpty(query))
sb.append("?").append(query);
if (!isEmpty(fragment))
sb.append("#").append(fragment);
return sb.toString();
@@ -210,16 +210,7 @@ public boolean isEmpty() {
* @return the link
*/
public DocLink fragment(String fragment) {
return new DocLink(path, null, fragment);
}

/**
* Creates a DocLink formed from this path and a query string.
* @param query the query string
* @return the link
*/
public DocLink query(String query) {
return new DocLink(path, query, null);
return new DocLink(path, fragment);
}

/**
@@ -190,7 +190,7 @@ public DocLink getExternalLink(Element element, DocPath relativepath, String fil
DocPath p = fnd.relative ?
relativepath.resolve(fnd.path).resolve(filename) :
fnd.path.resolve(filename);
return new DocLink(p, "is-external=true", memberName);
return new DocLink(p, memberName);
}

/**
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2020, 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
@@ -54,15 +54,15 @@ public void test() {
checkExit(Exit.OK);

checkOutput("C.html", true,
"<a href=\"" + uri + "java/math/package-summary.html?is-external=true\" class=\"externalLink\">"
"<a href=\"" + uri + "java/math/package-summary.html\" class=\"externalLink\">"
+ "<code>Link to math package</code></a>",
"<a href=\"" + uri + "javax/swing/text/AbstractDocument.AttributeContext.html?is-external=true\" "
"<a href=\"" + uri + "javax/swing/text/AbstractDocument.AttributeContext.html\" "
+ "title=\"class or interface in javax.swing.text\" class=\"externalLink\"><code>Link to AttributeContext innerclass</code></a>",
"<a href=\"" + uri + "java/math/BigDecimal.html?is-external=true\" "
"<a href=\"" + uri + "java/math/BigDecimal.html\" "
+ "title=\"class or interface in java.math\" class=\"externalLink\"><code>Link to external class BigDecimal</code></a>",
"<a href=\"" + uri + "java/math/BigInteger.html?is-external=true#gcd(java.math.BigInteger)\" "
"<a href=\"" + uri + "java/math/BigInteger.html#gcd(java.math.BigInteger)\" "
+ "title=\"class or interface in java.math\" class=\"externalLink\"><code>Link to external member gcd</code></a>",
"<a href=\"" + uri + "javax/tools/SimpleJavaFileObject.html?is-external=true#uri\" "
"<a href=\"" + uri + "javax/tools/SimpleJavaFileObject.html#uri\" "
+ "title=\"class or interface in javax.tools\" class=\"externalLink\"><code>Link to external member URI</code></a>",
"<dl>\n"
+ "<dt><span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n"
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2020, 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
@@ -55,10 +55,10 @@ public void test() {
checkExit(Exit.OK);

checkOutput("TestDocRootTag.html", true,
"<a href=\"" + uri + "/java/io/File.html?is-external=true\" "
"<a href=\"" + uri + "/java/io/File.html\" "
+ "title=\"class or interface in java.io\" class=\"externalLink\"><code>File</code></a>",
"<a href=\"./index-all.html\">index</a>",
"<a href=\"" + uri + "/java/io/File.html?is-external=true\" "
"<a href=\"" + uri + "/java/io/File.html\" "
+ "title=\"class or interface in java.io\" class=\"externalLink\"><code>Second File Link</code></a>",
"The value of @docRoot is \"./\"");

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, 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
@@ -54,14 +54,14 @@ public void test() {

checkOutput("pkg/XReader.html", true,
"<dt><span class=\"overrideSpecifyLabel\">Overrides:</span></dt>\n"
+ "<dd><code><a href=\"" + uri + "/java/io/FilterReader.html?is-external=true#read()\" "
+ "<dd><code><a href=\"" + uri + "/java/io/FilterReader.html#read()\" "
+ "title=\"class or interface in java.io\" class=\"externalLink\">read</a></code>&nbsp;in class&nbsp;<code>"
+ "<a href=\"" + uri + "/java/io/FilterReader.html?is-external=true\" "
+ "<a href=\"" + uri + "/java/io/FilterReader.html\" "
+ "title=\"class or interface in java.io\" class=\"externalLink\">FilterReader</a></code></dd>",
"<dt><span class=\"overrideSpecifyLabel\">Specified by:</span></dt>\n"
+ "<dd><code><a href=\"" + uri + "/java/io/DataInput.html?is-external=true#readInt()\" "
+ "<dd><code><a href=\"" + uri + "/java/io/DataInput.html#readInt()\" "
+ "title=\"class or interface in java.io\" class=\"externalLink\">readInt</a></code>&nbsp;in interface&nbsp;<code>"
+ "<a href=\"" + uri + "/java/io/DataInput.html?is-external=true\" "
+ "<a href=\"" + uri + "/java/io/DataInput.html\" "
+ "title=\"class or interface in java.io\" class=\"externalLink\">DataInput</a></code></dd>"
);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, 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
@@ -52,7 +52,7 @@ public void test() {

checkOutput("pkg/C1.html", true,
//External link.
"href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html?is-external=true#wait(long,int)\"",
"href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html#wait(long,int)\"",
//Member summary table link.
"href=\"#method(int,int,java.util.ArrayList)\"",
//Anchor test.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2020, 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
@@ -71,26 +71,26 @@ public void test() {
checkExit(Exit.OK);

checkOutput("pkg/C.html", true,
"<a href=\"" + url + "java/lang/String.html?is-external=true\" "
"<a href=\"" + url + "java/lang/String.html\" "
+ "title=\"class or interface in java.lang\" class=\"externalLink\"><code>Link to String Class</code></a>",
//Make sure the parameters are formatted properly when the -link option is used.
"(int&nbsp;p1,\n"
+ "int&nbsp;p2,\n"
+ "int&nbsp;p3)",
"(int&nbsp;p1,\n"
+ "int&nbsp;p2,\n"
+ "<a href=\"" + url + "java/lang/Object.html?is-external=true\" title=\"class or interface in java.lang\" class=\"externalLink\">"
+ "<a href=\"" + url + "java/lang/Object.html\" title=\"class or interface in java.lang\" class=\"externalLink\">"
+ "Object</a>&nbsp;p3)");

checkOutput("pkg/B.html", true,
"<div class=\"block\">A method with html tag the method "
+ "<a href=\"" + url + "java/lang/ClassLoader.html?is-external=true#getSystemClassLoader()\""
+ "<a href=\"" + url + "java/lang/ClassLoader.html#getSystemClassLoader()\""
+ " title=\"class or interface in java.lang\" class=\"externalLink\"><code><b>getSystemClassLoader()</b>"
+ "</code></a> as the parent class loader.</div>",
"<div class=\"block\">is equivalent to invoking <code>"
+ "<a href=\"#createTempFile(java.lang.String,java.lang.String,java.io.File)\">"
+ "<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code></a></code>.</div>",
"<a href=\"" + url + "java/lang/String.html?is-external=true\" "
"<a href=\"" + url + "java/lang/String.html\" "
+ "title=\"class or interface in java.lang\" class=\"externalLink\">Link-Plain to String Class</a>",
"<code><b>getSystemClassLoader()</b></code>",
"<code>createTempFile(prefix,&nbsp;suffix,&nbsp;null)</code>",
@@ -107,7 +107,7 @@ public void test() {

checkOutput("mylib/lang/StringBuilderChild.html", true,
"<pre>public abstract class <span class=\"typeNameLabel\">StringBuilderChild</span>\n"
+ "extends <a href=\"" + url + "java/lang/Object.html?is-external=true\" "
+ "extends <a href=\"" + url + "java/lang/Object.html\" "
+ "title=\"class or interface in java.lang\" class=\"externalLink\">Object</a></pre>"
);

@@ -121,7 +121,7 @@ public void test() {
"pkg2");
checkExit(Exit.OK);
checkOutput("pkg2/C2.html", true,
"This is a link to <a href=\"../../" + out1 + "/pkg/C.html?is-external=true\" " +
"This is a link to <a href=\"../../" + out1 + "/pkg/C.html\" " +
"title=\"class or interface in pkg\" class=\"externalLink\"><code>Class C</code></a>."
);

@@ -150,10 +150,10 @@ public void test() {
+ "extends java.lang.Object</pre>\n"
+ "<div class=\"block\">Test links.\n"
+ " <br>\n"
+ " <a href=\"../../out2/pkg2/C2.html?is-external=true\" "
+ " <a href=\"../../out2/pkg2/C2.html\" "
+ "title=\"class or interface in pkg2\" class=\"externalLink\"><code>link to pkg2.C2</code></a>\n"
+ " <br>\n"
+ " <a href=\"../../out1/mylib/lang/StringBuilderChild.html?is-external=true\" "
+ " <a href=\"../../out1/mylib/lang/StringBuilderChild.html\" "
+ "title=\"class or interface in mylib.lang\" class=\"externalLink\">"
+ "<code>link to mylib.lang.StringBuilderChild</code></a>.</div>\n"
);
@@ -171,10 +171,10 @@ public void test() {
+ "extends java.lang.Object</pre>\n"
+ "<div class=\"block\">Test links.\n"
+ " <br>\n"
+ " <a href=\"../../copy/out2/pkg2/C2.html?is-external=true\" "
+ " <a href=\"../../copy/out2/pkg2/C2.html\" "
+ "title=\"class or interface in pkg2\" class=\"externalLink\"><code>link to pkg2.C2</code></a>\n"
+ " <br>\n"
+ " <a href=\"../../copy/out1/mylib/lang/StringBuilderChild.html?is-external=true\" "
+ " <a href=\"../../copy/out1/mylib/lang/StringBuilderChild.html\" "
+ "title=\"class or interface in mylib.lang\" class=\"externalLink\">"
+ "<code>link to mylib.lang.StringBuilderChild</code></a>.</div>\n"
);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@@ -103,7 +103,7 @@ public void testLinkUnnamedToAutomaticModule(Path base) throws IOException {
"p");
checkExit(Exit.OK);
checkOutput("p/MyClass.html", true,
"extends <a href=\"http://myWebsite/lib/LibClass.html?is-external=true\" "
"extends <a href=\"http://myWebsite/lib/LibClass.html\" "
+ "title=\"class or interface in lib\" class=\"externalLink\">LibClass</a>");
}

@@ -127,7 +127,7 @@ public void testLinkNamedToAutomaticModule(Path base) throws IOException {
"--module", "my.module");
checkExit(Exit.OK);
checkOutput("my.module/p/MyClass.html", true,
"extends <a href=\"http://myWebsite/lib/LibClass.html?is-external=true\" "
"extends <a href=\"http://myWebsite/lib/LibClass.html\" "
+ "title=\"class or interface in lib\" class=\"externalLink\">LibClass</a>");
}

@@ -151,7 +151,7 @@ public void testLinkNamedToUnnamedModule(Path base) throws IOException {
"--module", "my.module");
checkExit(Exit.OK);
checkOutput("my.module/p/MyClass.html", true,
"extends <a href=\"http://myWebsite/lib/LibClass.html?is-external=true\" "
"extends <a href=\"http://myWebsite/lib/LibClass.html\" "
+ "title=\"class or interface in lib\" class=\"externalLink\">LibClass</a>");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, 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
@@ -76,7 +76,7 @@ public void testModuleLinkedToModule(Path base) throws Exception {

checkExit(Exit.OK);
checkOutput("com.ex2/com/ex2/B.html", true,
"<a href=\"../../../../out1a/com.ex1/com/ex1/A.html?is-external=true\" "
"<a href=\"../../../../out1a/com.ex1/com/ex1/A.html\" "
+ "title=\"class or interface in com.ex1\" class=\"externalLink\">A</a>");
}

@@ -95,7 +95,7 @@ public void testPackageLinkedToPackage(Path base) throws Exception {

checkExit(Exit.OK);
checkOutput("com/ex2/B.html", true,
"<a href=\"../../../out2a/com/ex1/A.html?is-external=true\" title=\"class or interface in com.ex1\" "
"<a href=\"../../../out2a/com/ex1/A.html\" title=\"class or interface in com.ex1\" "
+ "class=\"externalLink\">A</a>");
}

0 comments on commit bb7344d

Please sign in to comment.