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

package com.sun.tools.javadoc;

import com.sun.tools.javac.v8.code.*;
import com.sun.tools.javac.v8.comp.Attr;
import com.sun.tools.javac.v8.comp.Check;
import com.sun.tools.javac.v8.util.*;

// Referenced classes of package com.sun.tools.javadoc:
//            ClassDocImpl, ConstructorDocImpl, DocImpl, DocLocale, 
//            ExecutableMemberDocImpl, FieldDocImpl, JavadocClassReader, JavadocEnter, 
//            Messager, MethodDocImpl, ModifierFilter, PackageDocImpl

public class DocEnv
{

    public void exit()
    {
        messager.exit();
    }

    static int translateModifiers(long l)
    {
        int i = 0;
        if((l & 1024L) != 0L)
            i |= 0x400;
        if((l & 16L) != 0L)
            i |= 0x10;
        if((l & 512L) != 0L)
            i |= 0x200;
        if((l & 256L) != 0L)
            i |= 0x100;
        if((l & 2L) != 0L)
            i |= 2;
        if((l & 4L) != 0L)
            i |= 4;
        if((l & 1L) != 0L)
            i |= 1;
        if((l & 8L) != 0L)
            i |= 8;
        if((l & 32L) != 0L)
            i |= 0x20;
        if((l & 128L) != 0L)
            i |= 0x80;
        if((l & 64L) != 0L)
            i |= 0x40;
        return i;
    }

    protected boolean isVisible(com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol)
    {
        long l = classsymbol.flags_field;
        if(!showAccess.checkModifier(translateModifiers(l)))
        {
            return false;
        } else
        {
            com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol1 = classsymbol.owner.enclClass();
            return classsymbol1 == null || (l & 8L) != 0L || isVisible(classsymbol1);
        }
    }

    public boolean shouldDocument(com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol)
    {
        return (classsymbol.flags_field & 0x10000L) == 0L && (docClasses || getClassDoc(classsymbol).tree != null) && isVisible(classsymbol);
    }

    public boolean shouldDocument(com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol)
    {
        long l = methodsymbol.flags();
        if((l & 0x10000L) != 0L)
            return false;
        else
            return showAccess.checkModifier(translateModifiers(l));
    }

    public boolean shouldDocument(com.sun.tools.javac.v8.code.Symbol.VarSymbol varsymbol)
    {
        long l = varsymbol.flags();
        if((l & 0x10000L) != 0L)
            return false;
        else
            return showAccess.checkModifier(translateModifiers(l));
    }

    private DocEnv(Context context)
    {
        docClasses = false;
        packageMap = new Hashtable();
        classMap = new Hashtable();
        fieldMap = new Hashtable();
        methodMap = new Hashtable();
        context.put(docEnvKey, this);
        messager = Messager.instance0(context);
        syms = Symtab.instance(context);
        reader = JavadocClassReader.instance0(context);
        enter = JavadocEnter.instance0(context);
        attr = Attr.instance(context);
        names = com.sun.tools.javac.v8.util.Name.Table.instance(context);
        externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
        chk = Check.instance(context);
        doclocale = new DocLocale(this, "", breakiterator);
    }

    public String getEncoding()
    {
        return encoding;
    }

    public void notice(String s)
    {
        messager.notice(s);
    }

    public void setEncoding(String s)
    {
        encoding = s;
    }

    public void setLocale(String s)
    {
        doclocale = new DocLocale(this, s, breakiterator);
        messager.reset();
    }

    com.sun.tools.javac.v8.code.Symbol.ClassSymbol getClassSymbol(String s)
    {
        int i = s.length();
        char ac[] = s.toCharArray();
        int j = s.length();
        do
        {
            com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = (com.sun.tools.javac.v8.code.Symbol.ClassSymbol)syms.classes.get(names.fromChars(ac, 0, i));
            if(classsymbol != null)
                return classsymbol;
            j = s.substring(0, j).lastIndexOf('.');
            if(j >= 0)
                ac[j] = '$';
            else
                return null;
        } while(true);
    }

    ClassDocImpl getClassDoc(com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol)
    {
        ClassDocImpl classdocimpl = (ClassDocImpl)classMap.get(classsymbol);
        if(classdocimpl != null)
        {
            return classdocimpl;
        } else
        {
            ClassDocImpl classdocimpl1 = new ClassDocImpl(this, classsymbol);
            classMap.put(classsymbol, classdocimpl1);
            return classdocimpl1;
        }
    }

    ClassDocImpl getClassDoc(com.sun.tools.javac.v8.code.Type.ClassType classtype)
    {
        return getClassDoc((com.sun.tools.javac.v8.code.Symbol.ClassSymbol)classtype.tsym);
    }

    public ClassDocImpl loadClass(String s)
    {
        com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = reader.loadClass(names.fromString(s));
        return getClassDoc(classsymbol);
        com.sun.tools.javac.v8.code.Symbol.CompletionFailure completionfailure;
        completionfailure;
        chk.completionError(0, completionfailure);
        return null;
    }

    public ClassDocImpl lookupClass(String s)
    {
        com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = getClassSymbol(s);
        if(classsymbol != null)
            return getClassDoc(classsymbol);
        else
            return null;
    }

    public ConstructorDocImpl getConstructorDoc(com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol)
    {
        ExecutableMemberDocImpl executablememberdocimpl = getExecutableMemberDoc(methodsymbol);
        if(executablememberdocimpl != null)
        {
            return (ConstructorDocImpl)executablememberdocimpl;
        } else
        {
            ConstructorDocImpl constructordocimpl = new ConstructorDocImpl(this, methodsymbol);
            methodMap.put(methodsymbol, constructordocimpl);
            return constructordocimpl;
        }
    }

    public static DocEnv instance(Context context)
    {
        DocEnv docenv = (DocEnv)context.get(docEnvKey);
        if(docenv == null)
            docenv = new DocEnv(context);
        return docenv;
    }

    private ExecutableMemberDocImpl getExecutableMemberDoc(com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol)
    {
        ExecutableMemberDocImpl executablememberdocimpl = (ExecutableMemberDocImpl)methodMap.get(methodsymbol);
        return executablememberdocimpl;
    }

    FieldDocImpl getFieldDoc(com.sun.tools.javac.v8.code.Symbol.VarSymbol varsymbol)
    {
        FieldDocImpl fielddocimpl = (FieldDocImpl)fieldMap.get(varsymbol);
        if(fielddocimpl != null)
        {
            return fielddocimpl;
        } else
        {
            FieldDocImpl fielddocimpl1 = new FieldDocImpl(this, varsymbol);
            fieldMap.put(varsymbol, fielddocimpl1);
            return fielddocimpl1;
        }
    }

    public MethodDocImpl getMethodDoc(com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol)
    {
        ExecutableMemberDocImpl executablememberdocimpl = getExecutableMemberDoc(methodsymbol);
        if(executablememberdocimpl != null)
        {
            return (MethodDocImpl)executablememberdocimpl;
        } else
        {
            MethodDocImpl methoddocimpl = new MethodDocImpl(this, methodsymbol);
            methodMap.put(methodsymbol, methoddocimpl);
            return methoddocimpl;
        }
    }

    public PackageDocImpl getPackageDoc(com.sun.tools.javac.v8.code.Symbol.PackageSymbol packagesymbol)
    {
        PackageDocImpl packagedocimpl = (PackageDocImpl)packageMap.get(packagesymbol);
        if(packagedocimpl != null)
        {
            return packagedocimpl;
        } else
        {
            PackageDocImpl packagedocimpl1 = new PackageDocImpl(this, packagesymbol);
            packageMap.put(packagesymbol, packagedocimpl1);
            return packagedocimpl1;
        }
    }

    public PackageDocImpl lookupPackage(String s)
    {
        com.sun.tools.javac.v8.code.Symbol.PackageSymbol packagesymbol = (com.sun.tools.javac.v8.code.Symbol.PackageSymbol)syms.packages.get(names.fromString(s));
        com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = getClassSymbol(s);
        if(packagesymbol != null && classsymbol == null)
            return getPackageDoc(packagesymbol);
        else
            return null;
    }

    public void error(DocImpl docimpl, String s)
    {
        messager.error(docimpl != null ? docimpl.position() : null, s);
    }

    public void warning(DocImpl docimpl, String s)
    {
        messager.warning(docimpl != null ? docimpl.position() : null, s);
    }

    public void notice(String s, String s1)
    {
        messager.notice(s, s1);
    }

    void makeClassDoc(com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol, String s, com.sun.tools.javac.v8.tree.Tree.ClassDef classdef)
    {
        ClassDocImpl classdocimpl = (ClassDocImpl)classMap.get(classsymbol);
        if(classdocimpl != null)
        {
            if(s != null)
                classdocimpl.setRawCommentText(s);
        } else
        {
            classdocimpl = new ClassDocImpl(this, classsymbol, s, classdef);
            classMap.put(classsymbol, classdocimpl);
        }
        if(classdef != null)
            classdocimpl.tree = classdef;
    }

    void makeFieldDoc(com.sun.tools.javac.v8.code.Symbol.VarSymbol varsymbol, String s, com.sun.tools.javac.v8.tree.Tree.VarDef vardef)
    {
        FieldDocImpl fielddocimpl = (FieldDocImpl)fieldMap.get(varsymbol);
        if(fielddocimpl != null)
        {
            if(s != null)
                fielddocimpl.setRawCommentText(s);
        } else
        {
            fielddocimpl = new FieldDocImpl(this, varsymbol, s);
            fieldMap.put(varsymbol, fielddocimpl);
        }
        if(vardef != null)
            fielddocimpl.tree = vardef;
    }

    public void error(DocImpl docimpl, String s, String s1)
    {
        messager.error(docimpl != null ? docimpl.position() : null, s, s1);
    }

    public void warning(DocImpl docimpl, String s, String s1)
    {
        messager.warning(docimpl != null ? docimpl.position() : null, s, s1);
    }

    public void notice(String s, String s1, String s2)
    {
        messager.notice(s, s1, s2);
    }

    void makeConstructorDoc(com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol, String s, List list, com.sun.tools.javac.v8.tree.Tree.MethodDef methoddef)
    {
        ExecutableMemberDocImpl executablememberdocimpl = getExecutableMemberDoc(methodsymbol);
        if(executablememberdocimpl != null)
        {
            if(s != null)
                executablememberdocimpl.setRawCommentText(s);
            if(list != null)
                executablememberdocimpl.setArgNames(list);
            if(methoddef != null)
                executablememberdocimpl.tree = methoddef;
        } else
        {
            ConstructorDocImpl constructordocimpl = new ConstructorDocImpl(this, methodsymbol, s, list);
            methodMap.put(methodsymbol, constructordocimpl);
            if(methoddef != null)
                constructordocimpl.tree = methoddef;
        }
    }

    void makeMethodDoc(com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol, String s, List list, com.sun.tools.javac.v8.tree.Tree.MethodDef methoddef)
    {
        ExecutableMemberDocImpl executablememberdocimpl = getExecutableMemberDoc(methodsymbol);
        if(executablememberdocimpl != null)
        {
            if(s != null)
                executablememberdocimpl.setRawCommentText(s);
            if(list != null)
                executablememberdocimpl.setArgNames(list);
            if(methoddef != null)
                executablememberdocimpl.tree = methoddef;
        } else
        {
            MethodDocImpl methoddocimpl = new MethodDocImpl(this, methodsymbol, s, list);
            methodMap.put(methodsymbol, methoddocimpl);
            if(methoddef != null)
                methoddocimpl.tree = methoddef;
        }
    }

    public void error(DocImpl docimpl, String s, String s1, String s2)
    {
        messager.error(docimpl != null ? docimpl.position() : null, s, s1, s2);
    }

    public void warning(DocImpl docimpl, String s, String s1, String s2)
    {
        messager.warning(docimpl != null ? docimpl.position() : null, s, s1, s2);
    }

    public void notice(String s, String s1, String s2, String s3)
    {
        messager.notice(s, s1, s2, s3);
    }

    public void error(DocImpl docimpl, String s, String s1, String s2, String s3)
    {
        messager.error(docimpl != null ? docimpl.position() : null, s, s1, s2, s3);
    }

    public void warning(DocImpl docimpl, String s, String s1, String s2, String s3)
    {
        messager.warning(docimpl != null ? docimpl.position() : null, s, s1, s2, s3);
    }

    public void warning(DocImpl docimpl, String s, String s1, String s2, String s3, String s4)
    {
        messager.warning(docimpl != null ? docimpl.position() : null, s, s1, s2, s3, s4);
    }

    private static final com.sun.tools.javac.v8.util.Context.Key docEnvKey = new Key();
    Messager messager;
    DocLocale doclocale;
    Symtab syms;
    JavadocClassReader reader;
    Attr attr;
    JavadocEnter enter;
    com.sun.tools.javac.v8.util.Name.Table names;
    private String encoding;
    final Symbol externalizableSym;
    ModifierFilter showAccess;
    private ClassDocImpl runtimeException;
    boolean breakiterator;
    Check chk;
    boolean docClasses;
    private Hashtable packageMap;
    private Hashtable classMap;
    private Hashtable fieldMap;
    private Hashtable methodMap;

}
