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

package com.sun.tools.javadoc;

import com.sun.javadoc.*;
import com.sun.tools.javac.v8.code.Scope;
import com.sun.tools.javac.v8.code.Symbol;
import com.sun.tools.javac.v8.util.ListBuffer;
import com.sun.tools.javac.v8.util.Name;

// Referenced classes of package com.sun.tools.javadoc:
//            ClassDocImpl, DocEnv, FieldDocImpl, SerialFieldTagImpl

class SerializedForm
{

    boolean definesSerializableFields()
    {
        return definesSerializableFields;
    }

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

    MethodDoc[] methods()
    {
        return (MethodDoc[])methods.toArray(new MethodDoc[methods.length()]);
    }

    private com.sun.tools.javac.v8.code.Symbol.VarSymbol getDefinedSerializableFields(com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol)
    {
        com.sun.tools.javac.v8.util.Name.Table table = classsymbol.name.table;
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = classsymbol.members().lookup(table.fromString("serialPersistentFields")); entry != null; entry = entry.shadowed)
        {
            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((varsymbol.flags() & 8L) != 0L && (varsymbol.flags() & 2L) != 0L)
                return varsymbol;
        }

        return null;
    }

    private void mapSerialFieldTagImplsToFieldDocImpls(FieldDocImpl fielddocimpl, DocEnv docenv, com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol)
    {
        com.sun.tools.javac.v8.util.Name.Table table = classsymbol.name.table;
        SerialFieldTag aserialfieldtag[] = fielddocimpl.serialFieldTags();
label0:
        for(int i = 0; i < aserialfieldtag.length; i++)
        {
            Name name = table.fromString(aserialfieldtag[i].fieldName());
            com.sun.tools.javac.v8.code.Scope.Entry entry = classsymbol.members().lookup(name);
            do
            {
                if(entry == null)
                    continue label0;
                if(entry.sym != null && entry.sym.kind == 4)
                {
                    com.sun.tools.javac.v8.code.Symbol.VarSymbol varsymbol = (com.sun.tools.javac.v8.code.Symbol.VarSymbol)entry.sym;
                    FieldDocImpl fielddocimpl1 = docenv.getFieldDoc(varsymbol);
                    ((SerialFieldTagImpl)aserialfieldtag[i]).mapToFieldDocImpl(fielddocimpl1);
                    continue label0;
                }
                entry = entry.shadowed;
            } while(true);
        }

    }

    SerializedForm(DocEnv docenv, com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol, ClassDocImpl classdocimpl)
    {
        methods = new ListBuffer();
        definesSerializableFields = false;
        if(classdocimpl.isExternalizable())
        {
            String as[] = {
                "java.io.ObjectInput"
            };
            String as1[] = {
                "java.io.ObjectOutput"
            };
            MethodDocImpl methoddocimpl = classdocimpl.findMethod("readExternal", as);
            if(methoddocimpl != null)
                methods.append(methoddocimpl);
            methoddocimpl = classdocimpl.findMethod("writeExternal", as1);
            if(methoddocimpl != null)
            {
                methods.append(methoddocimpl);
                com.sun.javadoc.Tag atag[] = methoddocimpl.tags("serialData");
            }
        } else
        if(classdocimpl.isSerializable())
        {
            com.sun.tools.javac.v8.code.Symbol.VarSymbol varsymbol = getDefinedSerializableFields(classsymbol);
            if(varsymbol != null)
            {
                definesSerializableFields = true;
                FieldDocImpl fielddocimpl = docenv.getFieldDoc(varsymbol);
                fields.append(fielddocimpl);
                mapSerialFieldTagImplsToFieldDocImpls(fielddocimpl, docenv, classsymbol);
            } else
            {
                computeDefaultSerializableFields(docenv, classsymbol, classdocimpl);
            }
            addMethodIfExist(docenv, classsymbol, "readObject");
            addMethodIfExist(docenv, classsymbol, "writeObject");
            addMethodIfExist(docenv, classsymbol, "readResolve");
            addMethodIfExist(docenv, classsymbol, "writeReplace");
        }
    }

    private void computeDefaultSerializableFields(DocEnv docenv, com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol, ClassDocImpl classdocimpl)
    {
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = classsymbol.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((varsymbol.flags() & 8L) == 0L && (varsymbol.flags() & 128L) == 0L)
            {
                FieldDocImpl fielddocimpl = docenv.getFieldDoc(varsymbol);
                fields.prepend(fielddocimpl);
            }
        }

    }

    private void addMethodIfExist(DocEnv docenv, com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol, String s)
    {
        com.sun.tools.javac.v8.util.Name.Table table = classsymbol.name.table;
        for(com.sun.tools.javac.v8.code.Scope.Entry entry = classsymbol.members().lookup(table.fromString(s)); entry != null; entry = entry.shadowed)
        {
            if(entry.sym == null || entry.sym.kind != 16 || !entry.sym.name.toString().equals(s))
                continue;
            com.sun.tools.javac.v8.code.Symbol.MethodSymbol methodsymbol = (com.sun.tools.javac.v8.code.Symbol.MethodSymbol)entry.sym;
            if((methodsymbol.flags() & 8L) == 0L)
                methods.append(docenv.getMethodDoc(methodsymbol));
        }

    }

    ListBuffer methods;
    private final ListBuffer fields = new ListBuffer();
    private boolean definesSerializableFields;
    private static final String SERIALIZABLE_FIELDS = "serialPersistentFields";
    private static final String READOBJECT = "readObject";
    private static final String WRITEOBJECT = "writeObject";
    private static final String READRESOLVE = "readResolve";
    private static final String WRITEREPLACE = "writeReplace";
}
