aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config/gson
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config/gson')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java26
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java26
2 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java
new file mode 100644
index 0000000..8efa0b7
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java
@@ -0,0 +1,26 @@
+package cc.polyfrost.oneconfig.config.gson;
+
+import cc.polyfrost.oneconfig.config.annotations.Exclude;
+import cc.polyfrost.oneconfig.config.annotations.NonProfileSpecific;
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
+
+public class NonProfileSpecificExclusionStrategy implements ExclusionStrategy {
+ /**
+ * @param f the field object that is under test
+ * @return true if the field should be ignored; otherwise false
+ */
+ @Override
+ public boolean shouldSkipField(FieldAttributes f) {
+ return f.getAnnotation(NonProfileSpecific.class) == null || f.getAnnotation(Exclude.class) != null;
+ }
+
+ /**
+ * @param clazz the class object that is under test
+ * @return true if the class should be ignored; otherwise false
+ */
+ @Override
+ public boolean shouldSkipClass(Class<?> clazz) {
+ return clazz.getAnnotation(Exclude.class) != null;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java b/src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java
new file mode 100644
index 0000000..c94e8bd
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java
@@ -0,0 +1,26 @@
+package cc.polyfrost.oneconfig.config.gson;
+
+import cc.polyfrost.oneconfig.config.annotations.Exclude;
+import cc.polyfrost.oneconfig.config.annotations.NonProfileSpecific;
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
+
+public class ProfileExclusionStrategy implements ExclusionStrategy {
+ /**
+ * @param f the field object that is under test
+ * @return true if the field should be ignored; otherwise false
+ */
+ @Override
+ public boolean shouldSkipField(FieldAttributes f) {
+ return f.getAnnotation(NonProfileSpecific.class) != null || f.getAnnotation(Exclude.class) != null;
+ }
+
+ /**
+ * @param clazz the class object that is under test
+ * @return true if the class should be ignored; otherwise false
+ */
+ @Override
+ public boolean shouldSkipClass(Class<?> clazz) {
+ return clazz.getAnnotation(NonProfileSpecific.class) != null || clazz.getAnnotation(Exclude.class) != null;
+ }
+}