From e8c788ec5219cdb9cd4f2751c6c12a8175928481 Mon Sep 17 00:00:00 2001 From: RawDiamondMC Date: Fri, 4 Oct 2024 19:47:21 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=8E=E2=98=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/base/reflect/ModifiersUtil.java | 53 ++++--------------- .../kessoku/lib/base/reflect/ReflectUtil.java | 12 +---- 2 files changed, 13 insertions(+), 52 deletions(-) diff --git a/base/common/src/main/java/band/kessoku/lib/base/reflect/ModifiersUtil.java b/base/common/src/main/java/band/kessoku/lib/base/reflect/ModifiersUtil.java index 58bd6d3f..903be6c1 100644 --- a/base/common/src/main/java/band/kessoku/lib/base/reflect/ModifiersUtil.java +++ b/base/common/src/main/java/band/kessoku/lib/base/reflect/ModifiersUtil.java @@ -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 === */ } diff --git a/base/common/src/main/java/band/kessoku/lib/base/reflect/ReflectUtil.java b/base/common/src/main/java/band/kessoku/lib/base/reflect/ReflectUtil.java index ad8bd9cb..27db667e 100644 --- a/base/common/src/main/java/band/kessoku/lib/base/reflect/ReflectUtil.java +++ b/base/common/src/main/java/band/kessoku/lib/base/reflect/ReflectUtil.java @@ -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; }