1 52 53 package com.go.beandoc.teadoc; 54 55 import java.util.Arrays ; 56 57 63 public class ClassDoc extends ProgramElementDoc { 64 65 private com.sun.javadoc.ClassDoc mDoc; 66 private String [] mPath; 67 68 public static ClassDoc[] convert(RootDoc root, 69 com.sun.javadoc.ClassDoc[] docs) { 70 int length = docs.length; 71 ClassDoc[] newDocs = new ClassDoc[length]; 72 for (int i=0; i<length; i++) { 73 newDocs[i] = new ClassDoc(root, docs[i]); 74 } 75 return newDocs; 76 } 77 78 84 public static String [] parseClassName(String fullClassName) { 85 86 int dotIndex = fullClassName.lastIndexOf("."); 87 String packageName = null; 88 String className = fullClassName; 89 90 if (dotIndex > 0) { 91 packageName = fullClassName.substring(0, dotIndex); 92 className = fullClassName.substring(dotIndex + 1); 93 } 94 95 return new String [] { packageName, className }; 96 } 97 98 99 100 101 public ClassDoc(RootDoc root, com.sun.javadoc.ClassDoc doc) { 102 super(root, doc); 103 mDoc = doc; 104 } 105 106 public boolean isAbstract() { 107 return mDoc.isAbstract(); 108 } 109 110 public boolean isSerializable() { 111 return mDoc.isSerializable(); 112 } 113 114 public boolean isExternalizable() { 115 return mDoc.isExternalizable(); 116 } 117 118 public MethodDoc[] getSerializationMethods() { 119 return MethodDoc.convert(mRootDoc, mDoc.serializationMethods()); 120 } 121 122 public FieldDoc[] getSerializableFields() { 123 return FieldDoc.convert(mRootDoc, mDoc.serializableFields()); 124 } 125 126 public boolean getDefinesSerializableFields() { 127 return mDoc.definesSerializableFields(); 128 } 129 130 public PackageDoc getContainingPackage() { 131 return new PackageDoc(mRootDoc, mDoc.containingPackage()); 132 } 133 134 public String [] getPath() { 135 if (mPath == null) { 136 ClassDoc parent = getContainingClass(); 137 if (parent != null) { 138 String [] parentPath = parent.getPath(); 139 int length = parentPath.length; 140 mPath = new String [length]; 141 System.arraycopy(parentPath, 0, mPath, 0, length); 142 mPath[length - 1] = getName(); 143 } 144 else { 145 mPath = parseName(getQualifiedName()); 146 } 147 } 148 149 return mPath; 150 } 151 152 public ClassDoc getSuperclass() { 153 com.sun.javadoc.ClassDoc superclass = mDoc.superclass(); 154 if (superclass == null) { 155 return null; 156 } 157 158 return new ClassDoc(mRootDoc, superclass); 159 } 160 161 public ClassDoc[] getInterfaces() { 162 return convert(mRootDoc, mDoc.interfaces()); 163 } 164 165 public FieldDoc[] getFields() { 166 return FieldDoc.convert(mRootDoc, mDoc.fields()); 167 } 168 169 public FieldDoc[] getSortedFields() { 170 FieldDoc[] docs = (FieldDoc[])getFields().clone(); 171 Arrays.sort(docs); 172 return docs; 173 } 174 175 public MethodDoc[] getMethods() { 176 return MethodDoc.convert(mRootDoc, mDoc.methods()); 177 } 178 179 public MethodDoc[] getSortedMethods() { 180 MethodDoc[] docs = (MethodDoc[])getMethods().clone(); 181 Arrays.sort(docs); 182 return docs; 183 } 184 185 public PropertyDoc[] getProperties() { 186 return PropertyDoc.create(mRootDoc, getMethods()); 187 } 188 189 public PropertyDoc[] getSortedProperties() { 190 return PropertyDoc.create(mRootDoc, getSortedMethods()); 191 } 192 193 public ConstructorDoc[] getConstructors() { 194 return ConstructorDoc.convert(mRootDoc, mDoc.constructors()); 195 } 196 197 public ConstructorDoc[] getSortedConstructors() { 198 ConstructorDoc[] docs = (ConstructorDoc[])getConstructors().clone(); 199 Arrays.sort(docs); 200 return docs; 201 } 202 203 public ClassDoc[] getInnerClasses() { 204 return convert(mRootDoc, mDoc.innerClasses()); 205 } 206 207 public ClassDoc[] getSortedInnerClasses() { 208 ClassDoc[] docs = (ClassDoc[])getInnerClasses().clone(); 209 Arrays.sort(docs); 210 return docs; 211 } 212 213 public ClassDoc[] getImportedClasses() { 214 return convert(mRootDoc, mDoc.importedClasses()); 215 } 216 217 public PackageDoc[] getImportedPackages() { 218 return PackageDoc.convert(mRootDoc, mDoc.importedPackages()); 219 } 220 221 public String getTypeName() { 222 return mDoc.typeName(); 223 } 224 225 public String getQualifiedTypeName() { 226 return mDoc.qualifiedTypeName(); 227 } 228 229 232 public String getTypeNameForFile() { 233 return mDoc.typeName().replace('.', '$'); 234 } 235 236 239 public String getQualifiedTypeNameForFile() { 240 241 String typeName = getTypeNameForFile(); 242 String qualifiedTypeName = mDoc.qualifiedTypeName(); 243 244 int packageLength = qualifiedTypeName.length() - typeName.length(); 245 if (packageLength <= 0) { 246 return typeName; 247 } 248 249 String packagePath = qualifiedTypeName.substring(0, packageLength); 250 251 return packagePath + typeName; 252 } 253 254 257 public String getPackageName() { 258 return parseClassName(getQualifiedTypeNameForFile())[0]; 259 } 260 261 public String getDimension() { 262 return mDoc.dimension(); 263 } 264 265 public String toString() { 266 return mDoc.toString(); 267 } 268 269 public ClassDoc getAsClassDoc() { 270 return new ClassDoc(mRootDoc, mDoc.asClassDoc()); 271 } 272 273 277 public MethodDoc getMatchingMethod(MethodDoc method) { 278 279 MethodDoc[] methods = getMethods(); 280 for (int i = 0; i < methods.length; i++) { 281 282 if (method.getName().equals(methods[i].getName()) && 283 method.getSignature().equals(methods[i].getSignature())) { 284 285 return methods[i]; 286 } 287 } 288 return null; 289 } 290 291 296 public MethodDoc getMatchingMethod(MethodDoc method, MethodFinder mf) { 297 298 MethodDoc md = getMatchingMethod(method); 299 if (md != null) { 300 if (mf.checkMethod(md)) { 301 return md; 302 } 303 } 304 305 return null; 306 } 307 308 315 public MethodDoc findMatchingMethod(MethodDoc method, MethodFinder mf) { 316 317 MethodDoc md = findMatchingInterfaceMethod(method, mf); 319 320 if (md != null) { 321 return md; 322 } 323 324 ClassDoc superClass = getSuperclass(); 326 if (superClass != null) { 327 328 md = superClass.getMatchingMethod(method, mf); 329 if (md != null) { 330 return md; 331 } 332 333 return superClass.findMatchingMethod(method, mf); 334 } 335 336 return null; 337 } 338 339 private MethodDoc findMatchingInterfaceMethod(MethodDoc method, 340 MethodFinder mf) { 341 342 ClassDoc[] interfaces = getInterfaces(); 343 if (interfaces == null || interfaces.length == 0) { 344 return null; 345 } 346 347 for (int i = 0; i < interfaces.length; i++) { 349 350 MethodDoc m = 351 interfaces[i].getMatchingMethod(method, mf); 352 353 if (m != null) { 354 return m; 355 } 356 } 357 358 for (int i = 0; i < interfaces.length; i++) { 360 361 MethodDoc m = 362 interfaces[i].findMatchingInterfaceMethod(method, mf); 363 364 if (m != null) { 365 return m; 366 } 367 } 368 369 return null; 370 } 371 372 } 373 | Popular Tags |