Coverage Report - no.sesat.mojo.modes.ConfigElement
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigElement
0%
0/30
0%
0/12
0
 
 1  
 package no.sesat.mojo.modes;
 2  
 
 3  
 import java.util.List;
 4  
 import java.util.Set;
 5  
 import java.util.TreeSet;
 6  
 import java.util.Vector;
 7  
 
 8  
 import com.sun.javadoc.ClassDoc;
 9  
 import com.sun.javadoc.MethodDoc;
 10  
 import com.sun.javadoc.Parameter;
 11  
 
 12  
 /**
 13  
  * Represent a class/xml element.
 14  
  *
 15  
  */
 16  
 public class ConfigElement extends ConfigAbstract {
 17  
 
 18  0
     protected final List<ConfigAttribute> attributes = new Vector<ConfigAttribute>();
 19  0
     private final Set<String> attribNames = new TreeSet<String>();
 20  
     protected final int id;
 21  0
     private static int idCounter = 0;
 22  
 
 23  0
     protected List<ConfigElement> children = new Vector<ConfigElement>();
 24  
 
 25  
     /**
 26  
      * @param name Name of this element.
 27  
      */
 28  0
     public ConfigElement(final String name) {
 29  0
         id = ++idCounter;
 30  0
         this.name = name;
 31  0
     }
 32  
 
 33  
     /**
 34  
      * @param klass Class that this element should be based on.
 35  
      */
 36  
     public ConfigElement(final ClassDoc klass) {
 37  0
         this(klass.name());
 38  
 
 39  0
         doc = klass.commentText();
 40  
 
 41  
         // some fake attributes
 42  0
         attributes.add(new ConfigAttribute("inherit"));
 43  
 
 44  0
         build(klass);
 45  0
     }
 46  
 
 47  
     /**
 48  
      * @param filter filter used to modify the name
 49  
      */
 50  
     public void applyNameFilter(final NameFilter filter) {
 51  0
         name = filter.filter(name);
 52  0
     }
 53  
 
 54  
     /**
 55  
      * @param childrenList children that we want to add.
 56  
      */
 57  
     public void addChildren(final List<ConfigElement> childrenList) {
 58  0
         children.addAll(childrenList);
 59  0
     }
 60  
 
 61  
     /**
 62  
      * @param child child that we want to add.
 63  
      */
 64  
     public void addChild(final ConfigElement child) {
 65  0
         children.add(child);
 66  0
     }
 67  
 
 68  
     private void build(final ClassDoc klass) {
 69  
 
 70  0
         if (klass != null) {
 71  0
             final MethodDoc[] methods = klass.methods();
 72  0
             for (int i = 0; i < methods.length; i++) {
 73  
 
 74  0
                 final MethodDoc methodDoc = methods[i];
 75  
 
 76  0
                 if (!attribNames.contains(methodDoc.name())
 77  
                         && (methodDoc.name().startsWith("set") || methodDoc.name().startsWith("add"))) {
 78  0
                     final Parameter[] parameters = methodDoc.parameters();
 79  0
                     if (parameters.length == 1) {
 80  0
                         attribNames.add(methodDoc.name());
 81  0
                         attributes.add(new ConfigAttribute(methodDoc));
 82  
 
 83  
                     }
 84  
                 }
 85  
             }
 86  0
             build(klass.superclass());
 87  
         }
 88  0
     }
 89  
 }