Coverage Report - uk.co.badgersinfoil.asxsd.DocUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
DocUtils
15% 
25% 
2.667
 
 1  
 package uk.co.badgersinfoil.asxsd;
 2  
 
 3  
 import java.util.Iterator;
 4  
 import java.util.List;
 5  
 import org.eclipse.xsd.XSDAnnotation;
 6  
 import org.w3c.dom.Element;
 7  
 import uk.co.badgersinfoil.metaas.dom.Documentable;
 8  
 
 9  0
 public class DocUtils {
 10  
         /**
 11  
          * 
 12  
          * @param anno if null, this function does nothing
 13  
          * @param element the API element who's documentation is to be set
 14  
          */
 15  
         public static void assignDescriptionFromAnnotation(XSDAnnotation anno, Documentable element) {
 16  0
                 if (anno != null) {
 17  0
                         String doc = findDocumentation(anno);
 18  0
                         if (doc != null) {
 19  0
                                 element.setDescription(doc);
 20  
                         }
 21  
                 }
 22  0
         }
 23  
         /**
 24  
          * attempt to extract simple text from the documentation element of the
 25  
          * given annotation.
 26  
          */
 27  
         public static String findDocumentation(XSDAnnotation annotation) {
 28  27
                 if (annotation != null) {
 29  0
                         List docs = annotation.getUserInformation();
 30  0
                         for (Iterator i = docs.iterator(); i.hasNext(); ) {
 31  
                                 // maybe we can do better..?
 32  0
                                 Element doc = (Element)i.next();
 33  0
                                 return preProcessComment(doc.getTextContent());
 34  
                         }
 35  
                 }
 36  27
                 return null;
 37  
         }
 38  
 
 39  
         /**
 40  
          * Strip initial whitespace from all lines in the given string, and
 41  
          * return a string which starts each line with a single space character,
 42  
          * ready to go into a javadoc comment.
 43  
          */
 44  
         private static String preProcessComment(String text) {
 45  0
                 return text.replaceFirst("\\A\\s*", " ").replaceAll("([\n\r])\\s+", "$1 ");
 46  
         }
 47  
 }