package net.ranides.assira.reflection.util;

import net.ranides.assira.reflection.IReflectiveException;
import net.ranides.assira.system.RuntimeUtils;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Member;

public class FReflectSupport6 implements ReflectUtils.IReflectSupport {

    @Override
    public boolean isStable() {
        return RuntimeUtils.getJavaVersion() <= 8;
    }

    @Override
    public boolean isAccessible(Member object) {
        return true;
    }

    @Override
    public <T extends AccessibleObject> T access(T object) {
        if( object.isAccessible() ) {
            return object;
        }
        try {
            RuntimeUtils.doPrivileged(() -> object.setAccessible(true));
        } catch(SecurityException cause) {
            throw new IReflectiveException(cause);
        }
        return object;
    }
}
