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