src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java

changeset 1
9a66ca7c79fa
child 113
eff38cc97183
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,122 @@
     1.4 +/*
     1.5 + * Copyright 2003-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Sun designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Sun in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 + * have any questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.javadoc;
    1.30 +
    1.31 +
    1.32 +import com.sun.javadoc.*;
    1.33 +
    1.34 +import com.sun.tools.javac.code.Kinds;
    1.35 +import com.sun.tools.javac.code.Symbol;
    1.36 +import com.sun.tools.javac.code.Symbol.ClassSymbol;
    1.37 +import com.sun.tools.javac.code.Symbol.MethodSymbol;
    1.38 +import com.sun.tools.javac.code.Type;
    1.39 +import com.sun.tools.javac.code.Type.TypeVar;
    1.40 +import com.sun.tools.javac.util.List;
    1.41 +import com.sun.tools.javac.util.Name;
    1.42 +
    1.43 +/**
    1.44 + * Implementation of <code>TypeVariable</code>, which
    1.45 + * represents a type variable.
    1.46 + *
    1.47 + * @author Scott Seligman
    1.48 + * @since 1.5
    1.49 + */
    1.50 +public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
    1.51 +
    1.52 +    TypeVariableImpl(DocEnv env, TypeVar type) {
    1.53 +        super(env, type);
    1.54 +    }
    1.55 +
    1.56 +    /**
    1.57 +     * Return the bounds of this type variable.
    1.58 +     */
    1.59 +    public com.sun.javadoc.Type[] bounds() {
    1.60 +        return TypeMaker.getTypes(env, getBounds((TypeVar)type, env));
    1.61 +    }
    1.62 +
    1.63 +    /**
    1.64 +     * Return the class, interface, method, or constructor within
    1.65 +     * which this type variable is declared.
    1.66 +     */
    1.67 +    public ProgramElementDoc owner() {
    1.68 +        Symbol osym = type.tsym.owner;
    1.69 +        if ((osym.kind & Kinds.TYP) != 0) {
    1.70 +            return env.getClassDoc((ClassSymbol)osym);
    1.71 +        }
    1.72 +        Name.Table names = osym.name.table;
    1.73 +        if (osym.name == names.init) {
    1.74 +            return env.getConstructorDoc((MethodSymbol)osym);
    1.75 +        } else {
    1.76 +            return env.getMethodDoc((MethodSymbol)osym);
    1.77 +        }
    1.78 +    }
    1.79 +
    1.80 +    /**
    1.81 +     * Return the ClassDoc of the erasure of this type variable.
    1.82 +     */
    1.83 +    public ClassDoc asClassDoc() {
    1.84 +        return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
    1.85 +    }
    1.86 +
    1.87 +    public TypeVariable asTypeVariable() {
    1.88 +        return this;
    1.89 +    }
    1.90 +
    1.91 +    public String toString() {
    1.92 +        return typeVarToString(env, (TypeVar)type, true);
    1.93 +    }
    1.94 +
    1.95 +
    1.96 +    /**
    1.97 +     * Return the string form of a type variable along with any
    1.98 +     * "extends" clause.  Class names are qualified if "full" is true.
    1.99 +     */
   1.100 +    static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
   1.101 +        StringBuffer s = new StringBuffer(v.toString());
   1.102 +        List<Type> bounds = getBounds(v, env);
   1.103 +        if (bounds.nonEmpty()) {
   1.104 +            boolean first = true;
   1.105 +            for (Type b : bounds) {
   1.106 +                s.append(first ? " extends " : " & ");
   1.107 +                s.append(TypeMaker.getTypeString(env, b, full));
   1.108 +                first = false;
   1.109 +            }
   1.110 +        }
   1.111 +        return s.toString();
   1.112 +    }
   1.113 +
   1.114 +    /**
   1.115 +     * Get the bounds of a type variable as listed in the "extends" clause.
   1.116 +     */
   1.117 +    private static List<Type> getBounds(TypeVar v, DocEnv env) {
   1.118 +        Name boundname = v.getUpperBound().tsym.getQualifiedName();
   1.119 +        if (boundname == boundname.table.java_lang_Object) {
   1.120 +            return List.nil();
   1.121 +        } else {
   1.122 +            return env.types.getBounds(v);
   1.123 +        }
   1.124 +    }
   1.125 +}

mercurial