Thu, 31 Aug 2017 15:17:03 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.javadoc; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.io.IOException; |
aoqi@0 | 29 | import java.util.Collection; |
aoqi@0 | 30 | import java.util.Locale; |
aoqi@0 | 31 | |
aoqi@0 | 32 | import javax.tools.JavaFileManager; |
aoqi@0 | 33 | import javax.tools.JavaFileObject; |
aoqi@0 | 34 | import javax.tools.StandardJavaFileManager; |
aoqi@0 | 35 | |
aoqi@0 | 36 | import com.sun.javadoc.*; |
aoqi@0 | 37 | import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
aoqi@0 | 38 | import com.sun.tools.javac.util.List; |
aoqi@0 | 39 | import com.sun.tools.javac.util.ListBuffer; |
aoqi@0 | 40 | import com.sun.tools.javac.util.Position; |
aoqi@0 | 41 | |
aoqi@0 | 42 | /** |
aoqi@0 | 43 | * This class holds the information from one run of javadoc. |
aoqi@0 | 44 | * Particularly the packages, classes and options specified |
aoqi@0 | 45 | * by the user. |
aoqi@0 | 46 | * |
aoqi@0 | 47 | * <p><b>This is NOT part of any supported API. |
aoqi@0 | 48 | * If you write code that depends on this, you do so at your own risk. |
aoqi@0 | 49 | * This code and its internal interfaces are subject to change or |
aoqi@0 | 50 | * deletion without notice.</b> |
aoqi@0 | 51 | * |
aoqi@0 | 52 | * @since 1.2 |
aoqi@0 | 53 | * @author Robert Field |
aoqi@0 | 54 | * @author Atul M Dambalkar |
aoqi@0 | 55 | * @author Neal Gafter (rewrite) |
aoqi@0 | 56 | */ |
aoqi@0 | 57 | public class RootDocImpl extends DocImpl implements RootDoc { |
aoqi@0 | 58 | |
aoqi@0 | 59 | /** |
aoqi@0 | 60 | * list of classes specified on the command line. |
aoqi@0 | 61 | */ |
aoqi@0 | 62 | private List<ClassDocImpl> cmdLineClasses; |
aoqi@0 | 63 | |
aoqi@0 | 64 | /** |
aoqi@0 | 65 | * list of packages specified on the command line. |
aoqi@0 | 66 | */ |
aoqi@0 | 67 | private List<PackageDocImpl> cmdLinePackages; |
aoqi@0 | 68 | |
aoqi@0 | 69 | /** |
aoqi@0 | 70 | * a collection of all options. |
aoqi@0 | 71 | */ |
aoqi@0 | 72 | private List<String[]> options; |
aoqi@0 | 73 | |
aoqi@0 | 74 | /** |
aoqi@0 | 75 | * Constructor used when reading source files. |
aoqi@0 | 76 | * |
aoqi@0 | 77 | * @param env the documentation environment, state for this javadoc run |
aoqi@0 | 78 | * @param classes list of classes specified on the commandline |
aoqi@0 | 79 | * @param packages list of package names specified on the commandline |
aoqi@0 | 80 | * @param options list of options |
aoqi@0 | 81 | */ |
aoqi@0 | 82 | public RootDocImpl(DocEnv env, List<JCClassDecl> classes, List<String> packages, List<String[]> options) { |
aoqi@0 | 83 | super(env, null); |
aoqi@0 | 84 | this.options = options; |
aoqi@0 | 85 | setPackages(env, packages); |
aoqi@0 | 86 | setClasses(env, classes); |
aoqi@0 | 87 | } |
aoqi@0 | 88 | |
aoqi@0 | 89 | /** |
aoqi@0 | 90 | * Constructor used when reading class files. |
aoqi@0 | 91 | * |
aoqi@0 | 92 | * @param env the documentation environment, state for this javadoc run |
aoqi@0 | 93 | * @param classes list of class names specified on the commandline |
aoqi@0 | 94 | * @param options list of options |
aoqi@0 | 95 | */ |
aoqi@0 | 96 | public RootDocImpl(DocEnv env, List<String> classes, List<String[]> options) { |
aoqi@0 | 97 | super(env, null); |
aoqi@0 | 98 | this.options = options; |
aoqi@0 | 99 | cmdLinePackages = List.nil(); |
aoqi@0 | 100 | ListBuffer<ClassDocImpl> classList = new ListBuffer<ClassDocImpl>(); |
aoqi@0 | 101 | for (String className : classes) { |
aoqi@0 | 102 | ClassDocImpl c = env.loadClass(className); |
aoqi@0 | 103 | if (c == null) |
aoqi@0 | 104 | env.error(null, "javadoc.class_not_found", className); |
aoqi@0 | 105 | else |
aoqi@0 | 106 | classList = classList.append(c); |
aoqi@0 | 107 | } |
aoqi@0 | 108 | cmdLineClasses = classList.toList(); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | |
aoqi@0 | 111 | /** |
aoqi@0 | 112 | * Initialize classes information. Those classes are input from |
aoqi@0 | 113 | * command line. |
aoqi@0 | 114 | * |
aoqi@0 | 115 | * @param env the compilation environment |
aoqi@0 | 116 | * @param classes a list of ClassDeclaration |
aoqi@0 | 117 | */ |
aoqi@0 | 118 | private void setClasses(DocEnv env, List<JCClassDecl> classes) { |
aoqi@0 | 119 | ListBuffer<ClassDocImpl> result = new ListBuffer<ClassDocImpl>(); |
aoqi@0 | 120 | for (JCClassDecl def : classes) { |
aoqi@0 | 121 | //### Do we want modifier check here? |
aoqi@0 | 122 | if (env.shouldDocument(def.sym)) { |
aoqi@0 | 123 | ClassDocImpl cd = env.getClassDoc(def.sym); |
aoqi@0 | 124 | if (cd != null) { |
aoqi@0 | 125 | cd.isIncluded = true; |
aoqi@0 | 126 | result.append(cd); |
aoqi@0 | 127 | } //else System.out.println(" (classdoc is null)");//DEBUG |
aoqi@0 | 128 | } //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG |
aoqi@0 | 129 | } |
aoqi@0 | 130 | cmdLineClasses = result.toList(); |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | /** |
aoqi@0 | 134 | * Initialize packages information. |
aoqi@0 | 135 | * |
aoqi@0 | 136 | * @param env the compilation environment |
aoqi@0 | 137 | * @param packages a list of package names (String) |
aoqi@0 | 138 | */ |
aoqi@0 | 139 | private void setPackages(DocEnv env, List<String> packages) { |
aoqi@0 | 140 | ListBuffer<PackageDocImpl> packlist = new ListBuffer<PackageDocImpl>(); |
aoqi@0 | 141 | for (String name : packages) { |
aoqi@0 | 142 | PackageDocImpl pkg = env.lookupPackage(name); |
aoqi@0 | 143 | if (pkg != null) { |
aoqi@0 | 144 | pkg.isIncluded = true; |
aoqi@0 | 145 | packlist.append(pkg); |
aoqi@0 | 146 | } else { |
aoqi@0 | 147 | env.warning(null, "main.no_source_files_for_package", name); |
aoqi@0 | 148 | } |
aoqi@0 | 149 | } |
aoqi@0 | 150 | cmdLinePackages = packlist.toList(); |
aoqi@0 | 151 | } |
aoqi@0 | 152 | |
aoqi@0 | 153 | /** |
aoqi@0 | 154 | * Command line options. |
aoqi@0 | 155 | * |
aoqi@0 | 156 | * <pre> |
aoqi@0 | 157 | * For example, given: |
aoqi@0 | 158 | * javadoc -foo this that -bar other ... |
aoqi@0 | 159 | * |
aoqi@0 | 160 | * This method will return: |
aoqi@0 | 161 | * options()[0][0] = "-foo" |
aoqi@0 | 162 | * options()[0][1] = "this" |
aoqi@0 | 163 | * options()[0][2] = "that" |
aoqi@0 | 164 | * options()[1][0] = "-bar" |
aoqi@0 | 165 | * options()[1][1] = "other" |
aoqi@0 | 166 | * </pre> |
aoqi@0 | 167 | * |
aoqi@0 | 168 | * @return an array of arrays of String. |
aoqi@0 | 169 | */ |
aoqi@0 | 170 | public String[][] options() { |
aoqi@0 | 171 | return options.toArray(new String[options.length()][]); |
aoqi@0 | 172 | } |
aoqi@0 | 173 | |
aoqi@0 | 174 | /** |
aoqi@0 | 175 | * Packages specified on the command line. |
aoqi@0 | 176 | */ |
aoqi@0 | 177 | public PackageDoc[] specifiedPackages() { |
aoqi@0 | 178 | return (PackageDoc[])cmdLinePackages |
aoqi@0 | 179 | .toArray(new PackageDocImpl[cmdLinePackages.length()]); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | /** |
aoqi@0 | 183 | * Classes and interfaces specified on the command line. |
aoqi@0 | 184 | */ |
aoqi@0 | 185 | public ClassDoc[] specifiedClasses() { |
aoqi@0 | 186 | ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<ClassDocImpl>(); |
aoqi@0 | 187 | for (ClassDocImpl cd : cmdLineClasses) { |
aoqi@0 | 188 | cd.addAllClasses(classesToDocument, true); |
aoqi@0 | 189 | } |
aoqi@0 | 190 | return (ClassDoc[])classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]); |
aoqi@0 | 191 | } |
aoqi@0 | 192 | |
aoqi@0 | 193 | /** |
aoqi@0 | 194 | * Return all classes and interfaces (including those inside |
aoqi@0 | 195 | * packages) to be documented. |
aoqi@0 | 196 | */ |
aoqi@0 | 197 | public ClassDoc[] classes() { |
aoqi@0 | 198 | ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<ClassDocImpl>(); |
aoqi@0 | 199 | for (ClassDocImpl cd : cmdLineClasses) { |
aoqi@0 | 200 | cd.addAllClasses(classesToDocument, true); |
aoqi@0 | 201 | } |
aoqi@0 | 202 | for (PackageDocImpl pd : cmdLinePackages) { |
aoqi@0 | 203 | pd.addAllClassesTo(classesToDocument); |
aoqi@0 | 204 | } |
aoqi@0 | 205 | return classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]); |
aoqi@0 | 206 | } |
aoqi@0 | 207 | |
aoqi@0 | 208 | /** |
aoqi@0 | 209 | * Return a ClassDoc for the specified class/interface name |
aoqi@0 | 210 | * |
aoqi@0 | 211 | * @param qualifiedName qualified class name |
aoqi@0 | 212 | * (i.e. includes package name). |
aoqi@0 | 213 | * |
aoqi@0 | 214 | * @return a ClassDocImpl holding the specified class, null if |
aoqi@0 | 215 | * this class is not referenced. |
aoqi@0 | 216 | */ |
aoqi@0 | 217 | public ClassDoc classNamed(String qualifiedName) { |
aoqi@0 | 218 | return env.lookupClass(qualifiedName); |
aoqi@0 | 219 | } |
aoqi@0 | 220 | |
aoqi@0 | 221 | /** |
aoqi@0 | 222 | * Return a PackageDoc for the specified package name |
aoqi@0 | 223 | * |
aoqi@0 | 224 | * @param name package name |
aoqi@0 | 225 | * |
aoqi@0 | 226 | * @return a PackageDoc holding the specified package, null if |
aoqi@0 | 227 | * this package is not referenced. |
aoqi@0 | 228 | */ |
aoqi@0 | 229 | public PackageDoc packageNamed(String name) { |
aoqi@0 | 230 | return env.lookupPackage(name); |
aoqi@0 | 231 | } |
aoqi@0 | 232 | |
aoqi@0 | 233 | /** |
aoqi@0 | 234 | * Return the name of this Doc item. |
aoqi@0 | 235 | * |
aoqi@0 | 236 | * @return the string <code>"*RootDocImpl*"</code>. |
aoqi@0 | 237 | */ |
aoqi@0 | 238 | public String name() { |
aoqi@0 | 239 | return "*RootDocImpl*"; |
aoqi@0 | 240 | } |
aoqi@0 | 241 | |
aoqi@0 | 242 | /** |
aoqi@0 | 243 | * Return the name of this Doc item. |
aoqi@0 | 244 | * |
aoqi@0 | 245 | * @return the string <code>"*RootDocImpl*"</code>. |
aoqi@0 | 246 | */ |
aoqi@0 | 247 | public String qualifiedName() { |
aoqi@0 | 248 | return "*RootDocImpl*"; |
aoqi@0 | 249 | } |
aoqi@0 | 250 | |
aoqi@0 | 251 | /** |
aoqi@0 | 252 | * Return true if this Doc is include in the active set. |
aoqi@0 | 253 | * RootDocImpl isn't even a program entity so it is always false. |
aoqi@0 | 254 | */ |
aoqi@0 | 255 | public boolean isIncluded() { |
aoqi@0 | 256 | return false; |
aoqi@0 | 257 | } |
aoqi@0 | 258 | |
aoqi@0 | 259 | /** |
aoqi@0 | 260 | * Print error message, increment error count. |
aoqi@0 | 261 | * |
aoqi@0 | 262 | * @param msg message to print |
aoqi@0 | 263 | */ |
aoqi@0 | 264 | public void printError(String msg) { |
aoqi@0 | 265 | env.printError(msg); |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
aoqi@0 | 268 | /** |
aoqi@0 | 269 | * Print error message, increment error count. |
aoqi@0 | 270 | * |
aoqi@0 | 271 | * @param msg message to print |
aoqi@0 | 272 | */ |
aoqi@0 | 273 | public void printError(SourcePosition pos, String msg) { |
aoqi@0 | 274 | env.printError(pos, msg); |
aoqi@0 | 275 | } |
aoqi@0 | 276 | |
aoqi@0 | 277 | /** |
aoqi@0 | 278 | * Print warning message, increment warning count. |
aoqi@0 | 279 | * |
aoqi@0 | 280 | * @param msg message to print |
aoqi@0 | 281 | */ |
aoqi@0 | 282 | public void printWarning(String msg) { |
aoqi@0 | 283 | env.printWarning(msg); |
aoqi@0 | 284 | } |
aoqi@0 | 285 | |
aoqi@0 | 286 | /** |
aoqi@0 | 287 | * Print warning message, increment warning count. |
aoqi@0 | 288 | * |
aoqi@0 | 289 | * @param msg message to print |
aoqi@0 | 290 | */ |
aoqi@0 | 291 | public void printWarning(SourcePosition pos, String msg) { |
aoqi@0 | 292 | env.printWarning(pos, msg); |
aoqi@0 | 293 | } |
aoqi@0 | 294 | |
aoqi@0 | 295 | /** |
aoqi@0 | 296 | * Print a message. |
aoqi@0 | 297 | * |
aoqi@0 | 298 | * @param msg message to print |
aoqi@0 | 299 | */ |
aoqi@0 | 300 | public void printNotice(String msg) { |
aoqi@0 | 301 | env.printNotice(msg); |
aoqi@0 | 302 | } |
aoqi@0 | 303 | |
aoqi@0 | 304 | /** |
aoqi@0 | 305 | * Print a message. |
aoqi@0 | 306 | * |
aoqi@0 | 307 | * @param msg message to print |
aoqi@0 | 308 | */ |
aoqi@0 | 309 | public void printNotice(SourcePosition pos, String msg) { |
aoqi@0 | 310 | env.printNotice(pos, msg); |
aoqi@0 | 311 | } |
aoqi@0 | 312 | |
aoqi@0 | 313 | /** |
aoqi@0 | 314 | * Return the path of the overview file and null if it does not exist. |
aoqi@0 | 315 | * @return the path of the overview file and null if it does not exist. |
aoqi@0 | 316 | */ |
aoqi@0 | 317 | private JavaFileObject getOverviewPath() { |
aoqi@0 | 318 | for (String[] opt : options) { |
aoqi@0 | 319 | if (opt[0].equals("-overview")) { |
aoqi@0 | 320 | if (env.fileManager instanceof StandardJavaFileManager) { |
aoqi@0 | 321 | StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager; |
aoqi@0 | 322 | return fm.getJavaFileObjects(opt[1]).iterator().next(); |
aoqi@0 | 323 | } |
aoqi@0 | 324 | } |
aoqi@0 | 325 | } |
aoqi@0 | 326 | return null; |
aoqi@0 | 327 | } |
aoqi@0 | 328 | |
aoqi@0 | 329 | /** |
aoqi@0 | 330 | * Do lazy initialization of "documentation" string. |
aoqi@0 | 331 | */ |
aoqi@0 | 332 | @Override |
aoqi@0 | 333 | protected String documentation() { |
aoqi@0 | 334 | if (documentation == null) { |
aoqi@0 | 335 | JavaFileObject overviewPath = getOverviewPath(); |
aoqi@0 | 336 | if (overviewPath == null) { |
aoqi@0 | 337 | // no doc file to be had |
aoqi@0 | 338 | documentation = ""; |
aoqi@0 | 339 | } else { |
aoqi@0 | 340 | // read from file |
aoqi@0 | 341 | try { |
aoqi@0 | 342 | documentation = readHTMLDocumentation( |
aoqi@0 | 343 | overviewPath.openInputStream(), |
aoqi@0 | 344 | overviewPath); |
aoqi@0 | 345 | } catch (IOException exc) { |
aoqi@0 | 346 | documentation = ""; |
aoqi@0 | 347 | env.error(null, "javadoc.File_Read_Error", overviewPath.getName()); |
aoqi@0 | 348 | } |
aoqi@0 | 349 | } |
aoqi@0 | 350 | } |
aoqi@0 | 351 | return documentation; |
aoqi@0 | 352 | } |
aoqi@0 | 353 | |
aoqi@0 | 354 | /** |
aoqi@0 | 355 | * Return the source position of the entity, or null if |
aoqi@0 | 356 | * no position is available. |
aoqi@0 | 357 | */ |
aoqi@0 | 358 | @Override |
aoqi@0 | 359 | public SourcePosition position() { |
aoqi@0 | 360 | JavaFileObject path; |
aoqi@0 | 361 | return ((path = getOverviewPath()) == null) ? |
aoqi@0 | 362 | null : |
aoqi@0 | 363 | SourcePositionImpl.make(path, Position.NOPOS, null); |
aoqi@0 | 364 | } |
aoqi@0 | 365 | |
aoqi@0 | 366 | /** |
aoqi@0 | 367 | * Return the locale provided by the user or the default locale value. |
aoqi@0 | 368 | */ |
aoqi@0 | 369 | public Locale getLocale() { |
aoqi@0 | 370 | return env.doclocale.locale; |
aoqi@0 | 371 | } |
aoqi@0 | 372 | |
aoqi@0 | 373 | /** |
aoqi@0 | 374 | * Return the current file manager. |
aoqi@0 | 375 | */ |
aoqi@0 | 376 | public JavaFileManager getFileManager() { |
aoqi@0 | 377 | return env.fileManager; |
aoqi@0 | 378 | } |
aoqi@0 | 379 | |
aoqi@0 | 380 | public void initDocLint(Collection<String> opts, Collection<String> customTagNames) { |
aoqi@0 | 381 | env.initDoclint(opts, customTagNames); |
aoqi@0 | 382 | } |
aoqi@0 | 383 | |
aoqi@0 | 384 | public boolean isFunctionalInterface(AnnotationDesc annotationDesc) { |
aoqi@0 | 385 | return annotationDesc.annotationType().qualifiedName().equals( |
aoqi@0 | 386 | env.syms.functionalInterfaceType.toString()) && env.source.allowLambda(); |
aoqi@0 | 387 | } |
aoqi@0 | 388 | |
aoqi@0 | 389 | public boolean showTagMessages() { |
aoqi@0 | 390 | return env.showTagMessages(); |
aoqi@0 | 391 | } |
aoqi@0 | 392 | } |