Skip to content

Commit

Permalink
πŸ’Žβ˜•
Browse files Browse the repository at this point in the history
  • Loading branch information
RawDiamondMC committed Oct 4, 2024
1 parent 8f97c73 commit e8c788e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,86 +1,55 @@
package band.kessoku.lib.base.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;

public final class ModifiersUtil {
private ModifiersUtil() {
}

/* === Common === */

public static boolean isPublic(Field field) {
public static boolean isPublic(Member field) {
return Modifier.isPublic(field.getModifiers());
}

public static boolean isPublic(Method method) {
return Modifier.isPublic(method.getModifiers());
}

public static boolean isStatic(Field field) {
public static boolean isStatic(Member field) {
return Modifier.isStatic(field.getModifiers());
}

public static boolean isStatic(Method method) {
return Modifier.isStatic(method.getModifiers());
}

/* === Common Combo === */

public static boolean isPublicAndStatic(Field field) {
public static boolean isPublicAndStatic(Member field) {
return isPublic(field) && isStatic(field);
}

public static boolean isPublicAndStatic(Method method) {
return isPublic(method) && isStatic(method);
}

public static boolean isPublicOrStatic(Field field, boolean shouldPublic, boolean shouldStatic) {
public static boolean isPublicOrStatic(Member field, boolean shouldPublic, boolean shouldStatic) {
return shouldPublic == isPublic(field) && shouldStatic == isStatic(field);
}

public static boolean isPublicOrStatic(Method method, boolean shouldPublic, boolean shouldStatic) {
return shouldPublic == isPublic(method) && shouldStatic == isStatic(method);
}

/* === Common End === */

/* === Data Object === */

public static boolean isVolatile(Field field) {
public static boolean isVolatile(Member field) {
return Modifier.isVolatile(field.getModifiers());
}

public static boolean isVolatile(Method method) {
return Modifier.isVolatile(method.getModifiers());
}

public static boolean isTransient(Field field) {
public static boolean isTransient(Member field) {
return Modifier.isTransient(field.getModifiers());
}

public static boolean isTransient(Method method) {
return Modifier.isTransient(method.getModifiers());
}

/* === Data Object End === */

/* === Low Usage Tools === */

public static boolean isFinal(Field field) {
public static boolean isFinal(Member field) {
return Modifier.isFinal(field.getModifiers());
}

public static boolean isFinal(Method method) {
return Modifier.isFinal(method.getModifiers());
}

public static boolean isProtected(Field field) {
public static boolean isProtected(Member field) {
return Modifier.isProtected(field.getModifiers());
}

public static boolean isProtected(Method method) {
return Modifier.isProtected(method.getModifiers());
}

/* === Low Usage Tools End === */
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
package band.kessoku.lib.base.reflect;

import org.apache.logging.log4j.core.util.ReflectionUtil;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;

public final class ReflectUtil {
public static void makeAccessible(Field field) {
ReflectionUtil.makeAccessible(field);
}

public static void makeAccessible(Method method) {
ReflectionUtil.makeAccessible(method);
private ReflectUtil() {
}

public static boolean isAssignableFrom(Field field, Class<?> ... clazzs) {
public static boolean isAssignableFrom(Field field, Class<?>... clazzs) {
var flag = Arrays.stream(clazzs).anyMatch(clazz -> !field.getType().isAssignableFrom(clazz));
return !flag;
}
Expand Down

0 comments on commit e8c788e

Please sign in to comment.