langtools/src/java.compiler/share/classes/javax/lang/model/util/Types.java
author darcy
Wed, 22 Feb 2017 12:01:15 -0800
changeset 44014 56d15b6333fc
parent 25874 83c19f00452c
permissions -rw-r--r--
8175335: Improve handling of module types in javax.lang.model.util.Types Reviewed-by: jjg, abuckley
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
44014
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
     2
 * Copyright (c) 2005, 2017, 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
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package javax.lang.model.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 9303
diff changeset
    28
import java.lang.annotation.Annotation;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 9303
diff changeset
    29
import java.lang.annotation.AnnotationTypeMismatchException;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 9303
diff changeset
    30
import java.lang.annotation.IncompleteAnnotationException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import javax.lang.model.element.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import javax.lang.model.type.*;
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
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * <p><b>Compatibility Note:</b> Methods may be added to this interface
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * in future releases of the platform.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @see javax.annotation.processing.ProcessingEnvironment#getTypeUtils
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
public interface Types {
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * Returns the element corresponding to a type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     * The type may be a {@code DeclaredType} or {@code TypeVariable}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     * Returns {@code null} if the type is not one with a
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * corresponding element.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     *
17548
b0a4fd89079c 8013909: Fix doclint issues in javax.lang.model
darcy
parents: 16557
diff changeset
    55
     * @param t the type to map to an element
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * @return the element corresponding to the given type
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    Element asElement(TypeMirror t);
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * Tests whether two {@code TypeMirror} objects represent the same type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * <p>Caveat: if either of the arguments to this method represents a
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * wildcard, this method will return false.  As a consequence, a wildcard
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * is not the same type as itself.  This might be surprising at first,
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * but makes sense once you consider that an example like this must be
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * rejected by the compiler:
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     *   {@code List<?> list = new ArrayList<Object>();}
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     *   {@code list.add(list.get(0));}
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     *
22156
8eefa8ab3f41 8030080: Correct misstatement in JSR 269 MR (in javax.lang.model)
darcy
parents: 17548
diff changeset
    73
     * <p>Since annotations are only meta-data associated with a type,
8eefa8ab3f41 8030080: Correct misstatement in JSR 269 MR (in javax.lang.model)
darcy
parents: 17548
diff changeset
    74
     * the set of annotations on either argument is <em>not</em> taken
8eefa8ab3f41 8030080: Correct misstatement in JSR 269 MR (in javax.lang.model)
darcy
parents: 17548
diff changeset
    75
     * into account when computing whether or not two {@code
8eefa8ab3f41 8030080: Correct misstatement in JSR 269 MR (in javax.lang.model)
darcy
parents: 17548
diff changeset
    76
     * TypeMirror} objects are the same type. In particular, two
8eefa8ab3f41 8030080: Correct misstatement in JSR 269 MR (in javax.lang.model)
darcy
parents: 17548
diff changeset
    77
     * {@code TypeMirror} objects can have different annotations and
8eefa8ab3f41 8030080: Correct misstatement in JSR 269 MR (in javax.lang.model)
darcy
parents: 17548
diff changeset
    78
     * still be considered the same.
8eefa8ab3f41 8030080: Correct misstatement in JSR 269 MR (in javax.lang.model)
darcy
parents: 17548
diff changeset
    79
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     * @param t1  the first type
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * @param t2  the second type
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * @return {@code true} if and only if the two types are the same
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    boolean isSameType(TypeMirror t1, TypeMirror t2);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * Tests whether one type is a subtype of another.
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * Any type is considered to be a subtype of itself.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * @param t1  the first type
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * @param t2  the second type
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * @return {@code true} if and only if the first type is a subtype
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     *          of the second
44014
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
    94
     * @throws IllegalArgumentException if given a type for an executable, package, or module
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8235
diff changeset
    95
     * @jls 4.10 Subtyping
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    boolean isSubtype(TypeMirror t1, TypeMirror t2);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     * Tests whether one type is assignable to another.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * @param t1  the first type
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * @param t2  the second type
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * @return {@code true} if and only if the first type is assignable
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     *          to the second
44014
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   106
     * @throws IllegalArgumentException if given a type for an executable, package, or module
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8235
diff changeset
   107
     * @jls 5.2 Assignment Conversion
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    boolean isAssignable(TypeMirror t1, TypeMirror t2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * Tests whether one type argument <i>contains</i> another.
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * @param t1  the first type
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * @param t2  the second type
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     * @return {@code true} if and only if the first type contains the second
44014
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   117
     * @throws IllegalArgumentException if given a type for an executable, package, or module
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8235
diff changeset
   118
     * @jls 4.5.1.1 Type Argument Containment and Equivalence
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    boolean contains(TypeMirror t1, TypeMirror t2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * Tests whether the signature of one method is a <i>subsignature</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * of another.
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * @param m1  the first method
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * @param m2  the second method
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * @return {@code true} if and only if the first signature is a
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     *          subsignature of the second
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8235
diff changeset
   130
     * @jls 8.4.2 Method Signature
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    boolean isSubsignature(ExecutableType m1, ExecutableType m2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /**
23804
b5632efbc768 8034933: Update documentation for Types.directSupertypes to clarify behavior
pgovereau
parents: 22156
diff changeset
   135
     * Returns the direct supertypes of a type. The interface types, if any,
b5632efbc768 8034933: Update documentation for Types.directSupertypes to clarify behavior
pgovereau
parents: 22156
diff changeset
   136
     * will appear last in the list. For an interface type with no direct
b5632efbc768 8034933: Update documentation for Types.directSupertypes to clarify behavior
pgovereau
parents: 22156
diff changeset
   137
     * super-interfaces, a type mirror representing {@code java.lang.Object}
b5632efbc768 8034933: Update documentation for Types.directSupertypes to clarify behavior
pgovereau
parents: 22156
diff changeset
   138
     * is returned.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * @param t  the type being examined
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * @return the direct supertypes, or an empty list if none
44014
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   142
     * @throws IllegalArgumentException if given a type for an executable, package, or module
23804
b5632efbc768 8034933: Update documentation for Types.directSupertypes to clarify behavior
pgovereau
parents: 22156
diff changeset
   143
     * @jls 4.10 Subtyping
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    List<? extends TypeMirror> directSupertypes(TypeMirror t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * Returns the erasure of a type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * @param t  the type to be erased
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     * @return the erasure of the given type
44014
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   152
     * @throws IllegalArgumentException if given a type for a package or module
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8235
diff changeset
   153
     * @jls 4.6 Type Erasure
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    TypeMirror erasure(TypeMirror t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     * Returns the class of a boxed value of a given primitive type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     * That is, <i>boxing conversion</i> is applied.
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     * @param p  the primitive type to be converted
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     * @return the class of a boxed value of type {@code p}
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8235
diff changeset
   163
     * @jls 5.1.7 Boxing Conversion
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    TypeElement boxedClass(PrimitiveType p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * Returns the type (a primitive type) of unboxed values of a given type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * That is, <i>unboxing conversion</i> is applied.
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * @param t  the type to be unboxed
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * @return the type of an unboxed value of type {@code t}
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * @throws IllegalArgumentException if the given type has no
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     *          unboxing conversion
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8235
diff changeset
   175
     * @jls 5.1.8 Unboxing Conversion
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    PrimitiveType unboxedType(TypeMirror t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * Applies capture conversion to a type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * @param t  the type to be converted
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * @return the result of applying capture conversion
44014
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   184
     * @throws IllegalArgumentException if given a type for an executable, package, or module
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8235
diff changeset
   185
     * @jls 5.1.10 Capture Conversion
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    TypeMirror capture(TypeMirror t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * Returns a primitive type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * @param kind  the kind of primitive type to return
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     * @return a primitive type
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     * @throws IllegalArgumentException if {@code kind} is not a primitive kind
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    PrimitiveType getPrimitiveType(TypeKind kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * Returns the null type.  This is the type of {@code null}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     * @return the null type
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    NullType getNullType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     * Returns a pseudo-type used where no actual type is appropriate.
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     * The kind of type to return may be either
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     * {@link TypeKind#VOID VOID} or {@link TypeKind#NONE NONE}.
44014
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   209
     *
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   210
     * <p>To get the pseudo-type corresponding to a package or module,
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   211
     * call {@code asType()} on the element modeling the {@linkplain
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   212
     * PackageElement package} or {@linkplain ModuleElement
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   213
     * module}. Names can be converted to elements for packages or
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   214
     * modules using {@link Elements#getPackageElement(CharSequence)}
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   215
     * or {@link Elements#getModuleElement(CharSequence)},
56d15b6333fc 8175335: Improve handling of module types in javax.lang.model.util.Types
darcy
parents: 25874
diff changeset
   216
     * respectively.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * @param kind  the kind of type to return
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * @return a pseudo-type of kind {@code VOID} or {@code NONE}
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     * @throws IllegalArgumentException if {@code kind} is not valid
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    NoType getNoType(TypeKind kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     * Returns an array type with the specified component type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     * @param componentType  the component type
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * @return an array type with the specified component type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * @throws IllegalArgumentException if the component type is not valid for
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     *          an array
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    ArrayType getArrayType(TypeMirror componentType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     * Returns a new wildcard type argument.  Either of the wildcard's
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
     * bounds may be specified, or neither, but not both.
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     * @param extendsBound  the extends (upper) bound, or {@code null} if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     * @param superBound    the super (lower) bound, or {@code null} if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * @return a new wildcard
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * @throws IllegalArgumentException if bounds are not valid
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    WildcardType getWildcardType(TypeMirror extendsBound,
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                                 TypeMirror superBound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     * Returns the type corresponding to a type element and
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     * actual type arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     * Given the type element for {@code Set} and the type mirror
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * for {@code String},
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     * for example, this method may be used to get the
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * parameterized type {@code Set<String>}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     * <p> The number of type arguments must either equal the
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     * number of the type element's formal type parameters, or must be
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     * zero.  If zero, and if the type element is generic,
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     * then the type element's raw type is returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * <p> If a parameterized type is being returned, its type element
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * must not be contained within a generic outer class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     * The parameterized type {@code Outer<String>.Inner<Number>},
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     * for example, may be constructed by first using this
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     * method to get the type {@code Outer<String>}, and then invoking
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     * {@link #getDeclaredType(DeclaredType, TypeElement, TypeMirror...)}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * @param typeElem  the type element
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * @param typeArgs  the actual type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * @return the type corresponding to the type element and
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     *          actual type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     * @throws IllegalArgumentException if too many or too few
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     *          type arguments are given, or if an inappropriate type
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     *          argument or type element is provided
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     * Returns the type corresponding to a type element
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     * and actual type arguments, given a
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     * {@linkplain DeclaredType#getEnclosingType() containing type}
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * of which it is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     * The parameterized type {@code Outer<String>.Inner<Number>},
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     * for example, may be constructed by first using
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     * {@link #getDeclaredType(TypeElement, TypeMirror...)}
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     * to get the type {@code Outer<String>}, and then invoking
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
     * this method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
     * <p> If the containing type is a parameterized type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     * the number of type arguments must equal the
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     * number of {@code typeElem}'s formal type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     * If it is not parameterized or if it is {@code null}, this method is
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     * equivalent to {@code getDeclaredType(typeElem, typeArgs)}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
     * @param containing  the containing type, or {@code null} if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     * @param typeElem    the type element
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     * @param typeArgs    the actual type arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     * @return the type corresponding to the type element and
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     *          actual type arguments, contained within the given type
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     * @throws IllegalArgumentException if too many or too few
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     *          type arguments are given, or if an inappropriate type
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     *          argument, type element, or containing type is provided
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    DeclaredType getDeclaredType(DeclaredType containing,
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                                 TypeElement typeElem, TypeMirror... typeArgs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     * Returns the type of an element when that element is viewed as
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     * a member of, or otherwise directly contained by, a given type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
     * For example,
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     * when viewed as a member of the parameterized type {@code Set<String>},
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
     * the {@code Set.add} method is an {@code ExecutableType}
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
     * whose parameter is of type {@code String}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     * @param containing  the containing type
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     * @param element     the element
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     * @return the type of the element as viewed from the containing type
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     * @throws IllegalArgumentException if the element is not a valid one
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     *          for the given type
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    TypeMirror asMemberOf(DeclaredType containing, Element element);
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
}