src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java

changeset 1477
8c0c63a6e3b7
parent 1417
522a1ee72340
child 1521
71f35e4b93a5
child 1568
5f0731e4e5e6
equal deleted inserted replaced
1476:0e17c3c23e3b 1477:8c0c63a6e3b7
86 86
87 /** 87 /**
88 * To check whether annotation heading is printed or not. 88 * To check whether annotation heading is printed or not.
89 */ 89 */
90 protected boolean printedAnnotationHeading = false; 90 protected boolean printedAnnotationHeading = false;
91
92 /**
93 * To check whether the repeated annotations is documented or not.
94 */
95 private boolean isAnnotationDocumented = false;
96
97 /**
98 * To check whether the container annotations is documented or not.
99 */
100 private boolean isContainerDocumented = false;
91 101
92 /** 102 /**
93 * Constructor to construct the HtmlStandardWriter object. 103 * Constructor to construct the HtmlStandardWriter object.
94 * 104 *
95 * @param path File to be generated. 105 * @param path File to be generated.
1791 private List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) { 1801 private List<String> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
1792 List<String> results = new ArrayList<String>(); 1802 List<String> results = new ArrayList<String>();
1793 StringBuilder annotation; 1803 StringBuilder annotation;
1794 for (int i = 0; i < descList.length; i++) { 1804 for (int i = 0; i < descList.length; i++) {
1795 AnnotationTypeDoc annotationDoc = descList[i].annotationType(); 1805 AnnotationTypeDoc annotationDoc = descList[i].annotationType();
1796 if (! Util.isDocumentedAnnotation(annotationDoc)){ 1806 // If an annotation is not documented, do not add it to the list. If
1807 // the annotation is of a repeatable type, and if it is not documented
1808 // and also if its container annotation is not documented, do not add it
1809 // to the list. If an annotation of a repeatable type is not documented
1810 // but its container is documented, it will be added to the list.
1811 if (! Util.isDocumentedAnnotation(annotationDoc) &&
1812 (!isAnnotationDocumented && !isContainerDocumented)) {
1797 continue; 1813 continue;
1798 } 1814 }
1799 annotation = new StringBuilder(); 1815 annotation = new StringBuilder();
1816 isAnnotationDocumented = false;
1800 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, 1817 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
1801 LinkInfoImpl.CONTEXT_ANNOTATION, annotationDoc); 1818 LinkInfoImpl.CONTEXT_ANNOTATION, annotationDoc);
1802 linkInfo.label = "@" + annotationDoc.name();
1803 annotation.append(getLink(linkInfo));
1804 AnnotationDesc.ElementValuePair[] pairs = descList[i].elementValues(); 1819 AnnotationDesc.ElementValuePair[] pairs = descList[i].elementValues();
1805 if (pairs.length > 0) { 1820 // If the annotation is synthesized, do not print the container.
1806 annotation.append('('); 1821 if (descList[i].isSynthesized()) {
1807 for (int j = 0; j < pairs.length; j++) { 1822 for (int j = 0; j < pairs.length; j++) {
1808 if (j > 0) {
1809 annotation.append(",");
1810 if (linkBreak) {
1811 annotation.append(DocletConstants.NL);
1812 int spaces = annotationDoc.name().length() + 2;
1813 for (int k = 0; k < (spaces + indent); k++) {
1814 annotation.append(' ');
1815 }
1816 }
1817 }
1818 annotation.append(getDocLink(LinkInfoImpl.CONTEXT_ANNOTATION,
1819 pairs[j].element(), pairs[j].element().name(), false));
1820 annotation.append('=');
1821 AnnotationValue annotationValue = pairs[j].value(); 1823 AnnotationValue annotationValue = pairs[j].value();
1822 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>(); 1824 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
1823 if (annotationValue.value() instanceof AnnotationValue[]) { 1825 if (annotationValue.value() instanceof AnnotationValue[]) {
1824 AnnotationValue[] annotationArray = 1826 AnnotationValue[] annotationArray =
1825 (AnnotationValue[]) annotationValue.value(); 1827 (AnnotationValue[]) annotationValue.value();
1826 for (int k = 0; k < annotationArray.length; k++) { 1828 annotationTypeValues.addAll(Arrays.asList(annotationArray));
1827 annotationTypeValues.add(annotationArray[k]);
1828 }
1829 } else { 1829 } else {
1830 annotationTypeValues.add(annotationValue); 1830 annotationTypeValues.add(annotationValue);
1831 } 1831 }
1832 annotation.append(annotationTypeValues.size() == 1 ? "" : "{"); 1832 String sep = "";
1833 for (Iterator<AnnotationValue> iter = annotationTypeValues.iterator(); iter.hasNext(); ) { 1833 for (AnnotationValue av : annotationTypeValues) {
1834 annotation.append(annotationValueToString(iter.next())); 1834 annotation.append(sep);
1835 annotation.append(iter.hasNext() ? "," : ""); 1835 annotation.append(annotationValueToString(av));
1836 sep = " ";
1836 } 1837 }
1837 annotation.append(annotationTypeValues.size() == 1 ? "" : "}"); 1838 }
1838 } 1839 }
1839 annotation.append(")"); 1840 else if (isAnnotationArray(pairs)) {
1841 // If the container has 1 or more value defined and if the
1842 // repeatable type annotation is not documented, do not print
1843 // the container.
1844 if (pairs.length == 1 && isAnnotationDocumented) {
1845 AnnotationValue[] annotationArray =
1846 (AnnotationValue[]) (pairs[0].value()).value();
1847 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
1848 annotationTypeValues.addAll(Arrays.asList(annotationArray));
1849 String sep = "";
1850 for (AnnotationValue av : annotationTypeValues) {
1851 annotation.append(sep);
1852 annotation.append(annotationValueToString(av));
1853 sep = " ";
1854 }
1855 }
1856 // If the container has 1 or more value defined and if the
1857 // repeatable type annotation is not documented, print the container.
1858 else {
1859 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
1860 indent, false);
1861 }
1862 }
1863 else {
1864 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
1865 indent, linkBreak);
1840 } 1866 }
1841 annotation.append(linkBreak ? DocletConstants.NL : ""); 1867 annotation.append(linkBreak ? DocletConstants.NL : "");
1842 results.add(annotation.toString()); 1868 results.add(annotation.toString());
1843 } 1869 }
1844 return results; 1870 return results;
1871 }
1872
1873 /**
1874 * Add annotation to the annotation string.
1875 *
1876 * @param annotationDoc the annotation being documented
1877 * @param linkInfo the information about the link
1878 * @param annotation the annotation string to which the annotation will be added
1879 * @param pairs annotation type element and value pairs
1880 * @param indent the number of extra spaces to indent the annotations.
1881 * @param linkBreak if true, add new line between each member value
1882 */
1883 private void addAnnotations(AnnotationTypeDoc annotationDoc, LinkInfoImpl linkInfo,
1884 StringBuilder annotation, AnnotationDesc.ElementValuePair[] pairs,
1885 int indent, boolean linkBreak) {
1886 linkInfo.label = "@" + annotationDoc.name();
1887 annotation.append(getLink(linkInfo));
1888 if (pairs.length > 0) {
1889 annotation.append('(');
1890 for (int j = 0; j < pairs.length; j++) {
1891 if (j > 0) {
1892 annotation.append(",");
1893 if (linkBreak) {
1894 annotation.append(DocletConstants.NL);
1895 int spaces = annotationDoc.name().length() + 2;
1896 for (int k = 0; k < (spaces + indent); k++) {
1897 annotation.append(' ');
1898 }
1899 }
1900 }
1901 annotation.append(getDocLink(LinkInfoImpl.CONTEXT_ANNOTATION,
1902 pairs[j].element(), pairs[j].element().name(), false));
1903 annotation.append('=');
1904 AnnotationValue annotationValue = pairs[j].value();
1905 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
1906 if (annotationValue.value() instanceof AnnotationValue[]) {
1907 AnnotationValue[] annotationArray =
1908 (AnnotationValue[]) annotationValue.value();
1909 annotationTypeValues.addAll(Arrays.asList(annotationArray));
1910 } else {
1911 annotationTypeValues.add(annotationValue);
1912 }
1913 annotation.append(annotationTypeValues.size() == 1 ? "" : "{");
1914 String sep = "";
1915 for (AnnotationValue av : annotationTypeValues) {
1916 annotation.append(sep);
1917 annotation.append(annotationValueToString(av));
1918 sep = ",";
1919 }
1920 annotation.append(annotationTypeValues.size() == 1 ? "" : "}");
1921 isContainerDocumented = false;
1922 }
1923 annotation.append(")");
1924 }
1925 }
1926
1927 /**
1928 * Check if the annotation contains an array of annotation as a value. This
1929 * check is to verify if a repeatable type annotation is present or not.
1930 *
1931 * @param pairs annotation type element and value pairs
1932 *
1933 * @return true if the annotation contains an array of annotation as a value.
1934 */
1935 private boolean isAnnotationArray(AnnotationDesc.ElementValuePair[] pairs) {
1936 AnnotationValue annotationValue;
1937 for (int j = 0; j < pairs.length; j++) {
1938 annotationValue = pairs[j].value();
1939 if (annotationValue.value() instanceof AnnotationValue[]) {
1940 AnnotationValue[] annotationArray =
1941 (AnnotationValue[]) annotationValue.value();
1942 if (annotationArray.length > 1) {
1943 if (annotationArray[0].value() instanceof AnnotationDesc) {
1944 AnnotationTypeDoc annotationDoc =
1945 ((AnnotationDesc) annotationArray[0].value()).annotationType();
1946 isContainerDocumented = true;
1947 if (Util.isDocumentedAnnotation(annotationDoc)) {
1948 isAnnotationDocumented = true;
1949 }
1950 return true;
1951 }
1952 }
1953 }
1954 }
1955 return false;
1845 } 1956 }
1846 1957
1847 private String annotationValueToString(AnnotationValue annotationValue) { 1958 private String annotationValueToString(AnnotationValue annotationValue) {
1848 if (annotationValue.value() instanceof Type) { 1959 if (annotationValue.value() instanceof Type) {
1849 Type type = (Type) annotationValue.value(); 1960 Type type = (Type) annotationValue.value();

mercurial