langtools/src/share/sample/language/model/CoreReflectionFactory.java
author uta
Thu, 08 Aug 2013 09:16:16 +0400
changeset 19372 e404c834f1cd
parent 17806 b694bd72f635
child 25690 b1dac768ab79
permissions -rw-r--r--
7147084: (process) appA hangs when read output stream of appB which starts appC that runs forever Reviewed-by: alanb, robm, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17581
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     1
/*
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     3
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     6
 * are met:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     7
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    10
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    14
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    18
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    30
 */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    31
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    32
import java.lang.annotation.Annotation;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    33
import javax.annotation.processing.SupportedSourceVersion;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    34
import javax.lang.model.element.*;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    35
import javax.lang.model.element.Modifier;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    36
import javax.lang.model.type.*;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    37
import javax.lang.model.util.*;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    38
import java.lang.reflect.*;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    39
import java.io.Writer;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    40
import java.util.*;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    41
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    42
import static javax.lang.model.SourceVersion.RELEASE_8;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    43
import static java.util.Objects.*;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    44
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    45
/**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    46
 * This class provides a proof-of-concept implementation of the {@code
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    47
 * javax.lang.model.*} API backed by core reflection. That is, rather
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    48
 * than having a source file or compile-time class file as the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    49
 * originator of the information about an element or type, as done
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    50
 * during standard annotation processing, runtime core reflection
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    51
 * objects serve that purpose instead.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    52
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    53
 * With this kind of implementation, the same logic can be used for
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    54
 * both compile-time and runtime processing of annotations.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    55
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    56
 * The nested types in this class define a specialization of {@code
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    57
 * javax.lang.model.*} to provide some additional functionality and
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    58
 * type information. The original {@code javax.lang.model.*} API was
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    59
 * designed to accommodate such a specialization by using wildcards in
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    60
 * the return types of methods.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    61
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    62
 * It would be technically possible for further specializations of the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    63
 * API implemented in this class to define alternative semantics of
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    64
 * annotation look-up. For example to allow one annotation to have the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    65
 * effect of macro-expanding into a set of other annotations.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    66
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    67
 * Some aspects of the implementation are left as "exercises for the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    68
 * reader" to complete if interested.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    69
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    70
 * When passed null pointers, the methods defined in this type will
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    71
 * generally throw null pointer exceptions.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    72
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    73
 * To get started, first compile this file with a command line like:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    74
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    75
 * <pre>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    76
 * $JDK/bin/javac -parameters -Xdoclint:all/public -Xlint:all -d $OUTPUT_DIR CoreReflectionFactory.java
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    77
 * </pre>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    78
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    79
 * and then run the main method of {@code CoreReflectionFactory},
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    80
 * which will print out a representation of {@code
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    81
 * CoreReflectionFactory}. To use the printing logic defined in {@code
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    82
 * javac}, put {@code tools.jar} on the classpath as in:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    83
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    84
 * <pre>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    85
 * $JDK/bin/java -cp $OUTPUT_DIR:$JDK_ROOT/lib/tools.jar CoreReflectionFactory
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    86
 * </pre>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    87
 *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    88
 * @author Joseph D. Darcy (darcy)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    89
 * @author Joel Borggren-Franck (jfranck)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    90
 */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    91
public class CoreReflectionFactory {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    92
    private CoreReflectionFactory() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    93
        throw new AssertionError("No instances of CoreReflectionFactory for you!");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    94
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    95
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    96
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    97
     * Returns a reflection type element mirroring a {@code Class} object.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    98
     * @return a reflection type element mirroring a {@code Class} object
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
    99
     * @param clazz the {@code Class} to mirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   100
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   101
    public static ReflectionTypeElement createMirror(Class<?> clazz) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   102
        return new CoreReflTypeElement(Objects.requireNonNull(clazz));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   103
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   104
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   105
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   106
     * Returns a reflection package element mirroring a {@code Package} object.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   107
     * @return a reflection package element mirroring a {@code Package} object
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   108
     * @param pkg the {@code Package} to mirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   109
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   110
    public static ReflectionPackageElement createMirror(Package pkg) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   111
        // Treat a null pkg to mean an unnamed package.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   112
        return new CoreReflPackageElement(pkg);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   113
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   114
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   115
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   116
     * Returns a reflection variable element mirroring a {@code Field} object.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   117
     * @return a reflection variable element mirroring a {@code Field} object
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   118
     * @param field the {@code Field} to mirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   119
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   120
    public static ReflectionVariableElement createMirror(Field field) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   121
        return new CoreReflFieldVariableElement(Objects.requireNonNull(field));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   122
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   123
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   124
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   125
     * Returns a reflection executable element mirroring a {@code Method} object.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   126
     * @return a reflection executable element mirroring a {@code Method} object
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   127
     * @param method the {@code Method} to mirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   128
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   129
    public static ReflectionExecutableElement createMirror(Method method)  {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   130
        return new CoreReflMethodExecutableElement(Objects.requireNonNull(method));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   131
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   132
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   133
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   134
     * Returns a reflection executable element mirroring a {@code Constructor} object.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   135
     * @return a reflection executable element mirroring a {@code Constructor} object
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   136
     * @param constructor the {@code Constructor} to mirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   137
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   138
    public static ReflectionExecutableElement createMirror(Constructor<?> constructor)  {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   139
        return new CoreReflConstructorExecutableElement(Objects.requireNonNull(constructor));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   140
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   141
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   142
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   143
     * Returns a type parameter element mirroring a {@code TypeVariable} object.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   144
     * @return a type parameter element mirroring a {@code TypeVariable} object
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   145
     * @param tv the {@code TypeVariable} to mirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   146
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   147
    public static TypeParameterElement createMirror(java.lang.reflect.TypeVariable<?> tv) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   148
        return new CoreReflTypeParameterElement(Objects.requireNonNull(tv));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   149
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   150
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   151
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   152
     * Returns a variable element mirroring a {@code Parameter} object.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   153
     * @return a variable element mirroring a {@code Parameter} object
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   154
     * @param p the {Parameter} to mirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   155
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   156
    public static VariableElement createMirror(java.lang.reflect.Parameter p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   157
        return new CoreReflParameterVariableElement(Objects.requireNonNull(p));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   158
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   159
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   160
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   161
     * Returns an annotation mirror mirroring an annotation object.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   162
     * @return an annotation mirror mirroring an annotation object
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   163
     * @param annotation the annotation to mirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   164
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   165
    public static AnnotationMirror createMirror(Annotation annotation)  {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   166
        return new CoreReflAnnotationMirror(Objects.requireNonNull(annotation));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   167
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   168
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   169
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   170
     * Returns a {@code Types} utility object for type objects backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   171
     * @return a {@code Types} utility object for type objects backed by core reflection
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   172
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   173
    public static Types getTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   174
        return CoreReflTypes.instance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   175
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   176
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   177
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   178
     * Returns an {@code Elements} utility object for type objects backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   179
     * @return an {@code Elements} utility object for type objects backed by core reflection
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   180
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   181
    public static Elements getElements() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   182
        return CoreReflElements.instance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   183
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   184
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   185
    // Helper
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   186
    private static TypeMirror createTypeMirror(Class<?> c) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   187
        return TypeFactory.instance(Objects.requireNonNull(c));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   188
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   189
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   190
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   191
     * Main method; prints out a representation of this class.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   192
     * @param args command-line arguments, currently ignored
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   193
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   194
    public static void main(String... args) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   195
        getElements().printElements(new java.io.PrintWriter(System.out),
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   196
                                    createMirror(CoreReflectionFactory.class));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   197
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   198
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   199
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   200
     * A specialization of {@code javax.lang.model.element.Element} that is
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   201
     * backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   202
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   203
    public static interface ReflectionElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   204
        extends Element, AnnotatedElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   205
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   206
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   207
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   208
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   209
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   210
        ReflectionElement getEnclosingElement();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   211
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   212
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   213
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   214
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   215
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   216
        List<ReflectionElement> getEnclosedElements();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   217
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   218
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   219
         * Applies a visitor to this element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   220
         *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   221
         * @param v the visitor operating on this element
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   222
         * @param p additional parameter to the visitor
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   223
         * @param <R> the return type of the visitor's methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   224
         * @param <P> the type of the additional parameter to the visitor's methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   225
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   226
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   227
        <R,P> R accept(ReflectionElementVisitor<R,P> v, P p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   228
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   229
        // Functionality specific to the specialization
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   230
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   231
         * Returns the underlying core reflection source object, if applicable.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   232
         * @return the underlying core reflection source object, if applicable
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   233
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   234
        AnnotatedElement getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   235
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   236
        // Functionality from javax.lang.model.util.Elements
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   237
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   238
         * Returns the package of an element. The package of a package
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   239
         * is itself.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   240
         * @return the package of an element
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   241
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   242
        ReflectionPackageElement getPackage();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   243
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   244
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   245
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   246
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   247
     * A logical specialization of {@code
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   248
     * javax.lang.model.element.ElementVisitor} being backed by core
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   249
     * reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   250
     *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   251
     * @param <R> the return type of this visitor's methods.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   252
     * @param <P> the type of the additional parameter to this visitor's
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   253
     *            methods.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   254
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   255
    public static interface ReflectionElementVisitor<R, P> {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   256
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   257
         * Visits an element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   258
         * @param e  the element to visit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   259
         * @param p  a visitor-specified parameter
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   260
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   261
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   262
        R visit(ReflectionElement e, P p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   263
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   264
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   265
         * A convenience method equivalent to {@code v.visit(e, null)}.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   266
         * @param e  the element to visit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   267
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   268
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   269
        R visit(ReflectionElement e);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   270
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   271
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   272
         * Visits a package element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   273
         * @param e  the element to visit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   274
         * @param p  a visitor-specified parameter
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   275
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   276
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   277
        R visitPackage(ReflectionPackageElement e, P p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   278
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   279
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   280
         * Visits a type element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   281
         * @param e  the element to visit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   282
         * @param p  a visitor-specified parameter
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   283
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   284
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   285
        R visitType(ReflectionTypeElement e, P p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   286
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   287
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   288
         * Visits a variable element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   289
         * @param e  the element to visit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   290
         * @param p  a visitor-specified parameter
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   291
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   292
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   293
        R visitVariable(ReflectionVariableElement e, P p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   294
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   295
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   296
         * Visits an executable element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   297
         * @param e  the element to visit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   298
         * @param p  a visitor-specified parameter
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   299
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   300
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   301
        R visitExecutable(ReflectionExecutableElement e, P p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   302
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   303
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   304
         * Visits a type parameter element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   305
         * @param e  the element to visit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   306
         * @param p  a visitor-specified parameter
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   307
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   308
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   309
        R visitTypeParameter(ReflectionTypeParameterElement e, P p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   310
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   311
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   312
         * Visits an unknown kind of element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   313
         * This can occur if the language evolves and new kinds
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   314
         * of elements are added to the {@code Element} hierarchy.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   315
         *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   316
         * @param e  the element to visit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   317
         * @param p  a visitor-specified parameter
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   318
         * @return a visitor-specified result
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   319
         * @throws UnknownElementException
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   320
         * a visitor implementation may optionally throw this exception
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   321
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   322
        R visitUnknown(ReflectionElement e, P p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   323
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   324
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   325
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   326
     * A specialization of {@code javax.lang.model.element.ExecutableElement} that is
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   327
     * backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   328
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   329
    public static interface ReflectionExecutableElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   330
        extends ReflectionElement, ExecutableElement, ReflectionParameterizable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   331
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   332
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   333
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   334
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   335
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   336
        List<ReflectionTypeParameterElement> getTypeParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   337
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   338
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   339
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   340
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   341
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   342
        List<ReflectionVariableElement> getParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   343
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   344
        // Functionality specific to the specialization
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   345
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   346
         * Returns all parameters, including synthetic ones.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   347
         * @return all parameters, including synthetic ones
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   348
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   349
        List<ReflectionVariableElement> getAllParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   350
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   351
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   352
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   353
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   354
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   355
        Executable getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   356
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   357
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   358
         * Returns true if this executable is a synthetic construct; returns false otherwise.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   359
         * @return true if this executable is a synthetic construct; returns false otherwise
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   360
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   361
        boolean isSynthetic();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   362
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   363
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   364
         * Returns true if this executable is a bridge method; returns false otherwise.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   365
         * @return true if this executable is a bridge method; returns false otherwise
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   366
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   367
        boolean isBridge();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   368
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   369
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   370
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   371
     * A specialization of {@code javax.lang.model.element.PackageElement} being
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   372
     * backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   373
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   374
    public static interface ReflectionPackageElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   375
        extends ReflectionElement, PackageElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   376
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   377
        // Functionality specific to the specialization
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   378
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   379
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   380
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   381
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   382
        Package getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   383
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   384
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   385
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   386
     * A specialization of {@code javax.lang.model.element.TypeElement} that is
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   387
     * backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   388
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   389
    public static interface ReflectionTypeElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   390
        extends ReflectionElement, TypeElement, ReflectionParameterizable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   391
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   392
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   393
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   394
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   395
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   396
        List<ReflectionTypeParameterElement> getTypeParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   397
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   398
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   399
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   400
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   401
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   402
        List<ReflectionElement> getEnclosedElements();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   403
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   404
        // Methods specific to the specialization, but functionality
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   405
        // also present in javax.lang.model.util.Elements.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   406
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   407
         * Returns all members of a type element, whether inherited or
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   408
         * declared directly. For a class the result also includes its
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   409
         * constructors, but not local or anonymous classes.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   410
         * @return all members of the type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   411
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   412
        List<ReflectionElement> getAllMembers();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   413
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   414
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   415
         * Returns the binary name of a type element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   416
         * @return the binary name of a type element
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   417
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   418
        Name getBinaryName();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   419
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   420
        // Functionality specific to the specialization
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   421
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   422
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   423
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   424
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   425
        Class<?> getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   426
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   427
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   428
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   429
     * A specialization of {@code javax.lang.model.element.TypeParameterElement} being
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   430
     * backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   431
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   432
    public static interface ReflectionTypeParameterElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   433
        extends ReflectionElement, TypeParameterElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   434
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   435
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   436
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   437
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   438
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   439
        ReflectionElement getGenericElement();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   440
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   441
        // Functionality specific to the specialization
17806
b694bd72f635 8014836: Have GenericDeclaration extend AnnotatedElement
darcy
parents: 17581
diff changeset
   442
        /**
b694bd72f635 8014836: Have GenericDeclaration extend AnnotatedElement
darcy
parents: 17581
diff changeset
   443
         * {@inheritDoc}
b694bd72f635 8014836: Have GenericDeclaration extend AnnotatedElement
darcy
parents: 17581
diff changeset
   444
         */
b694bd72f635 8014836: Have GenericDeclaration extend AnnotatedElement
darcy
parents: 17581
diff changeset
   445
        @Override
b694bd72f635 8014836: Have GenericDeclaration extend AnnotatedElement
darcy
parents: 17581
diff changeset
   446
        java.lang.reflect.TypeVariable<?> getSource();
17581
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   447
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   448
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   449
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   450
     * A specialization of {@code javax.lang.model.element.VariableElement} that is
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   451
     * backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   452
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   453
    public static interface ReflectionVariableElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   454
        extends ReflectionElement, VariableElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   455
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   456
        // Functionality specific to the specialization
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   457
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   458
         * Returns true if this variable is a synthetic construct; returns false otherwise.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   459
         * @return true if this variable is a synthetic construct; returns false otherwise
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   460
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   461
        boolean isSynthetic();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   462
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   463
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   464
         * Returns true if this variable is implicitly declared in source code; returns false otherwise.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   465
         * @return true if this variable is implicitly declared in source code; returns false otherwise
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   466
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   467
        boolean isImplicit();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   468
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   469
        // The VariableElement concept covers fields, variables, and
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   470
        // method and constructor parameters. Therefore, this
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   471
        // interface cannot define a more precise override of
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   472
        // getSource since those three concept have different core
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   473
        // reflection types with no supertype more precise than
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   474
        // AnnotatedElement.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   475
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   476
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   477
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   478
     * A specialization of {@code javax.lang.model.element.Parameterizable} being
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   479
     * backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   480
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   481
    public static interface ReflectionParameterizable
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   482
        extends ReflectionElement, Parameterizable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   483
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   484
        List<ReflectionTypeParameterElement> getTypeParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   485
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   486
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   487
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   488
     * Base class for concrete visitors of elements backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   489
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   490
    public static abstract class AbstractReflectionElementVisitor8<R, P>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   491
        extends AbstractElementVisitor8<R, P>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   492
        implements ReflectionElementVisitor<R, P> {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   493
        protected AbstractReflectionElementVisitor8() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   494
            super();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   495
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   496
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   497
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   498
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   499
     * Base class for simple visitors of elements that are backed by core reflection.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   500
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   501
    @SupportedSourceVersion(value=RELEASE_8)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   502
    public static abstract class SimpleReflectionElementVisitor8<R, P>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   503
        extends SimpleElementVisitor8<R, P>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   504
        implements ReflectionElementVisitor<R, P> {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   505
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   506
        protected SimpleReflectionElementVisitor8(){
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   507
            super();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   508
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   509
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   510
        protected SimpleReflectionElementVisitor8(R defaultValue) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   511
            super(defaultValue);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   512
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   513
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   514
        // Create manual "bridge methods" for now.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   515
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   516
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   517
        public final R visitPackage(PackageElement e, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   518
            return visitPackage((ReflectionPackageElement) e , p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   519
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   520
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   521
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   522
        public final R visitType(TypeElement e, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   523
            return visitType((ReflectionTypeElement) e , p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   524
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   525
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   526
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   527
        public final R visitVariable(VariableElement e, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   528
            return visitVariable((ReflectionVariableElement) e , p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   529
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   530
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   531
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   532
        public final R visitExecutable(ExecutableElement e, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   533
            return visitExecutable((ReflectionExecutableElement) e , p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   534
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   535
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   536
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   537
        public final R visitTypeParameter(TypeParameterElement e, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   538
            return visitTypeParameter((ReflectionTypeParameterElement) e , p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   539
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   540
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   541
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   542
    /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   543
     * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   544
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   545
    public static interface ReflectionElements  extends Elements {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   546
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   547
         * Returns the innermost enclosing {@link ReflectionTypeElement}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   548
         * of the {@link ReflectionElement} or {@code null} if the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   549
         * supplied ReflectionElement is toplevel or represents a
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   550
         * Package.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   551
         *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   552
         * @param e the {@link ReflectionElement} whose innermost
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   553
         * enclosing {@link ReflectionTypeElement} is sought
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   554
         * @return the innermost enclosing {@link
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   555
         * ReflectionTypeElement} or @{code null} if the parameter
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   556
         * {@code e} is a toplevel element or a package
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   557
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   558
        ReflectionTypeElement getEnclosingTypeElement(ReflectionElement e);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   559
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   560
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   561
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   562
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   563
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   564
        List<? extends ReflectionElement> getAllMembers(TypeElement type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   565
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   566
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   567
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   568
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   569
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   570
        ReflectionPackageElement getPackageElement(CharSequence name);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   571
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   572
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   573
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   574
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   575
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   576
        ReflectionPackageElement getPackageOf(Element type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   577
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   578
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   579
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   580
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   581
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   582
        ReflectionTypeElement getTypeElement(CharSequence name);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   583
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   584
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   585
    // ------------------------- Implementation classes ------------------------
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   586
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   587
    // Exercise for the reader: review the CoreReflElement class
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   588
    // hierarchy below with an eye toward exposing it as an extensible
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   589
    // API that could be subclassed to provide customized behavior,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   590
    // such as alternate annotation lookup semantics.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   591
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   592
    private static abstract class CoreReflElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   593
        implements ReflectionElement, AnnotatedElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   594
        public abstract AnnotatedElement getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   595
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   596
        protected CoreReflElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   597
            super();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   598
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   599
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   600
        // ReflectionElement methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   601
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   602
        public ReflectionPackageElement getPackage() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   603
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   604
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   605
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   606
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   607
        public TypeMirror asType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   608
            throw new UnsupportedOperationException(getClass().toString());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   609
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   610
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   611
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   612
        public List<? extends AnnotationMirror> getAnnotationMirrors() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   613
            Annotation[] annotations = getSource().getDeclaredAnnotations();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   614
            int len = annotations.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   615
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   616
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   617
                List<AnnotationMirror> res = new ArrayList<>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   618
                for (Annotation a : annotations) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   619
                    res.add(createMirror(a));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   620
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   621
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   622
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   623
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   624
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   625
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   626
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   627
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   628
        public Set<Modifier> getModifiers() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   629
            return ModifierUtil.instance(0, false);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   630
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   631
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   632
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   633
        public abstract Name getSimpleName();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   634
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   635
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   636
        public abstract ReflectionElement getEnclosingElement();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   637
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   638
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   639
        public abstract List<ReflectionElement> getEnclosedElements();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   640
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   641
        //AnnotatedElement methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   642
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   643
        public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   644
            return getSource().getAnnotation(annotationClass);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   645
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   646
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   647
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   648
        public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   649
            return getSource().getAnnotationsByType(annotationClass);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   650
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   651
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   652
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   653
        public Annotation[] getAnnotations() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   654
            return getSource().getAnnotations();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   655
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   656
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   657
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   658
        public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   659
            return getSource().getDeclaredAnnotation(annotationClass);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   660
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   661
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   662
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   663
        public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   664
            return getSource().getDeclaredAnnotationsByType(annotationClass);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   665
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   666
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   667
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   668
        public Annotation[] getDeclaredAnnotations() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   669
            return getSource().getDeclaredAnnotations();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   670
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   671
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   672
        // java.lang.Object methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   673
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   674
        public boolean equals(Object obj) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   675
            if (obj instanceof CoreReflElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   676
                CoreReflElement other = (CoreReflElement)obj;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   677
                return Objects.equals(other.getSource(), this.getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   678
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   679
            return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   680
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   681
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   682
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   683
        public int hashCode() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   684
            return Objects.hashCode(getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   685
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   686
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   687
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   688
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   689
            return getKind().toString() + " " + getSimpleName().toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   690
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   691
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   692
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   693
    // Type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   694
    private static class CoreReflTypeElement extends CoreReflElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   695
        implements ReflectionTypeElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   696
        private final Class<?> source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   697
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   698
        protected CoreReflTypeElement(Class<?> source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   699
            Objects.requireNonNull(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   700
            if (source.isPrimitive() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   701
                source.isArray()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   702
                throw new IllegalArgumentException("Cannot create a ReflectionTypeElement based on class: " + source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   703
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   704
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   705
            this.source = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   706
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   707
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   708
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   709
        public TypeMirror asType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   710
            return createTypeMirror(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   711
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   712
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   713
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   714
        public Class<?> getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   715
            return source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   716
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   717
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   718
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   719
        public boolean equals(Object o) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   720
            if (o instanceof CoreReflTypeElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   721
                return source.equals(((CoreReflTypeElement)o).getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   722
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   723
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   724
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   725
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   726
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   727
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   728
        public <R,P> R accept(ElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   729
            return v.visitType(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   730
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   731
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   732
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   733
        public <R,P> R accept(ReflectionElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   734
            return v.visitType(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   735
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   736
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   737
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   738
        public Set<Modifier> getModifiers() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   739
            return ModifierUtil.instance(source.getModifiers() &
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   740
                                         (source.isInterface() ?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   741
                                          java.lang.reflect.Modifier.interfaceModifiers() :
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   742
                                          java.lang.reflect.Modifier.classModifiers()),
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   743
                                         false);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   744
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   745
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   746
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   747
        public List<ReflectionElement> getEnclosedElements() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   748
            List<ReflectionElement> enclosedElements = new ArrayList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   749
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   750
            for (Class<?> declaredClass : source.getDeclaredClasses()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   751
                enclosedElements.add(createMirror(declaredClass));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   752
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   753
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   754
            // Add elements in the conventional ordering: fields, then
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   755
            // constructors, then methods.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   756
            for (Field f : source.getDeclaredFields()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   757
                enclosedElements.add(createMirror(f));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   758
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   759
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   760
            for (Constructor<?> c : source.getDeclaredConstructors()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   761
                enclosedElements.add(createMirror(c));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   762
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   763
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   764
            for (Method m : source.getDeclaredMethods()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   765
                enclosedElements.add(createMirror(m));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   766
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   767
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   768
            return (enclosedElements.isEmpty() ?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   769
                    Collections.emptyList():
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   770
                    Collections.unmodifiableList(enclosedElements));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   771
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   772
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   773
        // Review for default method handling.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   774
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   775
        public List<ReflectionElement> getAllMembers() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   776
            List<ReflectionElement> allMembers = new ArrayList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   777
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   778
            // If I only had a MultiMap ...
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   779
            List<ReflectionElement> fields = new ArrayList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   780
            List<ReflectionExecutableElement> methods = new ArrayList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   781
            List<ReflectionElement> classes = new ArrayList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   782
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   783
            // Add all fields for this class
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   784
            for (Field f : source.getDeclaredFields()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   785
                fields.add(createMirror(f));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   786
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   787
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   788
            // Add all methods for this class
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   789
            for (Method m : source.getDeclaredMethods()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   790
                methods.add(createMirror(m));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   791
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   792
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   793
            // Add all classes for this class, except anonymous/local as per Elements.getAllMembers doc
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   794
            for (Class<?> c : source.getDeclaredClasses()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   795
                if (c.isLocalClass() || c.isAnonymousClass())
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   796
                    continue;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   797
                classes.add(createMirror(c));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   798
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   799
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   800
            Class<?> cls = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   801
            if (cls.isInterface()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   802
                cls = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   803
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   804
            do {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   805
                // Walk up superclasses adding non-private elements.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   806
                // If source is an interface, just add Object's
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   807
                // elements.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   808
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   809
                if (cls == null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   810
                    cls = java.lang.Object.class;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   811
                } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   812
                    cls = cls.getSuperclass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   813
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   814
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   815
                addMembers(cls, fields, methods, classes);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   816
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   817
            } while (cls != java.lang.Object.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   818
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   819
            // add members on (super)interface(s)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   820
            Set<Class<?>> seenInterfaces = new HashSet<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   821
            Queue<Class<?>> interfaces = new LinkedList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   822
            if (source.isInterface()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   823
                seenInterfaces.add(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   824
                interfaces.add(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   825
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   826
                Class<?>[] ifaces = source.getInterfaces();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   827
                for (Class<?> iface : ifaces) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   828
                    seenInterfaces.add(iface);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   829
                    interfaces.add(iface);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   830
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   831
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   832
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   833
            while (interfaces.peek() != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   834
                Class<?> head = interfaces.remove();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   835
                addMembers(head, fields, methods, classes);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   836
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   837
                Class<?>[] ifaces = head.getInterfaces();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   838
                for (Class<?> iface : ifaces) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   839
                    if (!seenInterfaces.contains(iface)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   840
                        seenInterfaces.add(iface);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   841
                        interfaces.add(iface);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   842
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   843
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   844
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   845
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   846
            // Add constructors
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   847
            for (Constructor<?> c : source.getDeclaredConstructors()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   848
                allMembers.add(createMirror(c));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   849
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   850
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   851
            // Add all unique methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   852
            allMembers.addAll(methods);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   853
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   854
            // Add all unique fields
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   855
            allMembers.addAll(fields);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   856
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   857
            // Add all unique classes
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   858
            allMembers.addAll(classes);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   859
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   860
            return Collections.unmodifiableList(allMembers);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   861
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   862
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   863
        private void addMembers(Class<?> cls,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   864
                                List<ReflectionElement> fields,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   865
                                List<ReflectionExecutableElement> methods,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   866
                                List<ReflectionElement> classes) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   867
            Elements elements = getElements();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   868
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   869
            for (Field f : cls.getDeclaredFields()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   870
                if (java.lang.reflect.Modifier.isPrivate(f.getModifiers())) { continue; }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   871
                ReflectionElement tmp = createMirror(f);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   872
                boolean add = true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   873
                for (ReflectionElement e : fields) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   874
                    if (elements.hides(e, tmp)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   875
                        add = false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   876
                        break;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   877
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   878
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   879
                if (add) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   880
                    fields.add(tmp);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   881
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   882
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   883
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   884
            for (Method m : cls.getDeclaredMethods()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   885
                if (java.lang.reflect.Modifier.isPrivate(m.getModifiers()))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   886
                    continue;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   887
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   888
                ReflectionExecutableElement tmp = createMirror(m);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   889
                boolean add = true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   890
                for (ReflectionExecutableElement e : methods) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   891
                    if (elements.hides(e, tmp)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   892
                        add = false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   893
                        break;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   894
                    } else if (elements.overrides(e, tmp, this)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   895
                        add = false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   896
                        break;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   897
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   898
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   899
                if (add) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   900
                    methods.add(tmp);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   901
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   902
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   903
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   904
            for (Class<?> c : cls.getDeclaredClasses()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   905
                if (java.lang.reflect.Modifier.isPrivate(c.getModifiers()) ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   906
                    c.isLocalClass() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   907
                    c.isAnonymousClass())
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   908
                    continue;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   909
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   910
                ReflectionElement tmp = createMirror(c);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   911
                boolean add = true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   912
                for (ReflectionElement e : classes) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   913
                    if (elements.hides(e, tmp)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   914
                        add = false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   915
                        break;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   916
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   917
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   918
                if (add) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   919
                    classes.add(tmp);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   920
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   921
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   922
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   923
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   924
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   925
        public ElementKind getKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   926
            if (source.isInterface()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   927
                if (source.isAnnotation())
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   928
                    return ElementKind.ANNOTATION_TYPE;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   929
                else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   930
                    return ElementKind.INTERFACE;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   931
            } else if (source.isEnum()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   932
                return ElementKind.ENUM;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   933
            } else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   934
                return ElementKind.CLASS;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   935
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   936
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   937
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   938
        public NestingKind getNestingKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   939
            if (source.isAnonymousClass())
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   940
                return NestingKind.ANONYMOUS;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   941
            else if (source.isLocalClass())
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   942
                return NestingKind.LOCAL;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   943
            else if (source.isMemberClass())
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   944
                return NestingKind.MEMBER;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   945
            else return
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   946
                NestingKind.TOP_LEVEL;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   947
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   948
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   949
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   950
        public Name getQualifiedName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   951
            String name = source.getCanonicalName(); // TODO, this should be a FQN for
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   952
                                                     // the current element
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   953
            if (name == null)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   954
                name = "";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   955
            return StringName.instance(name);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   956
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   957
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   958
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   959
        public Name getSimpleName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   960
            return StringName.instance(source.getSimpleName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   961
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   962
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   963
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   964
        public TypeMirror getSuperclass() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   965
            if (source.equals(java.lang.Object.class)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   966
                return NoType.getNoneInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   967
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   968
                return createTypeMirror(source.getSuperclass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   969
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   970
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   971
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   972
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   973
        public List<? extends TypeMirror> getInterfaces() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   974
            Class[] interfaces = source.getInterfaces();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   975
            int len = interfaces.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   976
            List<TypeMirror> res = new ArrayList<>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   977
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   978
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   979
                for (Class<?> c : interfaces) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   980
                    res.add(createTypeMirror(c));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   981
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   982
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   983
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   984
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   985
            return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   986
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   987
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   988
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   989
        public List<ReflectionTypeParameterElement> getTypeParameters() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   990
            return createTypeParameterList(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   991
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   992
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   993
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   994
        public ReflectionElement getEnclosingElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   995
            // Returns the package of a top-level type and returns the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   996
            // immediately lexically enclosing element for a nested type.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   997
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   998
            switch(getNestingKind()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
   999
            case TOP_LEVEL:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1000
                return createMirror(source.getPackage());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1001
            case MEMBER:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1002
                return createMirror(source.getEnclosingClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1003
            default:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1004
                if (source.getEnclosingConstructor() != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1005
                    return createMirror(source.getEnclosingConstructor());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1006
                } else if (source.getEnclosingMethod() != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1007
                    return createMirror(source.getEnclosingMethod());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1008
                } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1009
                    return createMirror(source.getEnclosingClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1010
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1011
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1012
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1013
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1014
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1015
        public Name getBinaryName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1016
            return StringName.instance(getSource().getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1017
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1018
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1019
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1020
    private static abstract class CoreReflExecutableElement extends CoreReflElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1021
        implements ReflectionExecutableElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1022
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1023
        protected Executable source = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1024
        protected final List<CoreReflParameterVariableElement> parameters;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1025
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1026
        protected CoreReflExecutableElement(Executable source,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1027
                                            List<CoreReflParameterVariableElement> parameters) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1028
            this.source = Objects.requireNonNull(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1029
            this.parameters = Objects.requireNonNull(parameters);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1030
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1031
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1032
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1033
        public <R,P> R accept(ElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1034
            return v.visitExecutable(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1035
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1036
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1037
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1038
        public <R,P> R accept(ReflectionElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1039
            return v.visitExecutable(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1040
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1041
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1042
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1043
        public abstract ExecutableType asType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1044
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1045
        // Only Types and Packages enclose elements; see Element.getEnclosedElements()
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1046
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1047
        public List<ReflectionElement> getEnclosedElements() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1048
            return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1049
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1050
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1051
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1052
        public List<ReflectionVariableElement> getParameters() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1053
            List<ReflectionVariableElement> tmp = new ArrayList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1054
            for (ReflectionVariableElement parameter : parameters) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1055
                if (!parameter.isSynthetic())
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1056
                    tmp.add(parameter);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1057
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1058
            return tmp;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1059
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1060
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1061
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1062
        public List<ReflectionVariableElement> getAllParameters() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1063
            // Could "fix" this if the return type included wildcards
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1064
            @SuppressWarnings("unchecked")
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1065
            List<ReflectionVariableElement> tmp = (List<ReflectionVariableElement>)(List)parameters;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1066
            return tmp;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1067
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1068
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1069
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1070
        public List<? extends TypeMirror> getThrownTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1071
            Class<?>[] thrown = source.getExceptionTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1072
            int len = thrown.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1073
            List<TypeMirror> res = new ArrayList<>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1074
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1075
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1076
                for (Class<?> c : thrown) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1077
                    res.add(createTypeMirror(c));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1078
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1079
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1080
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1081
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1082
            return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1083
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1084
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1085
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1086
        public boolean isVarArgs() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1087
            return source.isVarArgs();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1088
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1089
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1090
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1091
        public boolean isSynthetic() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1092
            return source.isSynthetic();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1093
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1094
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1095
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1096
        public boolean isBridge() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1097
            return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1098
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1099
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1100
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1101
        public List<ReflectionTypeParameterElement> getTypeParameters() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1102
            return createTypeParameterList(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1103
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1104
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1105
        public abstract AnnotationValue getDefaultValue();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1106
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1107
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1108
        public TypeMirror getReceiverType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1109
            // New in JDK 8
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1110
            throw new UnsupportedOperationException(this.toString());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1111
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1112
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1113
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1114
    private static class CoreReflConstructorExecutableElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1115
        extends CoreReflExecutableElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1116
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1117
        protected CoreReflConstructorExecutableElement(Constructor<?> source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1118
            super(Objects.requireNonNull(source),
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1119
                  createParameterList(source));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1120
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1121
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1122
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1123
        public  Constructor<?> getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1124
            return (Constructor<?>)source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1125
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1126
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1127
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1128
        public TypeMirror getReturnType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1129
            return NoType.getVoidInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1130
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1131
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1132
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1133
        public ExecutableType asType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1134
            throw new UnsupportedOperationException(getClass().toString());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1135
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1136
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1137
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1138
        public boolean equals(Object o) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1139
            if (o instanceof CoreReflConstructorExecutableElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1140
                return source.equals(((CoreReflConstructorExecutableElement)o).getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1141
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1142
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1143
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1144
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1145
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1146
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1147
        public ElementKind getKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1148
            return ElementKind.CONSTRUCTOR;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1149
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1150
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1151
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1152
        public Set<Modifier> getModifiers() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1153
            return ModifierUtil.instance(source.getModifiers() &
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1154
                                         java.lang.reflect.Modifier.constructorModifiers(), false);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1155
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1156
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1157
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1158
        public ReflectionElement getEnclosingElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1159
            return createMirror(source.getDeclaringClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1160
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1161
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1162
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1163
        public Name getSimpleName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1164
            return StringName.instance("<init>");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1165
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1166
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1167
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1168
        public AnnotationValue getDefaultValue() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1169
            // a constructor is never an annotation element
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1170
            return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1171
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1172
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1173
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1174
        public boolean isDefault() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1175
            return false; // A constructor cannot be a default method
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1176
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1177
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1178
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1179
    private static class CoreReflMethodExecutableElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1180
        extends CoreReflExecutableElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1181
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1182
        protected CoreReflMethodExecutableElement(Method source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1183
            super(Objects.requireNonNull(source),
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1184
                  createParameterList(source));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1185
            this.source = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1186
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1187
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1188
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1189
        public Method getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1190
            return (Method)source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1191
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1192
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1193
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1194
        public TypeMirror getReturnType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1195
            return TypeFactory.instance(getSource().getReturnType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1196
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1197
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1198
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1199
        public boolean equals(Object o) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1200
            if (o instanceof CoreReflMethodExecutableElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1201
                return source.equals( ((CoreReflMethodExecutableElement)o).getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1202
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1203
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1204
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1205
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1206
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1207
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1208
        public ElementKind getKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1209
            return ElementKind.METHOD;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1210
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1211
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1212
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1213
        public Set<Modifier> getModifiers() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1214
            return ModifierUtil.instance(source.getModifiers() &
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1215
                                         java.lang.reflect.Modifier.methodModifiers(),
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1216
                                         isDefault());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1217
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1218
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1219
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1220
        public ReflectionElement getEnclosingElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1221
            return createMirror(source.getDeclaringClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1222
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1223
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1224
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1225
        public Name getSimpleName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1226
            return StringName.instance(source.getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1227
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1228
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1229
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1230
        public AnnotationValue getDefaultValue() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1231
            Object value = getSource().getDefaultValue();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1232
            if (null == value) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1233
                return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1234
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1235
                return new CoreReflAnnotationValue(value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1236
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1237
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1238
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1239
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1240
        public boolean isDefault() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1241
            return getSource().isDefault();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1242
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1243
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1244
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1245
        public boolean isBridge() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1246
            return getSource().isBridge();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1247
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1248
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1249
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1250
        public ExecutableType asType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1251
            return TypeFactory.instance(getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1252
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1253
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1254
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1255
    private static List<CoreReflParameterVariableElement> createParameterList(Executable source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1256
        Parameter[] parameters = source.getParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1257
        int length = parameters.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1258
        if (length == 0)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1259
            return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1260
        else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1261
            List<CoreReflParameterVariableElement> tmp = new ArrayList<>(length);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1262
            for (Parameter parameter : parameters) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1263
                tmp.add(new CoreReflParameterVariableElement(parameter));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1264
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1265
            return Collections.unmodifiableList(tmp);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1266
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1267
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1268
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1269
    private static List<ReflectionTypeParameterElement> createTypeParameterList(GenericDeclaration source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1270
        java.lang.reflect.TypeVariable<?>[] typeParams = source.getTypeParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1271
        int length = typeParams.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1272
        if (length == 0)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1273
            return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1274
        else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1275
            List<ReflectionTypeParameterElement> tmp = new ArrayList<>(length);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1276
            for (java.lang.reflect.TypeVariable<?> typeVar : typeParams)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1277
                tmp.add(new CoreReflTypeParameterElement(typeVar));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1278
            return Collections.unmodifiableList(tmp);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1279
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1280
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1281
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1282
    private static class CoreReflTypeParameterElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1283
        extends CoreReflElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1284
        implements ReflectionTypeParameterElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1285
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1286
        private final GenericDeclaration source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1287
        private final java.lang.reflect.TypeVariable<?> sourceTypeVar;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1288
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1289
        protected CoreReflTypeParameterElement(java.lang.reflect.TypeVariable<?> sourceTypeVar) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1290
            this.sourceTypeVar = Objects.requireNonNull(sourceTypeVar);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1291
            this.source = Objects.requireNonNull(sourceTypeVar.getGenericDeclaration());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1292
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1293
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1294
        @Override
17806
b694bd72f635 8014836: Have GenericDeclaration extend AnnotatedElement
darcy
parents: 17581
diff changeset
  1295
        public java.lang.reflect.TypeVariable<?> getSource() {
b694bd72f635 8014836: Have GenericDeclaration extend AnnotatedElement
darcy
parents: 17581
diff changeset
  1296
            return sourceTypeVar;
17581
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1297
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1298
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1299
        protected java.lang.reflect.TypeVariable<?> getSourceTypeVar() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1300
            return sourceTypeVar;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1301
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1302
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1303
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1304
        public boolean equals(Object o) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1305
            if (o instanceof CoreReflTypeParameterElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1306
                return sourceTypeVar.equals(((CoreReflTypeParameterElement)o).sourceTypeVar);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1307
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1308
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1309
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1310
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1311
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1312
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1313
        public <R,P> R accept(ElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1314
            return v.visitTypeParameter(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1315
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1316
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1317
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1318
        public <R,P> R accept(ReflectionElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1319
            return v.visitTypeParameter(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1320
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1321
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1322
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1323
        public List<ReflectionElement> getEnclosedElements() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1324
            return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1325
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1326
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1327
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1328
        public ReflectionElement getEnclosingElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1329
            if (source instanceof Class)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1330
                return createMirror((Class<?>)source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1331
            else if (source instanceof Method)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1332
                return createMirror((Method)source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1333
            else if (source instanceof Constructor)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1334
                return createMirror((Constructor<?>)source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1335
            else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1336
                throw new AssertionError("Unexpected enclosing element: " + source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1337
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1338
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1339
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1340
        public ElementKind getKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1341
            return ElementKind.TYPE_PARAMETER;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1342
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1343
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1344
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1345
        public Name getSimpleName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1346
            return StringName.instance(sourceTypeVar.getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1347
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1348
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1349
        // TypeParameterElement methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1350
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1351
        public ReflectionElement getGenericElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1352
            return getEnclosingElement(); // As per the doc,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1353
                                          // getEnclosingElement and
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1354
                                          // getGenericElement return
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1355
                                          // the same information.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1356
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1357
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1358
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1359
        public List<? extends TypeMirror> getBounds() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1360
            Type[] types = getSourceTypeVar().getBounds();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1361
            int len = types.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1362
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1363
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1364
                List<TypeMirror> res = new ArrayList<>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1365
                for (Type t : types) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1366
                    res.add(TypeFactory.instance(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1367
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1368
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1369
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1370
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1371
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1372
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1373
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1374
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1375
    private abstract static class CoreReflVariableElement extends CoreReflElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1376
        implements ReflectionVariableElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1377
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1378
        protected CoreReflVariableElement() {}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1379
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1380
        // Element visitor
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1381
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1382
        public <R,P> R accept(ElementVisitor<R,P>v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1383
            return v.visitVariable(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1384
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1385
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1386
        // ReflectElement visitor
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1387
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1388
        public <R,P> R accept(ReflectionElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1389
            return v.visitVariable(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1390
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1391
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1392
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1393
        public List<ReflectionElement> getEnclosedElements() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1394
            return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1395
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1396
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1397
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1398
        public ReflectionElement getEnclosingElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1399
            return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1400
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1401
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1402
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1403
        public boolean isSynthetic() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1404
            return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1405
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1406
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1407
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1408
        public boolean isImplicit() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1409
            return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1410
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1411
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1412
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1413
    private static class CoreReflFieldVariableElement extends CoreReflVariableElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1414
        private final Field source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1415
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1416
        protected CoreReflFieldVariableElement(Field source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1417
            this.source = Objects.requireNonNull(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1418
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1419
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1420
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1421
        public Field getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1422
            return source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1423
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1424
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1425
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1426
        public TypeMirror asType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1427
            return createTypeMirror(getSource().getType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1428
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1429
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1430
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1431
        public ElementKind getKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1432
            if (source.isEnumConstant())
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1433
                return ElementKind.ENUM_CONSTANT;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1434
            else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1435
                return ElementKind.FIELD;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1436
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1437
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1438
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1439
        public Set<Modifier> getModifiers() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1440
            return ModifierUtil.instance(source.getModifiers() &
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1441
                                         java.lang.reflect.Modifier.fieldModifiers(), false);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1442
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1443
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1444
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1445
        public Name getSimpleName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1446
            return StringName.instance(source.getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1447
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1448
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1449
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1450
        public ReflectionElement getEnclosingElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1451
            return createMirror(source.getDeclaringClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1452
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1453
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1454
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1455
        public boolean equals(Object o) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1456
            if (o instanceof CoreReflFieldVariableElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1457
                return Objects.equals(source,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1458
                                      ((CoreReflFieldVariableElement)o).getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1459
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1460
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1461
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1462
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1463
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1464
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1465
        public Object getConstantValue() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1466
            Field target = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1467
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1468
            // The api says only Strings and primitives may be compile time constants.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1469
            // Ensure field is that, and final.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1470
            //
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1471
            // Also, we don't have an instance so restrict to static Fields
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1472
            //
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1473
            if (!(source.getType().equals(java.lang.String.class)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1474
                  || source.getType().isPrimitive())) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1475
                return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1476
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1477
            final int modifiers = target.getModifiers();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1478
            if (!( java.lang.reflect.Modifier.isFinal(modifiers) &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1479
                   java.lang.reflect.Modifier.isStatic(modifiers))) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1480
                return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1481
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1482
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1483
            try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1484
                return target.get(null);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1485
            } catch (IllegalAccessException e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1486
                try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1487
                    target.setAccessible(true);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1488
                    return target.get(null);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1489
                } catch (IllegalAccessException i) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1490
                    throw new SecurityException(i);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1491
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1492
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1493
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1494
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1495
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1496
    private static class CoreReflParameterVariableElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1497
        extends CoreReflVariableElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1498
        private final Parameter source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1499
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1500
        protected CoreReflParameterVariableElement(Parameter source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1501
            this.source = Objects.requireNonNull(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1502
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1503
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1504
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1505
        public Parameter getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1506
            return source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1507
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1508
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1509
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1510
        public Set<Modifier> getModifiers() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1511
            return ModifierUtil.instance(source.getModifiers() &
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1512
                                         java.lang.reflect.Modifier.parameterModifiers(), false);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1513
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1514
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1515
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1516
        public TypeMirror asType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1517
            // TODO : switch to parameterized type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1518
            return createTypeMirror(source.getType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1519
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1520
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1521
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1522
        public ElementKind getKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1523
            return ElementKind.PARAMETER;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1524
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1525
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1526
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1527
        public Name getSimpleName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1528
            return StringName.instance(source.getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1529
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1530
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1531
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1532
        public ReflectionElement getEnclosingElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1533
            Executable enclosing = source.getDeclaringExecutable();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1534
            if (enclosing instanceof Method)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1535
                return createMirror((Method)enclosing);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1536
            else if (enclosing instanceof Constructor)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1537
                return createMirror((Constructor<?>)enclosing);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1538
            else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1539
                throw new AssertionError("Bad enclosing value.");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1540
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1541
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1542
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1543
        public boolean equals(Object o) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1544
            if (o instanceof CoreReflParameterVariableElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1545
                return source.equals(((CoreReflParameterVariableElement) o).getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1546
            } else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1547
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1548
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1549
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1550
        // VariableElement methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1551
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1552
        public Object getConstantValue() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1553
            return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1554
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1555
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1556
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1557
        public boolean isSynthetic() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1558
            return source.isSynthetic();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1559
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1560
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1561
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1562
        public boolean isImplicit() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1563
            return source.isImplicit();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1564
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1565
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1566
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1567
    private static class CoreReflPackageElement extends CoreReflElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1568
        implements ReflectionPackageElement {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1569
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1570
        private final Package source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1571
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1572
        protected CoreReflPackageElement(Package source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1573
            this.source = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1574
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1575
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1576
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1577
        public Package getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1578
            return source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1579
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1580
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1581
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1582
        public <R,P> R accept(ElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1583
            return v.visitPackage(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1584
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1585
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1586
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1587
        public <R,P> R accept(ReflectionElementVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1588
            return v.visitPackage(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1589
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1590
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1591
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1592
        public boolean equals(Object o) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1593
            if (o instanceof CoreReflPackageElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1594
                return Objects.equals(source,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1595
                                      ((CoreReflPackageElement)o).getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1596
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1597
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1598
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1599
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1600
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1601
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1602
        public ElementKind getKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1603
            return ElementKind.PACKAGE;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1604
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1605
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1606
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1607
        public ReflectionElement getEnclosingElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1608
            return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1609
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1610
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1611
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1612
        public List<ReflectionElement> getEnclosedElements() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1613
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1614
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1615
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1616
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1617
        public Name getQualifiedName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1618
            return StringName.instance((source != null) ?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1619
                                       source.getName() :
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1620
                                       "" );
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1621
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1622
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1623
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1624
        public Name getSimpleName() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1625
            String n = ((source != null) ?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1626
                        source.getName() :
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1627
                        "");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1628
            int index = n.lastIndexOf('.');
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1629
            if (index > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1630
                return StringName.instance(n.substring(index + 1, n.length()));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1631
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1632
                return StringName.instance(n);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1633
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1634
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1635
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1636
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1637
        public boolean isUnnamed() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1638
            if (source != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1639
                String name = source.getName();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1640
                return(name == null || name.isEmpty());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1641
            } else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1642
                return true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1643
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1644
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1645
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1646
    private static class CoreReflAnnotationMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1647
        implements javax.lang.model.element.AnnotationMirror {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1648
        private final Annotation annotation;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1649
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1650
        protected CoreReflAnnotationMirror(Annotation annotation) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1651
            this.annotation = Objects.requireNonNull(annotation);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1652
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1653
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1654
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1655
        public DeclaredType getAnnotationType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1656
            return (DeclaredType)TypeFactory.instance(annotation.annotationType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1657
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1658
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1659
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1660
        public Map<? extends ReflectionExecutableElement, ? extends AnnotationValue> getElementValues() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1661
            // This differs from the javac implementation in that it returns default values
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1662
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1663
            Method[] elems = annotation.annotationType().getDeclaredMethods();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1664
            int len = elems.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1665
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1666
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1667
                Map<ReflectionExecutableElement, AnnotationValue> res = new HashMap<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1668
                for (Method m : elems) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1669
                    AnnotationValue v;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1670
                    try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1671
                        v = new CoreReflAnnotationValue(m.invoke(annotation));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1672
                    } catch (IllegalAccessException e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1673
                        try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1674
                            m.setAccessible(true);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1675
                            v = new CoreReflAnnotationValue(m.invoke(annotation));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1676
                        } catch (IllegalAccessException i) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1677
                            throw new SecurityException(i);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1678
                        } catch (InvocationTargetException ee) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1679
                            throw new RuntimeException(ee);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1680
                        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1681
                    } catch (InvocationTargetException ee) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1682
                        throw new RuntimeException(ee);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1683
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1684
                    ReflectionExecutableElement e = createMirror(m);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1685
                    res.put(e, v);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1686
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1687
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1688
                return Collections.unmodifiableMap(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1689
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1690
                return Collections.emptyMap();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1691
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1692
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1693
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1694
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1695
        public boolean equals(Object other) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1696
            if (other instanceof CoreReflAnnotationMirror) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1697
                return annotation.equals(((CoreReflAnnotationMirror)other).annotation);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1698
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1699
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1700
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1701
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1702
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1703
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1704
        public int hashCode() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1705
            return Objects.hashCode(annotation);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1706
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1707
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1708
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1709
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1710
            return annotation.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1711
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1712
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1713
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1714
    private static class CoreReflAnnotationValue
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1715
        implements javax.lang.model.element.AnnotationValue {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1716
        private Object value = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1717
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1718
        protected CoreReflAnnotationValue(Object value) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1719
            // Is this constraint really necessary?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1720
            Objects.requireNonNull(value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1721
            this.value = value;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1722
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1723
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1724
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1725
        public Object getValue() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1726
            return value;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1727
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1728
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1729
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1730
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1731
            return value.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1732
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1733
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1734
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1735
        public <R,P> R accept(AnnotationValueVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1736
            return v.visit(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1737
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1738
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1739
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1740
    // Helper utility classes
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1741
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1742
    private static class StringName implements Name {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1743
        private String name;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1744
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1745
        private StringName(String name) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1746
            this.name = Objects.requireNonNull(name);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1747
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1748
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1749
        public static StringName instance(String name) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1750
            return new StringName(name);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1751
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1752
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1753
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1754
        public int length() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1755
            return name.length();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1756
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1757
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1758
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1759
        public char charAt(int index) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1760
            return name.charAt(index);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1761
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1762
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1763
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1764
        public CharSequence subSequence(int start, int end) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1765
            return name.subSequence(start, end);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1766
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1767
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1768
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1769
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1770
            return name;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1771
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1772
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1773
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1774
        public boolean equals(Object other) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1775
            if (other instanceof StringName) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1776
                return name.equals(((StringName) other).name);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1777
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1778
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1779
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1780
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1781
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1782
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1783
        public int hashCode() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1784
            return name.hashCode();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1785
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1786
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1787
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1788
        public boolean contentEquals(CharSequence cs) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1789
            return name.contentEquals(cs);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1790
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1791
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1792
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1793
    /*
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1794
     * Given an {@code int} value of modifiers, return a proper immutable set
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1795
     * of {@code Modifier}s as a result.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1796
     */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1797
    private static class ModifierUtil {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1798
        private ModifierUtil() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1799
            throw new AssertionError("No instances for you.");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1800
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1801
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1802
        // Exercise for the reader: explore if caching of sets of
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1803
        // Modifiers would be helpful.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1804
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1805
        public static Set<Modifier> instance(int modifiers, boolean isDefault) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1806
            Set<Modifier> modSet = EnumSet.noneOf(Modifier.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1807
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1808
            if (java.lang.reflect.Modifier.isAbstract(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1809
                modSet.add(Modifier.ABSTRACT);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1810
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1811
            if (java.lang.reflect.Modifier.isFinal(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1812
                modSet.add(Modifier.FINAL);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1813
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1814
            if (java.lang.reflect.Modifier.isNative(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1815
                modSet.add(Modifier.NATIVE);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1816
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1817
            if (java.lang.reflect.Modifier.isPrivate(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1818
                modSet.add(Modifier.PRIVATE);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1819
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1820
            if (java.lang.reflect.Modifier.isProtected(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1821
                modSet.add(Modifier.PROTECTED);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1822
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1823
            if (java.lang.reflect.Modifier.isPublic(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1824
                modSet.add(Modifier.PUBLIC);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1825
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1826
            if (java.lang.reflect.Modifier.isStatic(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1827
                modSet.add(Modifier.STATIC);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1828
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1829
            if (java.lang.reflect.Modifier.isStrict(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1830
                modSet.add(Modifier.STRICTFP);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1831
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1832
            if (java.lang.reflect.Modifier.isSynchronized(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1833
                modSet.add(Modifier.SYNCHRONIZED);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1834
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1835
            if (java.lang.reflect.Modifier.isTransient(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1836
                modSet.add(Modifier.TRANSIENT);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1837
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1838
            if (java.lang.reflect.Modifier.isVolatile(modifiers))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1839
                modSet.add(Modifier.VOLATILE);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1840
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1841
            if (isDefault)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1842
                modSet.add(Modifier.DEFAULT);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1843
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1844
            return Collections.unmodifiableSet(modSet);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1845
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1846
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1847
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1848
    private abstract static class AbstractTypeMirror implements TypeMirror {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1849
        private final TypeKind kind;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1850
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1851
        protected AbstractTypeMirror(TypeKind kind) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1852
            this.kind = Objects.requireNonNull(kind);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1853
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1854
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1855
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1856
        public TypeKind getKind() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1857
            return kind;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1858
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1859
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1860
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1861
        public <R,P> R accept(TypeVisitor<R,P> v, P p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1862
            return v.visit(this, p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1863
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1864
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1865
        //Types methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1866
        abstract List<? extends TypeMirror> directSuperTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1867
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1868
        TypeMirror capture() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1869
            // Exercise for the reader: make this abstract and implement in subtypes
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1870
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1871
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1872
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1873
        TypeMirror erasure() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1874
            // Exercise for the reader: make this abstract and implement in subtypes
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1875
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1876
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1877
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1878
        // Exercise for the reader: implement the AnnotatedConstruct methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1879
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1880
        public List<? extends AnnotationMirror> getAnnotationMirrors() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1881
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1882
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1883
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1884
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1885
        public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1886
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1887
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1888
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1889
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1890
        public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1891
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1892
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1893
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1894
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1895
    private static class CoreReflArrayType extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1896
        implements javax.lang.model.type.ArrayType,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1897
                   Reifiable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1898
        private Class<?> source = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1899
        private Class<?> component = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1900
        private TypeMirror eagerComponent = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1901
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1902
        protected CoreReflArrayType(Class<?> source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1903
            super(TypeKind.ARRAY);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1904
            this.source = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1905
            this.component = source.getComponentType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1906
            this.eagerComponent = TypeFactory.instance(component);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1907
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1908
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1909
        public TypeMirror getComponentType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1910
            return eagerComponent;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1911
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1912
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1913
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1914
        public Class<?> getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1915
            return source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1916
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1917
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1918
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1919
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1920
            final TypeMirror componentType = getComponentType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1921
            final TypeMirror[] directSupers;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1922
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1923
            // JLS v4 4.10.3
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1924
            if (componentType.getKind().isPrimitive() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1925
                component.equals(java.lang.Object.class)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1926
                directSupers = new TypeMirror[3];
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1927
                directSupers[0] = TypeFactory.instance(java.lang.Object.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1928
                directSupers[1] = TypeFactory.instance(java.lang.Cloneable.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1929
                directSupers[2] = TypeFactory.instance(java.io.Serializable.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1930
            } else if (componentType.getKind() == TypeKind.ARRAY) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1931
                List<? extends TypeMirror> componentDirectSupertypes = CoreReflTypes.instance().directSupertypes(componentType);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1932
                directSupers = new TypeMirror[componentDirectSupertypes.size()];
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1933
                for (int i = 0; i < directSupers.length; i++) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1934
                    directSupers[i] = new CoreReflArrayType(Array.newInstance(((Reifiable)componentDirectSupertypes.get(i)).getSource(), 0).getClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1935
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1936
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1937
                Class<?> superClass = component.getSuperclass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1938
                Class<?>[] interfaces = component.getInterfaces();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1939
                directSupers = new TypeMirror[1 + interfaces.length];
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1940
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1941
                directSupers[0] = TypeFactory.instance(Array.newInstance(superClass, 0).getClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1942
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1943
                for (int i = 0; i < interfaces.length; i++) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1944
                    directSupers[i + 1] = TypeFactory.instance(Array.newInstance(interfaces[i],0).getClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1945
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1946
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1947
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1948
            return Collections.unmodifiableList(Arrays.asList(directSupers));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1949
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1950
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1951
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1952
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1953
            return getKind() + " of " + getComponentType().toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1954
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1955
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1956
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1957
    private static class CaptureTypeVariable extends AbstractTypeMirror implements javax.lang.model.type.TypeVariable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1958
        private TypeMirror source = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1959
        private TypeMirror upperBound = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1960
        private TypeMirror lowerBound = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1961
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1962
        CaptureTypeVariable(TypeMirror source,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1963
                            TypeMirror upperBound,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1964
                            TypeMirror lowerBound) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1965
            super(TypeKind.TYPEVAR);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1966
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1967
            this.source = Objects.requireNonNull(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1968
            this.upperBound = (upperBound == null ? CoreReflTypes.instance().getNullType() : upperBound);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1969
            this.lowerBound = (lowerBound == null ? CoreReflTypes.instance().getNullType() : lowerBound);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1970
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1971
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1972
        protected Class<?> getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1973
            if (source instanceof CoreReflDeclaredType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1974
                return ((CoreReflDeclaredType)source).getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1975
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1976
                return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1977
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1978
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1979
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1980
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1981
        public TypeMirror getUpperBound() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1982
            return upperBound;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1983
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1984
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1985
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1986
        public TypeMirror getLowerBound() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1987
            return lowerBound;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1988
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1989
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1990
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1991
        public Element asElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1992
            if (null == getSource()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1993
                return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1994
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1995
            return CoreReflectionFactory.createMirror(getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1996
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1997
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1998
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  1999
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2000
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2001
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2002
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2003
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2004
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2005
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2006
            return getKind() + " CAPTURE of: " + source.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2007
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2008
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2009
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2010
    private static class CoreReflElements implements ReflectionElements {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2011
        private CoreReflElements() {} // mostly one instance for you
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2012
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2013
        private static CoreReflElements instance = new CoreReflElements();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2014
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2015
        static CoreReflElements instance() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2016
            return instance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2017
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2018
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2019
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2020
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2021
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2022
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2023
        public ReflectionPackageElement getPackageElement(CharSequence name) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2024
            return createMirror(Package.getPackage(name.toString()));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2025
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2026
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2027
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2028
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2029
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2030
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2031
        public ReflectionTypeElement getTypeElement(CharSequence name) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2032
            // where name is a Canonical Name jls 6.7
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2033
            // but this method will probably accept an equivalent FQN
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2034
            // depending on Class.forName(String)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2035
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2036
            ReflectionTypeElement tmp = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2037
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2038
            // Filter out arrays
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2039
            String n = name.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2040
            if (n.contains("[")) return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2041
            if (n.equals("")) return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2042
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2043
            // The intention of this loop is to handle nested
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2044
            // elements.  If finding the element using Class.forName
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2045
            // fails, an attempt is made to find the element as an
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2046
            // enclosed element by trying fo find a prefix of the name
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2047
            // (dropping a trailing ".xyz") and looking for "xyz" as
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2048
            // an enclosed element.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2049
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2050
            Deque<String> parts = new ArrayDeque<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2051
            boolean again;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2052
            do {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2053
                again = false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2054
                try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2055
                    tmp = createMirror(Class.forName(n));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2056
                } catch (ClassNotFoundException e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2057
                    tmp = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2058
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2059
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2060
                if (tmp != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2061
                    if (parts.isEmpty()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2062
                        return tmp;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2063
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2064
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2065
                    tmp = findInner(tmp, parts);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2066
                    if (tmp != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2067
                        return tmp;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2068
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2069
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2070
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2071
                int indx = n.lastIndexOf('.');
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2072
                if (indx > -1) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2073
                    parts.addFirst(n.substring(indx + 1));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2074
                    n = n.substring(0, indx);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2075
                    again = true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2076
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2077
            } while (again);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2078
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2079
            return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2080
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2081
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2082
        // Recursively finds enclosed type elements named as part.top() popping part and repeating
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2083
        private ReflectionTypeElement findInner(ReflectionTypeElement e, Deque<String> parts) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2084
            if (parts.isEmpty()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2085
                return e;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2086
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2087
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2088
            String part = parts.removeFirst();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2089
            List<ReflectionElement> enclosed = e.getEnclosedElements();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2090
            for (ReflectionElement elm : enclosed) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2091
                if ((elm.getKind() == ElementKind.CLASS ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2092
                     elm.getKind() == ElementKind.INTERFACE ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2093
                     elm.getKind() == ElementKind.ENUM ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2094
                     elm.getKind() == ElementKind.ANNOTATION_TYPE)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2095
                    && elm.getSimpleName().toString().equals(part)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2096
                    ReflectionTypeElement t = findInner((ReflectionTypeElement)elm, parts);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2097
                    if (t != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2098
                        return t;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2099
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2100
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2101
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2102
            return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2103
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2104
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2105
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2106
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2107
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2108
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2109
        public Map<? extends ReflectionExecutableElement, ? extends AnnotationValue>
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2110
            getElementValuesWithDefaults(AnnotationMirror a) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2111
            if (a instanceof CoreReflAnnotationMirror) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2112
                return ((CoreReflAnnotationMirror)a).getElementValues();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2113
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2114
                throw new IllegalArgumentException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2115
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2116
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2117
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2118
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2119
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2120
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2121
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2122
        public String getDocComment(Element e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2123
            checkElement(e);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2124
            return null; // As per the doc
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2125
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2126
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2127
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2128
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2129
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2130
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2131
        public boolean isDeprecated(Element e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2132
            checkElement(e);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2133
            return ((CoreReflElement)e).getSource().isAnnotationPresent(java.lang.Deprecated.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2134
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2135
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2136
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2137
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2138
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2139
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2140
        public Name getBinaryName(TypeElement type) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2141
            checkElement(type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2142
            return StringName.instance(((CoreReflTypeElement)type)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2143
                                       .getSource()
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2144
                                       .getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2145
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2146
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2147
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2148
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2149
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2150
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2151
        public ReflectionPackageElement getPackageOf(Element type) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2152
            checkElement(type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2153
            if (type instanceof ReflectionPackageElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2154
                return (ReflectionPackageElement)type;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2155
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2156
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2157
            Package p;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2158
            if (type instanceof CoreReflTypeElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2159
                p = ((CoreReflTypeElement)type).getSource().getPackage();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2160
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2161
                CoreReflTypeElement enclosingTypeElement = (CoreReflTypeElement)getEnclosingTypeElement((ReflectionElement)type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2162
                p = enclosingTypeElement.getSource().getPackage();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2163
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2164
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2165
            return createMirror(p);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2166
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2167
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2168
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2169
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2170
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2171
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2172
        public List<? extends ReflectionElement> getAllMembers(TypeElement type) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2173
            checkElement(type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2174
            return getAllMembers((ReflectionTypeElement)type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2175
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2176
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2177
        // Exercise for the reader: should this method, and similar
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2178
        // ones that specialize on the more specific argument types,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2179
        // be addd to the public ReflectionElements API?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2180
        public List<? extends ReflectionElement> getAllMembers(ReflectionTypeElement type) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2181
            return type.getAllMembers();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2182
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2183
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2184
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2185
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2186
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2187
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2188
        public List<? extends AnnotationMirror> getAllAnnotationMirrors(Element e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2189
            checkElement(e);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2190
            AnnotatedElement ae = CoreReflElement.class.cast(e).getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2191
            Annotation[] annotations = ae.getAnnotations();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2192
            int len = annotations.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2193
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2194
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2195
                List<AnnotationMirror> res = new ArrayList<>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2196
                for (Annotation a : annotations) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2197
                    res.add(createMirror(a));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2198
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2199
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2200
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2201
                List<AnnotationMirror> ret = Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2202
                return ret;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2203
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2204
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2205
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2206
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2207
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2208
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2209
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2210
        public boolean hides(Element hider, Element hidden) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2211
            checkElement(hider);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2212
            checkElement(hidden);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2213
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2214
            // Names must be equal
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2215
            if (!hider.getSimpleName().equals(hidden.getSimpleName())) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2216
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2217
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2218
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2219
            // Hides isn't reflexive
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2220
            if (hider.equals(hidden)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2221
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2222
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2223
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2224
            // Hider and hidden needs to be field, method or type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2225
            // and fields hide fields, types hide types, methods hide methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2226
            // IE a Field doesn't hide a Methods etc
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2227
            ElementKind hiderKind = hider.getKind();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2228
            ElementKind hiddenKind = hidden.getKind();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2229
            if (hiderKind.isField() && !hiddenKind.isField()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2230
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2231
            } else if (hiderKind.isClass() &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2232
                       !(hiddenKind.isClass() || hiddenKind.isInterface())) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2233
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2234
            } else if (hiderKind.isInterface() &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2235
                       !(hiddenKind.isClass() || hiddenKind.isInterface())) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2236
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2237
            } else if (hiderKind == ElementKind.METHOD && hiddenKind != ElementKind.METHOD) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2238
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2239
            } else if (!(hiderKind.isClass() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2240
                         hiderKind.isInterface() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2241
                         hiderKind.isField() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2242
                         hiderKind == ElementKind.METHOD)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2243
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2244
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2245
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2246
            Set<Modifier> hm = hidden.getModifiers();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2247
            // jls 8.4.8.2 only static methods can hide methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2248
            if (hider.getKind() == ElementKind.METHOD) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2249
                if (!hider.getModifiers().contains(Modifier.STATIC)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2250
                    return false; // hider not static
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2251
                } else if (!hm.contains(Modifier.STATIC)) { // we know it's a method
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2252
                    return false; // hidden not static
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2253
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2254
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2255
                // For methods we also need to check parameter types
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2256
                Class<?>[] h1 = ((CoreReflMethodExecutableElement)hider).getSource().getParameterTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2257
                Class<?>[] h2 = ((CoreReflMethodExecutableElement)hidden).getSource().getParameterTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2258
                if (h1.length != h2.length) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2259
                    return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2260
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2261
                for (int i = 0; i < h1.length; i++) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2262
                    if (h1[i] != h2[i]) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2263
                        return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2264
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2265
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2266
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2267
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2268
            // You can only hide visible elements
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2269
            if (hm.contains(Modifier.PRIVATE)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2270
                return false; // hidden private, can't be hidden
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2271
            } else if ((!(hm.contains(Modifier.PUBLIC) || hm.contains(Modifier.PROTECTED))) && // not private, not (public or protected) IE package private
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2272
                       (!getPackageOf(hider).equals(getPackageOf(hidden)))) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2273
                return false; // hidden package private, and different packages, IE not visible
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2274
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2275
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2276
            // Ok so now hider actually hides hidden if hider is
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2277
            // declared on a subtype of hidden.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2278
            //
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2279
            // TODO: should this be a proper subtype or is that taken
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2280
            // care of by the reflexive check in the beginning?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2281
            //
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2282
            TypeMirror hiderType = getEnclosingTypeElement((ReflectionElement)hider).asType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2283
            TypeMirror hiddenType = getEnclosingTypeElement((ReflectionElement)hidden).asType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2284
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2285
            return getTypes().isSubtype(hiderType, hiddenType);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2286
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2287
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2288
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2289
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2290
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2291
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2292
        public ReflectionTypeElement getEnclosingTypeElement(ReflectionElement e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2293
            if (e.getKind() == ElementKind.PACKAGE) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2294
                return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2295
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2296
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2297
            if(e instanceof CoreReflTypeParameterElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2298
                ReflectionElement encElem = ((CoreReflTypeParameterElement)e).getEnclosingElement();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2299
                if (encElem instanceof ReflectionTypeElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2300
                    return (ReflectionTypeElement)encElem;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2301
                } else  {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2302
                    return getEnclosingTypeElement(encElem);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2303
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2304
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2305
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2306
            Class<?> encl = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2307
            if (e instanceof CoreReflTypeElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2308
                encl = ((CoreReflTypeElement)e).getSource().getDeclaringClass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2309
            } else if (e instanceof CoreReflExecutableElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2310
                encl = (((CoreReflExecutableElement)e).getSource()).getDeclaringClass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2311
            } else if (e instanceof CoreReflFieldVariableElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2312
                encl = ((CoreReflFieldVariableElement)e).getSource().getDeclaringClass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2313
            } else if (e instanceof CoreReflParameterVariableElement) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2314
                encl = ((CoreReflParameterVariableElement)e).getSource().getDeclaringExecutable().getDeclaringClass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2315
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2316
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2317
            return encl == null ? null : createMirror(encl);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2318
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2319
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2320
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2321
         *{@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2322
         *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2323
         * Note that this implementation does not handle the situation
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2324
         * where A overrides B and B overrides C but A does not
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2325
         * directly override C. In this case, this implementation will
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2326
         * erroneously return false.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2327
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2328
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2329
        public boolean overrides(ExecutableElement overrider, ExecutableElement overridden,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2330
                                 TypeElement type) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2331
            checkElement(overrider);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2332
            checkElement(overridden);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2333
            checkElement(type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2334
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2335
            // TODO handle transitive overrides
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2336
            return overridesDirect(overrider, overridden, type);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2337
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2338
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2339
        private boolean overridesDirect(ExecutableElement overrider, ExecutableElement overridden,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2340
                                         TypeElement type) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2341
            // Should we check that at least one of the types
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2342
            // overrider has is in fact a supertype of the TypeElement
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2343
            // 'type' supplied?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2344
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2345
            CoreReflExecutableElement rider = (CoreReflExecutableElement)overrider;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2346
            CoreReflExecutableElement ridden = (CoreReflExecutableElement)overridden;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2347
            CoreReflTypeElement riderType = (CoreReflTypeElement)type;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2348
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2349
            // Names must match, redundant - see subsignature below
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2350
            if (!rider.getSimpleName().equals(ridden.getSimpleName())) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2351
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2352
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2353
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2354
            // Constructors don't override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2355
            // TODO: verify this fact
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2356
            if (rider.getKind() == ElementKind.CONSTRUCTOR ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2357
                ridden.getKind() == ElementKind.CONSTRUCTOR) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2358
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2359
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2360
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2361
            // Overridden must be visible to be overridden
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2362
            // TODO Fix transitive visibility/override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2363
            Set<Modifier> rm = ridden.getModifiers();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2364
            if (rm.contains(Modifier.PRIVATE)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2365
                return false; // overridden private, can't be overridden
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2366
            } else if ((!(rm.contains(Modifier.PUBLIC) || rm.contains(Modifier.PROTECTED))) && // not private, not (public or protected) IE package private
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2367
                       (!getPackageOf(rider).equals(getPackageOf(ridden)))) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2368
                return false; // ridden package private, and different packages, IE not visible
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2369
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2370
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2371
            // Static methods doesn't override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2372
            if (rm.contains(Modifier.STATIC) ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2373
                rider.getModifiers().contains(Modifier.STATIC)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2374
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2375
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2376
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2377
            // Declaring class of overrider must be a subclass of declaring class of overridden
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2378
            // except we use the parameter type as declaring class of overrider
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2379
            if (!getTypes().isSubtype(riderType.asType(), getEnclosingTypeElement(ridden).asType())) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2380
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2381
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2382
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2383
            // Now overrider overrides overridden if the signature of rider is a subsignature of ridden
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2384
            return getTypes().isSubsignature(rider.asType(), ridden.asType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2385
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2386
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2387
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2388
         *{@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2389
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2390
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2391
        public String getConstantExpression(Object value) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2392
            return Constants.format(value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2393
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2394
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2395
        // If CoreReflectionFactory were a proper part of the JDK, the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2396
        // analogous functionality in javac could be reused.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2397
        private static class Constants {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2398
            /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2399
             * Returns a string representation of a constant value (given in
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2400
             * standard wrapped representation), quoted and formatted as in
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2401
             * Java source.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2402
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2403
            public static String format(Object value) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2404
                if (value instanceof Byte)      return formatByte((Byte) value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2405
                if (value instanceof Short)     return formatShort((Short) value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2406
                if (value instanceof Long)      return formatLong((Long) value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2407
                if (value instanceof Float)     return formatFloat((Float) value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2408
                if (value instanceof Double)    return formatDouble((Double) value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2409
                if (value instanceof Character) return formatChar((Character) value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2410
                if (value instanceof String)    return formatString((String) value);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2411
                if (value instanceof Integer ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2412
                    value instanceof Boolean)   return value.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2413
                else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2414
                    throw new IllegalArgumentException("Argument is not a primitive type or a string; it " +
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2415
                                                       ((value == null) ?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2416
                                                        "is a null value." :
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2417
                                                        "has class " +
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2418
                                                        value.getClass().getName()) + "." );
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2419
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2420
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2421
            private static String formatByte(byte b) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2422
                return String.format("(byte)0x%02x", b);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2423
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2424
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2425
            private static String formatShort(short s) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2426
                return String.format("(short)%d", s);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2427
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2428
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2429
            private static String formatLong(long lng) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2430
                return lng + "L";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2431
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2432
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2433
            private static String formatFloat(float f) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2434
                if (Float.isNaN(f))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2435
                    return "0.0f/0.0f";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2436
                else if (Float.isInfinite(f))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2437
                    return (f < 0) ? "-1.0f/0.0f" : "1.0f/0.0f";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2438
                else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2439
                    return f + "f";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2440
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2441
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2442
            private static String formatDouble(double d) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2443
                if (Double.isNaN(d))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2444
                    return "0.0/0.0";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2445
                else if (Double.isInfinite(d))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2446
                    return (d < 0) ? "-1.0/0.0" : "1.0/0.0";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2447
                else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2448
                    return d + "";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2449
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2450
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2451
            private static String formatChar(char c) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2452
                return '\'' + quote(c) + '\'';
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2453
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2454
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2455
            private static String formatString(String s) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2456
                return '"' + quote(s) + '"';
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2457
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2458
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2459
            /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2460
             * Escapes each character in a string that has an escape sequence or
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2461
             * is non-printable ASCII.  Leaves non-ASCII characters alone.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2462
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2463
            private static String quote(String s) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2464
                StringBuilder buf = new StringBuilder();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2465
                for (int i = 0; i < s.length(); i++) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2466
                    buf.append(quote(s.charAt(i)));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2467
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2468
                return buf.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2469
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2470
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2471
            /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2472
             * Escapes a character if it has an escape sequence or is
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2473
             * non-printable ASCII.  Leaves ASCII characters alone.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2474
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2475
            private static String quote(char ch) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2476
                switch (ch) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2477
                case '\b':  return "\\b";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2478
                case '\f':  return "\\f";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2479
                case '\n':  return "\\n";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2480
                case '\r':  return "\\r";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2481
                case '\t':  return "\\t";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2482
                case '\'':  return "\\'";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2483
                case '\"':  return "\\\"";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2484
                case '\\':  return "\\\\";
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2485
                default:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2486
                    return (isPrintableAscii(ch))
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2487
                        ? String.valueOf(ch)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2488
                        : String.format("\\u%04x", (int) ch);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2489
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2490
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2491
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2492
            /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2493
             * Is a character printable ASCII?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2494
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2495
            private static boolean isPrintableAscii(char ch) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2496
                return ch >= ' ' && ch <= '~';
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2497
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2498
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2499
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2500
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2501
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2502
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2503
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2504
        public void printElements(Writer w, Element... elements) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2505
            ElementVisitor<?, ?> printer = getPrinter(w);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2506
            try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2507
                for (Element e : elements) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2508
                    checkElement(e);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2509
                    printer.visit(e);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2510
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2511
            } finally {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2512
                try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2513
                    w.flush();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2514
                } catch (java.io.IOException e) { /* Ignore */;}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2515
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2516
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2517
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2518
        private ElementVisitor<?, ?> getPrinter(Writer w) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2519
            // First try a reflective call into javac and if that
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2520
            // fails, fallback to a very simple toString-based
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2521
            // scanner.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2522
            try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2523
                //reflective form of
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2524
                // return new com.sun.tools.javac.processing.PrintingProcessor.PrintingElementVisitor(w, getElements());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2525
                Class<?> printProcClass =
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2526
                    ClassLoader.getSystemClassLoader().loadClass("com.sun.tools.javac.processing.PrintingProcessor$PrintingElementVisitor");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2527
                Constructor<?> printProcCtor = printProcClass.getConstructor(Writer.class, Elements.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2528
                return (ElementVisitor) printProcCtor.newInstance(w, getElements());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2529
            } catch (ReflectiveOperationException | SecurityException e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2530
                return new ElementScanner8<Writer, Void>(w){
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2531
                    @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2532
                    public Writer scan(Element e, Void v) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2533
                        try {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2534
                            DEFAULT_VALUE.append(e.toString());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2535
                            DEFAULT_VALUE.append("\n");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2536
                        } catch (java.io.IOException ioe) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2537
                            throw new RuntimeException(ioe);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2538
                        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2539
                        return DEFAULT_VALUE;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2540
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2541
                };
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2542
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2543
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2544
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2545
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2546
         * {@inheritDoc}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2547
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2548
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2549
        public Name getName(CharSequence cs) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2550
            return StringName.instance(cs.toString());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2551
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2552
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2553
        private void checkElement(Element e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2554
            if(!(e instanceof CoreReflElement)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2555
                throw new IllegalArgumentException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2556
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2557
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2558
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2559
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2560
        public boolean isFunctionalInterface(TypeElement e) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2561
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2562
            // Update once this functionality is in core reflection
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2563
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2564
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2565
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2566
    private static class CoreReflTypes implements javax.lang.model.util.Types {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2567
        private static Types instance = new CoreReflTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2568
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2569
        public static Types instance() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2570
            return instance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2571
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2572
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2573
        // Private to suppress instantiation
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2574
        private CoreReflTypes() {}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2575
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2576
        // Types methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2577
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2578
        public Element asElement(TypeMirror t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2579
            checkType(t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2580
            if (t instanceof javax.lang.model.type.TypeVariable) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2581
                ((javax.lang.model.type.TypeVariable)t).asElement();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2582
            } else if (t instanceof DeclaredType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2583
                return ((DeclaredType)t).asElement();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2584
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2585
            return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2586
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2587
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2588
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2589
        public boolean isSameType(TypeMirror t1, TypeMirror t2) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2590
            if (t1.getKind() != t2.getKind()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2591
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2592
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2593
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2594
            if (t1.getKind() == TypeKind.WILDCARD ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2595
                t2.getKind() == TypeKind.WILDCARD) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2596
                // Wildcards are not equal to any type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2597
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2598
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2599
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2600
            if (t1 instanceof CoreReflDeclaredType &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2601
                t2 instanceof CoreReflDeclaredType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2602
                return ((CoreReflDeclaredType)t1).isSameType((CoreReflDeclaredType)t2);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2603
            } else if (t1 instanceof PrimitiveType &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2604
                       t2 instanceof PrimitiveType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2605
                return t1.getKind() == t2.getKind();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2606
            } else if (t1 instanceof NoType &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2607
                       t2 instanceof NoType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2608
                return true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2609
            } else if (t1 instanceof NullType &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2610
                       t2 instanceof NullType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2611
                return true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2612
            } else if (t1 instanceof ArrayType &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2613
                       t2 instanceof ArrayType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2614
                return isSameType(((ArrayType)t1).getComponentType(), ((ArrayType)t2).getComponentType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2615
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2616
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2617
            return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2618
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2619
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2620
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2621
        public boolean isSubtype(TypeMirror t1, TypeMirror t2) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2622
            checkType(t1);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2623
            checkType(t2);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2624
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2625
            if (isSameType(t1, t2)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2626
                return true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2627
            } else if(t1.getKind() == TypeKind.NULL) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2628
                return true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2629
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2630
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2631
            // This depth first traversal should terminate due to the ban on circular inheritance
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2632
            List<? extends TypeMirror> directSupertypes = directSupertypes(t1);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2633
            if (directSupertypes.isEmpty()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2634
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2635
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2636
            for (TypeMirror ti : directSupertypes) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2637
                if (isSameType(ti, t2) || isSubtype(ti, t2)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2638
                    return true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2639
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2640
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2641
            return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2642
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2643
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2644
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2645
        public boolean isAssignable(TypeMirror t1, TypeMirror t2) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2646
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2647
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2648
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2649
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2650
        public boolean contains(TypeMirror t1, TypeMirror t2) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2651
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2652
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2653
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2654
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2655
        public boolean isSubsignature(ExecutableType m1, ExecutableType m2) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2656
            checkType(m1);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2657
            checkType(m2);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2658
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2659
            ExecutableMethodType m0 = (ExecutableMethodType)m1;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2660
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2661
            return m0.sameSignature((ExecutableMethodType)m2) || m0.sameSignature((ExecutableMethodType)erasure(m2));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2662
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2663
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2664
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2665
        public List<? extends TypeMirror> directSupertypes(TypeMirror t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2666
            checkType(t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2667
            if (t instanceof ExecutableType ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2668
                t.getKind() == TypeKind.PACKAGE) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2669
                throw new IllegalArgumentException("You can't ask for direct supertypes for type: " + t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2670
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2671
            return ((AbstractTypeMirror)t).directSuperTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2672
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2673
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2674
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2675
        public TypeMirror erasure(TypeMirror t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2676
            checkType(t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2677
            return ((AbstractTypeMirror)t).erasure();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2678
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2679
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2680
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2681
        public TypeElement boxedClass(javax.lang.model.type.PrimitiveType p) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2682
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2683
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2684
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2685
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2686
        public PrimitiveType unboxedType(TypeMirror t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2687
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2688
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2689
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2690
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2691
        public TypeMirror capture(TypeMirror t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2692
            checkType(t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2693
            return ((AbstractTypeMirror)t).capture();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2694
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2695
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2696
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2697
        public PrimitiveType getPrimitiveType(TypeKind kind) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2698
            return PrimitiveType.instance(kind);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2699
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2700
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2701
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2702
        public NullType getNullType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2703
            return CoreReflNullType.getInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2704
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2705
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2706
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2707
        public javax.lang.model.type.NoType getNoType(TypeKind kind) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2708
            if (kind == TypeKind.NONE) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2709
                return NoType.getNoneInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2710
            } else if (kind == TypeKind.VOID) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2711
                return NoType.getVoidInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2712
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2713
                throw new IllegalArgumentException("No NoType of kind: " + kind);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2714
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2715
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2716
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2717
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2718
        public ArrayType getArrayType(TypeMirror componentType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2719
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2720
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2721
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2722
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2723
        public javax.lang.model.type.WildcardType getWildcardType(TypeMirror extendsBound,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2724
                                                                  TypeMirror superBound) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2725
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2726
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2727
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2728
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2729
        public DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2730
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2731
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2732
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2733
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2734
        public javax.lang.model.type.DeclaredType getDeclaredType(javax.lang.model.type.DeclaredType containing,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2735
                                                                  TypeElement typeElem,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2736
                                                                  TypeMirror... typeArgs) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2737
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2738
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2739
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2740
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2741
        public TypeMirror asMemberOf(javax.lang.model.type.DeclaredType containing, Element element) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2742
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2743
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2744
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2745
        private void checkType(TypeMirror t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2746
            if (!(t instanceof AbstractTypeMirror)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2747
                throw new IllegalArgumentException("This Types implementation can only operate on CoreReflectionFactory type classes");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2748
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2749
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2750
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2751
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2752
    private abstract static class CoreReflDeclaredType extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2753
        implements javax.lang.model.type.DeclaredType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2754
        private Class<?> source = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2755
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2756
        private CoreReflDeclaredType(Class<?> source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2757
            super(TypeKind.DECLARED);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2758
            this.source = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2759
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2760
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2761
        static DeclaredType instance(Class<?> source, Type genericSource) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2762
            if (genericSource instanceof ParameterizedType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2763
                return new ParameterizedDeclaredType(source, (ParameterizedType)genericSource);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2764
            } else if (genericSource instanceof Class) { // This happens when a field has a raw type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2765
                if (!source.equals(genericSource)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2766
                    throw new IllegalArgumentException("Don't know how to handle this");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2767
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2768
                return instance(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2769
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2770
            throw new IllegalArgumentException("Don't know how to create a declared type from: " +
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2771
                                               source +
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2772
                                               " and genericSource " +
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2773
                                               genericSource);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2774
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2775
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2776
        static DeclaredType instance(Class<?> source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2777
            return new RawDeclaredType(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2778
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2779
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2780
        protected Class<?> getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2781
            return source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2782
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2783
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2784
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2785
        public Element asElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2786
            return CoreReflectionFactory.createMirror(getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2787
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2788
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2789
        abstract boolean isSameType(DeclaredType other);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2790
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2791
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2792
        TypeMirror capture() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2793
            return new CaptureDeclaredType(this);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2794
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2795
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2796
        private static class CaptureDeclaredType extends CoreReflDeclaredType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2797
            CoreReflDeclaredType cap;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2798
            CaptureDeclaredType(CoreReflDeclaredType t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2799
                super(t.source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2800
                this.cap = t;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2801
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2802
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2803
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2804
            public List<? extends TypeMirror> getTypeArguments() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2805
                List<? extends TypeMirror> wrapped = cap.getTypeArguments();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2806
                ArrayList<TypeMirror> res = new ArrayList<>(wrapped.size());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2807
                res.ensureCapacity(wrapped.size());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2808
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2809
                for (int i = 0; i < wrapped.size(); i++) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2810
                    TypeMirror t = wrapped.get(i);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2811
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2812
                    if (t instanceof javax.lang.model.type.WildcardType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2813
                        res.add(i, convert(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2814
                    } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2815
                        res.add(i, t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2816
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2817
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2818
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2819
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2820
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2821
            private TypeMirror convert(TypeMirror t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2822
                if (!(t instanceof javax.lang.model.type.WildcardType)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2823
                    throw new IllegalArgumentException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2824
                } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2825
                    javax.lang.model.type.WildcardType w = (javax.lang.model.type.WildcardType)t;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2826
                    return TypeFactory.typeVariableInstance(w, w.getExtendsBound(), w.getSuperBound());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2827
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2828
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2829
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2830
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2831
            public TypeMirror getEnclosingType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2832
                return cap.getEnclosingType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2833
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2834
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2835
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2836
            List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2837
                return cap.directSuperTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2838
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2839
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2840
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2841
            boolean isSameType(DeclaredType other) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2842
                return other == this;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2843
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2844
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2845
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2846
            public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2847
                return " CAPTURE of: " + cap.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2848
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2849
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2850
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2851
        private static class RawDeclaredType extends CoreReflDeclaredType
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2852
            implements Reifiable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2853
            private RawDeclaredType(Class<?> source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2854
                super(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2855
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2856
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2857
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2858
            public Class<?> getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2859
                return super.getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2860
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2861
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2862
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2863
            public TypeMirror getEnclosingType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2864
                Class<?> enclosing = getSource().getEnclosingClass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2865
                if (null == enclosing) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2866
                    return NoType.getNoneInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2867
                } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2868
                    return TypeFactory.instance(enclosing);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2869
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2870
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2871
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2872
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2873
            public List<? extends TypeMirror> getTypeArguments() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2874
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2875
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2876
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2877
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2878
            List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2879
                if (getSource().isEnum()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2880
                    return enumSuper();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2881
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2882
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2883
                if (getSource() == java.lang.Object.class) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2884
                    return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2885
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2886
                List<TypeMirror> res = new ArrayList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2887
                Type[] superInterfaces = getSource().getInterfaces();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2888
                if (!getSource().isInterface()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2889
                    res.add(TypeFactory.instance(getSource().getSuperclass()));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2890
                } else if (superInterfaces.length == 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2891
                    // Interfaces that don't extend another interface
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2892
                    // have java.lang.Object as a direct supertype.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2893
                    return Collections.unmodifiableList(Arrays.asList(TypeFactory.instance(java.lang.Object.class)));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2894
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2895
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2896
                for (Type t : superInterfaces) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2897
                    res.add(TypeFactory.instance(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2898
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2899
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2900
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2901
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2902
            private List<? extends TypeMirror> enumSuper() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2903
                Class<?> rawSuper = getSource().getSuperclass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2904
                Type[] actualArgs = ((ParameterizedTypeImpl)getSource().getGenericSuperclass()).getActualTypeArguments();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2905
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2906
                // Reconsider this : assume the problem is making
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2907
                // Enum<MyEnum> rather than just a raw enum.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2908
                return Collections.unmodifiableList(Arrays.asList(TypeFactory.instance(ParameterizedTypeImpl.make(rawSuper,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2909
                                                                                                                  Arrays.copyOf(actualArgs,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2910
                                                                                                                                actualArgs.length),
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2911
                                                                                                                  null))));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2912
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2913
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2914
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2915
            boolean isSameType(DeclaredType other) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2916
                if (other instanceof RawDeclaredType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2917
                    return Objects.equals(getSource(), ((RawDeclaredType)other).getSource());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2918
                } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2919
                    return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2920
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2921
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2922
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2923
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2924
            public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2925
                return getSource().toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2926
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2927
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2928
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2929
        private static class ParameterizedDeclaredType extends CoreReflDeclaredType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2930
            private ParameterizedType genericSource = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2931
            private ParameterizedDeclaredType(Class<?> source, ParameterizedType genericSource) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2932
                super(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2933
                this.genericSource = genericSource;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2934
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2935
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2936
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2937
            public TypeMirror getEnclosingType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2938
                Type me = genericSource;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2939
                Type owner = GenericTypes.getEnclosingType(me);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2940
                if (owner == null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2941
                    return NoType.getNoneInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2942
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2943
                return TypeFactory.instance(owner);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2944
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2945
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2946
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2947
            public List<? extends TypeMirror> getTypeArguments() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2948
                Type[] typeArgs = genericSource.getActualTypeArguments();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2949
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2950
                int length = typeArgs.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2951
                if (length == 0)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2952
                    return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2953
                else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2954
                    List<TypeMirror> tmp = new ArrayList<>(length);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2955
                    for (Type t : typeArgs) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2956
                        tmp.add(TypeFactory.instance(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2957
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2958
                    return Collections.unmodifiableList(tmp);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2959
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2960
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2961
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2962
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2963
            List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2964
                if (getSource() == java.lang.Object.class) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2965
                    return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2966
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2967
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2968
                List<TypeMirror> res = new ArrayList<>();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2969
                Type[] superInterfaces = getSource().getGenericInterfaces();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2970
                if (!getSource().isInterface()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2971
                    // Replace actual type arguments with our type arguments
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2972
                    res.add(TypeFactory.instance(substituteTypeArgs(getSource().getGenericSuperclass())));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2973
                } else if (superInterfaces.length == 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2974
                    // Interfaces that don't extend another interface
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2975
                    // have java.lang.Object as a direct supertype, plus
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2976
                    // possibly the interface's raw type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2977
                    res.add(TypeFactory.instance(java.lang.Object.class));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2978
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2979
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2980
                for (Type t : superInterfaces) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2981
                    res.add(TypeFactory.instance(substituteTypeArgs(t)));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2982
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2983
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2984
                res.add(TypeFactory.instance(getSource())); // Add raw type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2985
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2986
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2987
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2988
            private Type substituteTypeArgs(Type type) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2989
                if (!(type instanceof ParameterizedType)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2990
                    return type;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2991
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2992
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2993
                ParameterizedType target = (ParameterizedType)type;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2994
                // Cast to get a Class instead of a plain type.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2995
                Class<?> raw = ((ParameterizedTypeImpl)target).getRawType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2996
                Type[] actualArgs = genericSource.getActualTypeArguments();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2997
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2998
                return  ParameterizedTypeImpl.make(raw, Arrays.copyOf(actualArgs, actualArgs.length), null);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  2999
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3000
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3001
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3002
            boolean isSameType(DeclaredType other) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3003
                if (other instanceof ParameterizedDeclaredType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3004
                    return GenericTypes.isSameGenericType(genericSource,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3005
                                                          ((ParameterizedDeclaredType)other).genericSource);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3006
                } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3007
                    return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3008
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3009
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3010
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3011
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3012
            public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3013
                return getKind().toString() + " " + genericSource.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3014
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3015
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3016
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3017
        /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3018
         * Implementing class for ParameterizedType interface.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3019
         * Derived from sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3020
         */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3021
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3022
        private static class ParameterizedTypeImpl implements ParameterizedType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3023
            private Type[] actualTypeArguments;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3024
            private Class<?>  rawType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3025
            private Type   ownerType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3026
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3027
            private ParameterizedTypeImpl(Class<?> rawType,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3028
                                          Type[] actualTypeArguments,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3029
                                          Type ownerType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3030
                this.actualTypeArguments = actualTypeArguments;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3031
                this.rawType             = rawType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3032
                if (ownerType != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3033
                    this.ownerType = ownerType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3034
                } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3035
                    this.ownerType = rawType.getDeclaringClass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3036
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3037
                validateConstructorArguments();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3038
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3039
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3040
            private void validateConstructorArguments() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3041
                java.lang.reflect.TypeVariable/*<?>*/[] formals = rawType.getTypeParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3042
                // check correct arity of actual type args
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3043
                if (formals.length != actualTypeArguments.length){
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3044
                    throw new MalformedParameterizedTypeException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3045
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3046
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3047
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3048
            /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3049
             * Static factory. Given a (generic) class, actual type arguments
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3050
             * and an owner type, creates a parameterized type.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3051
             * This class can be instantiated with a a raw type that does not
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3052
             * represent a generic type, provided the list of actual type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3053
             * arguments is empty.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3054
             * If the ownerType argument is null, the declaring class of the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3055
             * raw type is used as the owner type.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3056
             * <p> This method throws a MalformedParameterizedTypeException
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3057
             * under the following circumstances:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3058
             * If the number of actual type arguments (i.e., the size of the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3059
             * array {@code typeArgs}) does not correspond to the number of
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3060
             * formal type arguments.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3061
             * If any of the actual type arguments is not an instance of the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3062
             * bounds on the corresponding formal.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3063
             * @param rawType the Class representing the generic type declaration being
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3064
             * instantiated
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3065
             * @param actualTypeArguments - a (possibly empty) array of types
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3066
             * representing the actual type arguments to the parameterized type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3067
             * @param ownerType - the enclosing type, if known.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3068
             * @return An instance of {@code ParameterizedType}
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3069
             * @throws MalformedParameterizedTypeException - if the instantiation
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3070
             * is invalid
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3071
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3072
            public static ParameterizedTypeImpl make(Class<?> rawType,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3073
                                                     Type[] actualTypeArguments,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3074
                                                     Type ownerType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3075
                return new ParameterizedTypeImpl(rawType, actualTypeArguments,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3076
                                                 ownerType);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3077
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3078
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3079
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3080
            /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3081
             * Returns an array of {@code Type} objects representing the actual type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3082
             * arguments to this type.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3083
             *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3084
             * <p>Note that in some cases, the returned array be empty. This can occur
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3085
             * if this type represents a non-parameterized type nested within
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3086
             * a parameterized type.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3087
             *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3088
             * @return an array of {@code Type} objects representing the actual type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3089
             *     arguments to this type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3090
             * @throws {@code TypeNotPresentException} if any of the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3091
             *     actual type arguments refers to a non-existent type declaration
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3092
             * @throws {@code MalformedParameterizedTypeException} if any of the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3093
             *     actual type parameters refer to a parameterized type that cannot
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3094
             *     be instantiated for any reason
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3095
             * @since 1.5
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3096
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3097
            public Type[] getActualTypeArguments() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3098
                return actualTypeArguments.clone();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3099
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3100
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3101
            /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3102
             * Returns the {@code Type} object representing the class or interface
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3103
             * that declared this type.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3104
             *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3105
             * @return the {@code Type} object representing the class or interface
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3106
             *     that declared this type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3107
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3108
            public Class<?> getRawType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3109
                return rawType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3110
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3111
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3112
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3113
            /**
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3114
             * Returns a {@code Type} object representing the type that this type
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3115
             * is a member of.  For example, if this type is {@code O<T>.I<S>},
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3116
             * return a representation of {@code O<T>}.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3117
             *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3118
             * <p>If this type is a top-level type, {@code null} is returned.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3119
             *
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3120
             * @return a {@code Type} object representing the type that
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3121
             *     this type is a member of. If this type is a top-level type,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3122
             *     {@code null} is returned
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3123
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3124
            public Type getOwnerType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3125
                return ownerType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3126
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3127
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3128
            /*
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3129
             * From the JavaDoc for java.lang.reflect.ParameterizedType
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3130
             * "Instances of classes that implement this interface must
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3131
             * implement an equals() method that equates any two instances
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3132
             * that share the same generic type declaration and have equal
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3133
             * type parameters."
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3134
             */
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3135
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3136
            public boolean equals(Object o) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3137
                if (o instanceof ParameterizedType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3138
                    // Check that information is equivalent
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3139
                    ParameterizedType that = (ParameterizedType) o;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3140
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3141
                    if (this == that)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3142
                        return true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3143
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3144
                    Type thatOwner   = that.getOwnerType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3145
                    Type thatRawType = that.getRawType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3146
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3147
                    return Objects.equals(ownerType, thatOwner) &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3148
                        Objects.equals(rawType, thatRawType) &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3149
                        Arrays.equals(actualTypeArguments, // avoid clone
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3150
                                      that.getActualTypeArguments());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3151
                } else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3152
                    return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3153
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3154
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3155
            @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3156
            public int hashCode() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3157
                return
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3158
                    Arrays.hashCode(actualTypeArguments) ^
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3159
                    Objects.hashCode(ownerType) ^
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3160
                    Objects.hashCode(rawType);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3161
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3162
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3163
            public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3164
                StringBuilder sb = new StringBuilder();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3165
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3166
                if (ownerType != null) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3167
                    if (ownerType instanceof Class)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3168
                        sb.append(((Class)ownerType).getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3169
                    else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3170
                        sb.append(ownerType.toString());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3171
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3172
                    sb.append(".");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3173
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3174
                    if (ownerType instanceof ParameterizedTypeImpl) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3175
                        // Find simple name of nested type by removing the
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3176
                        // shared prefix with owner.
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3177
                        sb.append(rawType.getName().replace( ((ParameterizedTypeImpl)ownerType).rawType.getName() + "$",
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3178
                                                             ""));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3179
                    } else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3180
                        sb.append(rawType.getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3181
                } else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3182
                    sb.append(rawType.getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3183
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3184
                if (actualTypeArguments != null &&
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3185
                    actualTypeArguments.length > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3186
                    sb.append("<");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3187
                    boolean first = true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3188
                    for (Type t: actualTypeArguments) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3189
                        if (!first)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3190
                            sb.append(", ");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3191
                        if (t instanceof Class)
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3192
                            sb.append(((Class)t).getName());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3193
                        else
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3194
                            sb.append(t.toString());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3195
                        first = false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3196
                    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3197
                    sb.append(">");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3198
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3199
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3200
                return sb.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3201
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3202
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3203
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3204
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3205
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3206
    private static class ErasedMethodType extends ExecutableMethodType implements javax.lang.model.type.ExecutableType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3207
        private final Method m;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3208
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3209
        ErasedMethodType(Method m) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3210
            super(m);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3211
            this.m = Objects.requireNonNull(m);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3212
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3213
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3214
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3215
        public List<javax.lang.model.type.TypeVariable> getTypeVariables() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3216
            return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3217
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3218
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3219
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3220
        public List<? extends TypeMirror> getThrownTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3221
            Class<?>[] exceptions = m.getExceptionTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3222
            int len = exceptions.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3223
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3224
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3225
                List<TypeMirror> res = new ArrayList<TypeMirror>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3226
                for (Class<?> t : exceptions) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3227
                    res.add(TypeFactory.instance(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3228
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3229
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3230
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3231
                List<TypeMirror> ret = Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3232
                return ret;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3233
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3234
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3235
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3236
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3237
        public List<? extends TypeMirror> getParameterTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3238
            Class<?>[] params = m.getParameterTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3239
            int len = params.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3240
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3241
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3242
                List<TypeMirror> res = new ArrayList<TypeMirror>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3243
                for (Class<?> t : params) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3244
                    res.add(TypeFactory.instance(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3245
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3246
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3247
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3248
                List<TypeMirror> ret = Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3249
                return ret;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3250
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3251
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3252
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3253
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3254
        public TypeMirror getReturnType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3255
            return TypeFactory.instance(m.getReturnType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3256
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3257
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3258
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3259
        TypeMirror erasure() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3260
            return this;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3261
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3262
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3263
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3264
    private static class ErrorType extends AbstractTypeMirror implements javax.lang.model.type.ErrorType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3265
        private static ErrorType errorType = new ErrorType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3266
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3267
        public static ErrorType getErrorInstance() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3268
            return errorType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3269
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3270
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3271
        private ErrorType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3272
            super(TypeKind.ERROR);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3273
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3274
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3275
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3276
        public List<? extends TypeMirror> getTypeArguments() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3277
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3278
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3279
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3280
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3281
        public TypeMirror getEnclosingType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3282
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3283
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3284
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3285
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3286
        public Element asElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3287
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3288
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3289
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3290
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3291
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3292
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3293
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3294
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3295
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3296
    private static class ExecutableMethodType extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3297
        implements javax.lang.model.type.ExecutableType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3298
        private final Method m;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3299
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3300
        ExecutableMethodType(Method m) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3301
            super(TypeKind.EXECUTABLE);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3302
            this.m = Objects.requireNonNull(m);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3303
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3304
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3305
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3306
        public List<? extends TypeMirror> getThrownTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3307
            Type[] exceptions = m.getGenericExceptionTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3308
            int len = exceptions.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3309
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3310
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3311
                List<TypeMirror> res = new ArrayList<TypeMirror>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3312
                for (Type t : exceptions) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3313
                    res.add(TypeFactory.instance(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3314
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3315
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3316
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3317
                List<TypeMirror> ret = Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3318
                return ret;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3319
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3320
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3321
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3322
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3323
        public List<javax.lang.model.type.TypeVariable> getTypeVariables() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3324
            java.lang.reflect.TypeVariable[] variables = m.getTypeParameters();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3325
            int len = variables.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3326
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3327
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3328
                List<javax.lang.model.type.TypeVariable> res = new ArrayList<>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3329
                for (java.lang.reflect.TypeVariable<?> t : variables) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3330
                    res.add(TypeFactory.typeVariableInstance(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3331
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3332
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3333
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3334
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3335
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3336
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3337
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3338
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3339
        public TypeMirror getReturnType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3340
            return TypeFactory.instance(m.getGenericReturnType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3341
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3342
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3343
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3344
        public List<? extends TypeMirror> getParameterTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3345
            Type[] params = m.getGenericParameterTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3346
            int len = params.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3347
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3348
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3349
                List<TypeMirror> res = new ArrayList<TypeMirror>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3350
                for (Type t : params) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3351
                    res.add(TypeFactory.instance(t));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3352
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3353
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3354
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3355
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3356
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3357
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3358
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3359
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3360
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3361
            // Spec says we don't need this
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3362
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3363
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3364
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3365
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3366
        TypeMirror erasure() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3367
            return new ErasedMethodType(m);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3368
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3369
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3370
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3371
        public TypeMirror getReceiverType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3372
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3373
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3374
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3375
        boolean sameSignature(ExecutableMethodType other){
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3376
            if (!m.getName().equals(other.m.getName())) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3377
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3378
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3379
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3380
            List<? extends TypeMirror> thisParams = getParameterTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3381
            List<? extends TypeMirror> otherParams = other.getParameterTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3382
            if (thisParams.size() != otherParams.size()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3383
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3384
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3385
            for (int i = 0; i < thisParams.size(); i++) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3386
                if (!CoreReflTypes.instance().isSameType(thisParams.get(i), otherParams.get(i))) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3387
                    return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3388
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3389
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3390
            return true;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3391
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3392
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3393
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3394
    private static class GenericTypes {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3395
        public static boolean isSameGenericType(Type t1, Type t2) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3396
            if (t1 instanceof Class) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3397
                return ((Class)t1).equals(t2);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3398
            } else if (t1 instanceof ParameterizedType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3399
                return ((ParameterizedType)t1).equals(t2);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3400
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3401
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3402
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3403
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3404
        public static Type getEnclosingType(Type t1) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3405
            if (t1 instanceof Class) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3406
                return ((Class)t1).getEnclosingClass();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3407
            } else if (t1 instanceof ParameterizedType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3408
                return ((ParameterizedType)t1).getOwnerType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3409
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3410
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3411
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3412
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3413
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3414
    private static class IntersectionDeclaredType extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3415
        implements javax.lang.model.type.DeclaredType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3416
        private Type[] sources = null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3417
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3418
        IntersectionDeclaredType(Type[] sources) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3419
            super(TypeKind.DECLARED);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3420
            this.sources = Arrays.copyOf(Objects.requireNonNull(sources),
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3421
                                         sources.length);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3422
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3423
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3424
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3425
        public TypeMirror getEnclosingType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3426
            return NoType.getNoneInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3427
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3428
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3429
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3430
        public  Element asElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3431
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3432
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3433
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3434
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3435
        public List<? extends TypeMirror> getTypeArguments() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3436
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3437
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3438
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3439
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3440
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3441
            int len = sources.length;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3442
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3443
            if (len > 0) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3444
                List<TypeMirror> res = new ArrayList<TypeMirror>(len);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3445
                for (Type c : sources) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3446
                    res.add(TypeFactory.instance(c));
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3447
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3448
                return Collections.unmodifiableList(res);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3449
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3450
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3451
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3452
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3453
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3454
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3455
    private static class ModelWildcardType extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3456
        implements javax.lang.model.type.WildcardType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3457
        private java.lang.reflect.WildcardType genericSource;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3458
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3459
        ModelWildcardType(java.lang.reflect.WildcardType genericSource) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3460
            super(TypeKind.WILDCARD);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3461
            this.genericSource = Objects.requireNonNull(genericSource);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3462
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3463
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3464
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3465
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3466
            // TODO Add support for this operation
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3467
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3468
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3469
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3470
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3471
        public TypeMirror getExtendsBound() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3472
            Type[] t = genericSource.getUpperBounds();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3473
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3474
            if (t.length == 1) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3475
                if (t[0].equals(Object.class) && getSuperBound() != null) { // can't have both lower and upper explicit
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3476
                    return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3477
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3478
                return TypeFactory.instance(t[0]);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3479
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3480
            throw new UnsupportedOperationException(); // TODO: intersection type?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3481
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3482
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3483
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3484
        public TypeMirror getSuperBound() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3485
            Type[] t = genericSource.getLowerBounds();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3486
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3487
            if (t.length == 0) { // bound is null
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3488
                return null;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3489
            } else if (t.length == 1) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3490
                return TypeFactory.instance(t[0]);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3491
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3492
            throw new UnsupportedOperationException(); // TODO: intersection type?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3493
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3494
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3495
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3496
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3497
            return getKind() + " " + genericSource.toString();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3498
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3499
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3500
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3501
    private static class NoType extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3502
        implements javax.lang.model.type.NoType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3503
        private static NoType noneType = new NoType(TypeKind.NONE, "none");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3504
        private static NoType packageType = new NoType(TypeKind.PACKAGE, "package");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3505
        private static NoType voidType = new NoType(TypeKind.VOID, "void");
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3506
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3507
        private String str;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3508
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3509
        public static NoType getNoneInstance() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3510
            return noneType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3511
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3512
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3513
        public static NoType getPackageInstance() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3514
            return packageType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3515
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3516
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3517
        public static NoType getVoidInstance() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3518
            return voidType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3519
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3520
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3521
        private NoType(TypeKind k, String str) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3522
            super(k);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3523
            this.str = str;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3524
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3525
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3526
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3527
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3528
            // TODO We don't need this for the Package instance, how about the others?
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3529
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3530
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3531
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3532
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3533
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3534
            return str;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3535
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3536
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3537
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3538
    private static class CoreReflNullType extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3539
        implements javax.lang.model.type.NullType {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3540
        private static CoreReflNullType nullType = new CoreReflNullType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3541
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3542
        public static NullType getInstance() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3543
            return nullType;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3544
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3545
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3546
        private CoreReflNullType() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3547
            super(TypeKind.NULL);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3548
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3549
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3550
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3551
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3552
            // JLS 4.10.2 says:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3553
            // "The direct supertypes of the null type are all reference types other than the null type itself."
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3554
            // TODO return null? an empty list? the error type? anyhow fix this
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3555
            throw new UnsupportedOperationException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3556
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3557
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3558
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3559
    private static interface Reifiable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3560
        Class<?> getSource();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3561
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3562
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3563
    private static class PrimitiveType extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3564
        implements javax.lang.model.type.PrimitiveType,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3565
                   Reifiable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3566
        private Class<?> source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3567
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3568
        private static PrimitiveType booleanInstance = new PrimitiveType(TypeKind.BOOLEAN, boolean.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3569
        private static PrimitiveType byteInstance =    new PrimitiveType(TypeKind.BYTE, byte.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3570
        private static PrimitiveType charInstance =    new PrimitiveType(TypeKind.CHAR, char.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3571
        private static PrimitiveType shortInstance =   new PrimitiveType(TypeKind.SHORT, short.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3572
        private static PrimitiveType intInstance =     new PrimitiveType(TypeKind.INT, int.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3573
        private static PrimitiveType longInstance =    new PrimitiveType(TypeKind.LONG, long.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3574
        private static PrimitiveType floatInstance =   new PrimitiveType(TypeKind.FLOAT, float.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3575
        private static PrimitiveType doubleInstance =  new PrimitiveType(TypeKind.DOUBLE, double.class);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3576
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3577
        private PrimitiveType(TypeKind kind, Class<?> source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3578
            super(kind);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3579
            this.source = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3580
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3581
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3582
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3583
        public Class<?> getSource() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3584
            return source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3585
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3586
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3587
        static PrimitiveType instance(Class<?> c) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3588
            switch(c.getName()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3589
            case "boolean":
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3590
                return booleanInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3591
            case "byte":
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3592
                return byteInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3593
            case "char":
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3594
                return charInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3595
            case "short":
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3596
                return shortInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3597
            case "int":
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3598
                return intInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3599
            case "long":
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3600
                return longInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3601
            case "float":
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3602
                return floatInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3603
            case "double":
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3604
                return doubleInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3605
            default:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3606
                throw new IllegalArgumentException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3607
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3608
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3609
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3610
        static PrimitiveType instance(TypeKind k) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3611
            switch(k) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3612
            case BOOLEAN:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3613
                return booleanInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3614
            case BYTE:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3615
                return byteInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3616
            case CHAR:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3617
                return charInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3618
            case SHORT:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3619
                return shortInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3620
            case INT:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3621
                return intInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3622
            case LONG:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3623
                return longInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3624
            case FLOAT:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3625
                return floatInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3626
            case DOUBLE:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3627
                return doubleInstance;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3628
            default:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3629
                throw new IllegalArgumentException();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3630
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3631
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3632
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3633
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3634
        public String toString() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3635
            return source.getName();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3636
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3637
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3638
        //Types methods
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3639
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3640
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3641
            switch (getKind()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3642
            case DOUBLE:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3643
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3644
            case FLOAT:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3645
                return Arrays.asList(doubleInstance);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3646
            case LONG:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3647
                return Arrays.asList(floatInstance);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3648
            case INT:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3649
                return Arrays.asList(longInstance);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3650
            case CHAR:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3651
                return Arrays.asList(intInstance);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3652
            case SHORT:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3653
                return Arrays.asList(intInstance);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3654
            case BYTE:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3655
                return Arrays.asList(shortInstance);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3656
            default:
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3657
                return Collections.emptyList();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3658
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3659
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3660
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3661
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3662
    private static class TypeFactory {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3663
        private TypeFactory() { }// no instances for you
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3664
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3665
        public static TypeMirror instance(Class<?> c) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3666
            if (c.isPrimitive()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3667
                if (c.getName().equals("void")) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3668
                    return NoType.getVoidInstance();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3669
                } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3670
                    return PrimitiveType.instance(c);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3671
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3672
            } else if (c.isArray()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3673
                return new CoreReflArrayType(c);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3674
            } else if (c.isAnonymousClass() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3675
                       c.isLocalClass() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3676
                       c.isMemberClass() ||
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3677
                       c.isInterface() || // covers annotations
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3678
                       c.isEnum()) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3679
                return CoreReflDeclaredType.instance(c);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3680
            } else { // plain old class ??
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3681
                return CoreReflDeclaredType.instance(c);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3682
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3683
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3684
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3685
        public static TypeMirror instance(Type t) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3686
            if (t instanceof Class) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3687
                return instance((Class)t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3688
            } else if (t instanceof ParameterizedType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3689
                ParameterizedType tmp = (ParameterizedType)t;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3690
                Type raw = tmp.getRawType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3691
                if (!(raw instanceof Class)) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3692
                    throw new IllegalArgumentException(t + " " + raw );
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3693
                }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3694
                return CoreReflDeclaredType.instance((Class)raw, tmp);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3695
            } else if (t instanceof java.lang.reflect.WildcardType) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3696
                return new ModelWildcardType((java.lang.reflect.WildcardType)t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3697
            } else if (t instanceof java.lang.reflect.TypeVariable) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3698
            return new CoreReflTypeVariable((java.lang.reflect.TypeVariable)t);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3699
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3700
            throw new IllegalArgumentException("Don't know how to make instance from: " + t.getClass());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3701
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3702
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3703
        public static TypeMirror instance(Field f) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3704
            return CoreReflDeclaredType.instance(f.getType(), f.getGenericType());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3705
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3706
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3707
        public static ExecutableType instance(Method m) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3708
            return new ExecutableMethodType(m);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3709
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3710
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3711
        public static javax.lang.model.type.TypeVariable typeVariableInstance(java.lang.reflect.TypeVariable<?> v) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3712
            return new CoreReflTypeVariable(v);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3713
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3714
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3715
        public static javax.lang.model.type.TypeVariable typeVariableInstance(TypeMirror source,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3716
                                                        TypeMirror upperBound,
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3717
                                                        TypeMirror lowerBound) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3718
            return new CaptureTypeVariable(source, upperBound, lowerBound);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3719
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3720
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3721
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3722
    private static class CoreReflTypeVariable extends AbstractTypeMirror
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3723
        implements javax.lang.model.type.TypeVariable {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3724
        private final java.lang.reflect.TypeVariable<?> source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3725
        private boolean isCapture = false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3726
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3727
        protected CoreReflTypeVariable(java.lang.reflect.TypeVariable<?> source) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3728
            super(TypeKind.TYPEVAR);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3729
            Objects.requireNonNull(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3730
            this.source = source;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3731
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3732
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3733
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3734
        public TypeMirror getUpperBound() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3735
            return new IntersectionDeclaredType(source.getBounds());
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3736
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3737
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3738
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3739
        public TypeMirror getLowerBound() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3740
            return CoreReflTypes.instance().getNullType();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3741
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3742
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3743
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3744
        public Element asElement() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3745
            return CoreReflectionFactory.createMirror(source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3746
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3747
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3748
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3749
        List<? extends TypeMirror> directSuperTypes() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3750
            return ((AbstractTypeMirror)getUpperBound()).directSuperTypes();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3751
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3752
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3753
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3754
        public int hashCode() {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3755
            return source.hashCode();
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3756
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3757
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3758
        @Override
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3759
        public boolean equals(Object other) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3760
            if (other instanceof CoreReflTypeVariable) {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3761
                return this.source.equals(((CoreReflTypeVariable)other).source);
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3762
            } else {
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3763
                return false;
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3764
            }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3765
        }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3766
    }
69b191cb1d7e 8004133: Provide javax.lang.model.* implementation backed by core reflection
darcy
parents:
diff changeset
  3767
}