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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 113
eff38cc97183
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 2003-2005 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.javadoc;
    29 import com.sun.javadoc.*;
    31 import com.sun.tools.javac.code.Kinds;
    32 import com.sun.tools.javac.code.Symbol;
    33 import com.sun.tools.javac.code.Symbol.ClassSymbol;
    34 import com.sun.tools.javac.code.Symbol.MethodSymbol;
    35 import com.sun.tools.javac.code.Type;
    36 import com.sun.tools.javac.code.Type.TypeVar;
    37 import com.sun.tools.javac.util.List;
    38 import com.sun.tools.javac.util.Name;
    40 /**
    41  * Implementation of <code>TypeVariable</code>, which
    42  * represents a type variable.
    43  *
    44  * @author Scott Seligman
    45  * @since 1.5
    46  */
    47 public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
    49     TypeVariableImpl(DocEnv env, TypeVar type) {
    50         super(env, type);
    51     }
    53     /**
    54      * Return the bounds of this type variable.
    55      */
    56     public com.sun.javadoc.Type[] bounds() {
    57         return TypeMaker.getTypes(env, getBounds((TypeVar)type, env));
    58     }
    60     /**
    61      * Return the class, interface, method, or constructor within
    62      * which this type variable is declared.
    63      */
    64     public ProgramElementDoc owner() {
    65         Symbol osym = type.tsym.owner;
    66         if ((osym.kind & Kinds.TYP) != 0) {
    67             return env.getClassDoc((ClassSymbol)osym);
    68         }
    69         Name.Table names = osym.name.table;
    70         if (osym.name == names.init) {
    71             return env.getConstructorDoc((MethodSymbol)osym);
    72         } else {
    73             return env.getMethodDoc((MethodSymbol)osym);
    74         }
    75     }
    77     /**
    78      * Return the ClassDoc of the erasure of this type variable.
    79      */
    80     public ClassDoc asClassDoc() {
    81         return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
    82     }
    84     public TypeVariable asTypeVariable() {
    85         return this;
    86     }
    88     public String toString() {
    89         return typeVarToString(env, (TypeVar)type, true);
    90     }
    93     /**
    94      * Return the string form of a type variable along with any
    95      * "extends" clause.  Class names are qualified if "full" is true.
    96      */
    97     static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
    98         StringBuffer s = new StringBuffer(v.toString());
    99         List<Type> bounds = getBounds(v, env);
   100         if (bounds.nonEmpty()) {
   101             boolean first = true;
   102             for (Type b : bounds) {
   103                 s.append(first ? " extends " : " & ");
   104                 s.append(TypeMaker.getTypeString(env, b, full));
   105                 first = false;
   106             }
   107         }
   108         return s.toString();
   109     }
   111     /**
   112      * Get the bounds of a type variable as listed in the "extends" clause.
   113      */
   114     private static List<Type> getBounds(TypeVar v, DocEnv env) {
   115         Name boundname = v.getUpperBound().tsym.getQualifiedName();
   116         if (boundname == boundname.table.java_lang_Object) {
   117             return List.nil();
   118         } else {
   119             return env.types.getBounds(v);
   120         }
   121     }
   122 }

mercurial