aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config/gson/NonProfileSpecificExclusionStrategy.java
blob: e7732958200d4c091f9e52218e927772ef41679f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package cc.polyfrost.oneconfig.config.gson;

import cc.polyfrost.oneconfig.config.Config;
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 extends ExclusionUtils 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) {
        if (isSuperClassOf(f.getDeclaredClass(), Config.class)) return true;
        if (f.getAnnotation(NonProfileSpecific.class) == null) return true;
        Exclude exclude = f.getAnnotation(Exclude.class);
        return exclude != 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) {
        Exclude exclude = clazz.getAnnotation(Exclude.class);
        return exclude != null;
    }
}