/*
 * Copyright 2017 MovingBlocks
 *
 * 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.terasology.reflection;

import org.terasology.utilities.ReflectionUtil;

import java.lang.reflect.Type;

/**
 * Represents the type {@link T}. The type information generated is more comprehensive than {@link Class},
 * and {@link #type} correctly represents {@link T} whether it is generic or a wildcard type.
 *
 * Clients must create a subclass so that type information for the type can be retrieved at run-time:
 *
 * {@code TypeToken<List<String>> list = new TypeToken<List<String>>() {};}
 *
 * @param <T> The type for which type information is to be generated.
 */
public class TypeInfo<T> {
    private final Class<? super T> rawType;
    private final Type type;
    private final int hashCode;

    /**
     * Constructs a new type literal. Derives represented class from type
     * parameter.
     */
    @SuppressWarnings("unchecked")
    protected TypeInfo() {
        this.type = ReflectionUtil.getTypeParameterForSuper(getClass(), TypeInfo.class, 0);
        this.rawType = (Class<? super T>) ReflectionUtil.getClassOfType(type);
        this.hashCode = type.hashCode();
    }

    public Class<? super T> getRawType() {
        return rawType;
    }

    public Type getType() {
        return type;
    }

    @Override
    public final int hashCode() {
        return this.hashCode;
    }
}

@@ -915,16 +915,23 @@
 ype.%0A *%0A
+ * %3Cp%3E%0A
  * Clien
@@ -964,16 +964,25 @@
 so that 
+the full 
 type inf
@@ -994,21 +994,8 @@
 ion 
-for the type 
 can 
@@ -1023,16 +1023,23 @@
 ime:%0A *%0A
+ * %3Cp%3E%0A
  * %7B@cod
@@ -1040,29 +1040,28 @@
  %7B@code Type
-Token
+Info
 %3CList%3CString
@@ -1082,13 +1082,12 @@
 Type
-Token
+Info
 %3CLis
@@ -1102,16 +1102,184 @@
 %3E%3E() %7B%7D;
+ %7D%0A *%0A * %3Cp%3E%0A * However, if the type is a simple class, %7B@link TypeInfo#of(Class)%7D will suffice:%0A *%0A * %3Cp%3E%0A * %7B@code TypeInfo%3CString%3E list = TypeInfo.of(String.class); 
 %7D%0A *%0A * 
@@ -1518,64 +1518,76 @@
 new 
-type literal. Derives represented class from type%0A     *
+%7B@link TypeInfo%7D where the represented type is derived from the type
  par
@@ -1875,32 +1875,337 @@
 hCode();%0A    %7D%0A%0A
+    /**%0A     * Constructs a new %7B@link TypeInfo%7D directly from the type.%0A     */%0A    @SuppressWarnings(%22unchecked%22)%0A    protected TypeInfo(Type type) %7B%0A        this.type = type;%0A        this.rawType = (Class%3C? super T%3E) ReflectionUtil.getClassOfType(type);%0A        this.hashCode = type.hashCode();%0A    %7D%0A%0A
     public Class
@@ -2401,11 +2401,187 @@
 e;%0A    %7D
+%0A%0A    /**%0A     * Create a %7B@link TypeInfo%7D for the given %7B@link Class%7D.%0A     */%0A    public static %3CT%3E TypeInfo%3CT%3E of(Class%3CT%3E type) %7B%0A        return new TypeInfo%3C%3E(type);%0A    %7D
 %0A%7D%0A

Add TypeInfo.of