gt:         HtmlTree htmltree = new HtmlTree(HtmlTag.LI, nullCheck(body));
context: /*
   * Copyright (c) 2010, 2012, 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
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Oracle in the LICENSE file that accompanied this code.
   *
   * This code is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   * version 2 for more details (a copy is included in the LICENSE file that
   * accompanied this code).
   *
   * You should have received a copy of the GNU General Public License version
   * 2 along with this work; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   *
   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  package com.sun.tools.doclets.formats.html.markup;
  
  import java.io.IOException;
  import java.io.Writer;
  import java.util.*;
  
  import com.sun.tools.doclets.internal.toolkit.Content;
  import com.sun.tools.doclets.internal.toolkit.util.*;
  
  /**
   * Class for generating HTML tree for javadoc output.
   *
   *  <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.
   *  This code and its internal interfaces are subject to change or
   *  deletion without notice.</b>
   *
   * @author Bhavesh Patel
   */
  public class HtmlTree extends Content {
  
      private HtmlTag htmlTag;
      private Map<HtmlAttr,String> attrs = Collections.<HtmlAttr,String>emptyMap();
      private List<Content> content = Collections.<Content>emptyList();
      public static final Content EMPTY = new StringContent("");
  
      /**
       * Constructor to construct HtmlTree object.
       *
       * @param tag HTML tag for the HtmlTree object
       */
      public HtmlTree(HtmlTag tag) {
          htmlTag = nullCheck(tag);
      }
  
      /**
       * Constructor to construct HtmlTree object.
       *
       * @param tag HTML tag for the HtmlTree object
       * @param contents contents to be added to the tree
       */
      public HtmlTree(HtmlTag tag, Content... contents) {
          this(tag);
          for (Content content: contents)
              addContent(content);
      }
  
      /**
       * Adds an attribute for the HTML tag.
       *
       * @param attrName name of the attribute
       * @param attrValue value of the attribute
       */
      public void addAttr(HtmlAttr attrName, String attrValue) {
          if (attrs.isEmpty())
              attrs = new LinkedHashMap<HtmlAttr,String>();
          attrs.put(nullCheck(attrName), nullCheck(attrValue));
      }
  
      /**
       * Adds a style for the HTML tag.
       *
       * @param style style to be added
       */
      public void addStyle(HtmlStyle style) {
          addAttr(HtmlAttr.CLASS, style.toString());
      }
  
      /**
       * Adds content for the HTML tag.
       *
       * @param tagContent tag content to be added
       */
      public void addContent(Content tagContent) {
          if (tagContent == HtmlTree.EMPTY || tagContent.isValid()) {
              if (content.isEmpty())
                  content = new ArrayList<Content>();
              content.add(tagContent);
          }
      }
  
      /**
       * This method adds a string content to the htmltree. If the last content member
       * added is a StringContent, append the string to that StringContent or else
       * create a new StringContent and add it to the html tree.
       *
       * @param stringContent string content that needs to be added
       */
      public void addContent(String stringContent) {
          if (!content.isEmpty()) {
              Content lastContent = content.get(content.size() - 1);
              if (lastContent instanceof StringContent)
                  lastContent.addContent(stringContent);
              else
                  addContent(new StringContent(stringContent));
          }
          else
              addContent(new StringContent(stringContent));
      }
  
      /**
       * Generates an HTML anchor tag.
       *
       * @param ref reference url for the anchor tag
       * @param body content for the anchor tag
       * @return an HtmlTree object
       */
      public static HtmlTree A(String ref, Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.A, nullCheck(body));
          htmltree.addAttr(HtmlAttr.HREF, nullCheck(ref));
          return htmltree;
      }
  
      /**
       * Generates an HTML anchor tag with name attribute and content.
       *
       * @param name name for the anchor tag
       * @param body content for the anchor tag
       * @return an HtmlTree object
       */
      public static HtmlTree A_NAME(String name, Content body) {
          HtmlTree htmltree = HtmlTree.A_NAME(name);
          htmltree.addContent(nullCheck(body));
          return htmltree;
      }
  
      /**
       * Generates an HTML anchor tag with name attribute.
       *
       * @param name name for the anchor tag
       * @return an HtmlTree object
       */
      public static HtmlTree A_NAME(String name) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.A);
          htmltree.addAttr(HtmlAttr.NAME, nullCheck(name));
          return htmltree;
      }
  
      /**
       * Generates a CAPTION tag with some content.
       *
       * @param body content for the tag
       * @return an HtmlTree object for the CAPTION tag
       */
      public static HtmlTree CAPTION(Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.CAPTION, nullCheck(body));
          return htmltree;
      }
  
      /**
       * Generates a CODE tag with some content.
       *
       * @param body content for the tag
       * @return an HtmlTree object for the CODE tag
       */
      public static HtmlTree CODE(Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.CODE, nullCheck(body));
          return htmltree;
      }
  
      /**
       * Generates a DD tag with some content.
       *
       * @param body content for the tag
       * @return an HtmlTree object for the DD tag
       */
      public static HtmlTree DD(Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.DD, nullCheck(body));
          return htmltree;
      }
  
      /**
       * Generates a DL tag with some content.
       *
       * @param body content for the tag
       * @return an HtmlTree object for the DL tag
       */
      public static HtmlTree DL(Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.DL, nullCheck(body));
          return htmltree;
      }
  
      /**
       * Generates a DIV tag with the style class attributes. It also encloses
       * a content.
       *
       * @param styleClass stylesheet class for the tag
       * @param body content for the tag
       * @return an HtmlTree object for the DIV tag
       */
      public static HtmlTree DIV(HtmlStyle styleClass, Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.DIV, nullCheck(body));
          if (styleClass != null)
              htmltree.addStyle(styleClass);
          return htmltree;
      }
  
      /**
       * Generates a DIV tag with some content.
       *
       * @param body content for the tag
       * @return an HtmlTree object for the DIV tag
       */
      public static HtmlTree DIV(Content body) {
          return DIV(null, body);
      }
  
      /**
       * Generates a DT tag with some content.
       *
       * @param body content for the tag
       * @return an HtmlTree object for the DT tag
       */
      public static HtmlTree DT(Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.DT, nullCheck(body));
          return htmltree;
      }
  
      /**
       * Generates a EM tag with some content.
       *
       * @param body content to be added to the tag
       * @return an HtmlTree object for the EM tag
       */
      public static HtmlTree EM(Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.EM, nullCheck(body));
          return htmltree;
      }
  
      /**
       * Generates a FRAME tag.
       *
       * @param src the url of the document to be shown in the frame
       * @param name specifies the name of the frame
       * @param title the title for the frame
       * @param scrolling specifies whether to display scrollbars in the frame
       * @return an HtmlTree object for the FRAME tag
       */
      public static HtmlTree FRAME(String src, String name, String title, String scrolling) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.FRAME);
          htmltree.addAttr(HtmlAttr.SRC, nullCheck(src));
          htmltree.addAttr(HtmlAttr.NAME, nullCheck(name));
          htmltree.addAttr(HtmlAttr.TITLE, nullCheck(title));
          if (scrolling != null)
              htmltree.addAttr(HtmlAttr.SCROLLING, scrolling);
          return htmltree;
      }
  
      /**
       * Generates a Frame tag.
       *
       * @param src the url of the document to be shown in the frame
       * @param name specifies the name of the frame
       * @param title the title for the frame
       * @return an HtmlTree object for the SPAN tag
       */
      public static HtmlTree FRAME(String src, String name, String title) {
          return FRAME(src, name, title, null);
      }
  
      /**
       * Generates a FRAMESET tag.
       *
       * @param cols the size of columns in the frameset
       * @param rows the size of rows in the frameset
       * @param title the title for the frameset
       * @param onload the script to run when the document loads
       * @return an HtmlTree object for the FRAMESET tag
       */
      public static HtmlTree FRAMESET(String cols, String rows, String title, String onload) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.FRAMESET);
          if (cols != null)
              htmltree.addAttr(HtmlAttr.COLS, cols);
          if (rows != null)
              htmltree.addAttr(HtmlAttr.ROWS, rows);
          htmltree.addAttr(HtmlAttr.TITLE, nullCheck(title));
          htmltree.addAttr(HtmlAttr.ONLOAD, nullCheck(onload));
          return htmltree;
      }
  
      /**
       * Generates a heading tag (h1 to h6) with the title and style class attributes. It also encloses
       * a content.
       *
       * @param headingTag the heading tag to be generated
       * @param printTitle true if title for the tag needs to be printed else false
       * @param styleClass stylesheet class for the tag
       * @param body content for the tag
       * @return an HtmlTree object for the tag
       */
      public static HtmlTree HEADING(HtmlTag headingTag, boolean printTitle,
              HtmlStyle styleClass, Content body) {
          HtmlTree htmltree = new HtmlTree(headingTag, nullCheck(body));
          if (printTitle)
              htmltree.addAttr(HtmlAttr.TITLE, Util.stripHtml(body.toString()));
          if (styleClass != null)
              htmltree.addStyle(styleClass);
          return htmltree;
      }
  
      /**
       * Generates a heading tag (h1 to h6) with style class attribute. It also encloses
       * a content.
       *
       * @param headingTag the heading tag to be generated
       * @param styleClass stylesheet class for the tag
       * @param body content for the tag
       * @return an HtmlTree object for the tag
       */
      public static HtmlTree HEADING(HtmlTag headingTag, HtmlStyle styleClass, Content body) {
          return HEADING(headingTag, false, styleClass, body);
      }
  
      /**
       * Generates a heading tag (h1 to h6) with the title attribute. It also encloses
       * a content.
       *
       * @param headingTag the heading tag to be generated
       * @param printTitle true if the title for the tag needs to be printed else false
       * @param body content for the tag
       * @return an HtmlTree object for the tag
       */
      public static HtmlTree HEADING(HtmlTag headingTag, boolean printTitle, Content body) {
          return HEADING(headingTag, printTitle, null, body);
      }
  
      /**
       * Generates a heading tag (h1 to h6)  with some content.
       *
       * @param headingTag the heading tag to be generated
       * @param body content for the tag
       * @return an HtmlTree object for the tag
       */
      public static HtmlTree HEADING(HtmlTag headingTag, Content body) {
          return HEADING(headingTag, false, null, body);
      }
  
      /**
       * Generates an HTML tag with lang attribute. It also adds head and body
       * content to the HTML tree.
       *
       * @param lang language for the HTML document
       * @param head head for the HTML tag
       * @param body body for the HTML tag
       * @return an HtmlTree object for the HTML tag
       */
      public static HtmlTree HTML(String lang, Content head, Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.HTML, nullCheck(head), nullCheck(body));
          htmltree.addAttr(HtmlAttr.LANG, nullCheck(lang));
          return htmltree;
      }
  
      /**
       * Generates a I tag with some content.
       *
       * @param body content for the tag
       * @return an HtmlTree object for the I tag
       */
      public static HtmlTree I(Content body) {
          HtmlTree htmltree = new HtmlTree(HtmlTag.I, nullCheck(body));
          return htmltree;
      }
  
      /**
       * Generates a LI tag with some content.
       *
       * @param body content for the tag
       * @return an HtmlTree object for the LI tag
       */
      public static HtmlTree LI(Content body) {
          return LI(null, body);
      }
  
      /**
       * Generates a LI tag with some content.
       *
       * @param styleClass style for the tag
       * @param body content for the tag
       * @return an HtmlTree object for the LI tag
       */
      public static HtmlTree LI(HtmlStyle styleClass, Content body) {
  