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

package com.sun.tools.javadoc;

import com.sun.javadoc.*;
import com.sun.tools.javac.v8.code.*;
import com.sun.tools.javac.v8.comp.Env;
import com.sun.tools.javac.v8.tree.Tree;
import com.sun.tools.javac.v8.tree.TreeInfo;
import com.sun.tools.javac.v8.util.*;
import java.io.File;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;

// Referenced classes of package com.sun.tools.javadoc:
//            ProgramElementDocImpl, ConstructorDocImpl, DocEnv, FieldDocImpl, 
//            JavadocClassReader, JavadocEnter, MethodDocImpl, PackageDocImpl, 
//            SerializedForm, SourcePositionImpl, TypeMaker

public class ClassDocImpl extends ProgramElementDocImpl
    implements ClassDoc
{

    public int modifierSpecifier()
    {
        int i = getModifiers();
        return isInterface() ? i & 0xfffffbff : i;
    }

    protected long getFlags()
    {
_L2:
        return tsym.flags();
        com.sun.tools.javac.v8.code.Symbol.CompletionFailure completionfailure;
        completionfailure;
        if(true) goto _L2; else goto _L1
_L1:
    }

    public boolean definesSerializableFields()
    {
        if(!isSerializable() || isExternalizable())
            return false;
        if(serializedForm == null)
            serializedForm = new SerializedForm(env, tsym, this);
        return serializedForm.definesSerializableFields();
    }

    public boolean isAbstract()
    {
        return Modifier.isAbstract(getModifiers());
    }

    public boolean isArrayType()
    {
        return false;
    }

    public boolean isClass()
    {
        return !Modifier.isInterface(getModifiers());
    }

    public boolean isError()
    {
        if(Modifier.isInterface(getModifiers()))
            return false;
        for(Object obj = type; ((Type) (obj)).tag == 10; obj = ((Type) (obj)).supertype())
            if(((Type) (obj)).tsym == env.syms.errorType.tsym)
                return true;

        return false;
    }

    public boolean isException()
    {
        if(Modifier.isInterface(getModifiers()))
            return false;
        for(Object obj = type; ((Type) (obj)).tag == 10; obj = ((Type) (obj)).supertype())
            if(((Type) (obj)).tsym == env.syms.exceptionType.tsym)
                return true;

        return false;
    }

    public boolean isExternalizable()
    {
        return type.isSubType(env.externalizableSym.type);
        com.sun.tools.javac.v8.code.Symbol.CompletionFailure completionfailure;
        completionfailure;
        return false;
    }

    public boolean isIncluded()
    {
        if(isIncluded)
            return true;
        if(tsym.type != type)
            return false;
        if(env.shouldDocument(tsym))
        {
            if(containingPackage().isIncluded())
                return isIncluded = true;
            ClassDoc classdoc = containingClass();
            if(classdoc != null && classdoc.isIncluded())
                return isIncluded = true;
        }
        return false;
    }

    public boolean isInterface()
    {
        return Modifier.isInterface(getModifiers());
    }

    public boolean isOrdinaryClass()
    {
        if(Modifier.isInterface(getModifiers()))
            return false;
        for(Object obj = type; ((Type) (obj)).tag == 10; obj = ((Type) (obj)).supertype())
            if(((Type) (obj)).tsym == env.syms.errorType.tsym || ((Type) (obj)).tsym == env.syms.exceptionType.tsym)
                return false;

        return true;
    }

    public boolean isPrimitiveJavaType()
    {
        return false;
    }

    boolean isRuntimeException()
    {
        return tsym.isSubClass(env.syms.runtimeExceptionType.tsym);
    }

    public boolean isSerializable()
    {
        return type.isSubType(env.syms.serializableType);
        com.sun.tools.javac.v8.code.Symbol.CompletionFailure completionfailure;
        completionfailure;
        return false;
    }

    public boolean isSynthetic()
    {
        return (getFlags() & 0x10000L) != 0L;
    }

    public boolean isThrowable()
    {
        if(Modifier.isInterface(getModifiers()))
            return false;
        for(Object obj = type; ((Type) (obj)).tag == 10; obj = ((Type) (obj)).supertype())
            if(((Type) (obj)).tsym == env.syms.throwableType.tsym)
                return true;

        return false;
    }

    public ClassDoc asClassDoc()
    {
        return this;
    }

    public ClassDoc superclass()
    {
        if(isInterface())
            return null;
        if(tsym == env.syms.objectType.tsym)
            return null;
        com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = (com.sun.tools.javac.v8.code.Symbol.ClassSymbol)type.supertype().tsym;
        if(classsymbol == null)
            classsymbol = (com.sun.tools.javac.v8.code.Symbol.ClassSymbol)env.syms.objectType.tsym;
        return env.getClassDoc(classsymbol);
    }

    public ClassDoc[] importedClasses()
    {
        if(tsym.sourcefile == null)
            return new ClassDoc[0];
        ListBuffer listbuffer = new ListBuffer();
        Env env = this.env.enter.getEnv(tsym);
        if(env == null)
            return new ClassDocImpl[0];
        Name name1 = tsym.name.table.asterisk;
        for(List list = env.toplevel.defs; list.nonEmpty(); list = list.tail)
        {
            Tree tree1 = (Tree)list.head;
            if(tree1.tag != 2)
                continue;
            Tree tree2 = ((com.sun.tools.javac.v8.tree.Tree.Import)tree1).qualid;
            if(TreeInfo.name(tree2) != name1)
                listbuffer.append(this.env.getClassDoc((com.sun.tools.javac.v8.code.Symbol.ClassSymbol)tree2.type.tsym));
        }

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

    public ClassDoc[] innerClasses()
    {
        return innerClasses(true);
    }

    public ClassDoc[] interfaces()
    {
        ListBuffer listbuffer = new ListBuffer();
        for(List list = type.interfaces(); list.nonEmpty(); list = list.tail)
            listbuffer.append(env.getClassDoc((com.sun.tools.javac.v8.code.Symbol.ClassSymbol)((com.sun.tools.javac.v8.code.Type.ClassType)list.head).tsym));

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

    public boolean subclassOf(ClassDoc classdoc)
    {
        return tsym.isSubClass(((ClassDocImpl)classdoc).tsym);
    }

    public ClassDoc[] innerClasses(boolean flag)
    {
        ListBuffer listbuffer = new ListBuffer();
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = tsym.members().elems; entry != null; entry = entry.sibling)
        {
            if(entry.sym == null || entry.sym.kind != 2)
                continue;
            com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = (com.sun.tools.javac.v8.code.Symbol.ClassSymbol)entry.sym;
            if((classsymbol.flags_field & 0x10000L) == 0L && (!flag || env.isVisible(classsymbol)))
                listbuffer.prepend(env.getClassDoc(classsymbol));
        }

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

    public ConstructorDoc[] constructors()
    {
        return constructors(true);
    }

    public ConstructorDoc[] constructors(boolean flag)
    {
        com.sun.tools.javac.v8.util.Name.Table table = tsym.name.table;
        List list = new List();
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = tsym.members().elems; entry != null; entry = entry.sibling)
        {
            if(entry.sym == null || entry.sym.kind != 16 || entry.sym.name != table.init)
                continue;
            com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol = (com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym;
            if(!flag || env.shouldDocument(methodsymbol))
                list = list.prepend(env.getConstructorDoc(methodsymbol));
        }

        return (ConstructorDoc[])list.toArray(new ConstructorDocImpl[list.length()]);
    }

    public FieldDoc[] fields()
    {
        return fields(true);
    }

    public FieldDoc[] serializableFields()
    {
        if(serializedForm == null)
            serializedForm = new SerializedForm(env, tsym, this);
        return serializedForm.fields();
    }

    public FieldDoc[] fields(boolean flag)
    {
        List list = new List();
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = tsym.members().elems; entry != null; entry = entry.sibling)
        {
            if(entry.sym == null || entry.sym.kind != 4)
                continue;
            com.sun.tools.javac.v8.code.Symbol.VarSymbol varsymbol = (com.sun.tools.javac.v8.code.Symbol.VarSymbol)entry.sym;
            if(!flag || env.shouldDocument(varsymbol))
                list = list.prepend(env.getFieldDoc(varsymbol));
        }

        return (FieldDoc[])list.toArray(new FieldDocImpl[list.length()]);
    }

    public MethodDoc[] methods()
    {
        return methods(true);
    }

    public MethodDoc[] serializationMethods()
    {
        if(serializedForm == null)
            serializedForm = new SerializedForm(env, tsym, this);
        return serializedForm.methods();
    }

    public MethodDoc[] methods(boolean flag)
    {
        com.sun.tools.javac.v8.util.Name.Table table = tsym.name.table;
        List list = new List();
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = tsym.members().elems; entry != null; entry = entry.sibling)
        {
            if(entry.sym == null || entry.sym.kind != 16 || entry.sym.name == table.init)
                continue;
            com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol = (com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym;
            if(!flag || env.shouldDocument(methodsymbol))
                list = list.prepend(env.getMethodDoc(methodsymbol));
        }

        return (MethodDoc[])list.toArray(new MethodDocImpl[list.length()]);
    }

    public PackageDoc containingPackage()
    {
        PackageDocImpl packagedocimpl = env.getPackageDoc(tsym.packge());
        SourcePosition sourceposition = position();
        if(sourceposition != null && packagedocimpl.docPath == null && packagedocimpl.zipDocPath == null)
        {
            File file = sourceposition.file().getParentFile();
            if(file != null && (new File(file, "package.html")).exists())
                packagedocimpl.setDocPath(file.getPath());
        }
        return packagedocimpl;
    }

    public PackageDoc[] importedPackages()
    {
        if(tsym.sourcefile == null)
            return new PackageDoc[0];
        ListBuffer listbuffer = new ListBuffer();
        com.sun.tools.javac.v8.util.Name.Table table = tsym.name.table;
        listbuffer.append(this.env.getPackageDoc(this.env.reader.enterPackage(table.java_lang)));
        Env env = this.env.enter.getEnv(tsym);
        if(env == null)
            return new PackageDocImpl[0];
        for(List list = env.toplevel.defs; list.nonEmpty(); list = list.tail)
        {
            Tree tree1 = (Tree)list.head;
            if(tree1.tag != 2)
                continue;
            Tree tree2 = ((com.sun.tools.javac.v8.tree.Tree.Import)tree1).qualid;
            if(TreeInfo.name(tree2) != table.asterisk)
                continue;
            com.sun.tools.javac.v8.tree.Tree.Select select = (com.sun.tools.javac.v8.tree.Tree.Select)tree2;
            com.sun.tools.javac.v8.code.Symbol.TypeSymbol typesymbol = select.selected.type.tsym;
            PackageDocImpl packagedocimpl = this.env.getPackageDoc(typesymbol.packge());
            if(!listbuffer.contains(packagedocimpl))
                listbuffer.append(packagedocimpl);
        }

        return (PackageDoc[])listbuffer.toArray(new PackageDocImpl[listbuffer.length()]);
    }

    public SourcePosition position()
    {
        if(tsym.sourcefile == null)
            return null;
        else
            return SourcePositionImpl.make(tsym.sourcefile.toString(), tree != null ? tree.pos : 0);
    }

    protected com.sun.tools.javac.v8.code.Symbol.ClassSymbol getContainingClass()
    {
        return tsym.owner.enclClass();
    }

    void addAllClasses(ListBuffer listbuffer, boolean flag)
    {
        if(tsym.type != type)
            return;
        if(isSynthetic())
            return;
        if(flag && !env.shouldDocument(tsym))
            return;
        if(listbuffer.contains(this))
            return;
        try
        {
            listbuffer.append(this);
            List list = new List();
            for(com.sun.tools.javac.v8.code.Scope.Entry entry = tsym.members().elems; entry != null; entry = entry.sibling)
            {
                if(entry.sym == null || entry.sym.kind != 2)
                    continue;
                com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = (com.sun.tools.javac.v8.code.Symbol.ClassSymbol)entry.sym;
                ClassDocImpl classdocimpl = env.getClassDoc(classsymbol);
                if(!classdocimpl.isSynthetic() && classdocimpl != null)
                    list = list.prepend(classdocimpl);
            }

            for(; list.nonEmpty(); list = list.tail)
                ((ClassDocImpl)list.head).addAllClasses(listbuffer, flag);

        }
        catch(com.sun.tools.javac.v8.code.Symbol.CompletionFailure completionfailure) { }
        return;
    }

    public String dimension()
    {
        return "";
    }

    private String genericArgs()
    {
        return type.typarams().nonEmpty() ? "<" + type.typarams() + ">" : "";
    }

    public String modifiers()
    {
        return Modifier.toString(modifierSpecifier());
    }

    public String name()
    {
        String s = tsym.name.toString();
        for(com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = tsym.owner.enclClass(); classsymbol != null; classsymbol = classsymbol.owner.enclClass())
            s = classsymbol.name.toString() + "." + s;

        return s + genericArgs();
    }

    public String qualifiedName()
    {
        return tsym.fullName().toString() + genericArgs();
    }

    public String qualifiedTypeName()
    {
        return qualifiedName();
    }

    public String typeName()
    {
        return name();
    }

    public ClassDoc findClass(String s)
    {
        com.sun.tools.javac.v8.util.Name.Table table = tsym.name.table;
        Object obj = this.env.lookupClass(s);
        if(obj != null)
            return ((ClassDoc) (obj));
        ClassDoc aclassdoc[] = innerClasses();
        for(int i = 0; i < aclassdoc.length; i++)
        {
            if(aclassdoc[i].name().equals(s) || aclassdoc[i].name().endsWith(s))
                return aclassdoc[i];
            ClassDoc classdoc = aclassdoc[i].findClass(s);
            if(classdoc != null)
                return classdoc;
        }

        obj = containingPackage().findClass(s);
        if(obj != null)
            return ((ClassDoc) (obj));
        if(tsym.completer != null)
            tsym.complete();
        if(tsym.sourcefile != null)
        {
            Env env = this.env.enter.getEnv(tsym);
            if(env == null)
                return null;
            Scope scope = env.toplevel.namedImportScope;
            for(com.sun.tools.javac.v8.code.Scope.Entry entry = scope.lookup(table.fromString(s)); entry != null; entry = entry.shadowed)
            {
                if(entry.sym == null || entry.sym.kind != 2)
                    continue;
                ClassDocImpl classdocimpl = this.env.getClassDoc((com.sun.tools.javac.v8.code.Symbol.ClassSymbol)entry.sym);
                if(classdocimpl.name().equals(s))
                    return classdocimpl;
            }

            scope = env.toplevel.starImportScope;
            for(com.sun.tools.javac.v8.code.Scope.Entry entry1 = scope.lookup(table.fromString(s)); entry1 != null; entry1 = entry1.shadowed)
            {
                if(entry1.sym == null || entry1.sym.kind != 2)
                    continue;
                ClassDocImpl classdocimpl1 = this.env.getClassDoc((com.sun.tools.javac.v8.code.Symbol.ClassSymbol)entry1.sym);
                if(classdocimpl1.name().equals(s))
                    return classdocimpl1;
            }

        }
        return null;
    }

    public FieldDoc findField(String s)
    {
        return searchField(s, new HashSet());
    }

    public ClassDocImpl(DocEnv docenv, com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol)
    {
        ClassDocImpl(docenv, classsymbol, null, null);
    }

    public ClassDocImpl(DocEnv docenv, com.sun.tools.javac.v8.code.Type.ClassType classtype)
    {
        ProgramElementDocImpl(docenv, null);
        tree = null;
        isIncluded = false;
        type = classtype;
        tsym = (com.sun.tools.javac.v8.code.Symbol.ClassSymbol)classtype.tsym;
    }

    private boolean hasParameterTypes(com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol, String as[])
    {
        if(as == null)
            return true;
        int i = 0;
        List list = methodsymbol.type.argtypes();
        if(as.length != list.length())
            return false;
        for(; list.nonEmpty(); list = list.tail)
        {
            if(!hasTypeName((Type)list.head, as[i]))
                return false;
            i++;
        }

        return true;
    }

    private static boolean hasTypeName(Type type1, String s)
    {
        return s.equals(TypeMaker.getTypeName(type1, true)) || s.equals(TypeMaker.getTypeName(type1, false));
    }

    public ConstructorDoc findConstructor(String s, String as[])
    {
        com.sun.tools.javac.v8.util.Name.Table table = tsym.name.table;
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = tsym.members().lookup(table.fromString("<init>")); entry != null; entry = entry.shadowed)
            if(entry.sym != null && entry.sym.kind == 16 && entry.sym.name == table.init && hasParameterTypes((com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym, as) && env.shouldDocument((com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym))
                return env.getConstructorDoc((com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym);

        return null;
    }

    private FieldDocImpl searchField(String s, Set set)
    {
        com.sun.tools.javac.v8.util.Name.Table table = tsym.name.table;
        if(set.contains(this))
            return null;
        set.add(this);
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = tsym.members().lookup(table.fromString(s)); entry != null; entry = entry.shadowed)
            if(entry.sym != null && entry.sym.kind == 4 && entry.sym.name.toString().equals(s) && env.shouldDocument((com.sun.tools.javac.v8.code.Symbol.VarSymbol)entry.sym))
                return env.getFieldDoc((com.sun.tools.javac.v8.code.Symbol.VarSymbol)entry.sym);

        ClassDocImpl classdocimpl = (ClassDocImpl)containingClass();
        if(classdocimpl != null)
        {
            FieldDocImpl fielddocimpl = classdocimpl.searchField(s, set);
            if(fielddocimpl != null)
                return fielddocimpl;
        }
        classdocimpl = (ClassDocImpl)superclass();
        if(classdocimpl != null)
        {
            FieldDocImpl fielddocimpl1 = classdocimpl.searchField(s, set);
            if(fielddocimpl1 != null)
                return fielddocimpl1;
        }
        ClassDoc aclassdoc[] = interfaces();
        for(int i = 0; i < aclassdoc.length; i++)
        {
            ClassDocImpl classdocimpl1 = (ClassDocImpl)aclassdoc[i];
            FieldDocImpl fielddocimpl2 = classdocimpl1.searchField(s, set);
            if(fielddocimpl2 != null)
                return fielddocimpl2;
        }

        return null;
    }

    public MethodDocImpl findMethod(String s, String as[])
    {
        return searchMethod(s, as, new HashSet());
    }

    public ClassDocImpl(DocEnv docenv, com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol, String s, com.sun.tools.javac.v8.tree.Tree.ClassDef classdef)
    {
        ProgramElementDocImpl(docenv, s);
        tree = null;
        isIncluded = false;
        type = (com.sun.tools.javac.v8.code.Type.ClassType)classsymbol.type;
        tsym = classsymbol;
        tree = classdef;
    }

    private MethodDocImpl searchMethod(String s, String as[], Set set)
    {
        if(set.contains(this))
            return null;
        set.add(this);
        com.sun.tools.javac.v8.util.Name.Table table = tsym.name.table;
        com.sun.tools.javac.v8.code.Scope.Entry entry = tsym.members().lookup(table.fromString(s));
        if(as == null)
        {
            com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol = null;
            for(; entry != null; entry = entry.shadowed)
                if(entry.sym != null && entry.sym.kind == 16 && entry.sym.name != table.init && entry.sym.name.toString().equals(s) && env.shouldDocument((com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym))
                    methodsymbol = (com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym;

            if(methodsymbol != null)
                return env.getMethodDoc(methodsymbol);
        } else
        {
            for(; entry != null; entry = entry.shadowed)
                if(entry.sym != null && entry.sym.kind == 16 && entry.sym.name != table.init && entry.sym.name.toString().equals(s) && hasParameterTypes((com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym, as) && env.shouldDocument((com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym))
                    return env.getMethodDoc((com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym);

        }
        ClassDocImpl classdocimpl = (ClassDocImpl)superclass();
        if(classdocimpl != null)
        {
            MethodDocImpl methoddocimpl = classdocimpl.searchMethod(s, as, set);
            if(methoddocimpl != null)
                return methoddocimpl;
        }
        ClassDoc aclassdoc[] = interfaces();
        for(int i = 0; i < aclassdoc.length; i++)
        {
            classdocimpl = (ClassDocImpl)aclassdoc[i];
            MethodDocImpl methoddocimpl1 = classdocimpl.searchMethod(s, as, set);
            if(methoddocimpl1 != null)
                return methoddocimpl1;
        }

        classdocimpl = (ClassDocImpl)containingClass();
        if(classdocimpl != null)
        {
            MethodDocImpl methoddocimpl2 = classdocimpl.searchMethod(s, as, set);
            if(methoddocimpl2 != null)
                return methoddocimpl2;
        }
        return null;
    }

    protected final com.sun.tools.javac.v8.code.Type.ClassType type;
    protected final com.sun.tools.javac.v8.code.Symbol.ClassSymbol tsym;
    com.sun.tools.javac.v8.tree.Tree.ClassDef tree;
    boolean isIncluded;
    private SerializedForm serializedForm;
}
