InlineTagsWithBraces.java revision 3233:b5d08bc0d224
1255365Sdes/* 2255365Sdes * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. 3255365Sdes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4255365Sdes * 5255365Sdes * This code is free software; you can redistribute it and/or modify it 6255365Sdes * under the terms of the GNU General Public License version 2 only, as 7255365Sdes * published by the Free Software Foundation. 8255365Sdes * 9255365Sdes * This code is distributed in the hope that it will be useful, but WITHOUT 10255365Sdes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11255365Sdes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12255365Sdes * version 2 for more details (a copy is included in the LICENSE file that 13255365Sdes * accompanied this code). 14255365Sdes * 15255365Sdes * You should have received a copy of the GNU General Public License version 16255365Sdes * 2 along with this work; if not, write to the Free Software Foundation, 17255365Sdes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18255365Sdes * 19255365Sdes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20255365Sdes * or visit www.oracle.com if you need additional information or have any 21255365Sdes * questions. 22255365Sdes */ 23255365Sdes 24255365Sdes/* 25255365Sdes * @test 26255365Sdes * @bug 4965490 27255365Sdes * @summary Verify that matching braces can appear within inline tags. 28255365Sdes * @ignore API, re-evaluate @bold, @maybe causes doclint to throw up. 29255365Sdes * @modules jdk.javadoc 30255365Sdes */ 31255365Sdes 32255365Sdesimport java.io.File; 33255365Sdesimport java.util.Collections; 34255365Sdesimport java.util.List; 35255365Sdesimport java.util.Set; 36255365Sdes 37255365Sdesimport javax.lang.model.SourceVersion; 38255365Sdesimport javax.lang.model.element.TypeElement; 39255365Sdes 40255365Sdesimport com.sun.source.doctree.DocCommentTree; 41255365Sdesimport com.sun.source.doctree.DocTree; 42255365Sdesimport com.sun.source.util.DocTrees; 43255365Sdesimport jdk.javadoc.doclet.Doclet; 44255365Sdesimport jdk.javadoc.doclet.DocletEnvironment; 45255365Sdes 46255365Sdes/** 47255365Sdes * This is a {@code test} comment. 48255365Sdes * It is {@bold {@underline only} a test}. 49255365Sdes * We would like some code 50255365Sdes * {@code for (int i : nums) { doit(i); } return; } 51255365Sdes * to be embedded {@maybe {even {a couple {of levels}}} deep}. 52255365Sdes */ 53255365Sdespublic class InlineTagsWithBraces implements Doclet { 54255365Sdes 55255365Sdes private static String[] expectedTags = { 56255365Sdes "Text", "@code", "Text", 57 "@bold", "Text", "@code", "Text", 58 "@maybe", "Text" 59 }; 60 private static String[] expectedText = { 61 "This is a ", "test", " comment.\n" + 62 " It is ", "{@underline only} a test", ".\n" + 63 " We would like some code\n" + 64 " ", "for (int i : nums) { doit(i); } return; ", "\n" + 65 " to be embedded ", "{even {a couple {of levels}}} deep", "." 66 }; 67 68 public static void main(String[] args) { 69 String thisFile = "" + 70 new File(System.getProperty("test.src", "."), "InlineTagsWithBraces.java"); 71 72 String[] argarray = { 73 "InlineTagsWithBraces", 74 "-Xwerror", 75 thisFile 76 }; 77 if (jdk.javadoc.internal.tool.Main.execute(argarray) != 0) 78 throw new Error("Javadoc encountered warnings or errors."); 79 } 80 81 public boolean run(DocletEnvironment root) { 82 DocTrees trees = root.getDocTrees(); 83 TypeElement cd = root.getIncludedClasses().iterator().next(); 84 DocCommentTree docCommentTree = trees.getDocCommentTree(cd); 85 List<? extends DocTree> tags = docCommentTree.getBody(); 86 87 for (int i = 0; i < tags.size(); i++) { 88 System.out.println(tags.get(0).getKind()); 89// if (!tags[i].name().equals(expectedTags[i]) || 90// !tags[i].text().equals(expectedText[i])) { 91// throw new Error("Tag \"" + tags[i] + "\" not as expected"); 92// } 93 } 94 95 return true; 96 } 97 98 @Override 99 public String getName() { 100 return "Test"; 101 } 102 103 @Override 104 public Set<Option> getSupportedOptions() { 105 return Collections.emptySet(); 106 } 107 108 @Override 109 public SourceVersion getSupportedSourceVersion() { 110 return SourceVersion.latest(); 111 } 112} 113