diff --git a/litool-core/src/main/java/io/leaderli/litool/core/type/MetaAnnotation.java b/litool-core/src/main/java/io/leaderli/litool/core/type/MetaAnnotation.java index 60bc10bc..80699751 100644 --- a/litool-core/src/main/java/io/leaderli/litool/core/type/MetaAnnotation.java +++ b/litool-core/src/main/java/io/leaderli/litool/core/type/MetaAnnotation.java @@ -71,10 +71,17 @@ public Lira> relatives(AnnotatedElement annotatedElement) .swap() // swap to human readable ) .assertTrue(a -> - // if the annotated-annotation with meta, and meta's metaFunction first generic-type is - // not same the annotated-annotation - TypeUtil.resolve2Parameterized(a._1.getClass(), MetaFunction.class).getActualClassArgument() - .filter(annotatedByMeta -> annotatedByMeta == a._2.annotationType()) + { + // if the annotated-annotation with meta, and meta's metaFunction first generic-type is + // not same the annotated-annotation + return TypeUtil.resolve2Parameterized(a._1.getClass(), MetaFunction.class).getActualClassArgument() + .filter(annotatedByMeta -> annotatedByMeta == a._2.annotationType()); + + }, a -> { + + String expect = TypeUtil.resolve2Parameterized(a._1.getClass(), MetaFunction.class).getActualClassArgument().get() + ""; + return "\r\nexpect:" + expect + "\r\nactual:" + a._2.annotationType(); + } ); } diff --git a/litool-core/src/main/java/io/leaderli/litool/core/type/ObjectPriority.java b/litool-core/src/main/java/io/leaderli/litool/core/type/ObjectPriority.java deleted file mode 100644 index f6263c9b..00000000 --- a/litool-core/src/main/java/io/leaderli/litool/core/type/ObjectPriority.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.leaderli.litool.core.type; - -/** - * 该类用于封装一个对象和一个优先级,方便进行优先级排序 - * - * @param 对象类型 - */ -public class ObjectPriority { - - - public final T object; - public final int priority; - - public ObjectPriority(T object, int priority) { - this.object = object; - this.priority = priority; - } - - @Override - public int hashCode() { - return object == null ? 0 : object.hashCode(); - } - - public T getObject() { - return object; - } - - public int getPriority() { - return priority; - } - - @Override - public boolean equals(Object obj) { - - if (obj instanceof ObjectPriority) { - Object compare = ((ObjectPriority) obj).object; - if (object == null) { - return compare == null; - } - return object.equals(compare); - } - return false; - } - - @Override - public String toString() { - return object + ":" + priority; - } -} diff --git a/litool-core/src/test/java/io/leaderli/litool/core/type/MetaAnnotationTest.java b/litool-core/src/test/java/io/leaderli/litool/core/type/MetaAnnotationTest.java new file mode 100644 index 00000000..ee98c197 --- /dev/null +++ b/litool-core/src/test/java/io/leaderli/litool/core/type/MetaAnnotationTest.java @@ -0,0 +1,54 @@ +package io.leaderli.litool.core.type; + +import io.leaderli.litool.core.meta.LiTuple; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.lang.annotation.*; + +class MetaAnnotationTest { + + + @Test + void test() { + + MetaAnnotation metaAnnotation = new MetaAnnotation<>(Meta.class, IntValue.class); + LiTuple tuple = metaAnnotation.relative(Bean.class).get(); + Assertions.assertEquals(A1.class, tuple._2.annotationType()); + tuple = metaAnnotation.relative(Bean2.class).get(); + Assertions.assertEquals(A1.class, tuple._2.annotationType()); + + } + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.ANNOTATION_TYPE}) + private @interface Meta { + Class value() default IntValue.class; + } + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE}) + @Meta + private @interface A1 { + + int value() default 0; + } + + private static class IntValue implements MetaFunction { + + @Override + public Integer apply(A1 a1, Integer integer) { + return a1.value(); + } + } + + @A1 + private static class Bean { + + } + + @A1(1) + private static class Bean2 { + + } +} diff --git a/litool-core/src/test/java/io/leaderli/litool/core/type/PrimitiveEnumTest.java b/litool-core/src/test/java/io/leaderli/litool/core/type/PrimitiveEnumTest.java index 0cd647b9..edf13da1 100644 --- a/litool-core/src/test/java/io/leaderli/litool/core/type/PrimitiveEnumTest.java +++ b/litool-core/src/test/java/io/leaderli/litool/core/type/PrimitiveEnumTest.java @@ -50,6 +50,13 @@ void isNumber() { Assertions.assertTrue(PrimitiveEnum.isNumber(1.0)); Assertions.assertTrue(PrimitiveEnum.isNumber(1.f)); Assertions.assertFalse(PrimitiveEnum.isNumber((Object) null)); + + Assertions.assertTrue(PrimitiveEnum.isNumber(int.class)); + Assertions.assertTrue(PrimitiveEnum.isNumber(Integer.class)); + + Assertions.assertFalse(PrimitiveEnum.isNumber(char.class)); + + Assertions.assertThrows(IllegalStateException.class, () -> PrimitiveEnum.CHAR.read("abc")); } @Test @@ -74,6 +81,15 @@ void get() throws NoSuchMethodException { Type get = TypeUtil.resolve(type, Supplier.class.getMethod("get").getGenericReturnType()); Assertions.assertSame(PrimitiveEnum.INT, PrimitiveEnum.get(get)); + for (PrimitiveEnum value : PrimitiveEnum.values()) { + Assertions.assertSame(value, PrimitiveEnum.get(value.wrapper)); + value.read(1); + value.read(null); + if (PrimitiveEnum.isNumber(value)) { + + Assertions.assertThrows(IllegalStateException.class, () -> value.read("abc")); + } + } } }