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

Tue, 16 Sep 2008 18:35:18 -0700

author
jjg
date
Tue, 16 Sep 2008 18:35:18 -0700
changeset 113
eff38cc97183
parent 1
9a66ca7c79fa
child 554
9d9f26857129
permissions
-rw-r--r--

6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
Reviewed-by: darcy, mcimadamore

     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 static com.sun.javadoc.LanguageVersion.*;
    33 import com.sun.tools.javac.code.Symbol.ClassSymbol;
    34 import com.sun.tools.javac.code.Type;
    35 import com.sun.tools.javac.code.Type.ClassType;
    36 import com.sun.tools.javac.util.List;
    38 import static com.sun.tools.javac.code.TypeTags.*;
    41 /**
    42  * Implementation of <code>ParameterizedType</code>, which
    43  * represents an invocation of a generic class or interface.
    44  *
    45  * @author Scott Seligman
    46  * @since 1.5
    47  */
    48 public class ParameterizedTypeImpl
    49         extends AbstractTypeImpl implements ParameterizedType {
    51     ParameterizedTypeImpl(DocEnv env, Type type) {
    52         super(env, type);
    53     }
    55     /**
    56      * Return the generic class or interface that declared this type.
    57      */
    58     public ClassDoc asClassDoc() {
    59         return env.getClassDoc((ClassSymbol)type.tsym);
    60     }
    62     /**
    63      * Return the actual type arguments of this type.
    64      */
    65     public com.sun.javadoc.Type[] typeArguments() {
    66         return TypeMaker.getTypes(env, type.getTypeArguments());
    67     }
    69     /**
    70      * Return the class type that is a direct supertype of this one.
    71      * Return null if this is an interface type.
    72      */
    73     public com.sun.javadoc.Type superclassType() {
    74         if (asClassDoc().isInterface()) {
    75             return null;
    76         }
    77         Type sup = env.types.supertype(type);
    78         return TypeMaker.getType(env,
    79                                  (sup != type) ? sup : env.syms.objectType);
    80     }
    82     /**
    83      * Return the interface types directly implemented by or extended by this
    84      * parameterized type.
    85      * Return an empty array if there are no interfaces.
    86      */
    87     public com.sun.javadoc.Type[] interfaceTypes() {
    88         return TypeMaker.getTypes(env, env.types.interfaces(type));
    89     }
    91     /**
    92      * Return the type that contains this type as a member.
    93      * Return null is this is a top-level type.
    94      */
    95     public com.sun.javadoc.Type containingType() {
    96         if (type.getEnclosingType().tag == CLASS) {
    97             // This is the type of an inner class.
    98             return TypeMaker.getType(env, type.getEnclosingType());
    99         }
   100         ClassSymbol enclosing = type.tsym.owner.enclClass();
   101         if (enclosing != null) {
   102             // Nested but not inner.  Return the ClassDoc of the enclosing
   103             // class or interface.
   104             // See java.lang.reflect.ParameterizedType.getOwnerType().
   105             return env.getClassDoc(enclosing);
   106         }
   107         return null;
   108     }
   111     // Asking for the "name" of a parameterized type doesn't exactly make
   112     // sense.  It's a type expression.  Return the name of its generic
   113     // type.
   114     public String typeName() {
   115         return TypeMaker.getTypeName(type, false);
   116     }
   118     public ParameterizedType asParameterizedType() {
   119         return this;
   120     }
   122     public String toString() {
   123         return parameterizedTypeToString(env, (ClassType)type, true);
   124     }
   126     static String parameterizedTypeToString(DocEnv env, ClassType cl,
   127                                             boolean full) {
   128         if (env.legacyDoclet) {
   129             return TypeMaker.getTypeName(cl, full);
   130         }
   131         StringBuffer s = new StringBuffer();
   132         if (cl.getEnclosingType().tag != CLASS) {               // if not an inner class...
   133             s.append(TypeMaker.getTypeName(cl, full));
   134         } else {
   135             ClassType encl = (ClassType)cl.getEnclosingType();
   136             s.append(parameterizedTypeToString(env, encl, full))
   137              .append('.')
   138              .append(cl.tsym.name.toString());
   139         }
   140         s.append(TypeMaker.typeArgumentsString(env, cl, full));
   141         return s.toString();
   142     }
   143 }

mercurial