1 /* 2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8202462 27 * @summary {@index} may cause duplicate labels 28 * @library /tools/lib ../../lib 29 * @modules jdk.javadoc/jdk.javadoc.internal.tool 30 * @build javadoc.tester.* toolbox.ToolBox builder.ClassBuilder 31 * @run main TestIndexTaglet 32 */ 33 34 35 import java.nio.file.Path; 36 import java.nio.file.Paths; 37 38 import builder.ClassBuilder; 39 import builder.ClassBuilder.MethodBuilder; 40 import toolbox.ToolBox; 41 42 import javadoc.tester.JavadocTester; 43 44 public class TestIndexTaglet extends JavadocTester { 45 46 final ToolBox tb; 47 48 public static void main(String... args) throws Exception { 49 TestIndexTaglet tester = new TestIndexTaglet(); 50 tester.runTests(m -> new Object[] { Paths.get(m.getName()) }); 51 } 52 53 TestIndexTaglet() { 54 tb = new ToolBox(); 55 } 56 57 @Test 58 public void test(Path base) throws Exception { 59 Path srcDir = base.resolve("src"); 60 Path outDir = base.resolve("out"); 61 62 MethodBuilder method = MethodBuilder 63 .parse("public void func(A a) {}") 64 .setComments("test description with {@index search_phrase_a class a}"); 65 66 new ClassBuilder(tb, "pkg.A") 67 .setModifiers("public", "class") 68 .addMembers(method) 69 .write(srcDir); 70 71 javadoc("-d", outDir.toString(), 72 "-sourcepath", srcDir.toString(), 73 "pkg"); 74 75 checkExit(Exit.OK); 76 77 checkOrder("pkg/A.html", 78 "<h2>Method Details</h2>\n", 79 "<div class=\"block\">test description with <a id=\"search_phrase_a\" " 80 + "class=\"searchTagResult\">search_phrase_a</a></div>"); 81 82 checkOrder("pkg/A.html", 83 "<h2>Method Summary</h2>\n", 84 "<div class=\"block\">test description with search_phrase_a</div>"); 85 } 86 87 @Test 88 public void testIndexWithinATag(Path base) throws Exception { 89 Path srcDir = base.resolve("src"); 90 Path outDir = base.resolve("out"); 91 92 new ClassBuilder(tb, "pkg2.A") 93 .setModifiers("public", "class") 94 .addMembers(MethodBuilder.parse("public void func(){}") 95 .setComments("a within a : <a href='..'>{@index check}</a>")) 96 .write(srcDir); 97 98 javadoc("-d", outDir.toString(), 99 "-sourcepath", srcDir.toString(), 100 "pkg2"); 101 102 checkExit(Exit.OK); 103 104 checkOutput(Output.OUT, true, 105 "warning: {@index} tag, which expands to <a>, within <a>"); 106 } 107 108 @Test 109 public void testDuplicateReferences(Path base) throws Exception { 110 Path srcDir = base.resolve("src"); 111 Path outDir = base.resolve("out"); 112 113 new ClassBuilder(tb, "pkg.A") 114 .setModifiers("public", "class") 115 .setComments("This is a class. Here is {@index foo first}.") 116 .addMembers(MethodBuilder.parse("public void m() {}") 117 .setComments("This is a method. Here is {@index foo second}.")) 118 .write(srcDir); 119 120 javadoc("-d", outDir.toString(), 121 "-sourcepath", srcDir.toString(), 122 "pkg"); 123 124 checkExit(Exit.OK); 125 126 checkOutput("pkg/A.html", true, 127 "This is a class. Here is <a id=\"foo\" class=\"searchTagResult\">foo</a>.", 128 "This is a method. Here is <a id=\"foo-1\" class=\"searchTagResult\">foo</a>."); 129 } 130 }