// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) deadcode 
// Source File Name:   RootDocImpl.java

package com.sun.tools.javadoc;

import com.sun.javadoc.*;
import com.sun.tools.javac.v8.tree.Tree;
import com.sun.tools.javac.v8.util.List;
import com.sun.tools.javac.v8.util.ListBuffer;
import java.io.FileInputStream;
import java.io.IOException;

// Referenced classes of package com.sun.tools.javadoc:
//            DocImpl, ClassDocImpl, DocEnv, Messager, 
//            PackageDocImpl, SourcePositionImpl

public class RootDocImpl extends DocImpl
    implements RootDoc
{

    public boolean isIncluded()
    {
        return false;
    }

    public ClassDoc[] classes()
    {
        ListBuffer listbuffer = new ListBuffer();
        for(List list = cmdLineClasses; list.nonEmpty(); list = list.tail)
            ((ClassDocImpl)list.head).addAllClasses(listbuffer, true);

        for(List list1 = cmdLinePackages; list1.nonEmpty(); list1 = list1.tail)
            ((PackageDocImpl)list1.head).addAllClassesTo(listbuffer);

        return (ClassDoc[])listbuffer.toArray(new ClassDocImpl[listbuffer.length()]);
    }

    public ClassDoc[] specifiedClasses()
    {
        ListBuffer listbuffer = new ListBuffer();
        for(List list = cmdLineClasses; list.nonEmpty(); list = list.tail)
            ((ClassDocImpl)list.head).addAllClasses(listbuffer, true);

        return (ClassDoc[])listbuffer.toArray(new ClassDocImpl[listbuffer.length()]);
    }

    public PackageDoc[] specifiedPackages()
    {
        return (PackageDoc[])cmdLinePackages.toArray(new PackageDocImpl[cmdLinePackages.length()]);
    }

    public SourcePosition position()
    {
        String s;
        return (s = getOverviewPath()) != null ? SourcePositionImpl.make(s, 0) : null;
    }

    protected String documentation()
    {
        if(documentation == null)
        {
            int i = options.length();
            String s = getOverviewPath();
            if(s == null)
                documentation = "";
            else
                try
                {
                    documentation = readHTMLDocumentation(new FileInputStream(s), s);
                }
                catch(IOException ioexception)
                {
                    documentation = "";
                    env.error(null, "javadoc.File_Read_Error", s);
                }
        }
        return documentation;
    }

    private String getOverviewPath()
    {
        for(List list = options; list.nonEmpty(); list = list.tail)
        {
            String as[] = (String[])list.head;
            if(as[0].equals("-overview"))
                return as[1];
        }

        return null;
    }

    public String name()
    {
        return "*RootDocImpl*";
    }

    public String qualifiedName()
    {
        return "*RootDocImpl*";
    }

    public String[][] options()
    {
        return (String[][])options.toArray(new String[options.length()][]);
    }

    public void printError(String s)
    {
        env.messager.printError(s);
    }

    public void printNotice(String s)
    {
        env.messager.printNotice(s);
    }

    public void printWarning(String s)
    {
        env.messager.printWarning(s);
    }

    public ClassDoc classNamed(String s)
    {
        return env.lookupClass(s);
    }

    public PackageDoc packageNamed(String s)
    {
        return env.lookupPackage(s);
    }

    private void setClasses(DocEnv docenv, List list)
    {
        ListBuffer listbuffer = new ListBuffer();
        for(List list1 = list; list1.nonEmpty(); list1 = list1.tail)
        {
            com.sun.tools.javac.v8.tree.Tree.ClassDef classdef = (com.sun.tools.javac.v8.tree.Tree.ClassDef)list1.head;
            if(!docenv.shouldDocument(classdef.sym))
                continue;
            ClassDocImpl classdocimpl = docenv.getClassDoc(classdef.sym);
            if(classdocimpl != null)
            {
                classdocimpl.isIncluded = true;
                listbuffer.append(classdocimpl);
            }
        }

        cmdLineClasses = listbuffer.toList();
    }

    private void setPackages(DocEnv docenv, List list)
    {
        ListBuffer listbuffer = new ListBuffer();
        for(List list1 = list; list1.nonEmpty(); list1 = list1.tail)
        {
            String s = (String)list1.head;
            PackageDocImpl packagedocimpl = docenv.lookupPackage(s);
            if(packagedocimpl != null)
            {
                packagedocimpl.isIncluded = true;
                listbuffer.append(packagedocimpl);
            } else
            {
                docenv.warning(null, "main.no_source_files_for_package", s);
            }
        }

        cmdLinePackages = listbuffer.toList();
    }

    public void printError(SourcePosition sourceposition, String s)
    {
        env.messager.printError(sourceposition, s);
    }

    public void printNotice(SourcePosition sourceposition, String s)
    {
        env.messager.printNotice(sourceposition, s);
    }

    public void printWarning(SourcePosition sourceposition, String s)
    {
        env.messager.printWarning(sourceposition, s);
    }

    public RootDocImpl(DocEnv docenv, List list, List list1)
    {
        DocImpl(docenv, null);
        options = list1;
        cmdLinePackages = List.make();
        ListBuffer listbuffer = new ListBuffer();
        for(List list2 = list; list2.nonEmpty(); list2 = list2.tail)
        {
            String s = (String)list2.head;
            ClassDocImpl classdocimpl = docenv.loadClass(s);
            if(classdocimpl == null)
                docenv.error(null, "javadoc.class_not_found", s);
            else
                listbuffer = listbuffer.append(classdocimpl);
        }

        cmdLineClasses = listbuffer.toList();
    }

    public RootDocImpl(DocEnv docenv, List list, List list1, List list2)
    {
        DocImpl(docenv, null);
        options = list2;
        setPackages(docenv, list1);
        setClasses(docenv, list);
    }

    private List cmdLineClasses;
    private List cmdLinePackages;
    private List options;
}
