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

package com.sun.tools.javadoc;

import com.sun.javadoc.ClassDoc;
import com.sun.tools.javac.v8.code.Symbol;
import com.sun.tools.javac.v8.code.Type;
import com.sun.tools.javac.v8.code.TypeTags;
import com.sun.tools.javac.v8.util.List;
import com.sun.tools.javac.v8.util.Name;

// Referenced classes of package com.sun.tools.javadoc:
//            DocEnv, PrimitiveType

public class TypeMaker
    implements TypeTags
{
    private static class ArrayTypeImpl
        implements com.sun.javadoc.Type
    {

        public boolean isArrayType()
        {
            return true;
        }

        public boolean isPrimitiveJavaType()
        {
            return false;
        }

        public ClassDoc asClassDoc()
        {
            return TypeMaker.getType(env, skipArrays()).asClassDoc();
        }

        private Type skipArrays()
        {
            Type type;
            for(type = arrayType; type.tag == 11; type = type.elemtype());
            return type;
        }

        public String dimension()
        {
            StringBuffer stringbuffer = new StringBuffer();
            for(Type type = arrayType; type.tag == 11; type = type.elemtype())
                stringbuffer = stringbuffer.append("[]");

            return stringbuffer.toString();
        }

        public String qualifiedTypeName()
        {
            return TypeMaker.getType(env, skipArrays()).qualifiedTypeName();
        }

        public String toString()
        {
            return qualifiedTypeName() + dimension();
        }

        public String typeName()
        {
            return TypeMaker.getType(env, skipArrays()).typeName();
        }

        Type arrayType;
        DocEnv env;

        ArrayTypeImpl(DocEnv docenv, Type type)
        {
            env = docenv;
            arrayType = type;
        }
    }


    public TypeMaker()
    {
    }

    public static String getTypeName(Type type, boolean flag)
    {
        if(type.tag == 11)
        {
            StringBuffer stringbuffer = new StringBuffer();
            for(; type.tag == 11; type = type.elemtype())
                stringbuffer = stringbuffer.append("[]");

            return getTypeName(type, flag) + stringbuffer;
        }
        if(type.tag == 10)
        {
            com.sun.tools.javac.v8.code.Symbol.ClassSymbol classsymbol = (com.sun.tools.javac.v8.code.Symbol.ClassSymbol)((com.sun.tools.javac.v8.code.Type.ClassType)type).tsym;
            if(flag)
                return classsymbol.fullName().toString();
            String s = classsymbol.name.toString();
            for(classsymbol = classsymbol.owner.enclClass(); classsymbol != null; classsymbol = classsymbol.owner.enclClass())
                s = classsymbol.name.toString() + "." + s;

            if(type.typarams().nonEmpty())
                return s + "<" + type.typarams().toString() + ">";
            else
                return s;
        } else
        {
            return type.tsym.fullName().toString();
        }
    }

    public static com.sun.javadoc.Type getType(DocEnv docenv, Type type)
    {
        Type type1 = type;
        switch(type1.tag)
        {
        case 11: // '\013'
            return new ArrayTypeImpl(docenv, type);

        case 10: // '\n'
            return docenv.getClassDoc((com.sun.tools.javac.v8.code.Type.ClassType)type1);

        case 1: // '\001'
            return PrimitiveType.byteType;

        case 2: // '\002'
            return PrimitiveType.charType;

        case 3: // '\003'
            return PrimitiveType.shortType;

        case 4: // '\004'
            return PrimitiveType.intType;

        case 5: // '\005'
            return PrimitiveType.longType;

        case 6: // '\006'
            return PrimitiveType.floatType;

        case 7: // '\007'
            return PrimitiveType.doubleType;

        case 8: // '\b'
            return PrimitiveType.booleanType;

        case 9: // '\t'
            return PrimitiveType.voidType;
        }
        return new PrimitiveType(type.tsym.fullName().toString());
    }
}
