Clover coverage report - XJavaDoc - 1.1 Coverage timestamp: Sun Oct 3 2004 19:56:54 BST FRAMES NO FRAMES |
file stats: | LOC: | 270 |  | Methods: | 17
| NCLOC: | 183 |  | 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
BinaryClass.java | 77.8% | 85.7% | 70.6% | 81.5% |

1 |  |
     /*
2 |  |
      * Copyright (c) 2001-2003 The XDoclet team
3 |  |
      * All rights reserved.
4 |  |
      */
5 |  |
     package xjavadoc;
6 |  |
7 |  |
     import java.lang.reflect.Constructor;
8 |  |
     import java.lang.reflect.AccessibleObject;
9 |  |
     import java.lang.reflect.Method;
10 |  |
     import java.util.List;
11 |  |
     import java.util.Arrays;
12 |  |
13 |  |
     /**
14 |  |
      * Describe what this class does
15 |  |
      *
16 |  |
      * @author    Ara Abrahamian
17 |  |
      * @author    Aslak Hellesøy
18 |  |
      * @created   20. mars 2003
19 |  |
      */
20 |  |
     final class BinaryClass extends AbstractClass
21 |  |
     {
22 |  |
         public static int  instanceCount = 0;
23 |  |
24 |  |
         private final static List _primitiveTypes = Arrays.asList( new String[]{
25 |  |
             "java.lang.Boolean",
26 |  |
             "java.lang.Byte",
27 |  |
             "java.lang.Character",
28 |  |
             "java.lang.Double",
29 |  |
             "java.lang.Float",
30 |  |
             "java.lang.Integer",
31 |  |
             "java.lang.Long",
32 |  |
             "java.lang.Short",
33 |  |
             "java.lang.String"
34 |  |
             } );
35 |  |
         private final Class _clazz;
36 |  |
37 |  |
         private boolean    _isSuperclassSet = false;
38 |  |
39 |  |
         private boolean    _isInterfacesSet = false;
40 | 1368 |
         public BinaryClass( XJavaDoc xJavaDoc, Class clazz  )
41 |  |
         {
42 | 1368 |
             super( xJavaDoc, null );
43 | 1368 |
             _clazz = clazz;
44 | 1368 |
             setQualifiedName( clazz.getName() );
45 | 1368 |
             setContainingPackage( Util.getPackageNameFor( clazz.getName() ) );
46 |  |
47 | 1368 |
             addModifier( clazz.getModifiers() );
48 |  |
49 |  |
     //        setSuperclassMaybe();
50 |  |
     //        setInterfacesMaybe();
51 |  |
52 |  |
             // We gain speed by not instantiating the methods and constructors, and we probably don't need them (Aslak)
53 |  |
             // Well, looks like we need it anyway:
54 |  |
             // http://opensource.atlassian.com/projects/xdoclet/secure/ViewIssue.jspa?id=10100
55 |  |
             // To avoid sacrificing speed, this will be controlled with a system property.
56 | 1368 |
             if( "true".equals( System.getProperty( "xjavadoc.compiledmethods" ) ) )
57 |  |
             {
58 | 26 |
                 setMethods( _clazz );
59 | 26 |
                 setConstructors( _clazz );
60 |  |
             }
61 | 1368 |
             instanceCount++;
62 |  |
         }
63 |  |
64 | 1038 |
         private static int getDimension( Class c )
65 |  |
         {
66 | 1038 |
             return c.getName().lastIndexOf( '[' ) + 1;
67 |  |
         }
68 |  |
69 | 1038 |
         private static String getTypeName( Class c )
70 |  |
         {
71 | 1038 |
             return c.getComponentType() != null ? c.getComponentType().getName() : c.getName();
72 |  |
         }
73 |  |
74 | 774 |
         public XClass getSuperclass()
75 |  |
         {
76 | 774 |
             setSuperclassMaybe();
77 | 774 |
             return super.getSuperclass();
78 |  |
         }
79 |  |
80 | 300 |
         public List getInterfaces()
81 |  |
         {
82 | 300 |
             setInterfacesMaybe();
83 | 300 |
             return super.getInterfaces();
84 |  |
         }
85 |  |
86 |  |
         /**
87 |  |
          * whether this class is writeable an can be save ( it can not )
88 |  |
          *
89 |  |
          * @return   false since this class can not be mutated or saved
90 |  |
          */
91 | 0 |
         public boolean isWriteable()
92 |  |
         {
93 | 0 |
             return false;
94 |  |
         }
95 | 98 |
         public boolean isImplementingInterface( String full_qualified_type_name, boolean superclasses )
96 |  |
         {
97 | 98 |
             return isClassImplementingInterface( _clazz, full_qualified_type_name, superclasses );
98 |  |
         }
99 |  |
100 | 0 |
         public boolean isSubclassOf( String full_qualified_type_name, boolean superclasses )
101 |  |
         {
102 | 0 |
             Class superclass = _clazz.getSuperclass();
103 |  |
104 | 0 |
             if( superclass == null )
105 | 0 |
                 return false;
106 | 0 |
             do
107 |  |
             {
108 | 0 |
                 if( superclass.getName().equals( full_qualified_type_name ) )
109 | 0 |
                     return true;
110 |  |
111 | 0 |
                 superclass = superclass.getSuperclass();
112 | 0 |
             }while ( superclasses == true && superclass != null );
113 |  |
114 | 0 |
             return false;
115 |  |
         }
116 |  |
117 | 0 |
         public boolean isPrimitive()
118 |  |
         {
119 | 0 |
             return _primitiveTypes.contains( getQualifiedName() );
120 |  |
         }
121 |  |
122 |  |
         /**
123 |  |
          * no op since we do not save binary classes
124 |  |
          */
125 | 0 |
         public void setDirty()
126 |  |
         {
127 |  |
128 |  |
         }
129 |  |
130 |  |
         /**
131 |  |
          * this class is not intended to be saved
132 |  |
          *
133 |  |
          * @return   always false
134 |  |
          */
135 | 0 |
         public boolean saveNeeded()
136 |  |
         {
137 | 0 |
             return false;
138 |  |
         }
139 |  |
140 | 180 |
         private boolean isClassImplementingInterface( Class cur_class, String full_qualified_type_name, boolean superclasses )
141 |  |
         {
142 | 180 |
             do
143 |  |
             {
144 | 180 |
                 Class[] interfaces = cur_class.getInterfaces();
145 |  |
146 | 180 |
                 for( int i = 0; i < interfaces.length; i++ )
147 |  |
                 {
148 | 84 |
                     Class intf = interfaces[i];
149 |  |
150 | 84 |
                     if( intf.getName().equals( full_qualified_type_name ) || isClassImplementingInterface( intf, full_qualified_type_name, superclasses ) )
151 | 2 |
                         return true;
152 |  |
                 }
153 |  |
154 | 178 |
                 cur_class = cur_class.getSuperclass();
155 | 178 |
             }while ( superclasses == true && cur_class != null );
156 |  |
157 | 178 |
             return false;
158 |  |
         }
159 |  |
160 | 774 |
         private void setSuperclassMaybe()
161 |  |
         {
162 | 774 |
             if( !_isSuperclassSet )
163 |  |
             {
164 | 166 |
                 Class superclass = _clazz.getSuperclass();
165 |  |
166 | 166 |
                 if( superclass != null )
167 |  |
                 {
168 | 30 |
                     setSuperclass( superclass.getName() );
169 |  |
                 }
170 | 166 |
                 _isSuperclassSet = true;
171 |  |
             }
172 |  |
         }
173 |  |
174 | 300 |
         private void setInterfacesMaybe()
175 |  |
         {
176 | 300 |
             if( !_isInterfacesSet )
177 |  |
             {
178 | 162 |
                 Class[] interfaces = _clazz.getInterfaces();
179 |  |
180 | 162 |
                 for( int i = 0; i < interfaces.length; i++ )
181 |  |
                 {
182 | 98 |
                     addInterface( interfaces[i].getName() );
183 |  |
                 }
184 | 162 |
                 _isInterfacesSet = true;
185 |  |
             }
186 |  |
         }
187 |  |
188 |  |
         /**
189 |  |
          * Discovers constructors. This method is currently never called
190 |  |
          *
191 |  |
          * @param clazz
192 |  |
          */
193 | 26 |
         private void setConstructors( Class clazz )
194 |  |
         {
195 | 26 |
             Constructor[] constructors = clazz.getDeclaredConstructors();
196 |  |
197 | 26 |
             for( int i = 0; i < constructors.length; i++ )
198 |  |
             {
199 | 56 |
                 ConstructorImpl constructor = new ConstructorImpl( this, null );
200 |  |
201 | 56 |
                 constructor.addModifier( constructors[i].getModifiers() );
202 | 56 |
                 populateExecutableMember( constructor, constructors[i] );
203 | 56 |
                 addConstructor( constructor );
204 |  |
             }
205 |  |
         }
206 |  |
207 |  |
         /**
208 |  |
          * Discovers constructors. This method is currently never called
209 |  |
          *
210 |  |
          * @param clazz
211 |  |
          */
212 | 26 |
         private void setMethods( Class clazz )
213 |  |
         {
214 | 26 |
             Method[] methods = clazz.getDeclaredMethods();
215 |  |
216 | 26 |
             for( int i = 0; i < methods.length; i++ )
217 |  |
             {
218 |  |
                 // Don't include static initialiser "methods"
219 | 436 |
                 if( !"<clinit>".equals( methods[i].getName() ) )
220 |  |
                 {
221 | 436 |
                     MethodImpl method = new MethodImpl( this, null );
222 |  |
223 | 436 |
                     method.setName( methods[i].getName() );
224 |  |
225 | 436 |
                     method.addModifier( methods[i].getModifiers() );
226 | 436 |
                     populateExecutableMember( method, methods[i] );
227 |  |
228 | 436 |
                     Class returnType = methods[i].getReturnType();
229 |  |
230 | 436 |
                     String typeName = getTypeName( returnType );
231 | 436 |
                     int dimension = getDimension( returnType );
232 |  |
233 | 436 |
                     method.setReturnType( typeName );
234 | 436 |
                     method.setReturnDimension( dimension );
235 | 436 |
                     addMethod( method );
236 |  |
                 }
237 |  |
             }
238 |  |
         }
239 |  |
240 | 492 |
         private void populateExecutableMember( AbstractExecutableMember executableMember, AccessibleObject accessibleObject )
241 |  |
         {
242 | 492 |
             Class[] parameters;
243 | 492 |
             Class[] exceptions;
244 |  |
245 |  |
             // sadly, getParameterTypes is not in the AccesibleObject or Member interface
246 | 492 |
             if( accessibleObject instanceof Constructor )
247 |  |
             {
248 | 56 |
                 parameters = ( ( Constructor ) accessibleObject ).getParameterTypes();
249 | 56 |
                 exceptions = ( ( Constructor ) accessibleObject ).getExceptionTypes();
250 |  |
             }
251 |  |
             else
252 |  |
             {
253 |  |
                 // It's method then
254 | 436 |
                 parameters = ( ( Method ) accessibleObject ).getParameterTypes();
255 | 436 |
                 exceptions = ( ( Method ) accessibleObject ).getExceptionTypes();
256 |  |
             }
257 | 492 |
             for( int i = parameters.length - 1; i >= 0; i-- )
258 |  |
             {
259 | 602 |
                 String typeName = getTypeName( parameters[i] );
260 | 602 |
                 int dimension = getDimension( parameters[i] );
261 |  |
262 | 602 |
                 executableMember.addParameterData( typeName, "p" + i, dimension );
263 |  |
             }
264 | 492 |
             for( int i = exceptions.length - 1; i >= 0; i-- )
265 |  |
             {
266 | 252 |
                 executableMember.addThrownException( exceptions[i].getName() );
267 |  |
             }
268 |  |
         }
269 |  |
     }
270 |  |