2346 } 2347 2348 /** 2349 * Add annotation to the annotation string. 2350 * 2351 * @param annotationDoc the annotation being documented 2352 * @param linkInfo the information about the link 2353 * @param annotation the annotation string to which the annotation will be added 2354 * @param pairs annotation type element and value pairs 2355 * @param indent the number of extra spaces to indent the annotations. 2356 * @param linkBreak if true, add new line between each member value 2357 */ 2358 private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo, 2359 ContentBuilder annotation, Map<? extends ExecutableElement,? extends AnnotationValue>map, 2360 int indent, boolean linkBreak) { 2361 linkInfo.label = new StringContent("@" + annotationDoc.getSimpleName().toString()); 2362 annotation.addContent(getLink(linkInfo)); 2363 if (!map.isEmpty()) { 2364 annotation.addContent("("); 2365 boolean isFirst = true; 2366 for (ExecutableElement element : map.keySet()) { 2367 if (isFirst) { 2368 isFirst = false; 2369 } else { 2370 annotation.addContent(","); 2371 if (linkBreak) { 2372 annotation.addContent(DocletConstants.NL); 2373 int spaces = annotationDoc.getSimpleName().toString().length() + 2; 2374 for (int k = 0; k < (spaces + indent); k++) { 2375 annotation.addContent(" "); 2376 } 2377 } 2378 } 2379 annotation.addContent(getDocLink(LinkInfoImpl.Kind.ANNOTATION, 2380 element, element.getSimpleName().toString(), false)); 2381 annotation.addContent("="); 2382 AnnotationValue annotationValue = map.get(element); 2383 List<AnnotationValue> annotationTypeValues = new ArrayList<>(); 2384 new SimpleAnnotationValueVisitor9<Void, AnnotationValue>() { 2385 @Override @DefinedBy(Api.LANGUAGE_MODEL) 2386 public Void visitArray(List<? extends AnnotationValue> vals, AnnotationValue p) { 2387 annotationTypeValues.addAll(vals); 2388 return null; 2389 } 2390 @Override @DefinedBy(Api.LANGUAGE_MODEL) 2391 protected Void defaultAction(Object o, AnnotationValue p) { 2392 annotationTypeValues.add(p); 2393 return null; 2394 } 2395 }.visit(annotationValue, annotationValue); 2396 annotation.addContent(annotationTypeValues.size() == 1 ? "" : "{"); 2397 String sep = ""; 2398 for (AnnotationValue av : annotationTypeValues) { 2399 annotation.addContent(sep); 2400 annotation.addContent(annotationValueToContent(av)); 2401 sep = ","; | 2346 } 2347 2348 /** 2349 * Add annotation to the annotation string. 2350 * 2351 * @param annotationDoc the annotation being documented 2352 * @param linkInfo the information about the link 2353 * @param annotation the annotation string to which the annotation will be added 2354 * @param pairs annotation type element and value pairs 2355 * @param indent the number of extra spaces to indent the annotations. 2356 * @param linkBreak if true, add new line between each member value 2357 */ 2358 private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo, 2359 ContentBuilder annotation, Map<? extends ExecutableElement,? extends AnnotationValue>map, 2360 int indent, boolean linkBreak) { 2361 linkInfo.label = new StringContent("@" + annotationDoc.getSimpleName().toString()); 2362 annotation.addContent(getLink(linkInfo)); 2363 if (!map.isEmpty()) { 2364 annotation.addContent("("); 2365 boolean isFirst = true; 2366 Set<? extends ExecutableElement> keys = map.keySet(); 2367 boolean multipleValues = keys.size() > 1; 2368 for (ExecutableElement element : keys) { 2369 if (isFirst) { 2370 isFirst = false; 2371 } else { 2372 annotation.addContent(","); 2373 if (linkBreak) { 2374 annotation.addContent(DocletConstants.NL); 2375 int spaces = annotationDoc.getSimpleName().toString().length() + 2; 2376 for (int k = 0; k < (spaces + indent); k++) { 2377 annotation.addContent(" "); 2378 } 2379 } 2380 } 2381 String simpleName = element.getSimpleName().toString(); 2382 if (multipleValues || !"value".equals(simpleName)) { // Omit "value=" where unnecessary 2383 annotation.addContent(getDocLink(LinkInfoImpl.Kind.ANNOTATION, 2384 element, simpleName, false)); 2385 annotation.addContent("="); 2386 } 2387 AnnotationValue annotationValue = map.get(element); 2388 List<AnnotationValue> annotationTypeValues = new ArrayList<>(); 2389 new SimpleAnnotationValueVisitor9<Void, AnnotationValue>() { 2390 @Override @DefinedBy(Api.LANGUAGE_MODEL) 2391 public Void visitArray(List<? extends AnnotationValue> vals, AnnotationValue p) { 2392 annotationTypeValues.addAll(vals); 2393 return null; 2394 } 2395 @Override @DefinedBy(Api.LANGUAGE_MODEL) 2396 protected Void defaultAction(Object o, AnnotationValue p) { 2397 annotationTypeValues.add(p); 2398 return null; 2399 } 2400 }.visit(annotationValue, annotationValue); 2401 annotation.addContent(annotationTypeValues.size() == 1 ? "" : "{"); 2402 String sep = ""; 2403 for (AnnotationValue av : annotationTypeValues) { 2404 annotation.addContent(sep); 2405 annotation.addContent(annotationValueToContent(av)); 2406 sep = ","; |