src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ParameterizedTypeImpl.java
author ksrini
Fri, 09 Feb 2018 13:58:17 -0800
changeset 48840 5e2d2067da48
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194651: javadoc: mark the com.sun.javadoc API for removal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
37938
42baa89d2156 8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents: 25874
diff changeset
    26
package com.sun.tools.javadoc.main;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.code.Symbol.ClassSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.code.Type;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.code.Type.ClassType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
    34
import static com.sun.tools.javac.code.TypeTag.CLASS;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * Implementation of <code>ParameterizedType</code>, which
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * represents an invocation of a generic class or interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 8631
diff changeset
    41
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 8631
diff changeset
    42
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 8631
diff changeset
    43
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 8631
diff changeset
    44
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 8631
diff changeset
    45
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * @since 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 */
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    49
@Deprecated(since="9", forRemoval=true)
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    50
@SuppressWarnings("removal")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
public class ParameterizedTypeImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        extends AbstractTypeImpl implements ParameterizedType {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    ParameterizedTypeImpl(DocEnv env, Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        super(env, type);
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * Return the generic class or interface that declared this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
    61
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    public ClassDoc asClassDoc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        return env.getClassDoc((ClassSymbol)type.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * Return the actual type arguments of this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    public com.sun.javadoc.Type[] typeArguments() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        return TypeMaker.getTypes(env, type.getTypeArguments());
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * Return the class type that is a direct supertype of this one.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * Return null if this is an interface type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    public com.sun.javadoc.Type superclassType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        if (asClassDoc().isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        Type sup = env.types.supertype(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        return TypeMaker.getType(env,
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                                 (sup != type) ? sup : env.syms.objectType);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * Return the interface types directly implemented by or extended by this
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * parameterized type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     * Return an empty array if there are no interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    public com.sun.javadoc.Type[] interfaceTypes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return TypeMaker.getTypes(env, env.types.interfaces(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * Return the type that contains this type as a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * Return null is this is a top-level type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    public com.sun.javadoc.Type containingType() {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   100
        if (type.getEnclosingType().hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
            // This is the type of an inner class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            return TypeMaker.getType(env, type.getEnclosingType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        ClassSymbol enclosing = type.tsym.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        if (enclosing != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
            // Nested but not inner.  Return the ClassDoc of the enclosing
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
            // class or interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            // See java.lang.reflect.ParameterizedType.getOwnerType().
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
            return env.getClassDoc(enclosing);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    // Asking for the "name" of a parameterized type doesn't exactly make
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    // sense.  It's a type expression.  Return the name of its generic
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    // type.
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   118
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    public String typeName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        return TypeMaker.getTypeName(type, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   123
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    public ParameterizedType asParameterizedType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   128
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        return parameterizedTypeToString(env, (ClassType)type, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    static String parameterizedTypeToString(DocEnv env, ClassType cl,
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                                            boolean full) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        if (env.legacyDoclet) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            return TypeMaker.getTypeName(cl, full);
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        }
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   138
        StringBuilder s = new StringBuilder();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   139
        if (!(cl.getEnclosingType().hasTag(CLASS))) {               // if not an inner class...
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            s.append(TypeMaker.getTypeName(cl, full));
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            ClassType encl = (ClassType)cl.getEnclosingType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            s.append(parameterizedTypeToString(env, encl, full))
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
             .append('.')
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
             .append(cl.tsym.name.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        s.append(TypeMaker.typeArgumentsString(env, cl, full));
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        return s.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
}