aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config/gson/ProfileExclusionStrategy.java
blob: 0df63b04973dd3595125513896e6e81987e7cb27 (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
32
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 ProfileExclusionStrategy 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.getDeclaredClass().isAssignableFrom(Runnable.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;
    }
}