Clover coverage report - XJavaDoc - 1.1
Coverage timestamp: Mon Oct 4 2004 23:49:51 BST
file stats: LOC: 271   Methods: 23
NCLOC: 191   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AbstractProgramElement.java 82.1% 78.3% 65.2% 76.7%
coverage coverage
 1   
 /*
 2   
  * Copyright (c) 2001-2003 The XDoclet team
 3   
  * All rights reserved.
 4   
  */
 5   
 package xjavadoc;
 6   
 
 7   
 import java.lang.reflect.Modifier;
 8   
 import java.util.*;
 9   
 
 10   
 /**
 11   
  * Describe what this class does
 12   
  *
 13   
  * @author    Ara Abrahamian
 14   
  * @author    Aslak Hellesøy
 15   
  * @created   7. mars 2003
 16   
  */
 17   
 public abstract class AbstractProgramElement implements XProgramElement
 18   
 {
 19   
     final static List  EMPTY_LIST = Collections.unmodifiableList( new LinkedList() );
 20   
 
 21   
     private XJavaDoc _xJavaDoc;
 22   
     private AbstractClass _containingClass;
 23   
     private int        _modifiers = 0;
 24   
     private String     _modifierString;
 25   
     private XDoc       _doc;
 26   
     private Token      _token;
 27   
     private Token      _javadocToken;
 28   
     private final XTagFactory _tagFactory;
 29   
 
 30  5808
     protected AbstractProgramElement( AbstractClass containingClass, XTagFactory tagFactory )
 31   
     {
 32  5808
         _xJavaDoc = containingClass.getXJavaDoc();
 33  5808
         _containingClass = containingClass;
 34  5808
         _tagFactory = tagFactory;
 35   
     }
 36   
 
 37  1654
     protected AbstractProgramElement( XJavaDoc xJavaDoc,  XTagFactory tagFactory )
 38   
     {
 39  1654
         _xJavaDoc = xJavaDoc;
 40  1654
         _containingClass = null;
 41  1654
         _tagFactory = tagFactory;
 42   
     }
 43   
 
 44  10848
     public XJavaDoc getXJavaDoc() {
 45  10848
         return _xJavaDoc;
 46   
     }
 47   
 
 48  0
     public final boolean isFinal()
 49   
     {
 50  0
         return ( _modifiers & Modifier.FINAL ) != 0;
 51   
     }
 52   
 
 53  0
     public final boolean isAbstract()
 54   
     {
 55  0
         return ( _modifiers & Modifier.ABSTRACT ) != 0;
 56   
     }
 57   
 
 58  0
     public final boolean isPackagePrivate()
 59   
     {
 60  0
         return !isPrivate() && !isProtected() && !isPublic();
 61   
     }
 62   
 
 63  18
     public final boolean isPrivate()
 64   
     {
 65  18
         return ( _modifiers & Modifier.PRIVATE ) != 0;
 66   
     }
 67   
 
 68  0
     public final boolean isProtected()
 69   
     {
 70  0
         return ( _modifiers & Modifier.PROTECTED ) != 0;
 71   
     }
 72   
 
 73  9
     public final boolean isPublic()
 74   
     {
 75  9
         return ( _modifiers & Modifier.PUBLIC ) != 0;
 76   
     }
 77   
 
 78  0
     public final boolean isStatic()
 79   
     {
 80  0
         return ( _modifiers & Modifier.STATIC ) != 0;
 81   
     }
 82   
 
 83   
     /**
 84   
      * Get the doc. If this is a binary, primitive or unknown, null is returned.
 85   
      *
 86   
      * @return   the class level doc
 87   
      */
 88  355
     public final XDoc getDoc()
 89   
     {
 90  355
         if( _doc == null )
 91   
         {
 92  349
             if( _token == null )
 93   
             {
 94   
                 // We're not from source (we're binary, primitive or unknown)
 95  0
                 _doc = new XDoc( null, this, _tagFactory );
 96   
             }
 97   
             else
 98   
             {
 99  349
                 if( _javadocToken != null )
 100   
                 {
 101  225
                     _doc = new XDoc( _javadocToken, this, _tagFactory );
 102   
                 }
 103   
                 else
 104   
                 {
 105   
                     // there was no doc in the original source. Create it.
 106   
                     // We have to create a new token and attach it to _token as specialToken
 107   
                     // The pre and post tokens are only to ensure proper line breaks before and after
 108  124
                     Token preJavadocToken = Token.newToken( NodeParserConstants.DEFAULT );
 109   
 
 110  124
                     preJavadocToken.image = "\n\n";
 111   
 
 112  124
                     _javadocToken = Token.newToken( NodeParserConstants.FORMAL_COMMENT );
 113  124
                     _javadocToken.image = "";
 114   
 
 115  124
                     Token postJavadocToken = Token.newToken( NodeParserConstants.DEFAULT );
 116   
 
 117  124
                     postJavadocToken.image = "\n";
 118   
 
 119   
                     // Link the new tokens properly
 120  124
                     preJavadocToken.next = _javadocToken;
 121  124
                     _javadocToken.next = postJavadocToken;
 122   
 
 123  124
                     _token.specialToken = preJavadocToken;
 124  124
                     _doc = new XDoc( _javadocToken, this, _tagFactory );
 125   
                 }
 126   
             }
 127   
             // Help the GC. We don't need the tokens anymore.
 128  349
             _token = null;
 129  349
             _javadocToken = null;
 130   
         }
 131  355
         return _doc;
 132   
     }
 133   
 
 134   
     /**
 135   
      * Get modifiers string.
 136   
      *
 137   
      * @return
 138   
      */
 139  8
     public final String getModifiers()
 140   
     {
 141  8
         if( _modifierString == null )
 142   
         {
 143  8
             _modifierString = Modifier.toString( _modifiers );
 144   
         }
 145  8
         return _modifierString;
 146   
     }
 147   
 
 148   
     /**
 149   
      * Get the modifier specifier integer.
 150   
      *
 151   
      * @return
 152   
      */
 153  0
     public final int getModifierSpecifier()
 154   
     {
 155  0
         return _modifiers;
 156   
     }
 157   
 
 158  6471
     public final XClass getContainingClass()
 159   
     {
 160  6471
         return getContainingAbstractClass();
 161   
     }
 162   
 
 163  7931
     public final AbstractClass getContainingAbstractClass()
 164   
     {
 165  7931
         return _containingClass;
 166   
     }
 167   
 
 168  0
     public XPackage getContainingPackage()
 169   
     {
 170  0
         if( _containingClass != null )
 171   
         {
 172  0
             return getContainingClass().getContainingPackage();
 173   
         }
 174   
         else
 175   
         {
 176  0
             return null;
 177   
         }
 178   
     }
 179   
 
 180   
     /**
 181   
      * Sets the Token where we start. Useful for doc mutation.
 182   
      *
 183   
      * @param token  The new Token value
 184   
      */
 185  11134
     public final void setToken( Token token )
 186   
     {
 187  11134
         if( _token == null && token != null )
 188   
         {
 189  5880
             _token = token;
 190  5880
             setJavaDoc();
 191   
         }
 192   
     }
 193   
 
 194  8238
     public final void addModifier( int modifier )
 195   
     {
 196  8238
         _modifiers |= modifier;
 197   
     }
 198   
 
 199  1332
     public int compareTo( Object o )
 200   
     {
 201  1332
         XProgramElement other = ( XProgramElement ) o;
 202   
 
 203  1332
         return getName().compareTo( other.getName() );
 204   
     }
 205   
 
 206   
     /**
 207   
      * update javadoc
 208   
      */
 209  76
     public void updateDoc()
 210   
     {
 211  76
         if( _doc != null )
 212   
         {
 213  4
             _doc.updateToken();
 214   
         }
 215   
     }
 216   
 
 217  342
     protected XTagFactory getTagFactory() {
 218  342
         return _tagFactory;
 219   
     }
 220   
 
 221  0
     void reset()
 222   
     {
 223  0
         _doc = null;
 224  0
         _containingClass = null;
 225  0
         _token = null;
 226  0
         _javadocToken = null;
 227   
     }
 228   
 
 229  5880
     private final void setJavaDoc()
 230   
     {
 231  5880
         Token javadoc = null;
 232   
 
 233  5880
         Token tt = _token.specialToken;
 234   
 
 235  5880
         if( tt != null )
 236   
         {
 237  5877
             while( tt.specialToken != null )
 238   
             {
 239  21279
                 tt = tt.specialToken;
 240   
             }
 241  5877
             while( tt != null )
 242   
             {
 243  27156
                 if( tt.kind == NodeParserConstants.FORMAL_COMMENT )
 244   
                 {
 245   
                     // it's JavaDoc
 246  2805
                     javadoc = tt;
 247   
                 }
 248  24351
                 else if( tt.kind == NodeParserConstants.SINGLE_LINE_COMMENT || tt.kind == NodeParserConstants.MULTI_LINE_COMMENT )
 249   
                 {
 250   
                     // reset it. some other comment is standalone or followed what could have been a javadoc comment
 251  64
                     javadoc = null;
 252   
                 }
 253  27156
                 tt = tt.next;
 254   
             }
 255   
         }
 256  5880
         if( javadoc != null )
 257   
         {
 258   
             // There was javadoc here!
 259  2805
             if( _doc != null )
 260   
             {
 261  0
                 throw new IllegalStateException( "Doc has already been set!!" );
 262   
             }
 263   
             else
 264   
             {
 265  2805
                 _javadocToken = javadoc;
 266   
             }
 267   
         }
 268   
     }
 269   
 
 270   
 }
 271