org.elasticsearch.common.inject.TypeLiteral Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :server
/*
* Copyright (C) 2006 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.elasticsearch.common.inject;
import org.elasticsearch.common.inject.internal.MoreTypes;
import org.elasticsearch.common.inject.util.Types;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import static org.elasticsearch.common.inject.internal.MoreTypes.canonicalize;
/**
* Represents a generic type {@code T}. Java doesn't yet provide a way to
* represent generic types, so this class does. Forces clients to create a
* subclass of this class which enables retrieval the type information even at
* runtime.
*
* For example, to create a type literal for {@code List}, you can
* create an empty anonymous inner class:
*
* {@code TypeLiteral> list = new TypeLiteral>() {};}
*
* This syntax cannot be used to create type literals that have wildcard
* parameters, such as {@code Class} or {@code List}.
* Such type literals must be constructed programatically, either by {@link
* Method#getGenericReturnType extracting types from members} or by using the
* {@link Types} factory class.
*
* Along with modeling generic types, this class can resolve type parameters.
* For example, to figure out what type {@code keySet()} returns on a {@code
* Map}, use this code:{@code
*
* TypeLiteral