Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8338133

Cleanup direct use of `new HtmlTree`

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 24
    • 24
    • tools
    • None

    Description

      For clarity of code and ease of reading, we have tended towards using factory methods to create instances of `HtmlTree`, using `HtmlTree.TAG(...)` instead of `new HtmlTree(HtmlTag.TAG`.

      Auditing the remaining direct uses of `new HtmlTree` reveals that many can now be replaced by existing factory methods, and that only a few factory methods need be added to completely transition to this code pattern.

      Here are the stats for the remaining non-local uses of `new HtmlTree`:

      $ grep -r -o 'new HtmlTree(HtmlTag[^)]*)' open/src/jdk.javadoc | grep -v HtmlTree.java | sed -e 's/^.*://' | sort | uniq -c | sort -h -r
         7 new HtmlTree(HtmlTag.HR)
         7 new HtmlTree(HtmlTag.BR)
         6 new HtmlTree(HtmlTag.WBR)
         6 new HtmlTree(HtmlTag.BUTTON)
         5 new HtmlTree(HtmlTag.CODE)
         4 new HtmlTree(HtmlTag.DIV)
         3 new HtmlTree(HtmlTag.PRE)
         3 new HtmlTree(HtmlTag.LI)
         3 new HtmlTree(HtmlTag.DD)
         3 new HtmlTree(HtmlTag.BODY)
         2 new HtmlTree(HtmlTag.UL)
         2 new HtmlTree(HtmlTag.IMG)
         1 new HtmlTree(HtmlTag.SCRIPT)
         1 new HtmlTree(HtmlTag.P)
         1 new HtmlTree(HtmlTag.META)
         1 new HtmlTree(HtmlTag.LINK)
         1 new HtmlTree(HtmlTag.HEAD)
         1 new HtmlTree(HtmlTag.EM)


      Analyzing those results further, we can identify which tags have like-named factory methods, and which do not:

      HR:
      BR:
      WBR:
      BUTTON:
      CODE:
          public static HtmlTree CODE(Content body) {
      DIV:
          public static HtmlTree DIV(HtmlStyle style) {
          public static HtmlTree DIV(HtmlStyle style, Content body) {
          public static HtmlTree DIV(Content body) {
      PRE:
          public static HtmlTree PRE(Content body) {
      LI:
          public static HtmlTree LI(Content body) {
          public static HtmlTree LI(HtmlStyle style, Content body) {
      DD:
          public static HtmlTree DD(Content body) {
      BODY:
      UL:
          public static HtmlTree UL(HtmlStyle style) {
          public static HtmlTree UL(HtmlStyle style, Content first, Content... more) {
          public static <T> HtmlTree UL(HtmlStyle style, Collection<T> items, Function<T,Content> mapper) {
      IMG:
      SCRIPT:
          public static HtmlTree SCRIPT(String src) {
      P:
          public static HtmlTree P(Content body) {
          public static HtmlTree P(HtmlStyle style, Content body) {
      META:
          public static HtmlTree META(String httpEquiv, String content, String charset) {
          public static HtmlTree META(String name, String content) {
      LINK:
          public static HtmlTree LINK(String rel, String type, String href, String title) {
      HEAD:
      EM:

      Thus, the following tags do not have factory methods:

      HR, BR, WBR, BUTTON, BODY, IMG, HEAD, EM

      Also of note, HR, BR, and WBR could use singleton instances.

      Attachments

        Issue Links

          Activity

            People

              jjg Jonathan Gibbons
              jjg Jonathan Gibbons
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: