aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config/gson
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-08-26 16:58:59 +0200
committerGitHub <noreply@github.com>2022-08-26 16:58:59 +0200
commitbf2cf4d8166a36ed089040889ad950ad3b71bc08 (patch)
treeeb1e4a9c5db5c70be872c7924d3cc2e5ca1446c8 /src/main/java/cc/polyfrost/oneconfig/config/gson
parent8c6863a0c554ab75e8967618d6a0b90aaa4562f2 (diff)
downloadOneConfig-bf2cf4d8166a36ed089040889ad950ad3b71bc08.tar.gz
OneConfig-bf2cf4d8166a36ed089040889ad950ad3b71bc08.tar.bz2
OneConfig-bf2cf4d8166a36ed089040889ad950ad3b71bc08.zip
Finally remove stupid deserializePart method (#118)
* InstanceSupplier my beloved * Api my not so beloved * License header before moon kills me
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config/gson')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/InstanceSupplier.java44
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/GsonContext.java123
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/InterfaceAdapterFactory.java192
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonDeserialization.java63
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonDeserializes.java72
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonSerialization.java70
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/Reflection.java513
7 files changed, 44 insertions, 1033 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/InstanceSupplier.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/InstanceSupplier.java
new file mode 100644
index 0000000..f20b527
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/gson/InstanceSupplier.java
@@ -0,0 +1,44 @@
+/*
+ * This file is part of OneConfig.
+ * OneConfig - Next Generation Config Library for Minecraft: Java Edition
+ * Copyright (C) 2021, 2022 Polyfrost.
+ * <https://polyfrost.cc> <https://github.com/Polyfrost/>
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * OneConfig is licensed under the terms of version 3 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation, AND
+ * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
+ * either version 1.0 of the Additional Terms, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License. If not, see <https://www.gnu.org/licenses/>. You should
+ * have also received a copy of the Additional Terms Applicable
+ * to OneConfig, as published by Polyfrost. If not, see
+ * <https://polyfrost.cc/legal/oneconfig/additional-terms>
+ */
+
+package cc.polyfrost.oneconfig.config.gson;
+
+import com.google.gson.InstanceCreator;
+
+import java.lang.reflect.Type;
+
+public class InstanceSupplier<T> implements InstanceCreator<T> {
+ private final T instance;
+
+ public InstanceSupplier(T instance) {
+ this.instance = instance;
+ }
+
+ @Override
+ public T createInstance(Type type) {
+ return instance;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/GsonContext.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/GsonContext.java
deleted file mode 100644
index e27a362..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/GsonContext.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package cc.polyfrost.oneconfig.config.gson.gsoninterface;
-
-/*
- * This file is part of OneConfig.
- * OneConfig - Next Generation Config Library for Minecraft: Java Edition
- * Copyright (C) 2021, 2022 Polyfrost.
- *
- * <https://polyfrost.cc> <https://github.com/Polyfrost/>
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * OneConfig is licensed under the terms of version 3 of the GNU Lesser
- * General Public License as published by the Free Software Foundation, AND
- * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
- * either version 1.0 of the Additional Terms, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License. If not, see <https://www.gnu.org/licenses/>. You should
- * have also received a copy of the Additional Terms Applicable
- * to OneConfig, as published by Polyfrost. If not, see
- * <https://polyfrost.cc/legal/oneconfig/additional-terms>
-
- * This file contains an adaptation of code from gson-interface
- * Project found at <https://github.com/mintern/gson-interface>
- * For the avoidance of doubt, this file is still licensed under the terms
- * of OneConfig's Licensing.
- *
- * LICENSE NOTICE FOR ADAPTED CODE
- *
- * Copyright (C) 2012, Brandon Mintern, EasyESI, Berkeley, CA
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither gson-interface nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRANDON MINTERN OR EASYESI BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonIOException;
-import com.google.gson.TypeAdapter;
-import com.google.gson.internal.bind.JsonTreeReader;
-import com.google.gson.internal.bind.JsonTreeWriter;
-
-import java.io.IOException;
-import java.lang.reflect.Type;
-
-/**
- * @author mintern
- */
-public class GsonContext<T> {
- private final Gson gson;
- private final InterfaceAdapterFactory.InterfaceTypeAdapter<T> constructingAdapter;
-
- public GsonContext(Gson g, InterfaceAdapterFactory.InterfaceTypeAdapter<T> ita) {
- gson = g;
- constructingAdapter = ita;
- }
-
- public JsonElement toJsonTree(Object obj) {
- return gson.toJsonTree(obj);
- }
-
- public JsonElement thisToJsonTree(T obj) throws JsonIOException {
- JsonTreeWriter writer = new JsonTreeWriter();
- try {
- constructingAdapter.getDelegate().write(writer, obj);
- } catch (IOException e) {
- throw new JsonIOException(e);
- }
- return writer.get();
- }
-
- public <C> C fromJsonTree(JsonElement json, Class<C> type) {
- return gson.fromJson(json, type);
- }
-
- public <C> C fromJsonTree(JsonElement json, Type typeOfC) {
- return (C) gson.fromJson(json, typeOfC);
- }
-
- public T thisFromJsonTree(JsonElement json) throws JsonIOException {
- try {
- return constructingAdapter.getDelegate().read(new JsonTreeReader(json));
- } catch (IOException e) {
- throw new JsonIOException(e);
- }
- }
-
- public <C extends T> C thisFromJsonTree(JsonElement json, Type typeOfC) {
- TypeAdapter<C> adapter = constructingAdapter.getNextAdapter(typeOfC);
- try {
- return adapter.read(new JsonTreeReader(json));
- } catch (IOException e) {
- throw new JsonIOException(e);
- }
- }
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/InterfaceAdapterFactory.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/InterfaceAdapterFactory.java
deleted file mode 100644
index 8f7d9d6..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/InterfaceAdapterFactory.java
+++ /dev/null
@@ -1,192 +0,0 @@
-package cc.polyfrost.oneconfig.config.gson.gsoninterface;
-
-/*
- * This file is part of OneConfig.
- * OneConfig - Next Generation Config Library for Minecraft: Java Edition
- * Copyright (C) 2021, 2022 Polyfrost.
- *
- * <https://polyfrost.cc> <https://github.com/Polyfrost/>
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * OneConfig is licensed under the terms of version 3 of the GNU Lesser
- * General Public License as published by the Free Software Foundation, AND
- * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
- * either version 1.0 of the Additional Terms, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License. If not, see <https://www.gnu.org/licenses/>. You should
- * have also received a copy of the Additional Terms Applicable
- * to OneConfig, as published by Polyfrost. If not, see
- * <https://polyfrost.cc/legal/oneconfig/additional-terms>
-
- * This file contains an adaptation of code from gson-interface
- * Project found at <https://github.com/mintern/gson-interface>
- * For the avoidance of doubt, this file is still licensed under the terms
- * of OneConfig's Licensing.
- *
- * LICENSE NOTICE FOR ADAPTED CODE
- *
- * Copyright (C) 2012, Brandon Mintern, EasyESI, Berkeley, CA
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither gson-interface nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRANDON MINTERN OR EASYESI BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.gson.*;
-import com.google.gson.internal.Streams;
-import com.google.gson.reflect.TypeToken;
-import com.google.gson.stream.JsonReader;
-import com.google.gson.stream.JsonWriter;
-
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author mintern
- */
-public class InterfaceAdapterFactory implements TypeAdapterFactory {
- @Override
- public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> tt) {
- Class<T> rawType = Reflection.classOfType(tt.getRawType());
- boolean serializes = JsonSerialization.class.isAssignableFrom(rawType);
- Constructor<JsonDeserializes<T>> deserializerConstructor = null;
- Class<JsonDeserializes<T>>[] typeParameters = Reflection.getTypeParameters(rawType, JsonDeserialization.class);
- if (typeParameters != null) {
- deserializerConstructor = Reflection.getConstructor(typeParameters[0]);
- }
- if (serializes || deserializerConstructor != null) {
- return new InterfaceTypeAdapter(serializes, deserializerConstructor, gson, tt, this);
- }
- return null;
- }
-
- public static class InterfaceTypeAdapter<T> extends TypeAdapter<T> {
- // This map ensures that only one deserializer of each type exists.
- private static final Map<Class, JsonDeserializes<?>> deserializerInstances = new HashMap();
-
- // Fields set in the constructor
- private final boolean selfSerializing;
- private final Constructor<JsonDeserializes<T>> deserializerConstructor;
- private final Gson gson;
- private final TypeToken<T> typeToken;
- private final TypeAdapterFactory thisFactory;
-
- // Adapters that follow this one in the chain for the indicated type
- private final Map<Type, TypeAdapter> nextAdapters = new HashMap();
-
- // Lazily-initialized fields. Call their corresponding getters in
- // order to access them.
- private TypeAdapter<T> delegate;
- private GsonContext gsonContext;
-
- private InterfaceTypeAdapter(
- boolean serializes,
- Constructor<JsonDeserializes<T>> dsc,
- Gson g,
- TypeToken<T> tt,
- TypeAdapterFactory factory) {
- selfSerializing = serializes;
- if (dsc != null) {
- dsc.setAccessible(true);
- }
- deserializerConstructor = dsc;
- gson = g;
- typeToken = tt;
- thisFactory = factory;
- }
-
- @Override
- public void write(JsonWriter writer, T value) throws IOException {
- if (!selfSerializing) {
- getDelegate().write(writer, value);
- } else if (value == null) {
- writer.nullValue();
- } else {
- JsonElement tree = ((JsonSerialization) value).toJsonTree(gsonContext());
- Streams.write(tree, writer);
- }
- }
-
- @Override
- public T read(JsonReader reader) throws IOException {
- if (deserializerConstructor == null) {
- return getDelegate().read(reader);
- }
- JsonElement json = Streams.parse(reader);
- if (json.isJsonNull()) {
- return null;
- }
- return (T) deserializer().fromJsonTree(json, typeToken.getType(), gsonContext());
- }
-
- synchronized TypeAdapter<T> getDelegate() {
- if (delegate == null) {
- delegate = gson.getDelegateAdapter(thisFactory, typeToken);
- }
- return delegate;
- }
-
- private synchronized GsonContext gsonContext() {
- if (gsonContext == null) {
- gsonContext = new GsonContext(gson, this);
- }
- return gsonContext;
- }
-
- synchronized <C extends T> TypeAdapter<C> getNextAdapter(Type typeOfC) {
- TypeAdapter<C> nextAdapter = nextAdapters.get(typeOfC);
- if (nextAdapter == null) {
- nextAdapter = gson.getDelegateAdapter(thisFactory, (TypeToken<C>) TypeToken.get(typeOfC));
- nextAdapters.put(typeOfC, nextAdapter);
- }
- return nextAdapter;
- }
-
- private JsonDeserializes<T> deserializer() {
- synchronized (deserializerInstances) {
- Class<JsonDeserializes<T>> c = deserializerConstructor.getDeclaringClass();
- JsonDeserializes<T> deserializer = (JsonDeserializes<T>) deserializerInstances.get(c);
- if (deserializer == null) {
- try {
- deserializer = deserializerConstructor.newInstance();
- } catch (Exception e) {
- throw new JsonParseException(e);
- }
- deserializerInstances.put(c, deserializer);
- }
- return deserializer;
- }
- }
- }
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonDeserialization.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonDeserialization.java
deleted file mode 100644
index 436d897..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonDeserialization.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package cc.polyfrost.oneconfig.config.gson.gsoninterface;
-
-/*
- * This file is part of OneConfig.
- * OneConfig - Next Generation Config Library for Minecraft: Java Edition
- * Copyright (C) 2021, 2022 Polyfrost.
- *
- * <https://polyfrost.cc> <https://github.com/Polyfrost/>
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * OneConfig is licensed under the terms of version 3 of the GNU Lesser
- * General Public License as published by the Free Software Foundation, AND
- * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
- * either version 1.0 of the Additional Terms, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License. If not, see <https://www.gnu.org/licenses/>. You should
- * have also received a copy of the Additional Terms Applicable
- * to OneConfig, as published by Polyfrost. If not, see
- * <https://polyfrost.cc/legal/oneconfig/additional-terms>
-
- * This file contains an adaptation of code from gson-interface
- * Project found at <https://github.com/mintern/gson-interface>
- * For the avoidance of doubt, this file is still licensed under the terms
- * of OneConfig's Licensing.
- *
- * LICENSE NOTICE FOR ADAPTED CODE
- *
- * Copyright (C) 2012, Brandon Mintern, EasyESI, Berkeley, CA
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither gson-interface nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRANDON MINTERN OR EASYESI BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-public interface JsonDeserialization<D extends JsonDeserializes<? extends JsonDeserialization<D>>> {
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonDeserializes.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonDeserializes.java
deleted file mode 100644
index ecdf8e5..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonDeserializes.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package cc.polyfrost.oneconfig.config.gson.gsoninterface;
-
-/*
- * This file is part of OneConfig.
- * OneConfig - Next Generation Config Library for Minecraft: Java Edition
- * Copyright (C) 2021, 2022 Polyfrost.
- *
- * <https://polyfrost.cc> <https://github.com/Polyfrost/>
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * OneConfig is licensed under the terms of version 3 of the GNU Lesser
- * General Public License as published by the Free Software Foundation, AND
- * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
- * either version 1.0 of the Additional Terms, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License. If not, see <https://www.gnu.org/licenses/>. You should
- * have also received a copy of the Additional Terms Applicable
- * to OneConfig, as published by Polyfrost. If not, see
- * <https://polyfrost.cc/legal/oneconfig/additional-terms>
-
- * This file contains an adaptation of code from gson-interface
- * Project found at <https://github.com/mintern/gson-interface>
- * For the avoidance of doubt, this file is still licensed under the terms
- * of OneConfig's Licensing.
- *
- * LICENSE NOTICE FOR ADAPTED CODE
- *
- * Copyright (C) 2012, Brandon Mintern, EasyESI, Berkeley, CA
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither gson-interface nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRANDON MINTERN OR EASYESI BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.gson.JsonElement;
-
-import java.lang.reflect.Type;
-
-/**
- * @author mintern
- */
-public interface JsonDeserializes<T> {
- T fromJsonTree(JsonElement json, Type type, GsonContext<T> context);
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonSerialization.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonSerialization.java
deleted file mode 100644
index 3cae64d..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/JsonSerialization.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package cc.polyfrost.oneconfig.config.gson.gsoninterface;
-
-/*
- * This file is part of OneConfig.
- * OneConfig - Next Generation Config Library for Minecraft: Java Edition
- * Copyright (C) 2021, 2022 Polyfrost.
- *
- * <https://polyfrost.cc> <https://github.com/Polyfrost/>
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * OneConfig is licensed under the terms of version 3 of the GNU Lesser
- * General Public License as published by the Free Software Foundation, AND
- * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
- * either version 1.0 of the Additional Terms, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License. If not, see <https://www.gnu.org/licenses/>. You should
- * have also received a copy of the Additional Terms Applicable
- * to OneConfig, as published by Polyfrost. If not, see
- * <https://polyfrost.cc/legal/oneconfig/additional-terms>
-
- * This file contains an adaptation of code from gson-interface
- * Project found at <https://github.com/mintern/gson-interface>
- * For the avoidance of doubt, this file is still licensed under the terms
- * of OneConfig's Licensing.
- *
- * LICENSE NOTICE FOR ADAPTED CODE
- *
- * Copyright (C) 2012, Brandon Mintern, EasyESI, Berkeley, CA
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither gson-interface nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRANDON MINTERN OR EASYESI BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.gson.JsonElement;
-
-/**
- * @author mintern
- */
-public interface JsonSerialization<T extends JsonSerialization<T>> {
- public JsonElement toJsonTree(GsonContext<T> context);
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/Reflection.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/Reflection.java
deleted file mode 100644
index ee50b64..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/config/gson/gsoninterface/Reflection.java
+++ /dev/null
@@ -1,513 +0,0 @@
-package cc.polyfrost.oneconfig.config.gson.gsoninterface;
-
-/*
- * This file is part of OneConfig.
- * OneConfig - Next Generation Config Library for Minecraft: Java Edition
- * Copyright (C) 2021, 2022 Polyfrost.
- *
- * <https://polyfrost.cc> <https://github.com/Polyfrost/>
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * OneConfig is licensed under the terms of version 3 of the GNU Lesser
- * General Public License as published by the Free Software Foundation, AND
- * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
- * either version 1.0 of the Additional Terms, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License. If not, see <https://www.gnu.org/licenses/>. You should
- * have also received a copy of the Additional Terms Applicable
- * to OneConfig, as published by Polyfrost. If not, see
- * <https://polyfrost.cc/legal/oneconfig/additional-terms>
-
- * This file contains an adaptation of code from gson-interface
- * Project found at <https://github.com/mintern/gson-interface>
- * For the avoidance of doubt, this file is still licensed under the terms
- * of OneConfig's Licensing.
- *
- * LICENSE NOTICE FOR ADAPTED CODE
- *
- * Copyright (C) 2012, Brandon Mintern, EasyESI, Berkeley, CA
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither gson-interface nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRANDON MINTERN OR EASYESI BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.lang.reflect.*;
-import java.util.ArrayList;
-import java.util.EmptyStackException;
-
-/**
- * Provides various static helper methods that add a high-level interface to
- * introspection and reflection.
- *
- * @author mintern
- */
-public class Reflection {
- /**
- * A wrapper for Class.newInstance() that throws an unchecked Exception.
- * It also ensures that even private constructors can be called.
- *
- * @param c the class on which to call newInstance()
- * @return the object returned from c.newInstance()
- * @throws IllegalArgumentException if there was an exception
- * constructing the instance
- */
- public static <T> T newInstance(Class<T> c) {
- try {
- return constructAnyway(c.getDeclaredConstructor());
- } catch (Exception e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- /**
- * Gets the aClass constructor with the given paramaters, throwing an
- * unchecked exception in the case of errors.
- *
- * @param aClass the class whose constructor should be fetched.
- * @param params the parameters to the desired constructor
- * @return the constructor for aClass that accepts params, or null if
- * there is no such constructor
- */
- public static <T> Constructor<T> getConstructor(Class<T> aClass, Class... params) {
- try {
- return aClass.getDeclaredConstructor(params);
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Invokes the given constructor with the given args even if it's not
- * accessible.
- *
- * @param <T> the type of value to be constructed
- * @param constructor the constructor to invoke (see getConstructor)
- * @param args the args to send to the constructor
- * @return a new instance of type T
- * @throws IllegalArgumentException if there was an exception while
- * setting the constructor to be accessible or invoking it
- */
- public static <T> T constructAnyway(Constructor<T> constructor, Object... args)
- throws IllegalArgumentException {
- try {
- boolean wasAccessible = constructor.isAccessible();
- constructor.setAccessible(true);
- try {
- T instance = constructor.newInstance(args);
- return instance;
- } finally {
- constructor.setAccessible(wasAccessible);
- }
- } catch (Exception e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- /**
- * Checks whether a class is abstract.
- *
- * @param c the class to check
- * @return true iff c is an interface or abstract class
- */
- public static boolean isAbstract(Class c) {
- return c.isInterface() || Modifier.isAbstract(c.getModifiers());
- }
-
- /**
- * Obtain the value of a field even if it is not public.
- *
- * @param field the field value to obtain
- * @param fieldObj an instantiated object which defines field
- * @return the value of field in fieldObj
- * @throws IllegalArgumentException on any error
- */
- public static Object getFieldValue(Field field, Object fieldObj)
- throws IllegalArgumentException {
- try {
- boolean wasAccessible = field.isAccessible();
- field.setAccessible(true);
- try {
- return field.get(fieldObj);
- } finally {
- field.setAccessible(wasAccessible);
- }
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- /**
- * Returns a field on which field.get(...) can be called, even if the field
- * is private.
- *
- * @param aClass the class defining the desired field
- * @param fieldName the name of the desired field
- * @return a field that is accessible regardless of its modifiers
- * @throws IllegalArgumentException on any error
- */
- public static Field getAccessibleField(Class aClass, String fieldName)
- throws IllegalArgumentException {
- try {
- Field field = aClass.getDeclaredField(fieldName);
- field.setAccessible(true);
- return field;
- } catch (Exception e) {
- // NoSuchFieldException, SecurityException
- throw new IllegalArgumentException(e);
- }
- }