// 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:   JavadocTool.java

package com.sun.tools.javadoc;

import com.sun.tools.javac.v8.JavaCompiler;
import com.sun.tools.javac.v8.code.Symbol;
import com.sun.tools.javac.v8.tree.Tree;
import com.sun.tools.javac.v8.util.*;
import java.io.File;

// Referenced classes of package com.sun.tools.javadoc:
//            DocEnv, JavadocClassReader, JavadocEnter, Messager, 
//            RootDocImpl, ModifierFilter

public class JavadocTool extends JavaCompiler
{

    protected boolean keepComments()
    {
        return true;
    }

    private JavadocTool(Context context1)
    {
        JavaCompiler(context1);
        context = context1;
        messager = Messager.instance0(context1);
        reader = JavadocClassReader.instance0(context1);
        enter = JavadocEnter.instance0(context1);
    }

    private static boolean isValidClassName(String s)
    {
        if(s.length() < 1)
            return false;
        if(!Character.isJavaIdentifierStart(s.charAt(0)))
            return false;
        for(int i = 1; i < s.length(); i++)
            if(!Character.isJavaIdentifierPart(s.charAt(i)))
                return false;

        return true;
    }

    private static boolean isValidJavaClassFile(String s)
    {
        if(!s.endsWith(".class"))
        {
            return false;
        } else
        {
            String s1 = s.substring(0, s.length() - ".class".length());
            return isValidClassName(s1);
        }
    }

    private static boolean isValidJavaSourceFile(String s)
    {
        if(!s.endsWith(".java"))
        {
            return false;
        } else
        {
            String s1 = s.substring(0, s.length() - ".java".length());
            return isValidClassName(s1);
        }
    }

    boolean isValidPackageName(String s)
    {
        int i;
        while((i = s.indexOf('.')) != -1) 
        {
            if(!isValidClassName(s.substring(0, i)))
                return false;
            s = s.substring(i + 1);
        }
        return isValidClassName(s);
    }

    List listClasses(List list)
    {
        ListBuffer listbuffer = new ListBuffer();
        for(List list1 = list; list1.nonEmpty(); list1 = list1.tail)
        {
            Tree tree = (Tree)list1.head;
            if(tree.tag != 1)
                continue;
            for(List list2 = ((com.sun.tools.javac.v8.tree.Tree.TopLevel)tree).defs; list2.nonEmpty(); list2 = list2.tail)
            {
                Tree tree1 = (Tree)list2.head;
                if(tree1.tag == 3)
                    listbuffer.append((com.sun.tools.javac.v8.tree.Tree.ClassDef)tree1);
            }

        }

        return listbuffer.toList();
    }

    public static JavadocTool make0(Context context1)
    {
        Messager messager1 = null;
        messager1 = Messager.instance0(context1);
        JavadocClassReader javadocclassreader = JavadocClassReader.instance0(context1);
        JavadocEnter javadocenter = JavadocEnter.instance0(context1);
        return new JavadocTool(context1);
        com.sun.tools.javac.v8.code.Symbol.CompletionFailure completionfailure;
        completionfailure;
        messager1.error(0, completionfailure.getMessage());
        return null;
    }

    private void searchSubPackages(List list, ListBuffer listbuffer, List list1)
    {
        for(List list2 = list; list2.nonEmpty(); list2 = list2.tail)
            searchSubPackages((String)list2.head, listbuffer, list1);

    }

    private void parsePackageClasses(String s, ListBuffer listbuffer, List list)
    {
        if(list.contains(s))
            return;
        boolean flag = false;
        String s1 = reader.sourceClassPath;
        if(s1 == null)
            s1 = reader.classPath;
        int i = s1.length();
        int j = 0;
        messager.notice("main.Loading_source_files_for_package", s);
        s = s.replace('.', File.separatorChar);
        int k;
        for(; j < i; j = k + 1)
        {
            k = s1.indexOf(pathSep, j);
            String s2 = s1.substring(j, k);
            File file = new File(s2, s);
            String as[] = file.list();
            if(as == null)
                continue;
            String s3 = file.getAbsolutePath();
            if(!s3.endsWith(File.separator))
                s3 = s3 + File.separator;
            for(int l = 0; l < as.length; l++)
                if(isValidJavaSourceFile(as[l]))
                {
                    String s4 = s3 + as[l];
                    listbuffer.append(parse(s4));
                    flag = true;
                }

        }

        if(!flag)
            messager.warning(null, "main.no_source_files_for_package", s.replace(File.separatorChar, '.'));
    }

    private void searchSubPackages(String s, ListBuffer listbuffer, List list)
    {
        if(list.contains(s))
            return;
        String s1 = reader.sourceClassPath + pathSep + reader.classPath;
        int i = s1.length();
        int j = 0;
        String s2 = s.replace('.', File.separatorChar);
        boolean flag = false;
        int k;
        for(; j < i; j = k + 1)
        {
            k = s1.indexOf(pathSep, j);
            String s3 = s1.substring(j, k);
            File file = new File(s3, s2);
            String as[] = file.list();
            if(as == null)
                continue;
            for(int l = 0; l < as.length; l++)
            {
                if(!flag && (isValidJavaSourceFile(as[l]) || isValidJavaClassFile(as[l])) && !listbuffer.contains(s))
                {
                    listbuffer.append(s);
                    flag = true;
                    continue;
                }
                if((new File(file.getPath(), as[l])).isDirectory())
                    searchSubPackages(s + "." + as[l], listbuffer, list);
            }

        }

    }

    public RootDocImpl getRootDocImpl(String s, String s1, ModifierFilter modifierfilter, List list, List list1, boolean flag, List list2, 
            List list3, boolean flag1)
    {
        ListBuffer listbuffer;
        ListBuffer listbuffer1;
        ListBuffer listbuffer2;
        docenv = DocEnv.instance(context);
        docenv.showAccess = modifierfilter;
        docenv.breakiterator = flag;
        docenv.setLocale(s);
        docenv.setEncoding(s1);
        docenv.docClasses = flag1;
        reader.sourceCompleter = flag1 ? null : ((com.sun.tools.javac.v8.code.ClassReader.SourceCompleter) (this));
        listbuffer = new ListBuffer();
        listbuffer1 = new ListBuffer();
        listbuffer2 = new ListBuffer();
        for(List list4 = list; list4.nonEmpty(); list4 = list4.tail)
        {
            String s2 = (String)list4.head;
            if(!flag1 && s2.endsWith(".java") && (new File(s2)).exists())
            {
                messager.notice("main.Loading_source_file", s2);
                com.sun.tools.javac.v8.tree.Tree.TopLevel toplevel = parse(s2);
                listbuffer1.append(toplevel);
                continue;
            }
            if(isValidPackageName(s2))
            {
                listbuffer = listbuffer.append(s2);
                continue;
            }
            if(s2.endsWith(".java"))
                messager.error(null, "main.file_not_found", s2);
            else
                messager.error(null, "main.illegal_package_name", s2);
        }

        if(flag1)
            break MISSING_BLOCK_LABEL_349;
        searchSubPackages(list2, listbuffer, list3);
        for(List list5 = listbuffer.toList(); list5.nonEmpty(); list5 = list5.tail)
            parsePackageClasses((String)list5.head, listbuffer2, list3);

        if(messager.nerrors() != 0)
            return null;
        try
        {
            messager.notice("main.Building_tree");
            enter.main(listbuffer1.toList().appendList(listbuffer2.toList()));
        }
        catch(Abort abort) { }
        if(messager.nerrors() != 0)
            return null;
        if(flag1)
            return new RootDocImpl(docenv, list, list1);
        else
            return new RootDocImpl(docenv, listClasses(listbuffer1.toList()), listbuffer.toList(), list1);
    }

    DocEnv docenv;
    private final Context context;
    private final Messager messager;
    private final JavadocClassReader reader;
    private final JavadocEnter enter;
    private static final char pathSep;

    static 
    {
        pathSep = File.pathSeparatorChar;
    }
}
