184 |
184 |
185 public ClassUseMapper(RootDoc root, ClassTree classtree) { |
185 public ClassUseMapper(RootDoc root, ClassTree classtree) { |
186 this.classtree = classtree; |
186 this.classtree = classtree; |
187 |
187 |
188 // Map subclassing, subinterfacing implementing, ... |
188 // Map subclassing, subinterfacing implementing, ... |
189 for (Iterator<ClassDoc> it = classtree.baseclasses().iterator(); it.hasNext();) { |
189 for (ClassDoc doc : classtree.baseclasses()) { |
190 subclasses(it.next()); |
190 subclasses(doc); |
191 } |
191 } |
192 for (Iterator<ClassDoc> it = classtree.baseinterfaces().iterator(); it.hasNext();) { |
192 for (ClassDoc doc : classtree.baseinterfaces()) { |
193 // does subinterfacing as side-effect |
193 // does subinterfacing as side-effect |
194 implementingClasses(it.next()); |
194 implementingClasses(doc); |
195 } |
195 } |
196 // Map methods, fields, constructors using a class. |
196 // Map methods, fields, constructors using a class. |
197 ClassDoc[] classes = root.classes(); |
197 ClassDoc[] classes = root.classes(); |
198 for (int i = 0; i < classes.length; i++) { |
198 for (ClassDoc aClass : classes) { |
199 PackageDoc pkg = classes[i].containingPackage(); |
199 PackageDoc pkg = aClass.containingPackage(); |
200 mapAnnotations(classToPackageAnnotations, pkg, pkg); |
200 mapAnnotations(classToPackageAnnotations, pkg, pkg); |
201 ClassDoc cd = classes[i]; |
201 ClassDoc cd = aClass; |
202 mapTypeParameters(classToClassTypeParam, cd, cd); |
202 mapTypeParameters(classToClassTypeParam, cd, cd); |
203 mapAnnotations(classToClassAnnotations, cd, cd); |
203 mapAnnotations(classToClassAnnotations, cd, cd); |
204 FieldDoc[] fields = cd.fields(); |
204 FieldDoc[] fields = cd.fields(); |
205 for (int j = 0; j < fields.length; j++) { |
205 for (FieldDoc fd : fields) { |
206 FieldDoc fd = fields[j]; |
|
207 mapTypeParameters(classToFieldDocTypeParam, fd, fd); |
206 mapTypeParameters(classToFieldDocTypeParam, fd, fd); |
208 mapAnnotations(annotationToFieldDoc, fd, fd); |
207 mapAnnotations(annotationToFieldDoc, fd, fd); |
209 if (! fd.type().isPrimitive()) { |
208 if (!fd.type().isPrimitive()) { |
210 add(classToField, fd.type().asClassDoc(), fd); |
209 add(classToField, fd.type().asClassDoc(), fd); |
211 } |
210 } |
212 } |
211 } |
213 ConstructorDoc[] cons = cd.constructors(); |
212 ConstructorDoc[] cons = cd.constructors(); |
214 for (int j = 0; j < cons.length; j++) { |
213 for (ConstructorDoc con : cons) { |
215 mapAnnotations(classToConstructorAnnotations, cons[j], cons[j]); |
214 mapAnnotations(classToConstructorAnnotations, con, con); |
216 mapExecutable(cons[j]); |
215 mapExecutable(con); |
217 } |
216 } |
218 MethodDoc[] meths = cd.methods(); |
217 MethodDoc[] meths = cd.methods(); |
219 for (int j = 0; j < meths.length; j++) { |
218 for (MethodDoc md : meths) { |
220 MethodDoc md = meths[j]; |
|
221 mapExecutable(md); |
219 mapExecutable(md); |
222 mapTypeParameters(classToExecMemberDocTypeParam, md, md); |
220 mapTypeParameters(classToExecMemberDocTypeParam, md, md); |
223 mapAnnotations(classToExecMemberDocAnnotations, md, md); |
221 mapAnnotations(classToExecMemberDocAnnotations, md, md); |
224 if (! (md.returnType().isPrimitive() || md.returnType() instanceof TypeVariable)) { |
222 if (!(md.returnType().isPrimitive() || md.returnType() instanceof TypeVariable)) { |
225 mapTypeParameters(classToExecMemberDocReturnTypeParam, |
223 mapTypeParameters(classToExecMemberDocReturnTypeParam, |
226 md.returnType(), md); |
224 md.returnType(), md); |
227 add(classToMethodReturn, md.returnType().asClassDoc(), md); |
225 add(classToMethodReturn, md.returnType().asClassDoc(), md); |
228 } |
226 } |
229 } |
227 } |
230 } |
228 } |
231 } |
229 } |
296 /** |
294 /** |
297 * Determine classes used by a method or constructor, so they can be |
295 * Determine classes used by a method or constructor, so they can be |
298 * inverse mapped. |
296 * inverse mapped. |
299 */ |
297 */ |
300 private void mapExecutable(ExecutableMemberDoc em) { |
298 private void mapExecutable(ExecutableMemberDoc em) { |
301 Parameter[] params = em.parameters(); |
|
302 boolean isConstructor = em.isConstructor(); |
299 boolean isConstructor = em.isConstructor(); |
303 List<Type> classArgs = new ArrayList<Type>(); |
300 List<Type> classArgs = new ArrayList<Type>(); |
304 for (int k = 0; k < params.length; k++) { |
301 for (Parameter param : em.parameters()) { |
305 Type pcd = params[k].type(); |
302 Type pcd = param.type(); |
306 // primitives don't get mapped, also avoid dups |
303 // primitives don't get mapped, also avoid dups |
307 if ((! params[k].type().isPrimitive()) && |
304 if ((!param.type().isPrimitive()) && |
308 ! classArgs.contains(pcd) && |
305 !classArgs.contains(pcd) && |
309 ! (pcd instanceof TypeVariable)) { |
306 !(pcd instanceof TypeVariable)) { |
310 add(isConstructor? classToConstructorArgs :classToMethodArgs, |
307 add(isConstructor ? classToConstructorArgs : classToMethodArgs, |
311 pcd.asClassDoc(), em); |
308 pcd.asClassDoc(), em); |
312 classArgs.add(pcd); |
309 classArgs.add(pcd); |
313 mapTypeParameters(isConstructor? |
310 mapTypeParameters(isConstructor ? |
314 classToConstructorDocArgTypeParam : classToExecMemberDocArgTypeParam, |
311 classToConstructorDocArgTypeParam : classToExecMemberDocArgTypeParam, |
315 pcd, em); |
312 pcd, em); |
316 } |
313 } |
317 mapAnnotations( |
314 mapAnnotations( |
318 isConstructor ? |
315 isConstructor ? |
319 classToConstructorParamAnnotation : |
316 classToConstructorParamAnnotation : |
320 classToExecMemberDocParamAnnotation, |
317 classToExecMemberDocParamAnnotation, |
321 params[k], em); |
318 param, em); |
322 } |
319 } |
323 ClassDoc[] thr = em.thrownExceptions(); |
320 for (ClassDoc anException : em.thrownExceptions()) { |
324 for (int k = 0; k < thr.length; k++) { |
321 add(isConstructor ? classToConstructorThrows : classToMethodThrows, |
325 add(isConstructor? classToConstructorThrows : classToMethodThrows, |
322 anException, em); |
326 thr[k], em); |
|
327 } |
323 } |
328 } |
324 } |
329 |
325 |
330 private <T> List<T> refList(Map<String,List<T>> map, ClassDoc cd) { |
326 private <T> List<T> refList(Map<String,List<T>> map, ClassDoc cd) { |
331 List<T> list = map.get(cd.qualifiedName()); |
327 List<T> list = map.get(cd.qualifiedName()); |
398 T holder) { |
393 T holder) { |
399 TypeVariable[] typeVariables; |
394 TypeVariable[] typeVariables; |
400 if (doc instanceof ClassDoc) { |
395 if (doc instanceof ClassDoc) { |
401 typeVariables = ((ClassDoc) doc).typeParameters(); |
396 typeVariables = ((ClassDoc) doc).typeParameters(); |
402 } else if (doc instanceof WildcardType) { |
397 } else if (doc instanceof WildcardType) { |
403 Type[] extendsBounds = ((WildcardType) doc).extendsBounds(); |
398 for (Type extendsBound : ((WildcardType) doc).extendsBounds()) { |
404 for (int k = 0; k < extendsBounds.length; k++) { |
399 addTypeParameterToMap(map, extendsBound, holder); |
405 addTypeParameterToMap(map, extendsBounds[k], holder); |
400 } |
406 } |
401 for (Type superBound : ((WildcardType) doc).superBounds()) { |
407 Type[] superBounds = ((WildcardType) doc).superBounds(); |
402 addTypeParameterToMap(map, superBound, holder); |
408 for (int k = 0; k < superBounds.length; k++) { |
|
409 addTypeParameterToMap(map, superBounds[k], holder); |
|
410 } |
403 } |
411 return; |
404 return; |
412 } else if (doc instanceof ParameterizedType) { |
405 } else if (doc instanceof ParameterizedType) { |
413 Type[] typeArguments = ((ParameterizedType) doc).typeArguments(); |
406 for (Type typeArgument : ((ParameterizedType) doc).typeArguments()) { |
414 for (int k = 0; k < typeArguments.length; k++) { |
407 addTypeParameterToMap(map, typeArgument, holder); |
415 addTypeParameterToMap(map, typeArguments[k], holder); |
|
416 } |
408 } |
417 return; |
409 return; |
418 } else if (doc instanceof ExecutableMemberDoc) { |
410 } else if (doc instanceof ExecutableMemberDoc) { |
419 typeVariables = ((ExecutableMemberDoc) doc).typeParameters(); |
411 typeVariables = ((ExecutableMemberDoc) doc).typeParameters(); |
420 } else if (doc instanceof FieldDoc) { |
412 } else if (doc instanceof FieldDoc) { |
472 * @param doc the doc whose type parameters are being checked. |
463 * @param doc the doc whose type parameters are being checked. |
473 * @param holder the holder that owns the type parameters. |
464 * @param holder the holder that owns the type parameters. |
474 */ |
465 */ |
475 private <T extends PackageDoc> void mapAnnotations(Map<String,List<T>> map, PackageDoc doc, |
466 private <T extends PackageDoc> void mapAnnotations(Map<String,List<T>> map, PackageDoc doc, |
476 T holder) { |
467 T holder) { |
477 AnnotationDesc[] annotations; |
468 for (AnnotationDesc annotation : doc.annotations()) { |
478 annotations = doc.annotations(); |
469 AnnotationTypeDoc annotationDoc = annotation.annotationType(); |
479 for (int i = 0; i < annotations.length; i++) { |
|
480 AnnotationTypeDoc annotationDoc = annotations[i].annotationType(); |
|
481 refList(map, annotationDoc).add(holder); |
470 refList(map, annotationDoc).add(holder); |
482 } |
471 } |
483 } |
472 } |
484 |
473 |
485 private <T extends ProgramElementDoc> void addTypeParameterToMap(Map<String,List<T>> map, Type type, |
474 private <T extends ProgramElementDoc> void addTypeParameterToMap(Map<String,List<T>> map, Type type, |