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

package com.sun.tools.javadoc;

import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.FieldDoc;
import com.sun.javadoc.SerialFieldTag;
import com.sun.javadoc.SourcePosition;
import com.sun.tools.javac.v8.code.Symbol;
import com.sun.tools.javac.v8.code.Type;
import com.sun.tools.javac.v8.comp.Attr;
import com.sun.tools.javac.v8.tree.Tree;
import com.sun.tools.javac.v8.util.Name;
import java.lang.reflect.Modifier;

// Referenced classes of package com.sun.tools.javadoc:
//            MemberDocImpl, Comment, DocEnv, SourcePositionImpl, 
//            TypeMaker

public class FieldDocImpl extends MemberDocImpl
    implements FieldDoc
{

    protected long getFlags()
    {
        return sym.flags();
    }

    public boolean isField()
    {
        return true;
    }

    public boolean isIncluded()
    {
        return containingClass().isIncluded() && env.shouldDocument(sym);
    }

    public boolean isSynthetic()
    {
        return (sym.flags() & 0x10000L) != 0L;
    }

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

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

    private boolean isPrintableAscii(char c)
    {
        return c >= ' ' && c <= '~';
    }

    public SerialFieldTag[] serialFieldTags()
    {
        return comment().serialFieldTags();
    }

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

    public com.sun.javadoc.Type type()
    {
        return TypeMaker.getType(env, sym.type);
    }

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

    public Object constantValue()
    {
        if(sym.constValue != null)
            env.attr.evalInit(sym);
        Object obj = sym.constValue;
        if(obj != null && sym.type.tag == 8)
            obj = Boolean.valueOf(((Integer)obj).intValue() != 0);
        return obj;
    }

    public String constantValueExpression()
    {
        Object obj = constantValue();
        if(obj == null)
            return null;
        if(obj instanceof Character)
            return sourceForm(((Character)obj).charValue());
        if(obj instanceof Byte)
            return sourceForm(((Byte)obj).byteValue());
        if(obj instanceof String)
            return sourceForm((String)obj);
        if(obj instanceof Double)
            return sourceForm(((Double)obj).doubleValue(), 'd');
        if(obj instanceof Float)
            return sourceForm(((Float)obj).doubleValue(), 'f');
        if(obj instanceof Long)
            return obj + "l";
        else
            return obj.toString();
    }

    public String name()
    {
        return sym.name.toString();
    }

    public String qualifiedName()
    {
        return sym.enclClass().fullName().toString() + '.' + name();
    }

    private String sourceForm(byte byte0)
    {
        return "0x" + Integer.toString(byte0 & 0xff, 16);
    }

    private String sourceForm(char c)
    {
        StringBuffer stringbuffer = new StringBuffer(8);
        stringbuffer.append('\'');
        sourceChar(c, stringbuffer);
        stringbuffer.append('\'');
        return stringbuffer.toString();
    }

    private String sourceForm(double d, char c)
    {
        if(Double.isNaN(d))
            return "0" + c + "/0" + c;
        if(d == (1.0D / 0.0D))
            return "1" + c + "/0" + c;
        if(d == (-1.0D / 0.0D))
            return "-1" + c + "/0" + c;
        else
            return "" + d + c;
    }

    private void sourceChar(char c, StringBuffer stringbuffer)
    {
        switch(c)
        {
        case 8: // '\b'
            stringbuffer.append("\\b");
            return;

        case 9: // '\t'
            stringbuffer.append("\\t");
            return;

        case 10: // '\n'
            stringbuffer.append("\\n");
            return;

        case 12: // '\f'
            stringbuffer.append("\\f");
            return;

        case 13: // '\r'
            stringbuffer.append("\\r");
            return;

        case 34: // '"'
            stringbuffer.append("\\\"");
            return;

        case 39: // '\''
            stringbuffer.append("\\'");
            return;

        case 92: // '\\'
            stringbuffer.append("\\\\");
            return;
        }
        if(isPrintableAscii(c))
        {
            stringbuffer.append(c);
            return;
        } else
        {
            unicodeEscape(c, stringbuffer);
            return;
        }
    }

    private void unicodeEscape(char c, StringBuffer stringbuffer)
    {
        stringbuffer.append("\\u");
        stringbuffer.append("0123456789abcdef".charAt(0xf & c >> 12));
        stringbuffer.append("0123456789abcdef".charAt(0xf & c >> 8));
        stringbuffer.append("0123456789abcdef".charAt(0xf & c >> 4));
        stringbuffer.append("0123456789abcdef".charAt(0xf & c >> 0));
    }

    public FieldDocImpl(DocEnv docenv, com.sun.tools.javac.v8.code.Symbol.VarSymbol varsymbol)
    {
        FieldDocImpl(docenv, varsymbol, null);
    }

    private String sourceForm(String s)
    {
        StringBuffer stringbuffer = new StringBuffer(s.length() + 5);
        stringbuffer.append('"');
        for(int i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);
            sourceChar(c, stringbuffer);
        }

        stringbuffer.append('"');
        return stringbuffer.toString();
    }

    public FieldDocImpl(DocEnv docenv, com.sun.tools.javac.v8.code.Symbol.VarSymbol varsymbol, String s)
    {
        MemberDocImpl(docenv, s);
        tree = null;
        sym = varsymbol;
    }

    protected final com.sun.tools.javac.v8.code.Symbol.VarSymbol sym;
    com.sun.tools.javac.v8.tree.Tree.VarDef tree;
}
