aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.javadoc; aoqi@0: aoqi@0: import java.io.IOException; aoqi@0: import java.util.Collection; aoqi@0: import java.util.Locale; aoqi@0: aoqi@0: import javax.tools.JavaFileManager; aoqi@0: import javax.tools.JavaFileObject; aoqi@0: import javax.tools.StandardJavaFileManager; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.javac.tree.JCTree.JCClassDecl; aoqi@0: import com.sun.tools.javac.util.List; aoqi@0: import com.sun.tools.javac.util.ListBuffer; aoqi@0: import com.sun.tools.javac.util.Position; aoqi@0: aoqi@0: /** aoqi@0: * This class holds the information from one run of javadoc. aoqi@0: * Particularly the packages, classes and options specified aoqi@0: * by the user. aoqi@0: * aoqi@0: *
This is NOT part of any supported API.
aoqi@0: * If you write code that depends on this, you do so at your own risk.
aoqi@0: * This code and its internal interfaces are subject to change or
aoqi@0: * deletion without notice.
aoqi@0: *
aoqi@0: * @since 1.2
aoqi@0: * @author Robert Field
aoqi@0: * @author Atul M Dambalkar
aoqi@0: * @author Neal Gafter (rewrite)
aoqi@0: */
aoqi@0: public class RootDocImpl extends DocImpl implements RootDoc {
aoqi@0:
aoqi@0: /**
aoqi@0: * list of classes specified on the command line.
aoqi@0: */
aoqi@0: private List
aoqi@0: * For example, given:
aoqi@0: * javadoc -foo this that -bar other ...
aoqi@0: *
aoqi@0: * This method will return:
aoqi@0: * options()[0][0] = "-foo"
aoqi@0: * options()[0][1] = "this"
aoqi@0: * options()[0][2] = "that"
aoqi@0: * options()[1][0] = "-bar"
aoqi@0: * options()[1][1] = "other"
aoqi@0: *
aoqi@0: *
aoqi@0: * @return an array of arrays of String.
aoqi@0: */
aoqi@0: public String[][] options() {
aoqi@0: return options.toArray(new String[options.length()][]);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Packages specified on the command line.
aoqi@0: */
aoqi@0: public PackageDoc[] specifiedPackages() {
aoqi@0: return (PackageDoc[])cmdLinePackages
aoqi@0: .toArray(new PackageDocImpl[cmdLinePackages.length()]);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Classes and interfaces specified on the command line.
aoqi@0: */
aoqi@0: public ClassDoc[] specifiedClasses() {
aoqi@0: ListBuffer"*RootDocImpl*"
.
aoqi@0: */
aoqi@0: public String name() {
aoqi@0: return "*RootDocImpl*";
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Return the name of this Doc item.
aoqi@0: *
aoqi@0: * @return the string "*RootDocImpl*"
.
aoqi@0: */
aoqi@0: public String qualifiedName() {
aoqi@0: return "*RootDocImpl*";
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Return true if this Doc is include in the active set.
aoqi@0: * RootDocImpl isn't even a program entity so it is always false.
aoqi@0: */
aoqi@0: public boolean isIncluded() {
aoqi@0: return false;
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Print error message, increment error count.
aoqi@0: *
aoqi@0: * @param msg message to print
aoqi@0: */
aoqi@0: public void printError(String msg) {
aoqi@0: env.printError(msg);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Print error message, increment error count.
aoqi@0: *
aoqi@0: * @param msg message to print
aoqi@0: */
aoqi@0: public void printError(SourcePosition pos, String msg) {
aoqi@0: env.printError(pos, msg);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Print warning message, increment warning count.
aoqi@0: *
aoqi@0: * @param msg message to print
aoqi@0: */
aoqi@0: public void printWarning(String msg) {
aoqi@0: env.printWarning(msg);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Print warning message, increment warning count.
aoqi@0: *
aoqi@0: * @param msg message to print
aoqi@0: */
aoqi@0: public void printWarning(SourcePosition pos, String msg) {
aoqi@0: env.printWarning(pos, msg);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Print a message.
aoqi@0: *
aoqi@0: * @param msg message to print
aoqi@0: */
aoqi@0: public void printNotice(String msg) {
aoqi@0: env.printNotice(msg);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Print a message.
aoqi@0: *
aoqi@0: * @param msg message to print
aoqi@0: */
aoqi@0: public void printNotice(SourcePosition pos, String msg) {
aoqi@0: env.printNotice(pos, msg);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Return the path of the overview file and null if it does not exist.
aoqi@0: * @return the path of the overview file and null if it does not exist.
aoqi@0: */
aoqi@0: private JavaFileObject getOverviewPath() {
aoqi@0: for (String[] opt : options) {
aoqi@0: if (opt[0].equals("-overview")) {
aoqi@0: if (env.fileManager instanceof StandardJavaFileManager) {
aoqi@0: StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager;
aoqi@0: return fm.getJavaFileObjects(opt[1]).iterator().next();
aoqi@0: }
aoqi@0: }
aoqi@0: }
aoqi@0: return null;
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Do lazy initialization of "documentation" string.
aoqi@0: */
aoqi@0: @Override
aoqi@0: protected String documentation() {
aoqi@0: if (documentation == null) {
aoqi@0: JavaFileObject overviewPath = getOverviewPath();
aoqi@0: if (overviewPath == null) {
aoqi@0: // no doc file to be had
aoqi@0: documentation = "";
aoqi@0: } else {
aoqi@0: // read from file
aoqi@0: try {
aoqi@0: documentation = readHTMLDocumentation(
aoqi@0: overviewPath.openInputStream(),
aoqi@0: overviewPath);
aoqi@0: } catch (IOException exc) {
aoqi@0: documentation = "";
aoqi@0: env.error(null, "javadoc.File_Read_Error", overviewPath.getName());
aoqi@0: }
aoqi@0: }
aoqi@0: }
aoqi@0: return documentation;
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Return the source position of the entity, or null if
aoqi@0: * no position is available.
aoqi@0: */
aoqi@0: @Override
aoqi@0: public SourcePosition position() {
aoqi@0: JavaFileObject path;
aoqi@0: return ((path = getOverviewPath()) == null) ?
aoqi@0: null :
aoqi@0: SourcePositionImpl.make(path, Position.NOPOS, null);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Return the locale provided by the user or the default locale value.
aoqi@0: */
aoqi@0: public Locale getLocale() {
aoqi@0: return env.doclocale.locale;
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Return the current file manager.
aoqi@0: */
aoqi@0: public JavaFileManager getFileManager() {
aoqi@0: return env.fileManager;
aoqi@0: }
aoqi@0:
aoqi@0: public void initDocLint(Collection