1 /*
   2  * Copyright (c) 2003, 2015, 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 4965490
  27  * @summary Verify that matching braces can appear within inline tags.
  28  * @ignore API, re-evaluate @bold, @maybe causes doclint to throw up.
  29  * @modules jdk.javadoc
  30  */
  31 
  32 import java.io.File;
  33 import java.util.Collections;
  34 import java.util.List;
  35 import java.util.Set;
  36 
  37 import javax.lang.model.SourceVersion;
  38 import javax.lang.model.element.TypeElement;
  39 
  40 import com.sun.source.doctree.DocCommentTree;
  41 import com.sun.source.doctree.DocTree;
  42 import com.sun.source.util.DocTrees;
  43 import jdk.javadoc.doclet.Doclet;
  44 import jdk.javadoc.doclet.DocletEnvironment;
  45 
  46 /**
  47  * This is a {@code test} comment.
  48  * It is {@bold {@underline only} a test}.
  49  * We would like some code
  50  * {@code for (int i : nums) { doit(i); } return; }
  51  * to be embedded {@maybe {even {a couple {of levels}}} deep}.
  52  */
  53 public class InlineTagsWithBraces implements Doclet {
  54 
  55     private static String[] expectedTags = {
  56         "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 }