langtools/src/share/classes/com/sun/tools/javadoc/TypeMaker.java
author jjg
Thu, 25 Oct 2012 11:09:36 -0700
changeset 14359 d4099818ab70
parent 14260 727a84636f12
child 15385 ee1eebe7e210
permissions -rw-r--r--
7200915: convert TypeTags from a series of small ints to an enum Reviewed-by: jjg, mcimadamore Contributed-by: vicente.romero@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 8631
diff changeset
     2
 * Copyright (c) 1997, 2012, 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: 2212
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: 2212
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: 2212
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javadoc;
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
import com.sun.tools.javac.code.Symbol;
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;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 8631
diff changeset
    32
import com.sun.tools.javac.code.Type.ArrayType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.code.Type.ClassType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.code.Type.TypeVar;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.List;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
    36
import static com.sun.tools.javac.code.TypeTag.ARRAY;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    38
/**
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    39
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    40
 *  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: 14258
diff changeset
    41
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    42
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    43
 */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
public class TypeMaker {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    public static com.sun.javadoc.Type getType(DocEnv env, Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        return getType(env, t, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     * @param errToClassDoc  if true, ERROR type results in a ClassDoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     *          false preserves legacy behavior
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     */
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 10
diff changeset
    54
    @SuppressWarnings("fallthrough")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    public static com.sun.javadoc.Type getType(DocEnv env, Type t,
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
                                               boolean errToClassDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        if (env.legacyDoclet) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
            t = env.types.erasure(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
    60
        switch (t.getTag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        case CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
            if (ClassDocImpl.isGeneric((ClassSymbol)t.tsym)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
                return env.getParameterizedType((ClassType)t);
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
                return env.getClassDoc((ClassSymbol)t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        case WILDCARD:
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
            Type.WildcardType a = (Type.WildcardType)t;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
            return new WildcardTypeImpl(env, a);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        case TYPEVAR: return new TypeVariableImpl(env, (TypeVar)t);
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        case ARRAY: return new ArrayTypeImpl(env, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        case BYTE: return PrimitiveType.byteType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        case CHAR: return PrimitiveType.charType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        case SHORT: return PrimitiveType.shortType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        case INT: return PrimitiveType.intType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        case LONG: return PrimitiveType.longType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        case FLOAT: return PrimitiveType.floatType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        case DOUBLE: return PrimitiveType.doubleType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        case BOOLEAN: return PrimitiveType.booleanType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        case VOID: return PrimitiveType.voidType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        case ERROR:
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            if (errToClassDoc)
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                return env.getClassDoc((ClassSymbol)t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            // FALLTHRU
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            return new PrimitiveType(t.tsym.getQualifiedName().toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * Convert a list of javac types into an array of javadoc types.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    public static com.sun.javadoc.Type[] getTypes(DocEnv env, List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        return getTypes(env, ts, new com.sun.javadoc.Type[ts.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * Like the above version, but use and return the array given.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    public static com.sun.javadoc.Type[] getTypes(DocEnv env, List<Type> ts,
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                                                  com.sun.javadoc.Type res[]) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        int i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        for (Type t : ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
            res[i++] = getType(env, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        return res;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    public static String getTypeName(Type t, boolean full) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   110
        switch (t.getTag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        case ARRAY:
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   112
            StringBuilder s = new StringBuilder();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   113
            while (t.hasTag(ARRAY)) {
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   114
                s.append("[]");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
                t = ((ArrayType)t).elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            }
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   117
            s.insert(0, getTypeName(t, full));
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   118
            return s.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        case CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
            return t.tsym.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * Return the string representation of a type use.  Bounds of type
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * variables are not included; bounds of wildcard types are.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * Class names are qualified if "full" is true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    static String getTypeString(DocEnv env, Type t, boolean full) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   132
        switch (t.getTag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        case ARRAY:
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   134
            StringBuilder s = new StringBuilder();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   135
            while (t.hasTag(ARRAY)) {
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   136
                s.append("[]");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                t = env.types.elemtype(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            }
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   139
            s.insert(0, getTypeString(env, t, full));
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   140
            return s.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        case CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            return ParameterizedTypeImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                        parameterizedTypeToString(env, (ClassType)t, full);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        case WILDCARD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            Type.WildcardType a = (Type.WildcardType)t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            return WildcardTypeImpl.wildcardTypeToString(env, a, full);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
            return t.tsym.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     * Return the formal type parameters of a class or method as an
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * angle-bracketed string.  Each parameter is a type variable with
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * optional bounds.  Class names are qualified if "full" is true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     * Return "" if there are no type parameters or we're hiding generics.
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    static String typeParametersString(DocEnv env, Symbol sym, boolean full) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        if (env.legacyDoclet || sym.type.getTypeArguments().isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            return "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        }
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   162
        StringBuilder s = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        for (Type t : sym.type.getTypeArguments()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
            s.append(s.length() == 0 ? "<" : ", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            s.append(TypeVariableImpl.typeVarToString(env, (TypeVar)t, full));
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        s.append(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        return s.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * Return the actual type arguments of a parameterized type as an
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * angle-bracketed string.  Class name are qualified if "full" is true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * Return "" if there are no type arguments or we're hiding generics.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    static String typeArgumentsString(DocEnv env, ClassType cl, boolean full) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            return "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        }
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   180
        StringBuilder s = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        for (Type t : cl.getTypeArguments()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            s.append(s.length() == 0 ? "<" : ", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
            s.append(getTypeString(env, t, full));
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        s.append(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        return s.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    private static class ArrayTypeImpl implements com.sun.javadoc.Type {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        Type arrayType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        DocEnv env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        ArrayTypeImpl(DocEnv env, Type arrayType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            this.env = env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            this.arrayType = arrayType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        private com.sun.javadoc.Type skipArraysCache = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        private com.sun.javadoc.Type skipArrays() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            if (skipArraysCache == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
                Type t;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   206
                for (t = arrayType; t.hasTag(ARRAY); t = env.types.elemtype(t)) { }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                skipArraysCache = TypeMaker.getType(env, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            return skipArraysCache;
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
         * Return the type's dimension information, as a string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
         * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
         * For example, a two dimensional array of String returns '[][]'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        public String dimension() {
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   218
            StringBuilder dimension = new StringBuilder();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   219
            for (Type t = arrayType; t.hasTag(ARRAY); t = env.types.elemtype(t)) {
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   220
                dimension.append("[]");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            return dimension.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
         * Return unqualified name of type excluding any dimension information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
         * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
         * For example, a two dimensional array of String returns 'String'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        public String typeName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
            return skipArrays().typeName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
         * Return qualified name of type excluding any dimension information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
         *<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
         * For example, a two dimensional array of String
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
         * returns 'java.lang.String'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        public String qualifiedTypeName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            return skipArrays().qualifiedTypeName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
         * Return the simple name of this type excluding any dimension information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        public String simpleTypeName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
            return skipArrays().simpleTypeName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
         * Return this type as a class.  Array dimensions are ignored.
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
         * @return a ClassDocImpl if the type is a Class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
         * Return null if it is a primitive type..
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        public ClassDoc asClassDoc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
            return skipArrays().asClassDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
         * Return this type as a <code>ParameterizedType</code> if it
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
         * represents a parameterized type.  Array dimensions are ignored.
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        public ParameterizedType asParameterizedType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
            return skipArrays().asParameterizedType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
         * Return this type as a <code>TypeVariable</code> if it represents
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
         * a type variable.  Array dimensions are ignored.
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        public TypeVariable asTypeVariable() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            return skipArrays().asTypeVariable();
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
         * Return null, as there are no arrays of wildcard types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        public WildcardType asWildcardType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
         * Return this type as an <code>AnnotationTypeDoc</code> if it
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
         * represents an annotation type.  Array dimensions are ignored.
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        public AnnotationTypeDoc asAnnotationTypeDoc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            return skipArrays().asAnnotationTypeDoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
         * Return true if this is an array of a primitive type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        public boolean isPrimitive() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
            return skipArrays().isPrimitive();
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
         * Return a string representation of the type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
         * Return name of type including any dimension information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
         * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
         * For example, a two dimensional array of String returns
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
         * <code>String[][]</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
         * @return name of type including any dimension information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
         */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   309
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            return qualifiedTypeName() + dimension();
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
}