1 /* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.tools.doclets.formats.html; 27 28 import java.io.*; 29 30 import com.sun.tools.doclets.formats.html.markup.*; 31 import com.sun.tools.doclets.internal.toolkit.*; 32 import com.sun.tools.doclets.internal.toolkit.util.*; 33 34 /** 35 * Generate File to list all the deprecated classes and class members with the 36 * appropriate links. 37 * 38 * <p><b>This is NOT part of any supported API. 39 * If you write code that depends on this, you do so at your own risk. 40 * This code and its internal interfaces are subject to change or 41 * deletion without notice.</b> 42 * 43 * @see java.util.List 44 * @author Atul M Dambalkar 45 * @author Bhavesh Patel (Modified) 46 */ 47 public class DeprecatedListWriter extends SubWriterHolderWriter { 48 49 private static final String[] ANCHORS = new String[] { 50 "package", "interface", "class", "enum", "exception", "error", 51 "annotation.type", "field", "method", "constructor", "enum.constant", 52 "annotation.type.member" 53 }; 54 55 private static final String[] HEADING_KEYS = new String[] { 56 "doclet.Deprecated_Packages", "doclet.Deprecated_Interfaces", 57 "doclet.Deprecated_Classes", "doclet.Deprecated_Enums", 58 "doclet.Deprecated_Exceptions", "doclet.Deprecated_Errors", 59 "doclet.Deprecated_Annotation_Types", 60 "doclet.Deprecated_Fields", 61 "doclet.Deprecated_Methods", "doclet.Deprecated_Constructors", 62 "doclet.Deprecated_Enum_Constants", 63 "doclet.Deprecated_Annotation_Type_Members" 64 }; 65 66 private static final String[] SUMMARY_KEYS = new String[] { 67 "doclet.deprecated_packages", "doclet.deprecated_interfaces", 68 "doclet.deprecated_classes", "doclet.deprecated_enums", 69 "doclet.deprecated_exceptions", "doclet.deprecated_errors", 70 "doclet.deprecated_annotation_types", 71 "doclet.deprecated_fields", 72 "doclet.deprecated_methods", "doclet.deprecated_constructors", 73 "doclet.deprecated_enum_constants", 74 "doclet.deprecated_annotation_type_members" 75 }; 76 77 private static final String[] HEADER_KEYS = new String[] { 78 "doclet.Package", "doclet.Interface", "doclet.Class", 79 "doclet.Enum", "doclet.Exceptions", 80 "doclet.Errors", 81 "doclet.AnnotationType", 82 "doclet.Field", 83 "doclet.Method", "doclet.Constructor", 84 "doclet.Enum_Constant", 85 "doclet.Annotation_Type_Member" 86 }; 87 88 private AbstractMemberWriter[] writers; 89 90 private ConfigurationImpl configuration; 91 92 /** 93 * Constructor. 94 * 95 * @param filename the file to be generated. 96 */ 97 public DeprecatedListWriter(ConfigurationImpl configuration, 98 DocPath filename) throws IOException { 99 super(configuration, filename); 100 this.configuration = configuration; 101 NestedClassWriterImpl classW = new NestedClassWriterImpl(this); 102 writers = new AbstractMemberWriter[] 103 {classW, classW, classW, classW, classW, classW, 104 new FieldWriterImpl(this), 105 new MethodWriterImpl(this), 106 new ConstructorWriterImpl(this), 107 new EnumConstantWriterImpl(this), 108 new AnnotationTypeOptionalMemberWriterImpl(this, null)}; 109 } 110 111 /** 112 * Get list of all the deprecated classes and members in all the Packages 113 * specified on the Command Line. 114 * Then instantiate DeprecatedListWriter and generate File. 115 * 116 * @param configuration the current configuration of the doclet. 117 */ 118 public static void generate(ConfigurationImpl configuration) { 119 DocPath filename = DocPaths.DEPRECATED_LIST; 120 try { 121 DeprecatedListWriter depr = 122 new DeprecatedListWriter(configuration, filename); 123 depr.generateDeprecatedListFile( 124 new DeprecatedAPIListBuilder(configuration)); 125 depr.close(); 126 } catch (IOException exc) { 127 configuration.standardmessage.error( 128 "doclet.exception_encountered", 129 exc.toString(), filename); 130 throw new DocletAbortException(exc); 131 } 132 } 133 134 /** 135 * Generate the deprecated API list. 136 * 137 * @param deprapi list of deprecated API built already. 138 */ 139 protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi) 140 throws IOException { 141 HtmlTree body = getHeader(); 142 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 143 ? HtmlTree.MAIN() 144 : body; 145 htmlTree.addContent(getContentsList(deprapi)); 146 String memberTableSummary; 147 String[] memberTableHeader = new String[1]; 148 HtmlTree div = new HtmlTree(HtmlTag.DIV); 149 div.addStyle(HtmlStyle.contentContainer); 150 for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { 151 if (deprapi.hasDocumentation(i)) { 152 addAnchor(deprapi, i, div); 153 memberTableSummary = 154 configuration.getText("doclet.Member_Table_Summary", 155 configuration.getText(HEADING_KEYS[i]), 156 configuration.getText(SUMMARY_KEYS[i])); 157 memberTableHeader[0] = configuration.getText("doclet.0_and_1", 158 configuration.getText(HEADER_KEYS[i]), 159 configuration.getText("doclet.Description")); 160 // DeprecatedAPIListBuilder.PACKAGE == 0, so if i == 0, it is 161 // a PackageDoc. 162 if (i == DeprecatedAPIListBuilder.PACKAGE) 163 addPackageDeprecatedAPI(deprapi.getList(i), 164 HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); 165 else 166 writers[i - 1].addDeprecatedAPI(deprapi.getList(i), 167 HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); 168 } 169 } 170 if (configuration.allowTag(HtmlTag.MAIN)) { 171 htmlTree.addContent(div); 172 body.addContent(htmlTree); 173 } else { 174 body.addContent(div); 175 } 176 htmlTree = (configuration.allowTag(HtmlTag.FOOTER)) 177 ? HtmlTree.FOOTER() 178 : body; 179 addNavLinks(false, htmlTree); 180 addBottom(htmlTree); 181 if (configuration.allowTag(HtmlTag.FOOTER)) { 182 body.addContent(htmlTree); 183 } 184 printHtmlDocument(null, true, body); 185 } 186 187 /** 188 * Add the index link. 189 * 190 * @param builder the deprecated list builder 191 * @param type the type of list being documented 192 * @param contentTree the content tree to which the index link will be added 193 */ 194 private void addIndexLink(DeprecatedAPIListBuilder builder, 195 int type, Content contentTree) { 196 if (builder.hasDocumentation(type)) { 197 Content li = HtmlTree.LI(getHyperLink(ANCHORS[type], 198 getResource(HEADING_KEYS[type]))); 199 contentTree.addContent(li); 200 } 201 } 202 203 /** 204 * Get the contents list. 205 * 206 * @param deprapi the deprecated list builder 207 * @return a content tree for the contents list 208 */ 209 public Content getContentsList(DeprecatedAPIListBuilder deprapi) { 210 Content headContent = getResource("doclet.Deprecated_API"); 211 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, 212 HtmlStyle.title, headContent); 213 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 214 Content headingContent = getResource("doclet.Contents"); 215 div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, 216 headingContent)); 217 Content ul = new HtmlTree(HtmlTag.UL); 218 for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { 219 addIndexLink(deprapi, i, ul); 220 } 221 div.addContent(ul); 222 return div; 223 } 224 225 /** 226 * Add the anchor. 227 * 228 * @param builder the deprecated list builder 229 * @param type the type of list being documented 230 * @param htmlTree the content tree to which the anchor will be added 231 */ 232 private void addAnchor(DeprecatedAPIListBuilder builder, int type, Content htmlTree) { 233 if (builder.hasDocumentation(type)) { 234 htmlTree.addContent(getMarkerAnchor(ANCHORS[type])); 235 } 236 } 237 238 /** 239 * Get the header for the deprecated API Listing. 240 * 241 * @return a content tree for the header 242 */ 243 public HtmlTree getHeader() { 244 String title = configuration.getText("doclet.Window_Deprecated_List"); 245 HtmlTree bodyTree = getBody(true, getWindowTitle(title)); 246 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) 247 ? HtmlTree.HEADER() 248 : bodyTree; 249 addTop(htmlTree); 250 addNavLinks(true, htmlTree); 251 if (configuration.allowTag(HtmlTag.HEADER)) { 252 bodyTree.addContent(htmlTree); 253 } 254 return bodyTree; | 1 /* 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.javadoc.internal.doclets.formats.html; 27 28 import java.io.*; 29 import java.util.ArrayList; 30 import java.util.EnumMap; 31 import java.util.List; 32 33 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 37 import jdk.javadoc.internal.doclets.toolkit.Content; 38 import jdk.javadoc.internal.doclets.toolkit.util.DeprecatedAPIListBuilder; 39 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 40 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 41 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; 42 43 import static jdk.javadoc.internal.doclets.toolkit.util.DeprecatedAPIListBuilder.*; 44 45 /** 46 * Generate File to list all the deprecated classes and class members with the 47 * appropriate links. 48 * 49 * <p><b>This is NOT part of any supported API. 50 * If you write code that depends on this, you do so at your own risk. 51 * This code and its internal interfaces are subject to change or 52 * deletion without notice.</b> 53 * 54 * @see java.util.List 55 * @author Atul M Dambalkar 56 * @author Bhavesh Patel (Modified) 57 */ 58 public class DeprecatedListWriter extends SubWriterHolderWriter { 59 60 private String getAnchorName(DeprElementKind kind) { 61 switch (kind) { 62 case PACKAGE: 63 return "package"; 64 case INTERFACE: 65 return "interface"; 66 case CLASS: 67 return "class"; 68 case ENUM: 69 return "enum"; 70 case EXCEPTION: 71 return "exception"; 72 case ERROR: 73 return "error"; 74 case ANNOTATION_TYPE: 75 return "annotation.type"; 76 case FIELD: 77 return "field"; 78 case METHOD: 79 return "method"; 80 case CONSTRUCTOR: 81 return "constructor"; 82 case ENUM_CONSTANT: 83 return "enum.constant"; 84 case ANNOTATION_TYPE_MEMBER: 85 return "annotation.type.member"; 86 default: 87 throw new AssertionError("unknown kind: " + kind); 88 } 89 } 90 91 private String getHeadingKey(DeprElementKind kind) { 92 switch (kind) { 93 case PACKAGE: 94 return "doclet.Deprecated_Packages"; 95 case INTERFACE: 96 return "doclet.Deprecated_Interfaces"; 97 case CLASS: 98 return "doclet.Deprecated_Classes"; 99 case ENUM: 100 return "doclet.Deprecated_Enums"; 101 case EXCEPTION: 102 return "doclet.Deprecated_Exceptions"; 103 case ERROR: 104 return "doclet.Deprecated_Errors"; 105 case ANNOTATION_TYPE: 106 return "doclet.Deprecated_Annotation_Types"; 107 case FIELD: 108 return "doclet.Deprecated_Fields"; 109 case METHOD: 110 return "doclet.Deprecated_Methods"; 111 case CONSTRUCTOR: 112 return "doclet.Deprecated_Constructors"; 113 case ENUM_CONSTANT: 114 return "doclet.Deprecated_Enum_Constants"; 115 case ANNOTATION_TYPE_MEMBER: 116 return "doclet.Deprecated_Annotation_Type_Members"; 117 default: 118 throw new AssertionError("unknown kind: " + kind); 119 } 120 } 121 122 private String getSummaryKey(DeprElementKind kind) { 123 switch (kind) { 124 case PACKAGE: 125 return "doclet.deprecated_packages"; 126 case INTERFACE: 127 return "doclet.deprecated_interfaces"; 128 case CLASS: 129 return "doclet.deprecated_classes"; 130 case ENUM: 131 return "doclet.deprecated_enums"; 132 case EXCEPTION: 133 return "doclet.deprecated_exceptions"; 134 case ERROR: 135 return "doclet.deprecated_errors"; 136 case ANNOTATION_TYPE: 137 return "doclet.deprecated_annotation_types"; 138 case FIELD: 139 return "doclet.deprecated_fields"; 140 case METHOD: 141 return "doclet.deprecated_methods"; 142 case CONSTRUCTOR: 143 return "doclet.deprecated_constructors"; 144 case ENUM_CONSTANT: 145 return "doclet.deprecated_enum_constants"; 146 case ANNOTATION_TYPE_MEMBER: 147 return "doclet.deprecated_annotation_type_members"; 148 default: 149 throw new AssertionError("unknown kind: " + kind); 150 } 151 } 152 153 private String getHeaderKey(DeprElementKind kind) { 154 switch (kind) { 155 case PACKAGE: 156 return "doclet.Package"; 157 case INTERFACE: 158 return "doclet.Interface"; 159 case CLASS: 160 return "doclet.Class"; 161 case ENUM: 162 return "doclet.Enum"; 163 case EXCEPTION: 164 return "doclet.Exceptions"; 165 case ERROR: 166 return "doclet.Errors"; 167 case ANNOTATION_TYPE: 168 return "doclet.AnnotationType"; 169 case FIELD: 170 return "doclet.Field"; 171 case METHOD: 172 return "doclet.Method"; 173 case CONSTRUCTOR: 174 return "doclet.Constructor"; 175 case ENUM_CONSTANT: 176 return "doclet.Enum_Constant"; 177 case ANNOTATION_TYPE_MEMBER: 178 return "doclet.Annotation_Type_Member"; 179 default: 180 throw new AssertionError("unknown kind: " + kind); 181 } 182 } 183 184 private EnumMap<DeprElementKind, AbstractMemberWriter> writerMap; 185 186 private ConfigurationImpl configuration; 187 188 /** 189 * Constructor. 190 * 191 * @param filename the file to be generated. 192 */ 193 194 public DeprecatedListWriter(ConfigurationImpl configuration, 195 DocPath filename) throws IOException { 196 super(configuration, filename); 197 this.configuration = configuration; 198 NestedClassWriterImpl classW = new NestedClassWriterImpl(this); 199 writerMap = new EnumMap<>(DeprElementKind.class); 200 for (DeprElementKind kind : DeprElementKind.values()) { 201 switch (kind) { 202 case PACKAGE: 203 case INTERFACE: 204 case CLASS: 205 case ENUM: 206 case EXCEPTION: 207 case ERROR: 208 case ANNOTATION_TYPE: 209 writerMap.put(kind, classW); 210 break; 211 case FIELD: 212 writerMap.put(kind, new FieldWriterImpl(this)); 213 break; 214 case METHOD: 215 writerMap.put(kind, new MethodWriterImpl(this)); 216 break; 217 case CONSTRUCTOR: 218 writerMap.put(kind, new ConstructorWriterImpl(this)); 219 break; 220 case ENUM_CONSTANT: 221 writerMap.put(kind, new EnumConstantWriterImpl(this)); 222 break; 223 case ANNOTATION_TYPE_MEMBER: 224 writerMap.put(kind, new AnnotationTypeOptionalMemberWriterImpl(this, null)); 225 break; 226 default: 227 throw new AssertionError("unknown kind: " + kind); 228 } 229 } 230 } 231 232 /** 233 * Get list of all the deprecated classes and members in all the Packages 234 * specified on the Command Line. 235 * Then instantiate DeprecatedListWriter and generate File. 236 * 237 * @param configuration the current configuration of the doclet. 238 */ 239 public static void generate(ConfigurationImpl configuration) { 240 DocPath filename = DocPaths.DEPRECATED_LIST; 241 try { 242 DeprecatedListWriter depr = 243 new DeprecatedListWriter(configuration, filename); 244 depr.generateDeprecatedListFile( 245 new DeprecatedAPIListBuilder(configuration)); 246 depr.close(); 247 } catch (IOException exc) { 248 configuration.standardmessage.error( 249 "doclet.exception_encountered", 250 exc.toString(), filename); 251 throw new DocletAbortException(exc); 252 } 253 } 254 255 /** 256 * Generate the deprecated API list. 257 * 258 * @param deprapi list of deprecated API built already. 259 */ 260 protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi) 261 throws IOException { 262 HtmlTree body = getHeader(); 263 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 264 ? HtmlTree.MAIN() 265 : body; 266 htmlTree.addContent(getContentsList(deprapi)); 267 String memberTableSummary; 268 HtmlTree div = new HtmlTree(HtmlTag.DIV); 269 div.addStyle(HtmlStyle.contentContainer); 270 for (DeprElementKind kind : DeprElementKind.values()) { 271 if (deprapi.hasDocumentation(kind)) { 272 addAnchor(deprapi, kind, div); 273 memberTableSummary = 274 configuration.getText("doclet.Member_Table_Summary", 275 configuration.getText(getHeadingKey(kind)), 276 configuration.getText(getSummaryKey(kind))); 277 List<String> memberTableHeader = new ArrayList<>(); 278 memberTableHeader.add(configuration.getText("doclet.0_and_1", 279 configuration.getText(getHeaderKey(kind)), 280 configuration.getText("doclet.Description"))); 281 if (kind == DeprElementKind.PACKAGE) 282 addPackageDeprecatedAPI(deprapi.getSet(kind), 283 getHeadingKey(kind), memberTableSummary, memberTableHeader, div); 284 else 285 writerMap.get(kind).addDeprecatedAPI(deprapi.getSet(kind), 286 getHeadingKey(kind), memberTableSummary, memberTableHeader, div); 287 } 288 } 289 if (configuration.allowTag(HtmlTag.MAIN)) { 290 htmlTree.addContent(div); 291 body.addContent(htmlTree); 292 } else { 293 body.addContent(div); 294 } 295 htmlTree = (configuration.allowTag(HtmlTag.FOOTER)) 296 ? HtmlTree.FOOTER() 297 : body; 298 addNavLinks(false, htmlTree); 299 addBottom(htmlTree); 300 if (configuration.allowTag(HtmlTag.FOOTER)) { 301 body.addContent(htmlTree); 302 } 303 printHtmlDocument(null, true, body); 304 } 305 306 /** 307 * Add the index link. 308 * 309 * @param builder the deprecated list builder 310 * @param type the type of list being documented 311 * @param contentTree the content tree to which the index link will be added 312 */ 313 private void addIndexLink(DeprecatedAPIListBuilder builder, 314 DeprElementKind kind, Content contentTree) { 315 if (builder.hasDocumentation(kind)) { 316 Content li = HtmlTree.LI(getHyperLink(getAnchorName(kind), 317 getResource(getHeadingKey(kind)))); 318 contentTree.addContent(li); 319 } 320 } 321 322 /** 323 * Get the contents list. 324 * 325 * @param deprapi the deprecated list builder 326 * @return a content tree for the contents list 327 */ 328 public Content getContentsList(DeprecatedAPIListBuilder deprapi) { 329 Content headContent = getResource("doclet.Deprecated_API"); 330 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, 331 HtmlStyle.title, headContent); 332 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 333 Content headingContent = getResource("doclet.Contents"); 334 div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, 335 headingContent)); 336 Content ul = new HtmlTree(HtmlTag.UL); 337 for (DeprElementKind kind : DeprElementKind.values()) { 338 addIndexLink(deprapi, kind, ul); 339 } 340 div.addContent(ul); 341 return div; 342 } 343 344 /** 345 * Add the anchor. 346 * 347 * @param builder the deprecated list builder 348 * @param type the type of list being documented 349 * @param htmlTree the content tree to which the anchor will be added 350 */ 351 private void addAnchor(DeprecatedAPIListBuilder builder, DeprElementKind kind, Content htmlTree) { 352 if (builder.hasDocumentation(kind)) { 353 htmlTree.addContent(getMarkerAnchor(getAnchorName(kind))); 354 } 355 } 356 357 /** 358 * Get the header for the deprecated API Listing. 359 * 360 * @return a content tree for the header 361 */ 362 public HtmlTree getHeader() { 363 String title = configuration.getText("doclet.Window_Deprecated_List"); 364 HtmlTree bodyTree = getBody(true, getWindowTitle(title)); 365 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) 366 ? HtmlTree.HEADER() 367 : bodyTree; 368 addTop(htmlTree); 369 addNavLinks(true, htmlTree); 370 if (configuration.allowTag(HtmlTag.HEADER)) { 371 bodyTree.addContent(htmlTree); 372 } 373 return bodyTree; |