001package io.avaje.inject.spi;
002
003import java.lang.reflect.Type;
004
005/**
006 * Represents a full type including generics declaration, to avoid information loss due to type erasure.
007 * <p>
008 * This is a cut down version of Helidon GenericType Apache 2 licence.
009 *
010 * @param <T> the generic type parameter
011 */
012public class GenericType<T> implements Type {
013
014  private final Type type;
015
016  /**
017   * Constructs a new generic type, deriving the generic type and class from type parameter.
018   */
019  protected GenericType() throws IllegalArgumentException {
020    this.type = GenericTypeUtil.typeArgument(getClass());
021  }
022
023  /**
024   * Return the type represented by this generic type instance.
025   */
026  public Type type() {
027    return type;
028  }
029
030  @Override
031  public String getTypeName() {
032    return type.toString();
033  }
034
035  @Override
036  public int hashCode() {
037    return type.hashCode();
038  }
039
040  @Override
041  public boolean equals(Object obj) {
042    if (this == obj) {
043      return true;
044    }
045    if (obj instanceof GenericType) {
046      return ((GenericType<?>) obj).type.equals(this.type);
047    }
048    return false;
049  }
050
051  @Override
052  public String toString() {
053    return type.toString();
054  }
055}