1 /*
   2  * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.lang.model.type;
  27 
  28 import java.lang.annotation.Annotation;
  29 import java.util.List;
  30 import javax.lang.model.element.*;
  31 import javax.lang.model.util.Types;
  32 
  33 /**
  34  * Represents a type in the Java programming language.
  35  * Types include primitive types, declared types (class and interface types),
  36  * array types, type variables, and the null type.
  37  * Also represented are wildcard type arguments, the signature and
  38  * return types of executables, and pseudo-types corresponding to
  39  * packages, modules, and the keyword {@code void}.
  40  *
  41  * <p> Types should be compared using the utility methods in {@link
  42  * Types}.  There is no guarantee that any particular type will always
  43  * be represented by the same object.
  44  *
  45  * <p> To implement operations based on the class of an {@code
  46  * TypeMirror} object, either use a {@linkplain TypeVisitor visitor}
  47  * or use the result of the {@link #getKind} method.  Using {@code
  48  * instanceof} is <em>not</em> necessarily a reliable idiom for
  49  * determining the effective class of an object in this modeling
  50  * hierarchy since an implementation may choose to have a single
  51  * object implement multiple {@code TypeMirror} subinterfaces.
  52  *
  53  * @author Joseph D. Darcy
  54  * @author Scott Seligman
  55  * @author Peter von der Ah&eacute;
  56  * @see Element
  57  * @see Types
  58  * @since 1.6
  59  */
  60 public interface TypeMirror extends javax.lang.model.AnnotatedConstruct {
  61 
  62     /**
  63      * Returns the {@code kind} of this type.
  64      *
  65      * <ul>
  66      *
  67      * <li> The kind of a {@linkplain PrimitiveType primitive type} is
  68      * one of the kinds for which {@link TypeKind#isPrimitive} returns
  69      * {@code true}.
  70      *
  71      * <li> The kind of a {@linkplain NullType null type} is {@link
  72      * TypeKind#NULL NULL}.
  73      *
  74      * <li> The kind of an {@linkplain ArrayType array type} is {@link
  75      * TypeKind#ARRAY ARRAY}.
  76      *
  77      * <li> The kind of a {@linkplain DeclaredType declared type} is
  78      * {@link TypeKind#DECLARED DECLARED}.
  79      *
  80      * <li> The kind of an {@linkplain ErrorType error type} is {@link
  81      * TypeKind#ERROR ERROR}.
  82      *
  83      * <li> The kind of a {@linkplain TypeVariable type variable} is
  84      * {@link TypeKind#TYPEVAR TYPEVAR}.
  85      *
  86      * <li> The kind of a {@linkplain WildcardType wildcard type} is
  87      * {@link TypeKind#WILDCARD WILDCARD}.
  88      *
  89      * <li> The kind of an {@linkplain ExecutableType executable type}
  90      * is {@link TypeKind#EXECUTABLE EXECUTABLE}.
  91      *
  92      * <li> The kind of a {@linkplain NoType pseudo-type} is one
  93      * of {@link TypeKind#VOID VOID}, {@link TypeKind#PACKAGE
  94      * PACKAGE}, {@link TypeKind#MODULE MODULE}, or {@link
  95      * TypeKind#NONE NONE}.
  96      *
  97      * <li> The kind of a {@linkplain UnionType union type} is {@link
  98      * TypeKind#UNION UNION}.
  99      *
 100      * <li> The kind of an {@linkplain IntersectionType intersection
 101      * type} is {@link TypeKind#INTERSECTION INTERSECTION}.
 102      *
 103      * </ul>
 104      *
 105      * @return the kind of this type
 106      */
 107     TypeKind getKind();
 108 
 109     /**
 110      * Obeys the general contract of {@link Object#equals Object.equals}.
 111      * This method does not, however, indicate whether two types represent
 112      * the same type.
 113      * Semantic comparisons of type equality should instead use
 114      * {@link Types#isSameType(TypeMirror, TypeMirror)}.
 115      * The results of {@code t1.equals(t2)} and
 116      * {@code Types.isSameType(t1, t2)} may differ.
 117      *
 118      * @param obj  the object to be compared with this type
 119      * @return {@code true} if the specified object is equal to this one
 120      */
 121     boolean equals(Object obj);
 122 
 123     /**
 124      * Obeys the general contract of {@link Object#hashCode Object.hashCode}.
 125      *
 126      * @see #equals
 127      */
 128     int hashCode();
 129 
 130     /**
 131      * Returns an informative string representation of this type.  If
 132      * possible, the string should be of a form suitable for
 133      * representing this type in source code.  Any names embedded in
 134      * the result are qualified if possible.
 135      *
 136      * @return a string representation of this type
 137      */
 138     String toString();
 139 
 140     /**
 141      * Applies a visitor to this type.
 142      *
 143      * @param <R> the return type of the visitor's methods
 144      * @param <P> the type of the additional parameter to the visitor's methods
 145      * @param v   the visitor operating on this type
 146      * @param p   additional parameter to the visitor
 147      * @return a visitor-specified result
 148      */
 149     <R, P> R accept(TypeVisitor<R, P> v, P p);
 150 }