Coverage Report - de.smartics.exceptions.report.renderer.JavadocRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
JavadocRenderer
0%
0/54
0%
0/22
3,75
 
 1  
 /*
 2  
  * Copyright 2007-2013 smartics, Kronseder & Reiner GmbH
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package de.smartics.exceptions.report.renderer;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import com.thoughtworks.qdox.model.DocletTag;
 21  
 import com.thoughtworks.qdox.model.JavaAnnotatedElement;
 22  
 
 23  
 import de.smartics.exceptions.report.utils.InlineJavadocTags;
 24  
 
 25  
 /**
 26  
  * Renderer for Javadoc information.
 27  
  */
 28  
 public final class JavadocRenderer
 29  
 {
 30  
   // ********************************* Fields *********************************
 31  
 
 32  
   // --- constants ------------------------------------------------------------
 33  
 
 34  
   // --- members --------------------------------------------------------------
 35  
 
 36  
   /**
 37  
    * The factory to create the renderers to use.
 38  
    */
 39  
   private final RendererFactory factory;
 40  
 
 41  
   // ****************************** Initializer *******************************
 42  
 
 43  
   // ****************************** Constructors ******************************
 44  
 
 45  
   /**
 46  
    * Default constructor.
 47  
    *
 48  
    * @param factory the factory to create the renderers to use.
 49  
    */
 50  
   public JavadocRenderer(final RendererFactory factory)
 51  0
   {
 52  0
     this.factory = factory;
 53  0
   }
 54  
 
 55  
   // ****************************** Inner Classes *****************************
 56  
 
 57  
   // ********************************* Methods ********************************
 58  
 
 59  
   // --- init -----------------------------------------------------------------
 60  
 
 61  
   // --- get&set --------------------------------------------------------------
 62  
 
 63  
   // --- business -------------------------------------------------------------
 64  
 
 65  
   /**
 66  
    * Renders the information found in a Javadoc.
 67  
    *
 68  
    * @param doc the comment to render.
 69  
    * @return the rendered string.
 70  
    */
 71  
   public String render(final JavaAnnotatedElement doc)
 72  
   {
 73  0
     final StringBuilder buffer = new StringBuilder(256);
 74  
 
 75  0
     renderInlineTags(doc, buffer);
 76  0
     renderTags(doc, buffer);
 77  
 
 78  0
     return buffer.toString();
 79  
   }
 80  
 
 81  
   private void renderInlineTags(final JavaAnnotatedElement doc,
 82  
       final StringBuilder buffer)
 83  
   {
 84  0
     final InlineJavadocTags tags = new InlineJavadocTags(doc);
 85  
 
 86  0
     for (final DocletTag tag : tags)
 87  
     {
 88  0
       final String tagName = tag.getName();
 89  0
       if ("link".equals(tagName))
 90  
       {
 91  0
         final LinkTagRenderer renderer = factory.createLinkTagRenderer();
 92  0
         renderer.render(buffer, tag);
 93  0
       }
 94  0
       else if ("linkplain".equals(tagName))
 95  
       {
 96  0
         final LinkPlainTagRenderer renderer =
 97  
             factory.createLinkPlainTagRenderer();
 98  0
         renderer.render(buffer, tag);
 99  0
       }
 100  0
       else if ("literal".equals(tagName))
 101  
       {
 102  0
         final LiteralTagRenderer renderer = factory.createLiteralTagRenderer();
 103  0
         renderer.render(buffer, tag);
 104  0
       }
 105  0
       else if ("code".equals(tagName))
 106  
       {
 107  0
         final CodeTagRenderer renderer = factory.createCodeTagRenderer();
 108  0
         renderer.render(buffer, tag);
 109  0
       }
 110  0
       else if ("value".equals(tagName))
 111  
       {
 112  0
         final ValueTagRenderer renderer = factory.createValueTagRenderer();
 113  0
         renderer.render(buffer, tag);
 114  0
       }
 115  
       else
 116  
       {
 117  0
         final TextRenderer renderer = factory.createTextRenderer();
 118  0
         renderer.render(buffer, tag.getValue());
 119  
       }
 120  0
     }
 121  0
   }
 122  
 
 123  
   private void renderTags(final JavaAnnotatedElement doc,
 124  
       final StringBuilder buffer)
 125  
   {
 126  0
     final List<DocletTag> tags = doc.getTags();
 127  
 
 128  0
     if (!tags.isEmpty())
 129  
     {
 130  0
       final TagListRenderer listRenderer = factory.createTagListRenderer();
 131  0
       listRenderer.renderListStart(buffer);
 132  0
       for (final DocletTag tag : tags)
 133  
       {
 134  0
         final String tagName = tag.getName();
 135  0
         if ("see".equals(tagName))
 136  
         {
 137  0
           final SeeTagRenderer renderer = factory.createSeeTagRenderer();
 138  0
           renderer.render(buffer, tag);
 139  0
         }
 140  0
         else if ("version".equals(tagName))
 141  
         {
 142  0
           final SinceTagRenderer renderer = factory.createSinceTagRenderer();
 143  0
           renderer.render(buffer, tag);
 144  0
         }
 145  0
         else if ("since".equals(tagName))
 146  
         {
 147  0
           final VersionTagRenderer renderer =
 148  
               factory.createVersionTagRenderer();
 149  0
           renderer.render(buffer, tag);
 150  
         }
 151  0
       }
 152  0
       listRenderer.renderListEnd(buffer);
 153  
     }
 154  0
   }
 155  
 
 156  
   // --- object basics --------------------------------------------------------
 157  
 
 158  
 }