langtools/src/share/classes/com/sun/mirror/util/Types.java
author darcy
Sun, 26 Jul 2009 21:27:11 -0700
changeset 3378 22011d9a9398
parent 10 06bc494ca11e
child 5520 86e4b9a9da40
permissions -rw-r--r--
6381698: Warn of decommissioning of apt Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
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
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.mirror.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Collection;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.mirror.declaration.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.mirror.type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * Utility methods for operating on types.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *
3378
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    38
 * @deprecated All components of this API have been superseded by the
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    39
 * standardized annotation processing API.  The replacement for the
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    40
 * functionality of this interface is {@link
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    41
 * javax.lang.model.util.Types}.
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    42
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @since 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 */
3378
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    47
@Deprecated
22011d9a9398 6381698: Warn of decommissioning of apt
darcy
parents: 10
diff changeset
    48
@SuppressWarnings("deprecation")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
public interface Types {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     * Tests whether one type is a subtype of the another.
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * Any type is considered to be a subtype of itself.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * @param t1  the first type
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * @param t2  the second type
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     * @return <tt>true</tt> if and only if the first type is a subtype
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     *          of the second
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    boolean isSubtype(TypeMirror t1, TypeMirror t2);
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * Tests whether one type is assignable to another.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * @param t1  the first type
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * @param t2  the second type
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * @return <tt>true</tt> if and only if the first type is assignable
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     *          to the second
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    boolean isAssignable(TypeMirror t1, TypeMirror t2);
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * Returns the erasure of a type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * @param t  the type to be erased
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * @return the erasure of the given type
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    TypeMirror getErasure(TypeMirror t);
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * Returns a primitive type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * @param kind  the kind of primitive type to return
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * @return a primitive type
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    PrimitiveType getPrimitiveType(PrimitiveType.Kind kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     * Returns the pseudo-type representing the type of <tt>void</tt>.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * @return the pseudo-type representing the type of <tt>void</tt>
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    VoidType getVoidType();
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * Returns an array type with the specified component type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * @param componentType  the component type
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * @return an array type with the specified component type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     * @throws IllegalArgumentException if the component type is not valid for
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     *          an array
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    ArrayType getArrayType(TypeMirror componentType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * Returns the type variable declared by a type parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * @param tparam  the type parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @return the type variable declared by the type parameter
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    TypeVariable getTypeVariable(TypeParameterDeclaration tparam);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * Returns a new wildcard.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * Either the wildcards's upper bounds or lower bounds may be
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     * specified, or neither, but not both.
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * @param upperBounds  the upper bounds of this wildcard,
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     *          or an empty collection if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * @param lowerBounds  the lower bounds of this wildcard,
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     *          or an empty collection if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     * @return a new wildcard
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * @throws IllegalArgumentException if bounds are not valid
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    WildcardType getWildcardType(Collection<ReferenceType> upperBounds,
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                                 Collection<ReferenceType> lowerBounds);
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * Returns the type corresponding to a type declaration and
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * actual type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     * Given the declaration for <tt>String</tt>, for example, this
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     * method may be used to get the <tt>String</tt> type.  It may
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * then be invoked a second time, with the declaration for <tt>Set</tt>,
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     * to make the parameterized type {@code Set<String>}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * <p> The number of type arguments must either equal the
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * number of the declaration's formal type parameters, or must be
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     * zero.  If zero, and if the declaration is generic,
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     * then the declaration's raw type is returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * <p> If a parameterized type is being returned, its declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * must not be contained within a generic outer class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * The parameterized type {@code Outer<String>.Inner<Number>},
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * for example, may be constructed by first using this
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * method to get the type {@code Outer<String>}, and then invoking
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * {@link #getDeclaredType(DeclaredType, TypeDeclaration, TypeMirror...)}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * @param decl      the type declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     * @param typeArgs  the actual type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * @return the type corresponding to the type declaration and
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     *          actual type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     * @throws IllegalArgumentException if too many or too few
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     *          type arguments are given, or if an inappropriate type
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     *          argument or declaration is provided
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    DeclaredType getDeclaredType(TypeDeclaration decl,
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                                 TypeMirror... typeArgs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     * Returns the type corresponding to a type declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     * and actual arguments, given a
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     * {@linkplain DeclaredType#getContainingType() containing type}
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     * of which it is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     * The parameterized type {@code Outer<String>.Inner<Number>},
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     * for example, may be constructed by first using
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * {@link #getDeclaredType(TypeDeclaration, TypeMirror...)}
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * to get the type {@code Outer<String>}, and then invoking
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * this method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * <p> If the containing type is a parameterized type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * the number of type arguments must equal the
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * number of the declaration's formal type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * If it is not parameterized or if it is <tt>null</tt>, this method is
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * equivalent to <tt>getDeclaredType(decl, typeArgs)</tt>.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     * @param containing  the containing type, or <tt>null</tt> if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * @param decl        the type declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * @param typeArgs    the actual type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * @return the type corresponding to the type declaration and
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     *          actual type arguments,
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     *          contained within the given type
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * @throws IllegalArgumentException if too many or too few
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     *          type arguments are given, or if an inappropriate type
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     *          argument, declaration, or containing type is provided
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    DeclaredType getDeclaredType(DeclaredType containing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                                 TypeDeclaration decl,
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                                 TypeMirror... typeArgs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
}