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

Mon, 25 Apr 2011 20:16:46 -0700

author
mfang
date
Mon, 25 Apr 2011 20:16:46 -0700
changeset 975
841e1c6a5914
parent 910
ebf7c13df6c0
child 1359
25e14ad23cef
permissions
-rw-r--r--

7039493: incorporating WPTG translation bug fixes
Reviewed-by: yhuang

     1 /*
     2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.javadoc;
    28 import com.sun.javadoc.*;
    30 import com.sun.tools.javac.code.Symbol.ClassSymbol;
    31 import com.sun.tools.javac.code.Type;
    32 import com.sun.tools.javac.code.Type.ClassType;
    34 import static com.sun.tools.javac.code.TypeTags.*;
    37 /**
    38  * Implementation of <code>ParameterizedType</code>, which
    39  * represents an invocation of a generic class or interface.
    40  *
    41  * @author Scott Seligman
    42  * @since 1.5
    43  */
    44 public class ParameterizedTypeImpl
    45         extends AbstractTypeImpl implements ParameterizedType {
    47     ParameterizedTypeImpl(DocEnv env, Type type) {
    48         super(env, type);
    49     }
    51     /**
    52      * Return the generic class or interface that declared this type.
    53      */
    54     @Override
    55     public ClassDoc asClassDoc() {
    56         return env.getClassDoc((ClassSymbol)type.tsym);
    57     }
    59     /**
    60      * Return the actual type arguments of this type.
    61      */
    62     public com.sun.javadoc.Type[] typeArguments() {
    63         return TypeMaker.getTypes(env, type.getTypeArguments());
    64     }
    66     /**
    67      * Return the class type that is a direct supertype of this one.
    68      * Return null if this is an interface type.
    69      */
    70     public com.sun.javadoc.Type superclassType() {
    71         if (asClassDoc().isInterface()) {
    72             return null;
    73         }
    74         Type sup = env.types.supertype(type);
    75         return TypeMaker.getType(env,
    76                                  (sup != type) ? sup : env.syms.objectType);
    77     }
    79     /**
    80      * Return the interface types directly implemented by or extended by this
    81      * parameterized type.
    82      * Return an empty array if there are no interfaces.
    83      */
    84     public com.sun.javadoc.Type[] interfaceTypes() {
    85         return TypeMaker.getTypes(env, env.types.interfaces(type));
    86     }
    88     /**
    89      * Return the type that contains this type as a member.
    90      * Return null is this is a top-level type.
    91      */
    92     public com.sun.javadoc.Type containingType() {
    93         if (type.getEnclosingType().tag == CLASS) {
    94             // This is the type of an inner class.
    95             return TypeMaker.getType(env, type.getEnclosingType());
    96         }
    97         ClassSymbol enclosing = type.tsym.owner.enclClass();
    98         if (enclosing != null) {
    99             // Nested but not inner.  Return the ClassDoc of the enclosing
   100             // class or interface.
   101             // See java.lang.reflect.ParameterizedType.getOwnerType().
   102             return env.getClassDoc(enclosing);
   103         }
   104         return null;
   105     }
   108     // Asking for the "name" of a parameterized type doesn't exactly make
   109     // sense.  It's a type expression.  Return the name of its generic
   110     // type.
   111     @Override
   112     public String typeName() {
   113         return TypeMaker.getTypeName(type, false);
   114     }
   116     @Override
   117     public ParameterizedType asParameterizedType() {
   118         return this;
   119     }
   121     @Override
   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         StringBuilder s = new StringBuilder();
   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