1713 * @param packageElement the package to write annotations for. |
1713 * @param packageElement the package to write annotations for. |
1714 * @param htmltree the documentation tree to which the annotation info will be |
1714 * @param htmltree the documentation tree to which the annotation info will be |
1715 * added |
1715 * added |
1716 */ |
1716 */ |
1717 public void addAnnotationInfo(PackageElement packageElement, Content htmltree) { |
1717 public void addAnnotationInfo(PackageElement packageElement, Content htmltree) { |
1718 addAnnotationInfo(packageElement, packageElement.getAnnotationMirrors(), htmltree); |
1718 addAnnotationInfo(packageElement.getAnnotationMirrors(), htmltree); |
1719 } |
|
1720 |
|
1721 /** |
|
1722 * Add the annotation types of the executable receiver. |
|
1723 * |
|
1724 * @param method the executable to write the receiver annotations for. |
|
1725 * @param descList a list of annotation mirrors. |
|
1726 * @param htmltree the documentation tree to which the annotation info will be |
|
1727 * added |
|
1728 */ |
|
1729 public void addReceiverAnnotationInfo(ExecutableElement method, List<AnnotationMirror> descList, |
|
1730 Content htmltree) { |
|
1731 addAnnotationInfo(0, method, descList, false, htmltree); |
|
1732 } |
1719 } |
1733 |
1720 |
1734 /* |
1721 /* |
1735 * this is a hack to delay dealing with Annotations in the writers, the assumption |
1722 * this is a hack to delay dealing with Annotations in the writers, the assumption |
1736 * is that all necessary checks have been made to get here. |
1723 * is that all necessary checks have been made to get here. |
1737 */ |
1724 */ |
1738 public void addReceiverAnnotationInfo(ExecutableElement method, TypeMirror rcvrTypeMirror, |
1725 public void addReceiverAnnotationInfo(ExecutableElement method, TypeMirror rcvrTypeMirror, |
1739 List<? extends AnnotationMirror> annotationMirrors, Content htmltree) { |
1726 List<? extends AnnotationMirror> annotationMirrors, Content htmltree) { |
1740 TypeMirror rcvrType = method.getReceiverType(); |
1727 TypeMirror rcvrType = method.getReceiverType(); |
1741 List<? extends AnnotationMirror> annotationMirrors1 = rcvrType.getAnnotationMirrors(); |
1728 List<? extends AnnotationMirror> annotationMirrors1 = rcvrType.getAnnotationMirrors(); |
1742 addAnnotationInfo(0, method, annotationMirrors1, false, htmltree); |
1729 htmltree.add(getAnnotationInfo(annotationMirrors1, false)); |
1743 } |
1730 } |
1744 |
1731 |
1745 /** |
1732 /** |
1746 * Adds the annotation types for the given element. |
1733 * Adds the annotation types for the given element. |
1747 * |
1734 * |
1748 * @param element the package to write annotations for |
1735 * @param element the package to write annotations for |
1749 * @param htmltree the content tree to which the annotation types will be added |
1736 * @param htmltree the content tree to which the annotation types will be added |
1750 */ |
1737 */ |
1751 public void addAnnotationInfo(Element element, Content htmltree) { |
1738 public void addAnnotationInfo(Element element, Content htmltree) { |
1752 addAnnotationInfo(element, element.getAnnotationMirrors(), htmltree); |
1739 addAnnotationInfo(element.getAnnotationMirrors(), htmltree); |
1753 } |
1740 } |
1754 |
1741 |
1755 /** |
1742 /** |
1756 * Add the annotatation types for the given element and parameter. |
1743 * Add the annotatation types for the given element and parameter. |
1757 * |
1744 * |
1758 * @param indent the number of spaces to indent the parameters. |
|
1759 * @param element the element to write annotations for. |
|
1760 * @param param the parameter to write annotations for. |
1745 * @param param the parameter to write annotations for. |
1761 * @param tree the content tree to which the annotation types will be added |
1746 * @param tree the content tree to which the annotation types will be added |
1762 */ |
1747 */ |
1763 public boolean addAnnotationInfo(int indent, Element element, VariableElement param, |
1748 public boolean addAnnotationInfo(VariableElement param, Content tree) { |
1764 Content tree) { |
1749 Content annotaionInfo = getAnnotationInfo(param.getAnnotationMirrors(), false); |
1765 return addAnnotationInfo(indent, element, param.getAnnotationMirrors(), false, tree); |
1750 if (annotaionInfo.isEmpty()) { |
|
1751 return false; |
|
1752 } |
|
1753 tree.add(annotaionInfo); |
|
1754 return true; |
1766 } |
1755 } |
1767 |
1756 |
1768 /** |
1757 /** |
1769 * Adds the annotatation types for the given Element. |
1758 * Adds the annotatation types for the given Element. |
1770 * |
1759 * |
1771 * @param element the element to write annotations for. |
|
1772 * @param descList a list of annotation mirrors. |
1760 * @param descList a list of annotation mirrors. |
1773 * @param htmltree the documentation tree to which the annotation info will be |
1761 * @param htmltree the documentation tree to which the annotation info will be |
1774 * added |
1762 * added |
1775 */ |
1763 */ |
1776 private void addAnnotationInfo(Element element, List<? extends AnnotationMirror> descList, |
1764 private void addAnnotationInfo(List<? extends AnnotationMirror> descList, Content htmltree) { |
1777 Content htmltree) { |
1765 htmltree.add(getAnnotationInfo(descList, true)); |
1778 addAnnotationInfo(0, element, descList, true, htmltree); |
1766 } |
1779 } |
1767 |
1780 |
1768 /** |
1781 /** |
1769 * Return a content tree containing the annotation types for the given element. |
1782 * Adds the annotation types for the given element. |
1770 * |
1783 * |
|
1784 * @param indent the number of extra spaces to indent the annotations. |
|
1785 * @param element the element to write annotations for. |
|
1786 * @param descList a list of annotation mirrors. |
1771 * @param descList a list of annotation mirrors. |
1787 * @param htmltree the documentation tree to which the annotation info will be |
1772 * @return the documentation tree containing the annotation info. |
1788 * added |
1773 */ |
1789 */ |
1774 Content getAnnotationInfo(List<? extends AnnotationMirror> descList, boolean lineBreak) { |
1790 private boolean addAnnotationInfo(int indent, Element element, |
1775 List<Content> annotations = getAnnotations(descList, lineBreak); |
1791 List<? extends AnnotationMirror> descList, boolean lineBreak, Content htmltree) { |
|
1792 List<Content> annotations = getAnnotations(indent, descList, lineBreak); |
|
1793 String sep = ""; |
1776 String sep = ""; |
1794 if (annotations.isEmpty()) { |
1777 ContentBuilder builder = new ContentBuilder(); |
1795 return false; |
|
1796 } |
|
1797 for (Content annotation: annotations) { |
1778 for (Content annotation: annotations) { |
1798 htmltree.add(sep); |
1779 builder.add(sep); |
1799 htmltree.add(annotation); |
1780 builder.add(annotation); |
1800 if (!lineBreak) { |
1781 if (!lineBreak) { |
1801 sep = " "; |
1782 sep = " "; |
1802 } |
1783 } |
1803 } |
1784 } |
1804 return true; |
1785 return builder; |
1805 } |
1786 } |
1806 |
1787 |
1807 /** |
1788 /** |
1808 * Return the string representations of the annotation types for |
1789 * Return the string representations of the annotation types for |
1809 * the given doc. |
1790 * the given doc. |
1810 * |
1791 * |
1811 * @param indent the number of extra spaces to indent the annotations. |
|
1812 * @param descList a list of annotation mirrors. |
1792 * @param descList a list of annotation mirrors. |
1813 * @param linkBreak if true, add new line between each member value. |
1793 * @param linkBreak if true, add new line between each member value. |
1814 * @return a list of strings representing the annotations being |
1794 * @return a list of strings representing the annotations being |
1815 * documented. |
1795 * documented. |
1816 */ |
1796 */ |
1817 private List<Content> getAnnotations(int indent, List<? extends AnnotationMirror> descList, boolean linkBreak) { |
1797 public List<Content> getAnnotations(List<? extends AnnotationMirror> descList, boolean linkBreak) { |
1818 return getAnnotations(indent, descList, linkBreak, true); |
|
1819 } |
|
1820 |
|
1821 private List<Content> getAnnotations(int indent, AnnotationMirror amirror, boolean linkBreak) { |
|
1822 List<AnnotationMirror> descList = new ArrayList<>(); |
|
1823 descList.add(amirror); |
|
1824 return getAnnotations(indent, descList, linkBreak, true); |
|
1825 } |
|
1826 |
|
1827 /** |
|
1828 * Return the string representations of the annotation types for |
|
1829 * the given doc. |
|
1830 * |
|
1831 * A {@code null} {@code elementType} indicates that all the |
|
1832 * annotations should be returned without any filtering. |
|
1833 * |
|
1834 * @param indent the number of extra spaces to indent the annotations. |
|
1835 * @param descList a list of annotation mirrors. |
|
1836 * @param linkBreak if true, add new line between each member value. |
|
1837 * @param isJava5DeclarationLocation |
|
1838 * @return a list of strings representing the annotations being |
|
1839 * documented. |
|
1840 */ |
|
1841 public List<Content> getAnnotations(int indent, List<? extends AnnotationMirror> descList, |
|
1842 boolean linkBreak, boolean isJava5DeclarationLocation) { |
|
1843 List<Content> results = new ArrayList<>(); |
1798 List<Content> results = new ArrayList<>(); |
1844 ContentBuilder annotation; |
1799 ContentBuilder annotation; |
1845 for (AnnotationMirror aDesc : descList) { |
1800 for (AnnotationMirror aDesc : descList) { |
1846 TypeElement annotationElement = (TypeElement)aDesc.getAnnotationType().asElement(); |
1801 TypeElement annotationElement = (TypeElement)aDesc.getAnnotationType().asElement(); |
1847 // If an annotation is not documented, do not add it to the list. If |
1802 // If an annotation is not documented, do not add it to the list. If |
1936 * |
1882 * |
1937 * @param annotationDoc the annotation being documented |
1883 * @param annotationDoc the annotation being documented |
1938 * @param linkInfo the information about the link |
1884 * @param linkInfo the information about the link |
1939 * @param annotation the annotation string to which the annotation will be added |
1885 * @param annotation the annotation string to which the annotation will be added |
1940 * @param map annotation type element to annotation value pairs |
1886 * @param map annotation type element to annotation value pairs |
1941 * @param indent the number of extra spaces to indent the annotations. |
|
1942 * @param linkBreak if true, add new line between each member value |
1887 * @param linkBreak if true, add new line between each member value |
1943 */ |
1888 */ |
1944 private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo, |
1889 private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo, |
1945 ContentBuilder annotation, |
1890 ContentBuilder annotation, |
1946 Map<? extends ExecutableElement, ? extends AnnotationValue> map, |
1891 Map<? extends ExecutableElement, ? extends AnnotationValue> map, |
1947 int indent, boolean linkBreak) { |
1892 boolean linkBreak) { |
1948 linkInfo.label = new StringContent("@"); |
1893 linkInfo.label = new StringContent("@"); |
1949 linkInfo.label.add(annotationDoc.getSimpleName()); |
1894 linkInfo.label.add(annotationDoc.getSimpleName()); |
1950 annotation.add(getLink(linkInfo)); |
1895 annotation.add(getLink(linkInfo)); |
1951 if (!map.isEmpty()) { |
1896 if (!map.isEmpty()) { |
1952 annotation.add("("); |
1897 annotation.add("("); |