1
0
mirror of https://e.coding.net/circlecloud/GsonAgent.git synced 2024-11-22 01:48:50 +00:00

移除反射调用...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2016-01-09 13:14:53 +08:00
parent 6121d924b5
commit 7405e4fda0
3 changed files with 190 additions and 213 deletions

View File

@ -9,10 +9,8 @@ import cn.citycraft.GsonAgent.api.JsonNull;
import cn.citycraft.GsonAgent.api.JsonObject;
import cn.citycraft.GsonAgent.api.JsonParser;
import cn.citycraft.GsonAgent.api.JsonPrimitive;
import cn.citycraft.GsonAgent.api.TypeAdapter;
import cn.citycraft.GsonAgent.api.stream.JsonReader;
import cn.citycraft.GsonAgent.api.stream.JsonWriter;
import cn.citycraft.GsonAgent.api.utils.Utils;
/**
* Minecraft Gson代理类(用于兼容1.7-1.8Gson类库)
@ -21,24 +19,14 @@ import cn.citycraft.GsonAgent.api.utils.Utils;
* @since 2016年1月5日 下午12:51:30
* @author ,曲尘
*/
@SuppressWarnings({ "unchecked", "rawtypes", "unused" })
public class GsonAgent {
public static boolean newVersion = false;
private static String internalPackageName;
private static Class TypeAdapter;
static {
internalPackageName = "cn.citycraft.GsonAgent.";
try {
Thread.currentThread().getContextClassLoader().loadClass("com.google.gson.Gson");
newVersion = true;
internalPackageName += "normal.";
} catch (final Exception | Error e) {
internalPackageName += "nms.";
}
try {
TypeAdapter = getInternalClass("bind.TypeAdapter");
} catch (final Exception e) {
}
}
@ -123,22 +111,11 @@ public class GsonAgent {
}
return new cn.citycraft.GsonAgent.nms.stream.JsonWriterHandle(out);
}
public static TypeAdapter newTypeAdapter() {
return (TypeAdapter) Utils.newInstance(TypeAdapter);
}
private static Class<?> getInternalClass(final String className) throws ClassNotFoundException {
return Class.forName(internalPackageName + className + "Handle");
}
private void none() {
Class clazz;
clazz = cn.citycraft.GsonAgent.api.bind.TypeAdapter.class;
clazz = cn.citycraft.GsonAgent.nms.bind.TypeAdapterHandle.class;
clazz = cn.citycraft.GsonAgent.normal.bind.TypeAdapterHandle.class;
clazz = cn.citycraft.GsonAgent.api.bind.TypeAdapterFactory.class;
clazz = cn.citycraft.GsonAgent.nms.bind.TypeAdapterFactoryHandle.class;
clazz = cn.citycraft.GsonAgent.normal.bind.TypeAdapterFactoryHandle.class;
}
// FIXME ###会造成java.lang.StackOverflowError###
// public static <T> TypeAdapter newTypeAdapter(final TypeAdapter<T> typeAdapter) {
// if (newVersion) {
// return new cn.citycraft.GsonAgent.normal.bind.TypeAdapterHandle((com.google.gson.TypeAdapter) typeAdapter);
// }
// return new cn.citycraft.GsonAgent.nms.bind.TypeAdapterHandle((net.minecraft.util.com.google.gson.TypeAdapter) typeAdapter);
// }
}

View File

@ -12,7 +12,7 @@ public class TypeAdapterHandle<T> implements cn.citycraft.GsonAgent.api.TypeAdap
private final TypeAdapter<T> handle;
public TypeAdapterHandle(final TypeAdapter handle) {
public TypeAdapterHandle(final TypeAdapter<T> handle) {
this.handle = handle;
}

View File

@ -13,7 +13,7 @@ public class TypeAdapterHandle<T> implements cn.citycraft.GsonAgent.api.TypeAdap
private final TypeAdapter<T> handle;
public TypeAdapterHandle(final TypeAdapter handle) {
public TypeAdapterHandle(final TypeAdapter<T> handle) {
this.handle = handle;
}