0N/A/*
911N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.javadoc;
0N/A
0N/Aimport java.io.IOException;
196N/Aimport java.util.Locale;
196N/Aimport javax.tools.JavaFileObject;
196N/Aimport javax.tools.StandardJavaFileManager;
0N/A
0N/Aimport com.sun.javadoc.*;
0N/A
0N/Aimport com.sun.tools.javac.tree.JCTree.JCClassDecl;
0N/Aimport com.sun.tools.javac.util.List;
0N/Aimport com.sun.tools.javac.util.ListBuffer;
0N/Aimport com.sun.tools.javac.util.Position;
0N/A
0N/A/**
0N/A * This class holds the information from one run of javadoc.
0N/A * Particularly the packages, classes and options specified
0N/A * by the user..
0N/A *
0N/A * @since 1.2
0N/A * @author Robert Field
0N/A * @author Atul M Dambalkar
0N/A * @author Neal Gafter (rewrite)
0N/A */
0N/Apublic class RootDocImpl extends DocImpl implements RootDoc {
0N/A
0N/A /**
0N/A * list of classes specified on the command line.
0N/A */
0N/A private List<ClassDocImpl> cmdLineClasses;
0N/A
0N/A /**
0N/A * list of packages specified on the command line.
0N/A */
0N/A private List<PackageDocImpl> cmdLinePackages;
0N/A
0N/A /**
0N/A * a collection of all options.
0N/A */
0N/A private List<String[]> options;
0N/A
0N/A /**
0N/A * Constructor used when reading source files.
0N/A *
0N/A * @param env the documentation environment, state for this javadoc run
0N/A * @param classes list of classes specified on the commandline
0N/A * @param packages list of package names specified on the commandline
0N/A * @param options list of options
0N/A */
0N/A public RootDocImpl(DocEnv env, List<JCClassDecl> classes, List<String> packages, List<String[]> options) {
0N/A super(env, null);
0N/A this.options = options;
0N/A setPackages(env, packages);
0N/A setClasses(env, classes);
0N/A }
0N/A
0N/A /**
0N/A * Constructor used when reading class files.
0N/A *
0N/A * @param env the documentation environment, state for this javadoc run
0N/A * @param classes list of class names specified on the commandline
0N/A * @param options list of options
0N/A */
0N/A public RootDocImpl(DocEnv env, List<String> classes, List<String[]> options) {
0N/A super(env, null);
0N/A this.options = options;
0N/A cmdLinePackages = List.nil();
0N/A ListBuffer<ClassDocImpl> classList = new ListBuffer<ClassDocImpl>();
0N/A for (String className : classes) {
0N/A ClassDocImpl c = env.loadClass(className);
0N/A if (c == null)
0N/A env.error(null, "javadoc.class_not_found", className);
0N/A else
0N/A classList = classList.append(c);
0N/A }
0N/A cmdLineClasses = classList.toList();
0N/A }
0N/A
0N/A /**
0N/A * Initialize classes information. Those classes are input from
0N/A * command line.
0N/A *
0N/A * @param env the compilation environment
0N/A * @param classes a list of ClassDeclaration
0N/A */
0N/A private void setClasses(DocEnv env, List<JCClassDecl> classes) {
0N/A ListBuffer<ClassDocImpl> result = new ListBuffer<ClassDocImpl>();
0N/A for (JCClassDecl def : classes) {
0N/A //### Do we want modifier check here?
0N/A if (env.shouldDocument(def.sym)) {
0N/A ClassDocImpl cd = env.getClassDoc(def.sym);
0N/A if (cd != null) {
0N/A cd.isIncluded = true;
0N/A result.append(cd);
0N/A } //else System.out.println(" (classdoc is null)");//DEBUG
0N/A } //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG
0N/A }
0N/A cmdLineClasses = result.toList();
0N/A }
0N/A
0N/A /**
0N/A * Initialize packages information.
0N/A *
0N/A * @param env the compilation environment
0N/A * @param packages a list of package names (String)
0N/A */
0N/A private void setPackages(DocEnv env, List<String> packages) {
0N/A ListBuffer<PackageDocImpl> packlist = new ListBuffer<PackageDocImpl>();
0N/A for (String name : packages) {
0N/A PackageDocImpl pkg = env.lookupPackage(name);
0N/A if (pkg != null) {
0N/A pkg.isIncluded = true;
0N/A packlist.append(pkg);
0N/A } else {
0N/A env.warning(null, "main.no_source_files_for_package", name);
0N/A }
0N/A }
0N/A cmdLinePackages = packlist.toList();
0N/A }
0N/A
0N/A /**
0N/A * Command line options.
0N/A *
0N/A * <pre>
0N/A * For example, given:
0N/A * javadoc -foo this that -bar other ...
0N/A *
0N/A * This method will return:
0N/A * options()[0][0] = "-foo"
0N/A * options()[0][1] = "this"
0N/A * options()[0][2] = "that"
0N/A * options()[1][0] = "-bar"
0N/A * options()[1][1] = "other"
0N/A * </pre>
0N/A *
0N/A * @return an array of arrays of String.
0N/A */
0N/A public String[][] options() {
0N/A return options.toArray(new String[options.length()][]);
0N/A }
0N/A
0N/A /**
0N/A * Packages specified on the command line.
0N/A */
0N/A public PackageDoc[] specifiedPackages() {
0N/A return (PackageDoc[])cmdLinePackages
0N/A .toArray(new PackageDocImpl[cmdLinePackages.length()]);
0N/A }
0N/A
0N/A /**
0N/A * Classes and interfaces specified on the command line.
0N/A */
0N/A public ClassDoc[] specifiedClasses() {
0N/A ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<ClassDocImpl>();
0N/A for (ClassDocImpl cd : cmdLineClasses) {
0N/A cd.addAllClasses(classesToDocument, true);
0N/A }
0N/A return (ClassDoc[])classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]);
0N/A }
0N/A
0N/A /**
0N/A * Return all classes and interfaces (including those inside
0N/A * packages) to be documented.
0N/A */
0N/A public ClassDoc[] classes() {
0N/A ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<ClassDocImpl>();
0N/A for (ClassDocImpl cd : cmdLineClasses) {
0N/A cd.addAllClasses(classesToDocument, true);
0N/A }
0N/A for (PackageDocImpl pd : cmdLinePackages) {
0N/A pd.addAllClassesTo(classesToDocument);
0N/A }
0N/A return classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]);
0N/A }
0N/A
0N/A /**
0N/A * Return a ClassDoc for the specified class/interface name
0N/A *
0N/A * @param qualifiedName qualified class name
0N/A * (i.e. includes package name).
0N/A *
0N/A * @return a ClassDocImpl holding the specified class, null if
0N/A * this class is not referenced.
0N/A */
0N/A public ClassDoc classNamed(String qualifiedName) {
0N/A return env.lookupClass(qualifiedName);
0N/A }
0N/A
0N/A /**
0N/A * Return a PackageDoc for the specified package name
0N/A *
0N/A * @param name package name
0N/A *
0N/A * @return a PackageDoc holding the specified package, null if
0N/A * this package is not referenced.
0N/A */
0N/A public PackageDoc packageNamed(String name) {
0N/A return env.lookupPackage(name);
0N/A }
0N/A
0N/A /**
0N/A * Return the name of this Doc item.
0N/A *
0N/A * @return the string <code>"*RootDocImpl*"</code>.
0N/A */
0N/A public String name() {
0N/A return "*RootDocImpl*";
0N/A }
0N/A
0N/A /**
0N/A * Return the name of this Doc item.
0N/A *
0N/A * @return the string <code>"*RootDocImpl*"</code>.
0N/A */
0N/A public String qualifiedName() {
0N/A return "*RootDocImpl*";
0N/A }
0N/A
0N/A /**
0N/A * Return true if this Doc is include in the active set.
0N/A * RootDocImpl isn't even a program entity so it is always false.
0N/A */
0N/A public boolean isIncluded() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Print error message, increment error count.
0N/A *
0N/A * @param msg message to print
0N/A */
0N/A public void printError(String msg) {
0N/A env.printError(msg);
0N/A }
0N/A
0N/A /**
0N/A * Print error message, increment error count.
0N/A *
0N/A * @param msg message to print
0N/A */
0N/A public void printError(SourcePosition pos, String msg) {
0N/A env.printError(pos, msg);
0N/A }
0N/A
0N/A /**
0N/A * Print warning message, increment warning count.
0N/A *
0N/A * @param msg message to print
0N/A */
0N/A public void printWarning(String msg) {
0N/A env.printWarning(msg);
0N/A }
0N/A
0N/A /**
0N/A * Print warning message, increment warning count.
0N/A *
0N/A * @param msg message to print
0N/A */
0N/A public void printWarning(SourcePosition pos, String msg) {
0N/A env.printWarning(pos, msg);
0N/A }
0N/A
0N/A /**
0N/A * Print a message.
0N/A *
0N/A * @param msg message to print
0N/A */
0N/A public void printNotice(String msg) {
0N/A env.printNotice(msg);
0N/A }
0N/A
0N/A /**
0N/A * Print a message.
0N/A *
0N/A * @param msg message to print
0N/A */
0N/A public void printNotice(SourcePosition pos, String msg) {
0N/A env.printNotice(pos, msg);
0N/A }
0N/A
0N/A /**
0N/A * Return the path of the overview file and null if it does not exist.
0N/A * @return the path of the overview file and null if it does not exist.
0N/A */
196N/A private JavaFileObject getOverviewPath() {
0N/A for (String[] opt : options) {
0N/A if (opt[0].equals("-overview")) {
196N/A if (env.fileManager instanceof StandardJavaFileManager) {
196N/A StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager;
196N/A return fm.getJavaFileObjects(opt[1]).iterator().next();
196N/A }
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Do lazy initialization of "documentation" string.
0N/A */
911N/A @Override
0N/A protected String documentation() {
0N/A if (documentation == null) {
0N/A int cnt = options.length();
196N/A JavaFileObject overviewPath = getOverviewPath();
0N/A if (overviewPath == null) {
0N/A // no doc file to be had
0N/A documentation = "";
0N/A } else {
0N/A // read from file
0N/A try {
0N/A documentation = readHTMLDocumentation(
196N/A overviewPath.openInputStream(),
0N/A overviewPath);
0N/A } catch (IOException exc) {
0N/A documentation = "";
196N/A env.error(null, "javadoc.File_Read_Error", overviewPath.getName());
0N/A }
0N/A }
0N/A }
0N/A return documentation;
0N/A }
0N/A
0N/A /**
0N/A * Return the source position of the entity, or null if
0N/A * no position is available.
0N/A */
911N/A @Override
0N/A public SourcePosition position() {
196N/A JavaFileObject path;
0N/A return ((path = getOverviewPath()) == null) ?
0N/A null :
0N/A SourcePositionImpl.make(path, Position.NOPOS, null);
0N/A }
190N/A
190N/A /**
190N/A * Return the locale provided by the user or the default locale value.
190N/A */
190N/A public Locale getLocale() {
190N/A return env.doclocale.locale;
190N/A }
0N/A}