From 1e18f6b61613869a0bbc603d000634ca6cdc0c5c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 15:23:32 +0800 Subject: [PATCH 001/180] Update ExecutableElementComparatorTest.java --- .../util/ExecutableElementComparatorTest.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/ExecutableElementComparatorTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/ExecutableElementComparatorTest.java index a9e734a3b..9ce38cd9f 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/ExecutableElementComparatorTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/ExecutableElementComparatorTest.java @@ -1,12 +1,11 @@ package io.microsphere.annotation.processor.util; import io.microsphere.annotation.processor.AbstractAnnotationProcessingTest; -import io.microsphere.annotation.processor.model.Model; import org.junit.jupiter.api.Test; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; -import java.util.Set; +import java.lang.reflect.Type; import static io.microsphere.annotation.processor.util.ExecutableElementComparator.INSTANCE; import static io.microsphere.annotation.processor.util.MethodUtils.findMethod; @@ -23,32 +22,38 @@ public class ExecutableElementComparatorTest extends AbstractAnnotationProcessin private final ExecutableElementComparator comparator = INSTANCE; - @Override - protected void addCompiledClasses(Set> compiledClasses) { - compiledClasses.add(Model.class); + @Test + public void testCompareOnSameMethods() { + String methodName = "toString"; + ExecutableElement method = getMethod(methodName); + assertEquals(0, comparator.compare(method, method)); } @Test - public void testCompare() { - TypeElement type = getTypeElement(Model.class); - // Test methods from java.lang.Object - // Object#toString() - String toStringMethodName = "toString"; - ExecutableElement toStringMethod = findMethod(type.asType(), toStringMethodName); - - String hashCodeMethodName = "hashCode"; - ExecutableElement hashCodeMethod = findMethod(type.asType(), hashCodeMethodName); - assertEquals(0, comparator.compare(toStringMethod, toStringMethod)); - assertEquals(0, comparator.compare(hashCodeMethod, hashCodeMethod)); - assertEquals(toStringMethodName.compareTo(hashCodeMethodName), comparator.compare(toStringMethod, hashCodeMethod)); + public void testCompareOnDifferentMethods() { + assertEquals("toString".compareTo("hashCode"), comparator.compare(getMethod("toString"), getMethod("hashCode"))); + } + @Test + public void testCompareOnOverloadMethods() { + // Integer#valueOf(int) | Integer#valueOf(String) + TypeElement typeElement = getTypeElement(Integer.class); + String methodName = "valueOf"; + assertEquals(int.class.getName().compareTo(String.class.getName()), comparator.compare(findMethod(typeElement, methodName, int.class), findMethod(typeElement, methodName, String.class))); + } + + @Test + public void testCompare() { // Object#equals - assertEquals(0, comparator.compare(findMethod(getTypeMirror(getClass()), "equals", Object.class), - findMethod(getTypeMirror(Object.class), "equals", Object.class))); + assertEquals(0, comparator.compare(getMethod("equals", Object.class), getMethod("equals", Object.class))); } @Override public boolean equals(Object object) { return super.equals(object); } + + private ExecutableElement getMethod(String methodName, Type... parameterTypes) { + return findMethod(testTypeElement, methodName, parameterTypes); + } } \ No newline at end of file From 116b2209dbd304ee33f3642a0a72552fec9688bd Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 15:25:28 +0800 Subject: [PATCH 002/180] Update LoggerUtils.java --- .../processor/util/LoggerUtils.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/LoggerUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/LoggerUtils.java index e93d167f5..40b36b851 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/LoggerUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/LoggerUtils.java @@ -32,32 +32,22 @@ public interface LoggerUtils { Logger LOGGER = getLogger("microsphere-annotation-processor"); static void trace(String format, Object... args) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(format, args); - } + LOGGER.trace(format, args); } static void debug(String format, Object... args) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(format, args); - } + LOGGER.debug(format, args); } static void info(String format, Object... args) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(format, args); - } + LOGGER.info(format, args); } static void warn(String format, Object... args) { - if (LOGGER.isWarnEnabled()) { - LOGGER.warn(format, args); - } + LOGGER.warn(format, args); } static void error(String format, Object... args) { - if (LOGGER.isErrorEnabled()) { - LOGGER.error(format, args); - } + LOGGER.error(format, args); } } From cc193574c11d96dd710581ae9b8c034ced10a912 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 15:33:50 +0800 Subject: [PATCH 003/180] Update FieldUtilsTest.java --- .../annotation/processor/util/FieldUtilsTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java index f9b9f6e6e..0965df871 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java @@ -163,6 +163,15 @@ public void testIsNonStaticField() { type = getTypeElement(Color.class); assertFalse(isNonStaticField(findField(type, "BLUE"))); + + } + + @Test + public void testIsNonStaticFieldOnStaticField() { + TypeElement type = getTypeElement(Color.class); + for (Color color : Color.values()) { + assertFalse(isNonStaticField(findField(type, color.name()))); + } } @Test From 97c86acee633756c0cf13b1d23c45b2e328ae2ef Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 16:05:43 +0800 Subject: [PATCH 004/180] Update FieldUtils.java --- .../annotation/processor/util/FieldUtils.java | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/FieldUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/FieldUtils.java index 83cdce076..b6a32541d 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/FieldUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/FieldUtils.java @@ -20,19 +20,19 @@ import javax.lang.model.element.Modifier; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; -import java.util.Collection; import java.util.List; import java.util.function.Predicate; -import java.util.stream.Collectors; +import static io.microsphere.annotation.processor.util.MemberUtils.getAllDeclaredMembers; import static io.microsphere.annotation.processor.util.MemberUtils.getDeclaredMembers; import static io.microsphere.annotation.processor.util.MemberUtils.hasModifiers; import static io.microsphere.annotation.processor.util.MemberUtils.matchesElementKind; -import static io.microsphere.annotation.processor.util.TypeUtils.getAllDeclaredTypes; import static io.microsphere.annotation.processor.util.TypeUtils.isEnumType; +import static io.microsphere.collection.CollectionUtils.isEmpty; import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY; import static io.microsphere.lang.function.Streams.filterAll; import static io.microsphere.lang.function.Streams.filterFirst; +import static io.microsphere.util.ArrayUtils.isNotEmpty; import static java.util.Collections.emptyList; import static javax.lang.model.element.ElementKind.ENUM_CONSTANT; import static javax.lang.model.element.ElementKind.FIELD; @@ -47,6 +47,14 @@ */ public interface FieldUtils { + static VariableElement getDeclaredField(Element element, String fieldName) { + return element == null ? null : getDeclaredField(element.asType(), fieldName); + } + + static VariableElement getDeclaredField(TypeMirror type, String fieldName) { + return filterFirst(findDeclaredFields(type, field -> fieldName.equals(field.getSimpleName().toString()))); + } + static List getDeclaredFields(Element element) { return findDeclaredFields(element, EMPTY_PREDICATE_ARRAY); } @@ -63,12 +71,20 @@ static List getAllDeclaredFields(TypeMirror type) { return findAllDeclaredFields(type, EMPTY_PREDICATE_ARRAY); } + static VariableElement findField(Element element, String fieldName) { + return element == null ? null : findField(element.asType(), fieldName); + } + + static VariableElement findField(TypeMirror type, String fieldName) { + return filterFirst(findAllDeclaredFields(type, field -> equalsFieldName(field, fieldName))); + } + static List findDeclaredFields(Element element, Predicate... fieldFilters) { return element == null ? emptyList() : findDeclaredFields(element.asType(), fieldFilters); } static List findDeclaredFields(TypeMirror type, Predicate... fieldFilters) { - return filterAll(fieldsIn(getDeclaredMembers(type)), fieldFilters); + return filterDeclaredFields(type, false, fieldFilters); } static List findAllDeclaredFields(Element element, Predicate... fieldFilters) { @@ -76,27 +92,29 @@ static List findAllDeclaredFields(Element element, Predicate findAllDeclaredFields(TypeMirror type, Predicate... fieldFilters) { - return getAllDeclaredTypes(type) - .stream() - .map(t -> findDeclaredFields(t, fieldFilters)) - .flatMap(Collection::stream) - .collect(Collectors.toList()); + return filterDeclaredFields(type, true, fieldFilters); } - static VariableElement getDeclaredField(Element element, String fieldName) { - return element == null ? null : getDeclaredField(element.asType(), fieldName); - } + static List filterDeclaredFields(TypeMirror type, boolean all, Predicate... fieldFilters) { + if (type == null) { + return emptyList(); + } - static VariableElement getDeclaredField(TypeMirror type, String fieldName) { - return filterFirst(findDeclaredFields(type, field -> fieldName.equals(field.getSimpleName().toString()))); - } + List declaredMembers = all ? getAllDeclaredMembers(type) : getDeclaredMembers(type); + if (isEmpty(declaredMembers)) { + return emptyList(); + } - static VariableElement findField(Element element, String fieldName) { - return element == null ? null : findField(element.asType(), fieldName); - } + List fields = fieldsIn(declaredMembers); + if (isEmpty(fields)) { + return emptyList(); + } - static VariableElement findField(TypeMirror type, String fieldName) { - return filterFirst(findAllDeclaredFields(type, field -> equals(field, fieldName))); + if (isNotEmpty(fieldFilters)) { + fields = filterAll(fields, fieldFilters); + } + + return isEmpty(fields) ? emptyList() : fields; } /** @@ -140,8 +158,7 @@ static List getAllNonStaticFields(Element element) { return element == null ? emptyList() : getAllNonStaticFields(element.asType()); } - static boolean equals(VariableElement field, CharSequence fieldName) { + static boolean equalsFieldName(VariableElement field, CharSequence fieldName) { return field != null && fieldName != null && field.getSimpleName().toString().equals(fieldName.toString()); } - } From e80a93d7b7fa75a302412d2dc26e45d87477aa72 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 16:05:45 +0800 Subject: [PATCH 005/180] Update FieldUtilsTest.java --- .../processor/util/FieldUtilsTest.java | 150 ++++++++++++++---- 1 file changed, 120 insertions(+), 30 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java index 0965df871..90e6f583c 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import static io.microsphere.annotation.processor.util.FieldUtils.equalsFieldName; import static io.microsphere.annotation.processor.util.FieldUtils.findAllDeclaredFields; import static io.microsphere.annotation.processor.util.FieldUtils.findDeclaredFields; import static io.microsphere.annotation.processor.util.FieldUtils.findField; @@ -42,6 +43,9 @@ import static io.microsphere.annotation.processor.util.FieldUtils.isEnumMemberField; import static io.microsphere.annotation.processor.util.FieldUtils.isField; import static io.microsphere.annotation.processor.util.FieldUtils.isNonStaticField; +import static io.microsphere.lang.function.Predicates.alwaysFalse; +import static io.microsphere.lang.function.Predicates.alwaysTrue; +import static java.util.Collections.emptyList; import static javax.lang.model.element.Modifier.FINAL; import static javax.lang.model.element.Modifier.PRIVATE; import static javax.lang.model.element.Modifier.PUBLIC; @@ -49,6 +53,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -59,6 +64,33 @@ */ public class FieldUtilsTest extends AbstractAnnotationProcessingTest { + @Test + public void testGetDeclaredField() { + TypeElement type = getTypeElement(Model.class); + testGetDeclaredField(type, "f", float.class); + testGetDeclaredField(type, "d", double.class); + testGetDeclaredField(type, "tu", TimeUnit.class); + testGetDeclaredField(type, "str", String.class); + testGetDeclaredField(type, "bi", BigInteger.class); + testGetDeclaredField(type, "bd", BigDecimal.class); + } + + @Test + public void testGetDeclaredFieldOnNotFound() { + TypeElement type = getTypeElement(Model.class); + assertNull(getDeclaredField(type, "b")); + assertNull(getDeclaredField(type, "s")); + assertNull(getDeclaredField(type, "i")); + assertNull(getDeclaredField(type, "l")); + assertNull(getDeclaredField(type, "z")); + } + + @Test + public void testGetDeclaredFieldOnNull() { + assertNull(getDeclaredField((Element) null, "z")); + assertNull(getDeclaredField((TypeMirror) null, "z")); + } + @Test public void testGetDeclaredFields() { TypeElement type = getTypeElement(Model.class); @@ -67,49 +99,25 @@ public void testGetDeclaredFields() { fields = getDeclaredFields(type.asType()); assertModelFields(fields); + } + @Test + public void testGetDeclaredFieldsOnNull() { assertTrue(getDeclaredFields((Element) null).isEmpty()); assertTrue(getDeclaredFields((TypeMirror) null).isEmpty()); - - fields = findDeclaredFields(type, f -> "f".equals(f.getSimpleName().toString())); - assertEquals(1, fields.size()); - assertEquals("f", fields.get(0).getSimpleName().toString()); } @Test public void testGetAllDeclaredFields() { TypeElement type = getTypeElement(Model.class); - List fields = getAllDeclaredFields(type); - assertModelAllFields(fields); - - assertTrue(getAllDeclaredFields((Element) null).isEmpty()); - assertTrue(getAllDeclaredFields((TypeMirror) null).isEmpty()); - - fields = findAllDeclaredFields(type, f -> "f".equals(f.getSimpleName().toString())); - assertEquals(1, fields.size()); - assertEquals("f", fields.get(0).getSimpleName().toString()); } @Test - public void testGetDeclaredField() { - TypeElement type = getTypeElement(Model.class); - testGetDeclaredField(type, "f", float.class); - testGetDeclaredField(type, "d", double.class); - testGetDeclaredField(type, "tu", TimeUnit.class); - testGetDeclaredField(type, "str", String.class); - testGetDeclaredField(type, "bi", BigInteger.class); - testGetDeclaredField(type, "bd", BigDecimal.class); - - assertNull(getDeclaredField(type, "b")); - assertNull(getDeclaredField(type, "s")); - assertNull(getDeclaredField(type, "i")); - assertNull(getDeclaredField(type, "l")); - assertNull(getDeclaredField(type, "z")); - - assertNull(getDeclaredField((Element) null, "z")); - assertNull(getDeclaredField((TypeMirror) null, "z")); + public void testGetAllDeclaredFieldsOnNull() { + assertTrue(getAllDeclaredFields((Element) null).isEmpty()); + assertTrue(getAllDeclaredFields((TypeMirror) null).isEmpty()); } @Test @@ -126,7 +134,11 @@ public void testFindField() { testFindField(type, "i", int.class); testFindField(type, "l", long.class); testFindField(type, "z", boolean.class); + } + @Test + public void testFindFieldOnNull() { + TypeElement type = getTypeElement(Model.class); assertNull(findField((Element) null, "f")); assertNull(findField((Element) null, null)); @@ -137,9 +149,52 @@ public void testFindField() { assertNull(findField(type.asType(), null)); } + @Test + public void testFindDeclaredFields() { + TypeElement type = getTypeElement(Model.class); + + List fields = findAllDeclaredFields(type, alwaysTrue()); + assertModelFields(fields); + + fields = findAllDeclaredFields(type, alwaysFalse()); + assertSame(emptyList(), fields); + + fields = findDeclaredFields(type, f -> "f".equals(f.getSimpleName().toString())); + assertEquals(1, fields.size()); + assertEquals("f", fields.get(0).getSimpleName().toString()); + } + + @Test + public void testFindDeclaredFieldsOnNull() { + assertSame(emptyList(), findDeclaredFields((Element) null, alwaysTrue())); + assertSame(emptyList(), findDeclaredFields((TypeMirror) null, alwaysTrue())); + } + + @Test + public void testFindAllDeclaredFields() { + TypeElement type = getTypeElement(Model.class); + + List fields = findAllDeclaredFields(type, alwaysTrue()); + assertModelAllFields(fields); + + fields = findAllDeclaredFields(type, alwaysFalse()); + assertSame(emptyList(), fields); + + fields = findAllDeclaredFields(type, f -> "f".equals(f.getSimpleName().toString())); + assertEquals(1, fields.size()); + assertEquals("f", fields.get(0).getSimpleName().toString()); + } + + @Test + public void testFindAllDeclaredFieldsOnNull() { + assertSame(emptyList(), findAllDeclaredFields((Element) null, alwaysTrue())); + assertSame(emptyList(), findAllDeclaredFields((TypeMirror) null, alwaysTrue())); + } + @Test public void testIsEnumField() { TypeElement type = getTypeElement(Color.class); + VariableElement field = findField(type, "RED"); assertTrue(isEnumMemberField(field)); @@ -202,6 +257,19 @@ public void testGetNonStaticFields() { assertTrue(getAllNonStaticFields((TypeMirror) null).isEmpty()); } + @Test + public void testGetNonStaticFieldsOnNull() { + assertTrue(getNonStaticFields((TypeMirror) null).isEmpty()); + assertTrue(getNonStaticFields((Element) null).isEmpty()); + } + + @Test + public void testGetNonStaticFieldsOnEnum() { + TypeElement type = getTypeElement(Color.class); + List fields = getNonStaticFields(type); + assertSame(emptyList(), fields); + } + @Test public void testGetAllNonStaticFields() { TypeElement type = getTypeElement(Model.class); @@ -216,6 +284,25 @@ public void testGetAllNonStaticFields() { assertTrue(getAllNonStaticFields((TypeMirror) null).isEmpty()); } + @Test + public void testEqualsFieldName() { + TypeElement type = getTypeElement(Model.class); + String fieldName = "f"; + VariableElement field = findField(type, fieldName); + assertTrue(equalsFieldName(field, fieldName)); + assertFalse(equalsFieldName(field, "d")); + } + + @Test + public void testEqualsFieldNameOnNull() { + TypeElement type = getTypeElement(Model.class); + String fieldName = "f"; + VariableElement field = findField(type, fieldName); + + assertFalse(equalsFieldName(null, "")); + assertFalse(equalsFieldName(field, null)); + } + private void assertModelFields(List fields) { assertEquals(6, fields.size()); assertEquals("d", fields.get(1).getSimpleName().toString()); @@ -243,6 +330,9 @@ private void assertModelAllFields(List fields) { private void testGetDeclaredField(TypeElement type, String fieldName, Type fieldType) { VariableElement field = getDeclaredField(type, fieldName); assertField(field, fieldName, fieldType); + + field = getDeclaredField(type.asType(), fieldName); + assertField(field, fieldName, fieldType); } private void testFindField(TypeElement type, String fieldName, Type fieldType) { From b93833eb125b1ecdd2e1b9849d5e35f5c8cdb13f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 16:09:05 +0800 Subject: [PATCH 006/180] Update FieldUtilsTest.java --- .../annotation/processor/util/FieldUtilsTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java index 90e6f583c..d64d2c016 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java @@ -25,6 +25,7 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; +import java.lang.annotation.ElementType; import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; @@ -154,7 +155,7 @@ public void testFindDeclaredFields() { TypeElement type = getTypeElement(Model.class); List fields = findAllDeclaredFields(type, alwaysTrue()); - assertModelFields(fields); + assertModelAllFields(fields); fields = findAllDeclaredFields(type, alwaysFalse()); assertSame(emptyList(), fields); @@ -265,7 +266,7 @@ public void testGetNonStaticFieldsOnNull() { @Test public void testGetNonStaticFieldsOnEnum() { - TypeElement type = getTypeElement(Color.class); + TypeElement type = getTypeElement(ElementType.class); List fields = getNonStaticFields(type); assertSame(emptyList(), fields); } From 69d5cb8bb0fdcd3aa74ffef539fb913786b55c81 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 16:20:10 +0800 Subject: [PATCH 007/180] Update FieldUtilsTest.java --- .../processor/util/FieldUtilsTest.java | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java index d64d2c016..cbdac0521 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java @@ -25,6 +25,7 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; +import java.io.Serializable; import java.lang.annotation.ElementType; import java.lang.reflect.Type; import java.math.BigDecimal; @@ -33,6 +34,7 @@ import java.util.concurrent.TimeUnit; import static io.microsphere.annotation.processor.util.FieldUtils.equalsFieldName; +import static io.microsphere.annotation.processor.util.FieldUtils.filterDeclaredFields; import static io.microsphere.annotation.processor.util.FieldUtils.findAllDeclaredFields; import static io.microsphere.annotation.processor.util.FieldUtils.findDeclaredFields; import static io.microsphere.annotation.processor.util.FieldUtils.findField; @@ -192,6 +194,50 @@ public void testFindAllDeclaredFieldsOnNull() { assertSame(emptyList(), findAllDeclaredFields((TypeMirror) null, alwaysTrue())); } + @Test + public void testFilterDeclaredFieldsOnNull() { + assertFilterDeclaredFieldsReturningEmptyList(null); + } + + @Test + public void testFilterDeclaredFields() { + TypeMirror type = getTypeMirror(Model.class); + List fields = filterDeclaredFields(type, true, alwaysTrue()); + assertModelAllFields(fields); + + fields = filterDeclaredFields(type, true, alwaysFalse()); + assertSame(emptyList(), fields); + + fields = filterDeclaredFields(type, false, alwaysTrue()); + assertModelFields(fields); + + fields = filterDeclaredFields(type, false, alwaysFalse()); + assertSame(emptyList(), fields); + } + + @Test + public void testFilterDeclaredFieldsOnNoDeclaredMembers() { + TypeMirror type = getTypeMirror(Serializable.class); + assertFilterDeclaredFieldsReturningEmptyList(type); + } + + @Test + public void testFilterDeclaredFieldsOnNoDeclaredFields() { + TypeMirror type = getTypeMirror(Object.class); + assertFilterDeclaredFieldsReturningEmptyList(type); + } + + private void assertFilterDeclaredFieldsReturningEmptyList(TypeMirror type) { + assertSame(emptyList(), filterDeclaredFields(type, true, alwaysTrue())); + assertSame(emptyList(), filterDeclaredFields(type, false, alwaysTrue())); + assertSame(emptyList(), filterDeclaredFields(type, true, alwaysFalse())); + assertSame(emptyList(), filterDeclaredFields(type, false, alwaysFalse())); + assertSame(emptyList(), filterDeclaredFields(type, true, null)); + assertSame(emptyList(), filterDeclaredFields(type, false, null)); + assertSame(emptyList(), filterDeclaredFields(type, true)); + assertSame(emptyList(), filterDeclaredFields(type, false)); + } + @Test public void testIsEnumField() { TypeElement type = getTypeElement(Color.class); @@ -219,7 +265,6 @@ public void testIsNonStaticField() { type = getTypeElement(Color.class); assertFalse(isNonStaticField(findField(type, "BLUE"))); - } @Test From 91f002a3bb9c032eb17d92c9ec403670ca24de86 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 16:26:47 +0800 Subject: [PATCH 008/180] Update FieldUtilsTest.java --- .../processor/util/FieldUtilsTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java index cbdac0521..a9f972bd7 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test; import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; @@ -46,6 +47,7 @@ import static io.microsphere.annotation.processor.util.FieldUtils.isEnumMemberField; import static io.microsphere.annotation.processor.util.FieldUtils.isField; import static io.microsphere.annotation.processor.util.FieldUtils.isNonStaticField; +import static io.microsphere.annotation.processor.util.MethodUtils.findMethod; import static io.microsphere.lang.function.Predicates.alwaysFalse; import static io.microsphere.lang.function.Predicates.alwaysTrue; import static java.util.Collections.emptyList; @@ -275,6 +277,15 @@ public void testIsNonStaticFieldOnStaticField() { } } + @Test + public void testIsNonStaticFieldOnMethod() { + TypeElement type = getTypeElement(Model.class); + ExecutableElement method = findMethod(type, "getF"); + for (VariableElement parameter : method.getParameters()) { + assertFalse(isNonStaticField(parameter)); + } + } + @Test public void testIsField() { TypeElement type = getTypeElement(Model.class); @@ -283,8 +294,19 @@ public void testIsField() { type = getTypeElement(Color.class); assertTrue(isField(findField(type, "BLUE"), PUBLIC, STATIC, FINAL)); + } + @Test + public void testIsFieldOnMethod() { + TypeElement type = getTypeElement(Model.class); + ExecutableElement method = findMethod(type, "getF"); + for (VariableElement parameter : method.getParameters()) { + assertFalse(isField(parameter)); + } + } + @Test + public void testIsFieldOnNull() { assertFalse(isField(null)); assertFalse(isField(null, PUBLIC, STATIC, FINAL)); } From a2476882d84ce5b7a7b596b19c5de2e4762ccd85 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 17:37:15 +0800 Subject: [PATCH 009/180] Update FieldUtilsTest.java --- .../annotation/processor/util/FieldUtilsTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java index a9f972bd7..07e6cfce3 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java @@ -264,9 +264,6 @@ public void testIsEnumField() { public void testIsNonStaticField() { TypeElement type = getTypeElement(Model.class); assertTrue(isNonStaticField(findField(type, "f"))); - - type = getTypeElement(Color.class); - assertFalse(isNonStaticField(findField(type, "BLUE"))); } @Test @@ -280,7 +277,7 @@ public void testIsNonStaticFieldOnStaticField() { @Test public void testIsNonStaticFieldOnMethod() { TypeElement type = getTypeElement(Model.class); - ExecutableElement method = findMethod(type, "getF"); + ExecutableElement method = findMethod(type, "setF", float.class); for (VariableElement parameter : method.getParameters()) { assertFalse(isNonStaticField(parameter)); } @@ -309,6 +306,9 @@ public void testIsFieldOnMethod() { public void testIsFieldOnNull() { assertFalse(isField(null)); assertFalse(isField(null, PUBLIC, STATIC, FINAL)); + + TypeElement type = getTypeElement(Model.class); + assertFalse(isField(findField(type, "f"), null)); } @Test From eb03dd9fc18d22e5983d7390b8587b7849ee0c2e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 18:26:03 +0800 Subject: [PATCH 010/180] Update TypeUtils.java --- .../io/microsphere/annotation/processor/util/TypeUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java index b72ef264e..6018e81e0 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java @@ -278,6 +278,10 @@ static List getAllTypeElementsOfInterfaces(TypeElement type) { return findAllTypeElementsOfInterfaces(type, EMPTY_PREDICATE_ARRAY); } + static List getTypeElements(TypeElement type) { + return getTypeElements(type, true, false, true, true); + } + static List getAllTypeElements(TypeElement type) { return getTypeElements(type, true, true, true, true); } From 30a833722bfea7025808ce049e45579a96fde681 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 18:26:06 +0800 Subject: [PATCH 011/180] Update TypeUtilsTest.java --- .../annotation/processor/util/TypeUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java index 064926f12..9a863b544 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java @@ -503,6 +503,12 @@ public void testGetAllTypeElementsOnNull() { assertTrue(getAllTypeElements(null).isEmpty()); } + @Test + public void testGetTypeElementsWithNoArgument() { + List typeElements = TypeUtils.getTypeElements(testTypeElement); + assertTypeElements(typeElements, SELF_TYPE_PLUS_SUPER_CLASS_PLUS_SUPER_INTERFACES); + } + @Test public void testGetTypeElements() { // true true true true : all types From dacebc499a623e35730762406a68ade8c0dea353 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 19:36:41 +0800 Subject: [PATCH 012/180] Update AnnotationUtils.java --- .../processor/util/AnnotationUtils.java | 186 ++++++++++++++---- 1 file changed, 149 insertions(+), 37 deletions(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java index 34d36b608..f633fbc75 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java @@ -22,6 +22,7 @@ import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; import javax.lang.model.type.ArrayType; import javax.lang.model.type.TypeMirror; import java.lang.annotation.Annotation; @@ -33,12 +34,17 @@ import java.util.Objects; import java.util.function.Predicate; +import static io.microsphere.annotation.processor.util.TypeUtils.getAllTypeElements; +import static io.microsphere.annotation.processor.util.TypeUtils.getTypeElement; +import static io.microsphere.annotation.processor.util.TypeUtils.getTypeElements; import static io.microsphere.annotation.processor.util.TypeUtils.isSameType; import static io.microsphere.annotation.processor.util.TypeUtils.isTypeElement; import static io.microsphere.annotation.processor.util.TypeUtils.ofTypeElement; +import static io.microsphere.collection.CollectionUtils.isEmpty; +import static io.microsphere.collection.CollectionUtils.size; import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY; -import static io.microsphere.lang.function.Streams.filterAll; -import static io.microsphere.lang.function.Streams.filterFirst; +import static io.microsphere.lang.function.Predicates.and; +import static io.microsphere.util.ArrayUtils.isNotEmpty; import static io.microsphere.util.ClassLoaderUtils.resolveClass; import static java.lang.Enum.valueOf; import static java.util.Collections.emptyList; @@ -53,111 +59,217 @@ public interface AnnotationUtils { static AnnotationMirror getAnnotation(AnnotatedConstruct annotatedConstruct, Class annotationClass) { - return annotationClass == null ? null : getAnnotation(annotatedConstruct, annotationClass.getTypeName()); + if (annotationClass == null || annotatedConstruct == null) { + return null; + } + return getAnnotation(annotatedConstruct, annotationClass.getName()); } static AnnotationMirror getAnnotation(AnnotatedConstruct annotatedConstruct, CharSequence annotationClassName) { + if (annotatedConstruct == null || annotationClassName == null) { + return null; + } List annotations = getAnnotations(annotatedConstruct, annotationClassName); return annotations.isEmpty() ? null : annotations.get(0); } static List getAnnotations(AnnotatedConstruct annotatedConstruct, Class annotationClass) { - return annotationClass == null ? emptyList() : getAnnotations(annotatedConstruct, annotationClass.getTypeName()); + if (annotatedConstruct == null || annotationClass == null) { + return emptyList(); + } + return getAnnotations(annotatedConstruct, annotationClass.getTypeName()); } static List getAnnotations(AnnotatedConstruct annotatedConstruct, CharSequence annotationClassName) { - return findAnnotations(annotatedConstruct, annotation -> isSameType(annotation.getAnnotationType(), annotationClassName)); + if (annotatedConstruct == null || annotationClassName == null) { + return emptyList(); + } + return findAnnotations(annotatedConstruct, annotation -> matchesAnnotationType(annotation, annotationClassName)); } static List getAnnotations(AnnotatedConstruct annotatedConstruct) { + if (annotatedConstruct == null) { + return emptyList(); + } return findAnnotations(annotatedConstruct, EMPTY_PREDICATE_ARRAY); } static List getAllAnnotations(TypeMirror type) { + if (type == null) { + return emptyList(); + } return getAllAnnotations(ofTypeElement(type)); } static List getAllAnnotations(Element element) { + if (element == null) { + return emptyList(); + } return findAllAnnotations(element, EMPTY_PREDICATE_ARRAY); } static List getAllAnnotations(TypeMirror type, Class annotationClass) { + if (type == null || annotationClass == null) { + return emptyList(); + } return getAllAnnotations(ofTypeElement(type), annotationClass); } static List getAllAnnotations(Element element, Class annotationClass) { - return element == null || annotationClass == null ? emptyList() : getAllAnnotations(element, annotationClass.getTypeName()); + if (element == null || annotationClass == null) { + return emptyList(); + } + return getAllAnnotations(element, annotationClass.getTypeName()); } static List getAllAnnotations(TypeMirror type, CharSequence annotationClassName) { + if (type == null || annotationClassName == null) { + return emptyList(); + } return getAllAnnotations(ofTypeElement(type), annotationClassName); } static List getAllAnnotations(Element element, CharSequence annotationClassName) { - return findAllAnnotations(element, annotation -> isSameType(annotation.getAnnotationType(), annotationClassName)); + if (element == null || annotationClassName == null) { + return emptyList(); + } + return findAllAnnotations(element, annotation -> matchesAnnotationType(annotation, annotationClassName)); } static List getAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType) { + if (processingEnv == null || annotatedType == null) { + return emptyList(); + } return findAllAnnotations(processingEnv, annotatedType, EMPTY_PREDICATE_ARRAY); } + static AnnotationMirror findAnnotation(TypeMirror type, Class annotationClass) { + if (type == null || annotationClass == null) { + return null; + } + return findAnnotation(type, annotationClass.getTypeName()); + } + + static AnnotationMirror findAnnotation(TypeMirror type, CharSequence annotationClassName) { + if (type == null || annotationClassName == null) { + return null; + } + return findAnnotation(ofTypeElement(type), annotationClassName); + } + + static AnnotationMirror findAnnotation(Element element, Class annotationClass) { + if (element == null || annotationClass == null) { + return null; + } + return findAnnotation(element, annotationClass.getTypeName()); + } + + static AnnotationMirror findAnnotation(Element element, CharSequence annotationClassName) { + if (element == null || annotationClassName == null) { + return null; + } + List annotations = findAllAnnotations(element, annotation -> matchesAnnotationType(annotation, annotationClassName)); + return isEmpty(annotations) ? null : annotations.get(0); + } + + static AnnotationMirror findMetaAnnotation(Element annotatedConstruct, CharSequence metaAnnotationClassName) { + if (annotatedConstruct == null || metaAnnotationClassName == null) { + return null; + } + + AnnotationMirror metaAnnotation = null; + + List annotations = getAllAnnotations(annotatedConstruct); + int size = size(annotations); + + for (int i = 0; i < size; i++) { + AnnotationMirror annotation = annotations.get(i); + if ((metaAnnotation = findAnnotation(annotation.getAnnotationType(), metaAnnotationClassName)) != null) { + break; + } + } + + return metaAnnotation; + } + + static boolean isAnnotationPresent(Element element, CharSequence annotationClassName) { + if (element == null || annotationClassName == null) { + return false; + } + return findAnnotation(element, annotationClassName) != null || findMetaAnnotation(element, annotationClassName) != null; + } + static List findAnnotations(AnnotatedConstruct annotatedConstruct, Predicate... annotationFilters) { + if (annotatedConstruct == null) { + return emptyList(); + } - AnnotatedConstruct actualAnnotatedConstruct = annotatedConstruct; + List annotations = (List) annotatedConstruct.getAnnotationMirrors(); + if (isEmpty(annotations)) { + return emptyList(); + } - if (annotatedConstruct instanceof TypeMirror) { - actualAnnotatedConstruct = ofTypeElement((TypeMirror) actualAnnotatedConstruct); + if (isNotEmpty(annotationFilters)) { + annotations = annotations.stream() + .filter(and(annotationFilters)) + .collect(toList()); } - return actualAnnotatedConstruct == null ? emptyList() : filterAll((List) actualAnnotatedConstruct.getAnnotationMirrors(), annotationFilters); + return annotations.isEmpty() ? emptyList() : annotations; } static List findAllAnnotations(TypeMirror type, Predicate... annotationFilters) { + if (type == null) { + return emptyList(); + } return findAllAnnotations(ofTypeElement(type), annotationFilters); } static List findAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType, Predicate... annotationFilters) { + if (processingEnv == null || annotatedType == null) { + return emptyList(); + } return annotatedType == null ? emptyList() : findAllAnnotations(processingEnv, annotatedType.getTypeName(), annotationFilters); } static List findAllAnnotations(ProcessingEnvironment processingEnv, CharSequence annotatedTypeName, Predicate... annotationFilters) { - return findAllAnnotations(TypeUtils.getTypeElement(processingEnv, annotatedTypeName), annotationFilters); + if (processingEnv == null || annotatedTypeName == null) { + return emptyList(); + } + return findAllAnnotations(getTypeElement(processingEnv, annotatedTypeName), annotationFilters); } static List findAllAnnotations(Element element, Predicate... annotationFilters) { - - List allAnnotations = isTypeElement(element) ? - TypeUtils.getAllTypeElements(ofTypeElement(element)) - .stream() - .map(AnnotationUtils::getAnnotations) - .flatMap(Collection::stream) - .collect(toList()) : element == null ? emptyList() : (List) element.getAnnotationMirrors(); - - return filterAll(allAnnotations, annotationFilters); - } - - static AnnotationMirror findAnnotation(TypeMirror type, Class annotationClass) { - return annotationClass == null ? null : findAnnotation(type, annotationClass.getTypeName()); + if (element == null) { + return emptyList(); + } + return filterAnnotations(element, true, annotationFilters); } - static AnnotationMirror findAnnotation(TypeMirror type, CharSequence annotationClassName) { - return findAnnotation(ofTypeElement(type), annotationClassName); + static List filterAnnotations(Element element, boolean all, Predicate... annotationFilters) { + if (isTypeElement(element)) { + return filterAnnotations((TypeElement) element, all, annotationFilters); + } + return findAnnotations(element, annotationFilters); } - static AnnotationMirror findAnnotation(Element element, Class annotationClass) { - return annotationClass == null ? null : findAnnotation(element, annotationClass.getTypeName()); - } + static List filterAnnotations(TypeElement typeElement, boolean all, Predicate... annotationFilters) { + List typeElements = all ? getAllTypeElements(typeElement) : getTypeElements(typeElement); - static AnnotationMirror findAnnotation(Element element, CharSequence annotationClassName) { - return filterFirst(findAllAnnotations(element, annotation -> isSameType(annotation.getAnnotationType(), annotationClassName))); - } + List annotations = typeElements.stream() + .map(AnnotationUtils::getAnnotations) + .flatMap(Collection::stream) + .filter(and(annotationFilters)) + .collect(toList()); - static AnnotationMirror findMetaAnnotation(Element annotatedConstruct, CharSequence metaAnnotationClassName) { - return annotatedConstruct == null ? null : getAnnotations(annotatedConstruct).stream().map(annotation -> findAnnotation(annotation.getAnnotationType(), metaAnnotationClassName)).filter(Objects::nonNull).findFirst().orElse(null); + return isEmpty(annotations) ? emptyList() : annotations; } - static boolean isAnnotationPresent(Element element, CharSequence annotationClassName) { - return findAnnotation(element, annotationClassName) != null || findMetaAnnotation(element, annotationClassName) != null; + static boolean matchesAnnotationType(AnnotationMirror annotationMirror, CharSequence annotationClassName) { + if (annotationMirror == null) { + return false; + } + return isSameType(annotationMirror.getAnnotationType(), annotationClassName); } static T getAttribute(AnnotationMirror annotation, String attributeName) { From e0507358fe52df45b355188e934e22cedb7ece91 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 19:36:43 +0800 Subject: [PATCH 013/180] Update AnnotationUtilsTest.java --- .../processor/util/AnnotationUtilsTest.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java index 60b04e7ed..48dbc07c2 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java @@ -34,7 +34,6 @@ import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Target; -import java.util.Iterator; import java.util.List; import static io.microsphere.annotation.processor.util.AnnotationUtils.findAllAnnotations; @@ -77,26 +76,25 @@ public void testGetAnnotationWithClassName() { @Test public void testGetAnnotationOnNull() { assertNull(getAnnotation(testTypeElement, (Class) null)); - assertNull(getAnnotation(testTypeElement, (String) null)); - assertNull(getAnnotation(testTypeElement.asType(), (Class) null)); - assertNull(getAnnotation(testTypeElement.asType(), (String) null)); - assertNull(getAnnotation(null, (Class) null)); - assertNull(getAnnotation(null, (String) null)); - assertNull(getAnnotation(null, (Class) null)); + } + + @Test + public void testGetAnnotationWithClassNameOnNull() { + assertNull(getAnnotation(testTypeElement, (String) null)); + assertNull(getAnnotation(testTypeElement.asType(), (String) null)); + assertNull(getAnnotation(null, (String) null)); assertNull(getAnnotation(null, (String) null)); } @Test public void testGetAnnotations() { List annotations = getAnnotations(testTypeElement); - Iterator iterator = annotations.iterator(); - assertEquals(2, annotations.size()); - assertEquals(Service.class.getName(), iterator.next().getAnnotationType().toString()); - assertEquals(ServiceMode.class.getName(), iterator.next().getAnnotationType().toString()); + assertEquals(Service.class.getName(), annotations.get(0).getAnnotationType().toString()); + assertEquals(ServiceMode.class.getName(), annotations.get(1).getAnnotationType().toString()); } @Test @@ -120,12 +118,15 @@ public void testGetAnnotationsWithAnnotationClassName() { @Test public void testGetAnnotationsOnNull() { assertTrue(getAnnotations(null, (Class) null).isEmpty()); - assertTrue(getAnnotations(null, (String) null).isEmpty()); assertTrue(getAnnotations(testTypeElement, (Class) null).isEmpty()); - assertTrue(getAnnotations(testTypeElement, (String) null).isEmpty()); - assertTrue(getAnnotations(null, Service.class).isEmpty()); - assertTrue(getAnnotations(null, Service.class.getTypeName()).isEmpty()); + } + + @Test + public void testGetAnnotationsWithAnnotationClassNameOnNull() { + assertTrue(getAnnotations(null, (String) null).isEmpty()); + assertTrue(getAnnotations(testTypeElement, (String) null).isEmpty()); + assertTrue(getAnnotations(null, Service.class.getName()).isEmpty()); } @Test @@ -195,6 +196,12 @@ public void testFindMetaAnnotation() { }); } + @Test + public void testFindMetaAnnotationOnNull() { + assertNull(findMetaAnnotation(null, null)); + assertNull(findMetaAnnotation(null, "test")); + } + @Test public void testGetAttribute() { assertEquals("testService", getAttribute(findAnnotation(testTypeElement, Service.class), "value")); @@ -244,19 +251,11 @@ private void assertGetAnnotations(Class annotationType) { List annotations = getAnnotations(testTypeElement, annotationType); assertEquals(1, annotations.size()); assertEquals(annotationType.getName(), annotations.get(0).getAnnotationType().toString()); - - annotations = getAnnotations(testTypeElement.asType(), annotationType); - assertEquals(1, annotations.size()); - assertEquals(annotationType.getName(), annotations.get(0).getAnnotationType().toString()); } private void assertGetAnnotations(String annotationClassName) { List annotations = getAnnotations(testTypeElement, annotationClassName); assertEquals(1, annotations.size()); assertEquals(annotationClassName, annotations.get(0).getAnnotationType().toString()); - - annotations = getAnnotations(testTypeElement.asType(), annotationClassName); - assertEquals(1, annotations.size()); - assertEquals(annotationClassName, annotations.get(0).getAnnotationType().toString()); } } From dc1bf65098ef441bba56e31243b79b9302dccf2b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 21:58:03 +0800 Subject: [PATCH 014/180] Update AbstractAnnotationProcessingTest.java --- .../AbstractAnnotationProcessingTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java index 64b4b49df..3fceb277a 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java @@ -22,8 +22,13 @@ import org.junit.jupiter.api.extension.ExtendWith; import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.AnnotatedConstruct; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; @@ -33,6 +38,7 @@ import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.function.Predicate; import static io.microsphere.annotation.processor.util.TypeUtils.ofDeclaredType; @@ -55,8 +61,12 @@ public abstract class AbstractAnnotationProcessingTest { protected static final Collection NULL_COLLECTION = null; + protected static final List NULL_LIST = null; + protected static final Element NULL_ELEMENT = null; + protected static final ElementKind NULL_ELEMENT_KIND = null; + protected static final Element[] EMPTY_ELEMENT_ARRAY = new Element[0]; protected static final Element[] NULL_ELEMENT_ARRAY = null; @@ -75,6 +85,24 @@ public abstract class AbstractAnnotationProcessingTest { protected static final String[] NULL_STRING_ARRAY = null; + protected static final Class NULL_CLASS = null; + + protected static final Class[] NULL_CLASS_ARRAY = null; + + protected static final AnnotatedConstruct NULL_ANNOTATED_CONSTRUCT = null; + + protected static final Predicate[] NULL_PREDICATE_ARRAY = null; + + protected static final VariableElement NULL_FIELD = null; + + protected static final Modifier NULL_MODIFIER = null; + + protected static final Modifier[] NULL_MODIFIER_ARRAY = null; + + protected static final ExecutableElement NULL_METHOD = null; + + protected static final ExecutableElement[] NULL_METHOD_ARRAY = null; + static ThreadLocal testInstanceHolder = new ThreadLocal<>(); protected ProcessingEnvironment processingEnv; From b84c9050571b498cd3043bc4191cf8f083de5599 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 21:58:06 +0800 Subject: [PATCH 015/180] Update AnnotationUtils.java --- .../processor/util/AnnotationUtils.java | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java index f633fbc75..9a729e547 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java @@ -59,7 +59,7 @@ public interface AnnotationUtils { static AnnotationMirror getAnnotation(AnnotatedConstruct annotatedConstruct, Class annotationClass) { - if (annotationClass == null || annotatedConstruct == null) { + if (annotatedConstruct == null || annotationClass == null) { return null; } return getAnnotation(annotatedConstruct, annotationClass.getName()); @@ -73,6 +73,13 @@ static AnnotationMirror getAnnotation(AnnotatedConstruct annotatedConstruct, Cha return annotations.isEmpty() ? null : annotations.get(0); } + static List getAnnotations(AnnotatedConstruct annotatedConstruct) { + if (annotatedConstruct == null) { + return emptyList(); + } + return findAnnotations(annotatedConstruct, EMPTY_PREDICATE_ARRAY); + } + static List getAnnotations(AnnotatedConstruct annotatedConstruct, Class annotationClass) { if (annotatedConstruct == null || annotationClass == null) { return emptyList(); @@ -87,13 +94,6 @@ static List getAnnotations(AnnotatedConstruct annotatedConstru return findAnnotations(annotatedConstruct, annotation -> matchesAnnotationType(annotation, annotationClassName)); } - static List getAnnotations(AnnotatedConstruct annotatedConstruct) { - if (annotatedConstruct == null) { - return emptyList(); - } - return findAnnotations(annotatedConstruct, EMPTY_PREDICATE_ARRAY); - } - static List getAllAnnotations(TypeMirror type) { if (type == null) { return emptyList(); @@ -225,6 +225,20 @@ static List findAllAnnotations(TypeMirror type, Predicate findAllAnnotations(TypeElement element, Predicate... annotationFilters) { + if (element == null) { + return emptyList(); + } + return filterAnnotations(element, true, annotationFilters); + } + + static List findAllAnnotations(Element element, Predicate... annotationFilters) { + if (element == null) { + return emptyList(); + } + return filterAnnotations(element, true, annotationFilters); + } + static List findAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType, Predicate... annotationFilters) { if (processingEnv == null || annotatedType == null) { return emptyList(); @@ -239,12 +253,6 @@ static List findAllAnnotations(ProcessingEnvironment processin return findAllAnnotations(getTypeElement(processingEnv, annotatedTypeName), annotationFilters); } - static List findAllAnnotations(Element element, Predicate... annotationFilters) { - if (element == null) { - return emptyList(); - } - return filterAnnotations(element, true, annotationFilters); - } static List filterAnnotations(Element element, boolean all, Predicate... annotationFilters) { if (isTypeElement(element)) { @@ -265,8 +273,15 @@ static List filterAnnotations(TypeElement typeElement, boolean return isEmpty(annotations) ? emptyList() : annotations; } + static boolean matchesAnnotationType(AnnotationMirror annotationMirror, Type annotationType) { + if (annotationMirror == null || annotationType == null) { + return false; + } + return matchesAnnotationType(annotationMirror, annotationType.getTypeName()); + } + static boolean matchesAnnotationType(AnnotationMirror annotationMirror, CharSequence annotationClassName) { - if (annotationMirror == null) { + if (annotationMirror == null || annotationClassName == null) { return false; } return isSameType(annotationMirror.getAnnotationType(), annotationClassName); From dd4097382523a458d09ee24232a0704a2281bba8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 21:58:08 +0800 Subject: [PATCH 016/180] Update TestServiceImpl.java --- .../annotation/processor/TestServiceImpl.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/TestServiceImpl.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/TestServiceImpl.java index 9bf49bbf1..91bc84d94 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/TestServiceImpl.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/TestServiceImpl.java @@ -16,7 +16,10 @@ */ package io.microsphere.annotation.processor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; +import org.springframework.context.ApplicationContext; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import javax.xml.ws.ServiceMode; @@ -30,6 +33,19 @@ @ServiceMode public class TestServiceImpl extends GenericTestService implements TestService, AutoCloseable, Serializable { + @Autowired + private ApplicationContext context; + + private Environment environment; + + public TestServiceImpl() { + this(null); + } + + public TestServiceImpl(@Autowired Environment environment) { + this.environment = environment; + } + @Override @Cacheable(cacheNames = {"cache-1", "cache-2"}) public String echo(String message) { From 28df7c922b0350159c4fa4dcfe1fa56e15982f79 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 21:58:10 +0800 Subject: [PATCH 017/180] Update AnnotationUtilsTest.java --- .../processor/util/AnnotationUtilsTest.java | 245 +++++++++++++----- 1 file changed, 186 insertions(+), 59 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java index 48dbc07c2..9dd56e93e 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java @@ -19,17 +19,20 @@ import io.microsphere.annotation.processor.AbstractAnnotationProcessingTest; import io.microsphere.annotation.processor.TestService; import io.microsphere.annotation.processor.TestServiceImpl; +import io.microsphere.annotation.processor.model.Model; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; -import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.xml.ws.ServiceMode; import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; @@ -45,14 +48,20 @@ import static io.microsphere.annotation.processor.util.AnnotationUtils.getAttribute; import static io.microsphere.annotation.processor.util.AnnotationUtils.getValue; import static io.microsphere.annotation.processor.util.AnnotationUtils.isAnnotationPresent; +import static io.microsphere.annotation.processor.util.AnnotationUtils.matchesAnnotationType; +import static io.microsphere.annotation.processor.util.FieldUtils.findField; import static io.microsphere.annotation.processor.util.MethodUtils.findMethod; import static io.microsphere.annotation.processor.util.MethodUtils.getAllDeclaredMethods; +import static io.microsphere.lang.function.Predicates.alwaysFalse; +import static io.microsphere.lang.function.Predicates.alwaysTrue; import static io.microsphere.util.ArrayUtils.ofArray; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; +import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -75,18 +84,16 @@ public void testGetAnnotationWithClassName() { @Test public void testGetAnnotationOnNull() { - assertNull(getAnnotation(testTypeElement, (Class) null)); - assertNull(getAnnotation(testTypeElement.asType(), (Class) null)); - assertNull(getAnnotation(null, (Class) null)); - assertNull(getAnnotation(null, (Class) null)); + assertNull(getAnnotation(testTypeElement, NULL_CLASS)); + assertNull(getAnnotation(testTypeElement.asType(), NULL_CLASS)); + assertNull(getAnnotation(NULL_ANNOTATED_CONSTRUCT, NULL_CLASS)); } @Test public void testGetAnnotationWithClassNameOnNull() { - assertNull(getAnnotation(testTypeElement, (String) null)); - assertNull(getAnnotation(testTypeElement.asType(), (String) null)); - assertNull(getAnnotation(null, (String) null)); - assertNull(getAnnotation(null, (String) null)); + assertNull(getAnnotation(testTypeElement, NULL_STRING)); + assertNull(getAnnotation(testTypeElement.asType(), NULL_STRING)); + assertNull(getAnnotation(NULL_ANNOTATED_CONSTRUCT, NULL_STRING)); } @Test @@ -97,12 +104,25 @@ public void testGetAnnotations() { assertEquals(ServiceMode.class.getName(), annotations.get(1).getAnnotationType().toString()); } + @Test + public void testGetAnnotationsOnNull() { + List annotations = getAnnotations(NULL_ANNOTATED_CONSTRUCT); + assertSame(emptyList(), annotations); + } + @Test public void testGetAnnotationsWithAnnotationType() { assertGetAnnotations(Service.class); assertGetAnnotations(ServiceMode.class); } + @Test + public void testGetAnnotationsWithAnnotationTypeOnNull() { + assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, NULL_CLASS).isEmpty()); + assertTrue(getAnnotations(testTypeElement, NULL_CLASS).isEmpty()); + assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, Service.class).isEmpty()); + } + @Test public void testGetAnnotationsWithAnnotationTypeOnNotFound() { List annotations = getAnnotations(testTypeElement, Override.class); @@ -115,78 +135,106 @@ public void testGetAnnotationsWithAnnotationClassName() { assertGetAnnotations(ServiceMode.class.getName()); } - @Test - public void testGetAnnotationsOnNull() { - assertTrue(getAnnotations(null, (Class) null).isEmpty()); - assertTrue(getAnnotations(testTypeElement, (Class) null).isEmpty()); - assertTrue(getAnnotations(null, Service.class).isEmpty()); - } - @Test public void testGetAnnotationsWithAnnotationClassNameOnNull() { - assertTrue(getAnnotations(null, (String) null).isEmpty()); - assertTrue(getAnnotations(testTypeElement, (String) null).isEmpty()); - assertTrue(getAnnotations(null, Service.class.getName()).isEmpty()); + assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, NULL_STRING).isEmpty()); + assertTrue(getAnnotations(testTypeElement, NULL_STRING).isEmpty()); + assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, Service.class.getName()).isEmpty()); } @Test public void testGetAllAnnotations() { - List annotations = getAllAnnotations(testTypeElement); assertEquals(3, annotations.size()); - annotations = findAllAnnotations(testTypeElement.asType(), annotation -> true); + annotations = getAllAnnotations(testTypeMirror); assertEquals(3, annotations.size()); + } - annotations = getAllAnnotations(processingEnv, TestServiceImpl.class); - assertEquals(3, annotations.size()); + @Test + public void testGetAllAnnotationsOnNull() { + assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT)); + assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR)); + } - annotations = getAllAnnotations(testTypeElement.asType(), Service.class); - assertEquals(1, annotations.size()); + @Test + public void testGetAllAnnotationsWithAnnotationType() { + List annotations = getAllAnnotations(testTypeElement, Override.class); + assertEquals(0, annotations.size()); - annotations = getAllAnnotations(testTypeElement, Override.class); + annotations = getAllAnnotations(testTypeMirror, Override.class); assertEquals(0, annotations.size()); - assertTrue(getAllAnnotations((Element) null, (Class) null).isEmpty()); - assertTrue(getAllAnnotations((TypeMirror) null, (String) null).isEmpty()); - assertTrue(getAllAnnotations((ProcessingEnvironment) null, (Class) null).isEmpty()); - assertTrue(findAllAnnotations((ProcessingEnvironment) null, (String) null).isEmpty()); + annotations = getAllAnnotations(testTypeElement, Service.class); + assertEquals(1, annotations.size()); - assertTrue(getAllAnnotations((Element) null).isEmpty()); - assertTrue(getAllAnnotations((TypeMirror) null).isEmpty()); - assertTrue(getAllAnnotations(processingEnv, (Class) null).isEmpty()); - assertTrue(findAllAnnotations(processingEnv, (String) null).isEmpty()); + annotations = getAllAnnotations(testTypeMirror, Service.class); + assertEquals(1, annotations.size()); + annotations = getAllAnnotations(processingEnv, TestServiceImpl.class); + assertEquals(3, annotations.size()); + } - assertTrue(getAllAnnotations(testTypeElement, (Class) null).isEmpty()); - assertTrue(getAllAnnotations(testTypeElement.asType(), (Class) null).isEmpty()); + @Test + public void testGetAllAnnotationsWithAnnotationTypeOnNull() { + assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT, NULL_CLASS)); + assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR, NULL_CLASS)); + assertSame(emptyList(), getAllAnnotations(NULL_PROCESSING_ENVIRONMENT, NULL_CLASS)); - assertTrue(getAllAnnotations(testTypeElement, (String) null).isEmpty()); - assertTrue(getAllAnnotations(testTypeElement.asType(), (String) null).isEmpty()); + assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT, Service.class)); + assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR, Service.class)); + assertSame(emptyList(), getAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class)); - assertTrue(getAllAnnotations((Element) null, Service.class).isEmpty()); - assertTrue(getAllAnnotations((TypeMirror) null, Service.class.getTypeName()).isEmpty()); + assertSame(emptyList(), getAllAnnotations(testTypeElement, NULL_CLASS)); + assertSame(emptyList(), getAllAnnotations(testTypeMirror, NULL_CLASS)); } + @Test + public void testGetAllAnnotationsWithAnnotationClassName() { + List annotations = getAllAnnotations(testTypeElement, Override.class.getName()); + assertEquals(0, annotations.size()); + + annotations = getAllAnnotations(testTypeMirror, Service.class.getName()); + assertEquals(1, annotations.size()); + } + + @Test + public void testGetAllAnnotationsWithAnnotationClassNameOnNull() { + assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT, NULL_STRING)); + assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR, NULL_STRING)); + + assertTrue(getAllAnnotations(NULL_ELEMENT, Service.class.getName()).isEmpty()); + assertTrue(getAllAnnotations(NULL_TYPE_MIRROR, Service.class.getName()).isEmpty()); + + assertSame(emptyList(), getAllAnnotations(testTypeElement, NULL_STRING)); + assertSame(emptyList(), getAllAnnotations(testTypeMirror, NULL_STRING)); + } @Test public void testFindAnnotation() { + assertFindAnnotation(Service.class); + assertFindAnnotation(Path.class); + } - assertEquals("org.springframework.stereotype.Service", findAnnotation(testTypeElement, Service.class).getAnnotationType().toString()); - assertEquals("javax.ws.rs.Path", findAnnotation(testTypeElement, Path.class).getAnnotationType().toString()); - assertEquals("javax.ws.rs.Path", findAnnotation(testTypeElement.asType(), Path.class).getAnnotationType().toString()); - assertEquals("javax.ws.rs.Path", findAnnotation(testTypeElement.asType(), Path.class.getTypeName()).getAnnotationType().toString()); + @Test + public void testFindAnnotationOnNotFound() { + assertNull(findAnnotation(testTypeMirror, Target.class)); + assertNull(findAnnotation(testTypeElement, Target.class)); + assertNull(findAnnotation(testTypeMirror, Override.class)); assertNull(findAnnotation(testTypeElement, Override.class)); + } - assertNull(findAnnotation((Element) null, (Class) null)); - assertNull(findAnnotation((Element) null, (String) null)); - assertNull(findAnnotation((TypeMirror) null, (Class) null)); - assertNull(findAnnotation((TypeMirror) null, (String) null)); - - assertNull(findAnnotation(testTypeElement, (Class) null)); - assertNull(findAnnotation(testTypeElement, (String) null)); - assertNull(findAnnotation(testTypeElement.asType(), (Class) null)); - assertNull(findAnnotation(testTypeElement.asType(), (String) null)); + @Test + public void testFindAnnotationOnNull() { + assertNull(findAnnotation(NULL_ELEMENT, NULL_CLASS)); + assertNull(findAnnotation(NULL_TYPE_MIRROR, NULL_CLASS)); + assertNull(findAnnotation(testTypeMirror, NULL_CLASS)); + assertNull(findAnnotation(testTypeElement, NULL_CLASS)); + + assertNull(findAnnotation(NULL_ELEMENT, NULL_STRING)); + assertNull(findAnnotation(NULL_TYPE_MIRROR, NULL_STRING)); + assertNull(findAnnotation(testTypeMirror, NULL_STRING)); + assertNull(findAnnotation(testTypeElement, NULL_STRING)); } @Test @@ -198,8 +246,79 @@ public void testFindMetaAnnotation() { @Test public void testFindMetaAnnotationOnNull() { - assertNull(findMetaAnnotation(null, null)); - assertNull(findMetaAnnotation(null, "test")); + assertNull(findMetaAnnotation(NULL_ELEMENT, NULL_STRING)); + assertNull(findMetaAnnotation(NULL_ELEMENT, "test")); + } + + @Test + public void testFindAllAnnotationsWithTypeMirror() { + List annotations = findAllAnnotations(testTypeMirror, alwaysTrue()); + assertEquals(3, annotations.size()); + + annotations = findAllAnnotations(testTypeMirror, alwaysFalse()); + assertSame(emptyList(), annotations); + } + + @Test + public void testFindAllAnnotationsWithTypeElement() { + List annotations = findAllAnnotations(testTypeElement, alwaysTrue()); + assertEquals(3, annotations.size()); + + annotations = findAllAnnotations(testTypeElement, alwaysFalse()); + assertSame(emptyList(), annotations); + } + + @Test + public void testFindAllAnnotationsWithMethod() { + ExecutableElement method = findMethod(testTypeElement, "echo", String.class); + + List annotations = findAllAnnotations(method, alwaysTrue()); + assertEquals(1, annotations.size()); + assertTrue(matchesAnnotationType(annotations.get(0), Cacheable.class)); + + method = findMethod(getTypeElement(TestService.class), "echo", String.class); + + annotations = findAllAnnotations(method); + assertEquals(1, annotations.size()); + assertTrue(matchesAnnotationType(annotations.get(0), GET.class)); + } + + @Test + public void testFindAllAnnotationsWithMethodParameters() { + ExecutableElement method = findMethod(getTypeElement(TestService.class), "echo", String.class); + List parameters = method.getParameters(); + assertEquals(1, parameters.size()); + + List annotations = findAllAnnotations(parameters.get(0), alwaysTrue()); + assertEquals(2, annotations.size()); + assertTrue(matchesAnnotationType(annotations.get(0), PathParam.class)); + assertTrue(matchesAnnotationType(annotations.get(1), DefaultValue.class)); + + method = findMethod(getTypeElement(TestService.class), "model", Model.class); + parameters = method.getParameters(); + assertEquals(1, parameters.size()); + + annotations = findAllAnnotations(parameters.get(0)); + assertEquals(1, annotations.size()); + assertTrue(matchesAnnotationType(annotations.get(0), PathParam.class)); + } + + @Test + public void testFindAllAnnotationsWithField() { + VariableElement field = findField(testTypeElement, "context"); + + List annotations = findAllAnnotations(field, alwaysTrue()); + assertEquals(1, annotations.size()); + assertTrue(matchesAnnotationType(annotations.get(0), Autowired.class)); + + field = findField(testTypeElement, "environment"); + annotations = findAllAnnotations(field, alwaysTrue()); + assertSame(emptyList(), annotations); + } + + @Test + public void testFindAllAnnotationsWithElementOnNull() { + assertSame(emptyList(), findAllAnnotations(NULL_ELEMENT, alwaysTrue())); } @Test @@ -208,8 +327,8 @@ public void testGetAttribute() { assertEquals("testService", getAttribute(findAnnotation(testTypeElement, Service.class).getElementValues(), "value")); assertEquals("/echo", getAttribute(findAnnotation(testTypeElement, Path.class), "value")); - assertNull(getAttribute(findAnnotation(testTypeElement, Path.class), null)); - assertNull(getAttribute(findAnnotation(testTypeElement, (Class) null), null)); + assertNull(getAttribute(findAnnotation(testTypeElement, Path.class), NULL_STRING)); + assertNull(getAttribute(findAnnotation(testTypeElement, NULL_CLASS), NULL_STRING)); ExecutableElement echoMethod = findMethod(testTypeElement, "echo", String.class); AnnotationMirror cacheableAnnotation = findAnnotation(echoMethod, Cacheable.class); @@ -236,6 +355,13 @@ public void testIsAnnotationPresent() { assertTrue(isAnnotationPresent(testTypeElement, "javax.ws.rs.Path")); } + private void assertFindAnnotation(Class annotationType) { + assertTrue(matchesAnnotationType(findAnnotation(testTypeMirror, annotationType), annotationType)); + assertTrue(matchesAnnotationType(findAnnotation(testTypeElement, annotationType), annotationType)); + assertTrue(matchesAnnotationType(findAnnotation(testTypeMirror, annotationType.getName()), annotationType)); + assertTrue(matchesAnnotationType(findAnnotation(testTypeElement, annotationType.getName()), annotationType)); + } + private void asserGetAnnotation(Class annotationClass) { AnnotationMirror serviceAnnotation = getAnnotation(testTypeElement, annotationClass); @@ -250,6 +376,7 @@ private void asserGetAnnotation(String annotationClassName) { private void assertGetAnnotations(Class annotationType) { List annotations = getAnnotations(testTypeElement, annotationType); assertEquals(1, annotations.size()); + assertTrue(matchesAnnotationType(annotations.get(0), annotationType)); assertEquals(annotationType.getName(), annotations.get(0).getAnnotationType().toString()); } From 9526a6fd9be346fe6bb4731bb0caa802cafd85e3 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 21:58:12 +0800 Subject: [PATCH 018/180] Update FieldUtilsTest.java --- .../processor/util/FieldUtilsTest.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java index 07e6cfce3..b0e014eba 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java @@ -21,7 +21,6 @@ import io.microsphere.annotation.processor.model.Model; import org.junit.jupiter.api.Test; -import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; @@ -50,6 +49,7 @@ import static io.microsphere.annotation.processor.util.MethodUtils.findMethod; import static io.microsphere.lang.function.Predicates.alwaysFalse; import static io.microsphere.lang.function.Predicates.alwaysTrue; +import static io.microsphere.util.StringUtils.EMPTY_STRING; import static java.util.Collections.emptyList; import static javax.lang.model.element.Modifier.FINAL; import static javax.lang.model.element.Modifier.PRIVATE; @@ -92,8 +92,8 @@ public void testGetDeclaredFieldOnNotFound() { @Test public void testGetDeclaredFieldOnNull() { - assertNull(getDeclaredField((Element) null, "z")); - assertNull(getDeclaredField((TypeMirror) null, "z")); + assertNull(getDeclaredField(NULL_ELEMENT, "z")); + assertNull(getDeclaredField(NULL_TYPE_MIRROR, "z")); } @Test @@ -108,8 +108,8 @@ public void testGetDeclaredFields() { @Test public void testGetDeclaredFieldsOnNull() { - assertTrue(getDeclaredFields((Element) null).isEmpty()); - assertTrue(getDeclaredFields((TypeMirror) null).isEmpty()); + assertTrue(getDeclaredFields(NULL_ELEMENT).isEmpty()); + assertTrue(getDeclaredFields(NULL_TYPE_MIRROR).isEmpty()); } @Test @@ -121,8 +121,8 @@ public void testGetAllDeclaredFields() { @Test public void testGetAllDeclaredFieldsOnNull() { - assertTrue(getAllDeclaredFields((Element) null).isEmpty()); - assertTrue(getAllDeclaredFields((TypeMirror) null).isEmpty()); + assertTrue(getAllDeclaredFields(NULL_ELEMENT).isEmpty()); + assertTrue(getAllDeclaredFields(NULL_TYPE_MIRROR).isEmpty()); } @Test @@ -144,14 +144,14 @@ public void testFindField() { @Test public void testFindFieldOnNull() { TypeElement type = getTypeElement(Model.class); - assertNull(findField((Element) null, "f")); - assertNull(findField((Element) null, null)); + assertNull(findField(NULL_ELEMENT, "f")); + assertNull(findField(NULL_ELEMENT, NULL_STRING)); - assertNull(findField((TypeMirror) null, "f")); - assertNull(findField((TypeMirror) null, null)); + assertNull(findField(NULL_TYPE_MIRROR, "f")); + assertNull(findField(NULL_TYPE_MIRROR, NULL_STRING)); - assertNull(findField(type, null)); - assertNull(findField(type.asType(), null)); + assertNull(findField(type, NULL_STRING)); + assertNull(findField(type.asType(), NULL_STRING)); } @Test @@ -171,8 +171,8 @@ public void testFindDeclaredFields() { @Test public void testFindDeclaredFieldsOnNull() { - assertSame(emptyList(), findDeclaredFields((Element) null, alwaysTrue())); - assertSame(emptyList(), findDeclaredFields((TypeMirror) null, alwaysTrue())); + assertSame(emptyList(), findDeclaredFields(NULL_ELEMENT, alwaysTrue())); + assertSame(emptyList(), findDeclaredFields(NULL_TYPE_MIRROR, alwaysTrue())); } @Test @@ -192,13 +192,13 @@ public void testFindAllDeclaredFields() { @Test public void testFindAllDeclaredFieldsOnNull() { - assertSame(emptyList(), findAllDeclaredFields((Element) null, alwaysTrue())); - assertSame(emptyList(), findAllDeclaredFields((TypeMirror) null, alwaysTrue())); + assertSame(emptyList(), findAllDeclaredFields(NULL_ELEMENT, alwaysTrue())); + assertSame(emptyList(), findAllDeclaredFields(NULL_TYPE_MIRROR, alwaysTrue())); } @Test public void testFilterDeclaredFieldsOnNull() { - assertFilterDeclaredFieldsReturningEmptyList(null); + assertFilterDeclaredFieldsReturningEmptyList(NULL_TYPE_MIRROR); } @Test @@ -234,8 +234,8 @@ private void assertFilterDeclaredFieldsReturningEmptyList(TypeMirror type) { assertSame(emptyList(), filterDeclaredFields(type, false, alwaysTrue())); assertSame(emptyList(), filterDeclaredFields(type, true, alwaysFalse())); assertSame(emptyList(), filterDeclaredFields(type, false, alwaysFalse())); - assertSame(emptyList(), filterDeclaredFields(type, true, null)); - assertSame(emptyList(), filterDeclaredFields(type, false, null)); + assertSame(emptyList(), filterDeclaredFields(type, true, NULL_PREDICATE_ARRAY)); + assertSame(emptyList(), filterDeclaredFields(type, false, NULL_PREDICATE_ARRAY)); assertSame(emptyList(), filterDeclaredFields(type, true)); assertSame(emptyList(), filterDeclaredFields(type, false)); } @@ -257,7 +257,7 @@ public void testIsEnumField() { field = findField(type, "f"); assertFalse(isEnumMemberField(field)); - assertFalse(isEnumMemberField(null)); + assertFalse(isEnumMemberField(NULL_FIELD)); } @Test @@ -304,11 +304,11 @@ public void testIsFieldOnMethod() { @Test public void testIsFieldOnNull() { - assertFalse(isField(null)); - assertFalse(isField(null, PUBLIC, STATIC, FINAL)); + assertFalse(isField(NULL_FIELD)); + assertFalse(isField(NULL_FIELD, PUBLIC, STATIC, FINAL)); TypeElement type = getTypeElement(Model.class); - assertFalse(isField(findField(type, "f"), null)); + assertFalse(isField(findField(type, "f"), NULL_MODIFIER_ARRAY)); } @Test @@ -321,14 +321,14 @@ public void testGetNonStaticFields() { fields = getNonStaticFields(type.asType()); assertModelFields(fields); - assertTrue(getAllNonStaticFields((Element) null).isEmpty()); - assertTrue(getAllNonStaticFields((TypeMirror) null).isEmpty()); + assertTrue(getAllNonStaticFields(NULL_ELEMENT).isEmpty()); + assertTrue(getAllNonStaticFields(NULL_TYPE_MIRROR).isEmpty()); } @Test public void testGetNonStaticFieldsOnNull() { - assertTrue(getNonStaticFields((TypeMirror) null).isEmpty()); - assertTrue(getNonStaticFields((Element) null).isEmpty()); + assertTrue(getNonStaticFields(NULL_TYPE_MIRROR).isEmpty()); + assertTrue(getNonStaticFields(NULL_ELEMENT).isEmpty()); } @Test @@ -348,8 +348,8 @@ public void testGetAllNonStaticFields() { fields = getAllNonStaticFields(type.asType()); assertModelAllFields(fields); - assertTrue(getAllNonStaticFields((Element) null).isEmpty()); - assertTrue(getAllNonStaticFields((TypeMirror) null).isEmpty()); + assertTrue(getAllNonStaticFields(NULL_ELEMENT).isEmpty()); + assertTrue(getAllNonStaticFields(NULL_TYPE_MIRROR).isEmpty()); } @Test @@ -367,8 +367,8 @@ public void testEqualsFieldNameOnNull() { String fieldName = "f"; VariableElement field = findField(type, fieldName); - assertFalse(equalsFieldName(null, "")); - assertFalse(equalsFieldName(field, null)); + assertFalse(equalsFieldName(NULL_FIELD, EMPTY_STRING)); + assertFalse(equalsFieldName(field, NULL_STRING)); } private void assertModelFields(List fields) { From 8aa4b498764247c7cbda6bc4692c819ec9f822ce Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 21:58:14 +0800 Subject: [PATCH 019/180] Update MemberUtilsTest.java --- .../processor/util/MemberUtilsTest.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java index 27df17e95..a22e13e61 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java @@ -42,6 +42,7 @@ import static io.microsphere.lang.function.Predicates.alwaysFalse; import static io.microsphere.lang.function.Predicates.alwaysTrue; import static java.util.Collections.emptyList; +import static javax.lang.model.element.ElementKind.FIELD; import static javax.lang.model.element.Modifier.PRIVATE; import static javax.lang.model.util.ElementFilter.fieldsIn; import static javax.lang.model.util.ElementFilter.methodsIn; @@ -69,24 +70,24 @@ protected void beforeTest() { @Test public void testMatchesElementKind() { assertTrue(matchesElementKind(echoMethod, ElementKind.METHOD)); - assertFalse(matchesElementKind(echoMethod, ElementKind.FIELD)); + assertFalse(matchesElementKind(echoMethod, FIELD)); } @Test public void testMatchesElementKindOnNull() { - assertFalse(matchesElementKind(null, ElementKind.FIELD)); - assertFalse(matchesElementKind(echoMethod, null)); + assertFalse(matchesElementKind(NULL_ELEMENT, FIELD)); + assertFalse(matchesElementKind(echoMethod, NULL_ELEMENT_KIND)); } @Test public void testIsPublicNonStatic() { - assertFalse(isPublicNonStatic(null)); + assertFalse(isPublicNonStatic(NULL_ELEMENT)); methodsIn(getDeclaredMembers(testTypeElement.asType())).forEach(method -> assertTrue(isPublicNonStatic(method))); } @Test public void testHasModifiers() { - assertFalse(hasModifiers(null)); + assertFalse(hasModifiers(NULL_ELEMENT)); List members = getAllDeclaredMembers(testTypeElement.asType()); List fields = fieldsIn(members); assertTrue(hasModifiers(fields.get(0), PRIVATE)); @@ -148,9 +149,9 @@ public void testFilterMembers() { @Test public void testFilterMembersOnNull() { - assertSame(emptyList(), filterMembers(null, alwaysTrue())); + assertSame(emptyList(), filterMembers(NULL_LIST, alwaysTrue())); List methods = ofList(echoMethod); - assertSame(methods, filterMembers(methods, null)); + assertSame(methods, filterMembers(methods, NULL_PREDICATE_ARRAY)); } @Test @@ -168,8 +169,8 @@ public void testMatchParameterTypes() { @Test public void testMatchParameterTypesOnNull() { - assertFalse(matchParameterTypes(null, String.class)); - assertFalse(matchParameterTypes(emptyList(), null)); + assertFalse(matchParameterTypes(NULL_LIST, String.class)); + assertFalse(matchParameterTypes(emptyList(), NULL_CLASS_ARRAY)); } @Test @@ -180,8 +181,8 @@ public void testMatchParameterTypeNames() { @Test public void testMatchParameterTypeNamesOnNull() { - assertFalse(matchParameterTypeNames(null, "java.lang.String")); - assertFalse(matchParameterTypeNames(emptyList(), null)); + assertFalse(matchParameterTypeNames(NULL_LIST, "java.lang.String")); + assertFalse(matchParameterTypeNames(emptyList(), NULL_STRING_ARRAY)); } private void assertFindDeclaredMembersOfModel() { From 479aa171eb67b60117dbf936f9fd8ce020901cb8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 21:58:16 +0800 Subject: [PATCH 020/180] Update MethodUtilsTest.java --- .../processor/util/MethodUtilsTest.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java index 159d765d5..eab0a8ef6 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java @@ -220,7 +220,7 @@ public void testIsMethod() { @Test public void testIsMethodOnNull() { - assertFalse(isMethod(null)); + assertFalse(isMethod(NULL_METHOD)); } @Test @@ -231,7 +231,7 @@ public void testIsPublicNonStaticMethod() { @Test public void testIsPublicNonStaticMethodOnNull() { - assertFalse(isPublicNonStaticMethod(null)); + assertFalse(isPublicNonStaticMethod(NULL_METHOD)); } @Test @@ -273,8 +273,8 @@ public void testFindMethod() { public void testFindMethodOnNull() { assertNull(findMethod(NULL_TYPE_ELEMENT, "toString")); assertNull(findMethod(NULL_TYPE_MIRROR, "toString")); - assertNull(findMethod(testTypeElement, null)); - assertNull(findMethod(testTypeMirror, null)); + assertNull(findMethod(testTypeElement, NULL_STRING)); + assertNull(findMethod(testTypeMirror, NULL_STRING)); assertNull(findMethod(testTypeElement, "toString", NULL_TYPE_ARRAY)); assertNull(findMethod(testTypeMirror, "toString", NULL_STRING_ARRAY)); } @@ -299,14 +299,14 @@ public void testFilterMethods() { @Test public void testFilterMethodsOnNull() { - assertSame(emptyList(), filterMethods(null, alwaysTrue())); - assertSame(emptyList(), filterMethods(null, null)); + assertSame(emptyList(), filterMethods(NULL_LIST, alwaysTrue())); + assertSame(emptyList(), filterMethods(NULL_LIST, NULL_PREDICATE_ARRAY)); } @Test public void testFilterMethodsOnEmpty() { assertSame(emptyList(), filterMethods(emptyList(), alwaysTrue())); - assertSame(emptyList(), filterMethods(emptyList(), null)); + assertSame(emptyList(), filterMethods(emptyList(), NULL_PREDICATE_ARRAY)); } @Test @@ -320,12 +320,12 @@ public void testFilterMethodsOnReturningEmptyList() { public void testGetMethodName() { ExecutableElement method = findMethod(testTypeElement, "echo", "java.lang.String"); assertEquals("echo", getMethodName(method)); - assertNull(getMethodName(null)); + assertNull(getMethodName(NULL_METHOD)); } @Test public void testGetMethodNameOnNull() { - assertNull(getMethodName(null)); + assertNull(getMethodName(NULL_METHOD)); } @Test @@ -336,7 +336,7 @@ public void testReturnTypeName() { @Test public void testReturnTypeNameOnNull() { - assertNull(getReturnTypeName(null)); + assertNull(getReturnTypeName(NULL_METHOD)); } @Test @@ -348,7 +348,7 @@ public void testMatchParameterTypeNames() { @Test public void testMatchParameterTypeNamesOnNull() { - assertSame(EMPTY_STRING_ARRAY, getMethodParameterTypeNames(null)); + assertSame(EMPTY_STRING_ARRAY, getMethodParameterTypeNames(NULL_METHOD)); } @Test @@ -363,7 +363,7 @@ public void testMatchParameterTypes() { @Test public void testMatchParameterTypesOnNull() { - assertSame(emptyList(), getMethodParameterTypeMirrors(null)); + assertSame(emptyList(), getMethodParameterTypeMirrors(NULL_METHOD)); } @Test @@ -393,11 +393,11 @@ public void testMatchesOnNull() { String[] parameterTypeNames = getTypeNames(parameterTypes); ExecutableElement method = findMethod(testTypeElement, methodName, parameterTypes); - assertFalse(matches(null, NULL_STRING, parameterTypes)); + assertFalse(matches(NULL_METHOD, NULL_STRING, parameterTypes)); assertFalse(matches(method, NULL_STRING, parameterTypes)); assertFalse(matches(method, methodName, NULL_TYPE_ARRAY)); - assertFalse(matches(null, NULL_STRING, parameterTypeNames)); + assertFalse(matches(NULL_METHOD, NULL_STRING, parameterTypeNames)); assertFalse(matches(method, NULL_STRING, parameterTypeNames)); assertFalse(matches(method, methodName, NULL_STRING_ARRAY)); } @@ -412,7 +412,7 @@ public void testGetEnclosingElement() { @Test public void testGetEnclosingElementOnNull() { - assertNull(getEnclosingElement(null)); + assertNull(getEnclosingElement(NULL_METHOD)); } private void assertFindMethod(Type type, String methodName, Type... parameterTypes) { From 8c8ed0241f43992e8cf4e2ce0f2971fb22b3850f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 28 Mar 2025 21:58:19 +0800 Subject: [PATCH 021/180] Update TypeUtilsTest.java --- .../processor/util/TypeUtilsTest.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java index 9a863b544..7a7e00ba0 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java @@ -213,7 +213,7 @@ public void testIsSimpleType() { @Test public void testIsSimpleTypeOnNull() { - assertFalse(isSimpleType((TypeElement) null)); + assertFalse(isSimpleType(NULL_TYPE_ELEMENT)); assertFalse(isSimpleType(NULL_TYPE_MIRROR)); } @@ -231,16 +231,16 @@ public void testIsSameTypeOnNull() { assertFalse(isSameType(NULL_ELEMENT, testClass)); assertFalse(isSameType(NULL_ELEMENT, testClassName)); - assertFalse(isSameType(testTypeElement, (Type) null)); - assertFalse(isSameType(testTypeElement, (String) null)); + assertFalse(isSameType(testTypeElement, NULL_TYPE)); + assertFalse(isSameType(testTypeElement, NULL_STRING)); - assertFalse(isSameType(testTypeMirror, (Type) null)); - assertFalse(isSameType(testTypeMirror, (String) null)); + assertFalse(isSameType(testTypeMirror, NULL_TYPE)); + assertFalse(isSameType(testTypeMirror, NULL_STRING)); - assertTrue(isSameType(NULL_TYPE_MIRROR, (Type) null)); - assertTrue(isSameType(NULL_TYPE_MIRROR, (String) null)); - assertTrue(isSameType(NULL_ELEMENT, (Type) null)); - assertTrue(isSameType(NULL_ELEMENT, (String) null)); + assertTrue(isSameType(NULL_TYPE_MIRROR, NULL_TYPE)); + assertTrue(isSameType(NULL_TYPE_MIRROR, NULL_STRING)); + assertTrue(isSameType(NULL_ELEMENT, NULL_TYPE)); + assertTrue(isSameType(NULL_ELEMENT, NULL_STRING)); } @Test @@ -456,7 +456,7 @@ public void testGetTypeElementOfSuperclass() { @Test public void testGetTypeElementOfSuperclassOnNull() { - assertNull(getTypeElementOfSuperclass(null)); + assertNull(getTypeElementOfSuperclass(NULL_TYPE_ELEMENT)); } @Test @@ -467,7 +467,7 @@ public void testGetAllTypeElementsOfSuperclasses() { @Test public void testGetAllTypeElementsOfSuperclassesOnNull() { - assertTrue(getAllTypeElementsOfSuperclasses(null).isEmpty()); + assertTrue(getAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT).isEmpty()); } @Test @@ -478,7 +478,7 @@ public void testGetTypeElementsOfInterfaces() { @Test public void testGetTypeElementsOfInterfacesOnNull() { - assertTrue(getTypeElementsOfInterfaces(null).isEmpty()); + assertTrue(getTypeElementsOfInterfaces(NULL_TYPE_ELEMENT).isEmpty()); } @Test @@ -489,7 +489,7 @@ public void testGetAllTypeElementsOfInterfaces() { @Test public void testGetAllTypeElementsOfInterfacesOnNull() { - assertTrue(getAllTypeElementsOfInterfaces(null).isEmpty()); + assertTrue(getAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT).isEmpty()); } @Test @@ -500,7 +500,7 @@ public void testGetAllTypeElements() { @Test public void testGetAllTypeElementsOnNull() { - assertTrue(getAllTypeElements(null).isEmpty()); + assertTrue(getAllTypeElements(NULL_TYPE_ELEMENT).isEmpty()); } @Test @@ -618,8 +618,8 @@ public void testFindAllTypeElementsOfSuperclasses() { @Test public void testFindAllTypeElementsOfSuperclassesOnNull() { - assertSame(emptyList(), findAllTypeElementsOfSuperclasses(null, alwaysTrue())); - assertSame(emptyList(), findAllTypeElementsOfSuperclasses(null, alwaysFalse())); + assertSame(emptyList(), findAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT, alwaysTrue())); + assertSame(emptyList(), findAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT, alwaysFalse())); } @Test @@ -633,8 +633,8 @@ public void testFindAllTypeElementsOfInterfaces() { @Test public void testFindAllTypeElementsOfInterfacesOnNull() { - assertSame(emptyList(), findAllTypeElementsOfInterfaces(null, alwaysTrue())); - assertSame(emptyList(), findAllTypeElementsOfInterfaces(null, alwaysFalse())); + assertSame(emptyList(), findAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysTrue())); + assertSame(emptyList(), findAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysFalse())); } @Test @@ -648,8 +648,8 @@ public void testFindTypeElementsOfInterfaces() { @Test public void testFindTypeElementsOfInterfacesOnNull() { - assertSame(emptyList(), findTypeElementsOfInterfaces(null, alwaysTrue())); - assertSame(emptyList(), findTypeElementsOfInterfaces(null, alwaysFalse())); + assertSame(emptyList(), findTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysTrue())); + assertSame(emptyList(), findTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysFalse())); } @Test @@ -1481,10 +1481,10 @@ public void testGetTypeElementOnType() { @Test public void testGetTypeElementOnNull() { - assertNull(TypeUtils.getTypeElement(processingEnv, (Type) null)); + assertNull(TypeUtils.getTypeElement(processingEnv, NULL_TYPE)); assertNull(TypeUtils.getTypeElement(processingEnv, NULL_TYPE_MIRROR)); - assertNull(TypeUtils.getTypeElement(processingEnv, (CharSequence) null)); - assertNull(TypeUtils.getTypeElement(null, (CharSequence) null)); + assertNull(TypeUtils.getTypeElement(processingEnv, NULL_STRING)); + assertNull(TypeUtils.getTypeElement(NULL_PROCESSING_ENVIRONMENT, NULL_STRING)); } @Test From 6d6ac3b6ab7a438f7788550ebd9c3ad0946f0b5e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 12:00:02 +0800 Subject: [PATCH 022/180] Update AnnotationUtils.java --- .../processor/util/AnnotationUtils.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java index 9a729e547..6b60bc839 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java @@ -44,6 +44,7 @@ import static io.microsphere.collection.CollectionUtils.size; import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY; import static io.microsphere.lang.function.Predicates.and; +import static io.microsphere.lang.function.Streams.filterAll; import static io.microsphere.util.ArrayUtils.isNotEmpty; import static io.microsphere.util.ClassLoaderUtils.resolveClass; import static java.lang.Enum.valueOf; @@ -172,6 +173,13 @@ static AnnotationMirror findAnnotation(Element element, CharSequence annotationC return isEmpty(annotations) ? null : annotations.get(0); } + static AnnotationMirror findMetaAnnotation(Element annotatedConstruct, Class metaAnnotationClass) { + if (annotatedConstruct == null || metaAnnotationClass == null) { + return null; + } + return findMetaAnnotation(annotatedConstruct, metaAnnotationClass.getName()); + } + static AnnotationMirror findMetaAnnotation(Element annotatedConstruct, CharSequence metaAnnotationClassName) { if (annotatedConstruct == null || metaAnnotationClassName == null) { return null; @@ -192,6 +200,13 @@ static AnnotationMirror findMetaAnnotation(Element annotatedConstruct, CharSeque return metaAnnotation; } + static boolean isAnnotationPresent(Element element, Class annotationClass) { + if (element == null || annotationClass == null) { + return false; + } + return findAnnotation(element, annotationClass) != null || findMetaAnnotation(element, annotationClass) != null; + } + static boolean isAnnotationPresent(Element element, CharSequence annotationClassName) { if (element == null || annotationClassName == null) { return false; @@ -210,9 +225,7 @@ static List findAnnotations(AnnotatedConstruct annotatedConstr } if (isNotEmpty(annotationFilters)) { - annotations = annotations.stream() - .filter(and(annotationFilters)) - .collect(toList()); + annotations = filterAll(annotations, annotationFilters); } return annotations.isEmpty() ? emptyList() : annotations; From 612fe7013d8bd8059521c1cc4bb1decd17b1828c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 12:00:04 +0800 Subject: [PATCH 023/180] Update AnnotationUtilsTest.java --- .../processor/util/AnnotationUtilsTest.java | 153 ++++++++++++++---- 1 file changed, 122 insertions(+), 31 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java index 9dd56e93e..6eaa29171 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java @@ -26,14 +26,17 @@ import org.springframework.stereotype.Service; import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; +import javax.ws.rs.HttpMethod; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.xml.ws.ServiceMode; +import java.io.Serializable; import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Target; @@ -41,6 +44,7 @@ import static io.microsphere.annotation.processor.util.AnnotationUtils.findAllAnnotations; import static io.microsphere.annotation.processor.util.AnnotationUtils.findAnnotation; +import static io.microsphere.annotation.processor.util.AnnotationUtils.findAnnotations; import static io.microsphere.annotation.processor.util.AnnotationUtils.findMetaAnnotation; import static io.microsphere.annotation.processor.util.AnnotationUtils.getAllAnnotations; import static io.microsphere.annotation.processor.util.AnnotationUtils.getAnnotation; @@ -60,6 +64,7 @@ import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -100,8 +105,8 @@ public void testGetAnnotationWithClassNameOnNull() { public void testGetAnnotations() { List annotations = getAnnotations(testTypeElement); assertEquals(2, annotations.size()); - assertEquals(Service.class.getName(), annotations.get(0).getAnnotationType().toString()); - assertEquals(ServiceMode.class.getName(), annotations.get(1).getAnnotationType().toString()); + assertAnnotation(annotations.get(0), Service.class); + assertAnnotation(annotations.get(1), ServiceMode.class); } @Test @@ -111,20 +116,20 @@ public void testGetAnnotationsOnNull() { } @Test - public void testGetAnnotationsWithAnnotationType() { + public void testGetAnnotationsWithAnnotationClass() { assertGetAnnotations(Service.class); assertGetAnnotations(ServiceMode.class); } @Test - public void testGetAnnotationsWithAnnotationTypeOnNull() { + public void testGetAnnotationsWithAnnotationClassOnNull() { assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, NULL_CLASS).isEmpty()); assertTrue(getAnnotations(testTypeElement, NULL_CLASS).isEmpty()); assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, Service.class).isEmpty()); } @Test - public void testGetAnnotationsWithAnnotationTypeOnNotFound() { + public void testGetAnnotationsWithAnnotationClassOnNotFound() { List annotations = getAnnotations(testTypeElement, Override.class); assertEquals(0, annotations.size()); } @@ -158,7 +163,7 @@ public void testGetAllAnnotationsOnNull() { } @Test - public void testGetAllAnnotationsWithAnnotationType() { + public void testGetAllAnnotationsWithAnnotationClass() { List annotations = getAllAnnotations(testTypeElement, Override.class); assertEquals(0, annotations.size()); @@ -176,7 +181,7 @@ public void testGetAllAnnotationsWithAnnotationType() { } @Test - public void testGetAllAnnotationsWithAnnotationTypeOnNull() { + public void testGetAllAnnotationsWithAnnotationClassOnNull() { assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT, NULL_CLASS)); assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR, NULL_CLASS)); assertSame(emptyList(), getAllAnnotations(NULL_PROCESSING_ENVIRONMENT, NULL_CLASS)); @@ -187,6 +192,7 @@ public void testGetAllAnnotationsWithAnnotationTypeOnNull() { assertSame(emptyList(), getAllAnnotations(testTypeElement, NULL_CLASS)); assertSame(emptyList(), getAllAnnotations(testTypeMirror, NULL_CLASS)); + assertSame(emptyList(), getAllAnnotations(processingEnv, NULL_CLASS)); } @Test @@ -238,16 +244,41 @@ public void testFindAnnotationOnNull() { } @Test - public void testFindMetaAnnotation() { + public void testFindMetaAnnotationWithAnnotationClass() { getAllDeclaredMethods(getTypeElement(TestService.class)).forEach(method -> { - assertEquals("javax.ws.rs.HttpMethod", findMetaAnnotation(method, "javax.ws.rs.HttpMethod").getAnnotationType().toString()); + assertFindMetaAnnotation(method, HttpMethod.class); }); } @Test - public void testFindMetaAnnotationOnNull() { + public void testFindMetaAnnotationWithAnnotationClassOnNotFound() { + assertNull(findMetaAnnotation(testTypeElement, Service.class)); + } + + @Test + public void testFindMetaAnnotationWithAnnotationClassNameOnNotFound() { + assertNull(findMetaAnnotation(testTypeElement, Service.class.getName())); + } + + @Test + public void testFindMetaAnnotationWithAnnotationClassOnNull() { + assertNull(findMetaAnnotation(NULL_ELEMENT, NULL_CLASS)); + assertNull(findMetaAnnotation(NULL_ELEMENT, Service.class)); + assertNull(findMetaAnnotation(testTypeElement, NULL_CLASS)); + } + + @Test + public void testFindMetaAnnotationWithAnnotationClassName() { + getAllDeclaredMethods(getTypeElement(TestService.class)).forEach(method -> { + assertFindMetaAnnotation(method, HttpMethod.class.getName()); + }); + } + + @Test + public void testFindMetaAnnotationWithAnnotationClassNameOnNull() { assertNull(findMetaAnnotation(NULL_ELEMENT, NULL_STRING)); assertNull(findMetaAnnotation(NULL_ELEMENT, "test")); + assertNull(findMetaAnnotation(testTypeElement, NULL_STRING)); } @Test @@ -274,13 +305,13 @@ public void testFindAllAnnotationsWithMethod() { List annotations = findAllAnnotations(method, alwaysTrue()); assertEquals(1, annotations.size()); - assertTrue(matchesAnnotationType(annotations.get(0), Cacheable.class)); + assertAnnotation(annotations.get(0), Cacheable.class); method = findMethod(getTypeElement(TestService.class), "echo", String.class); annotations = findAllAnnotations(method); assertEquals(1, annotations.size()); - assertTrue(matchesAnnotationType(annotations.get(0), GET.class)); + assertAnnotation(annotations.get(0), GET.class); } @Test @@ -291,8 +322,8 @@ public void testFindAllAnnotationsWithMethodParameters() { List annotations = findAllAnnotations(parameters.get(0), alwaysTrue()); assertEquals(2, annotations.size()); - assertTrue(matchesAnnotationType(annotations.get(0), PathParam.class)); - assertTrue(matchesAnnotationType(annotations.get(1), DefaultValue.class)); + assertAnnotation(annotations.get(0), PathParam.class); + assertAnnotation(annotations.get(1), DefaultValue.class); method = findMethod(getTypeElement(TestService.class), "model", Model.class); parameters = method.getParameters(); @@ -300,7 +331,7 @@ public void testFindAllAnnotationsWithMethodParameters() { annotations = findAllAnnotations(parameters.get(0)); assertEquals(1, annotations.size()); - assertTrue(matchesAnnotationType(annotations.get(0), PathParam.class)); + assertAnnotation(annotations.get(0), PathParam.class); } @Test @@ -309,7 +340,7 @@ public void testFindAllAnnotationsWithField() { List annotations = findAllAnnotations(field, alwaysTrue()); assertEquals(1, annotations.size()); - assertTrue(matchesAnnotationType(annotations.get(0), Autowired.class)); + assertAnnotation(annotations.get(0), Autowired.class); field = findField(testTypeElement, "environment"); annotations = findAllAnnotations(field, alwaysTrue()); @@ -349,40 +380,100 @@ public void testGetValue() { } @Test - public void testIsAnnotationPresent() { + public void testIsAnnotationPresentOnAnnotationClass() { + assertTrue(isAnnotationPresent(testTypeElement, Service.class)); + assertTrue(isAnnotationPresent(testTypeElement, ServiceMode.class)); + assertTrue(isAnnotationPresent(testTypeElement, Path.class)); + } + + @Test + public void testIsAnnotationPresentOnAnnotationClassOnNull() { + assertFalse(isAnnotationPresent(NULL_ELEMENT, Service.class)); + assertFalse(isAnnotationPresent(testTypeElement, NULL_CLASS)); + } + + @Test + public void testIsAnnotationPresentOnAnnotationClassName() { assertTrue(isAnnotationPresent(testTypeElement, "org.springframework.stereotype.Service")); assertTrue(isAnnotationPresent(testTypeElement, "javax.xml.ws.ServiceMode")); assertTrue(isAnnotationPresent(testTypeElement, "javax.ws.rs.Path")); } - private void assertFindAnnotation(Class annotationType) { - assertTrue(matchesAnnotationType(findAnnotation(testTypeMirror, annotationType), annotationType)); - assertTrue(matchesAnnotationType(findAnnotation(testTypeElement, annotationType), annotationType)); - assertTrue(matchesAnnotationType(findAnnotation(testTypeMirror, annotationType.getName()), annotationType)); - assertTrue(matchesAnnotationType(findAnnotation(testTypeElement, annotationType.getName()), annotationType)); + @Test + public void testIsAnnotationPresentOnAnnotationClassNameOnNull() { + assertFalse(isAnnotationPresent(NULL_ELEMENT, "org.springframework.stereotype.Service")); + assertFalse(isAnnotationPresent(testTypeElement, NULL_STRING)); + } + + @Test + public void testFindAnnotations() { + List annotations = findAnnotations(testTypeElement); + assertEquals(2, annotations.size()); + assertAnnotation(annotations.get(0), Service.class); + assertAnnotation(annotations.get(1), ServiceMode.class); + + annotations = findAnnotations(testTypeElement, alwaysTrue()); + assertEquals(2, annotations.size()); + assertAnnotation(annotations.get(0), Service.class); + assertAnnotation(annotations.get(1), ServiceMode.class); + + annotations = findAnnotations(testTypeElement, alwaysFalse()); + assertSame(emptyList(), annotations); + } + + @Test + public void testFindAnnotationsOnNotFound() { + assertSame(emptyList(), findAnnotations(getTypeElement(Serializable.class))); + } + + @Test + public void testFindAnnotationsOnNull() { + assertSame(emptyList(), findAnnotations(NULL_ELEMENT)); + } + + private void assertFindMetaAnnotation(Element element, Class annotationClass) { + assertAnnotation(findMetaAnnotation(element, annotationClass), annotationClass); } + private void assertFindMetaAnnotation(Element element, String annotationClassName) { + assertAnnotation(findMetaAnnotation(element, annotationClassName), annotationClassName); + } + + private void assertFindAnnotation(Class annotationClass) { + assertAnnotation(findAnnotation(testTypeMirror, annotationClass), annotationClass); + assertAnnotation(findAnnotation(testTypeElement, annotationClass), annotationClass); + assertAnnotation(findAnnotation(testTypeMirror, annotationClass.getName()), annotationClass); + assertAnnotation(findAnnotation(testTypeElement, annotationClass.getName()), annotationClass); + } private void asserGetAnnotation(Class annotationClass) { - AnnotationMirror serviceAnnotation = getAnnotation(testTypeElement, annotationClass); - assertEquals(annotationClass.getName(), serviceAnnotation.getAnnotationType().toString()); + AnnotationMirror annotation = getAnnotation(testTypeElement, annotationClass); + assertAnnotation(annotation, annotationClass); } private void asserGetAnnotation(String annotationClassName) { - AnnotationMirror serviceAnnotation = getAnnotation(testTypeElement, annotationClassName); - assertEquals(annotationClassName, serviceAnnotation.getAnnotationType().toString()); + AnnotationMirror annotation = getAnnotation(testTypeElement, annotationClassName); + assertAnnotation(annotation, annotationClassName); } - private void assertGetAnnotations(Class annotationType) { - List annotations = getAnnotations(testTypeElement, annotationType); + private void assertGetAnnotations(Class annotationClass) { + List annotations = getAnnotations(testTypeElement, annotationClass); assertEquals(1, annotations.size()); - assertTrue(matchesAnnotationType(annotations.get(0), annotationType)); - assertEquals(annotationType.getName(), annotations.get(0).getAnnotationType().toString()); + assertAnnotation(annotations.get(0), annotationClass); } private void assertGetAnnotations(String annotationClassName) { List annotations = getAnnotations(testTypeElement, annotationClassName); assertEquals(1, annotations.size()); - assertEquals(annotationClassName, annotations.get(0).getAnnotationType().toString()); + assertAnnotation(annotations.get(0), annotationClassName); + } + + private void assertAnnotation(AnnotationMirror annotationMirror, Class annotationClass) { + assertTrue(matchesAnnotationType(annotationMirror, annotationClass)); + assertAnnotation(annotationMirror, annotationClass.getName()); + } + + private void assertAnnotation(AnnotationMirror annotationMirror, String annotationClassName) { + assertEquals(annotationMirror.getAnnotationType().toString(), annotationClassName); } } From aa804c589c61650b3418f08391b8ae78f61040a1 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 12:48:02 +0800 Subject: [PATCH 024/180] Update AbstractAnnotationProcessingTest.java --- .../annotation/processor/AbstractAnnotationProcessingTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java index 3fceb277a..e07730bb8 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java @@ -23,6 +23,7 @@ import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.AnnotatedConstruct; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -103,6 +104,8 @@ public abstract class AbstractAnnotationProcessingTest { protected static final ExecutableElement[] NULL_METHOD_ARRAY = null; + protected static final AnnotationMirror NULL_ANNOTATION_MIRROR = null; + static ThreadLocal testInstanceHolder = new ThreadLocal<>(); protected ProcessingEnvironment processingEnv; From be65e3e07a74515e5f8dfd5bfa5bc66f224c2bdd Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 12:48:04 +0800 Subject: [PATCH 025/180] Update AnnotationUtils.java --- .../processor/util/AnnotationUtils.java | 59 +++++++++---------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java index 6b60bc839..f7d8aed46 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java @@ -36,14 +36,11 @@ import static io.microsphere.annotation.processor.util.TypeUtils.getAllTypeElements; import static io.microsphere.annotation.processor.util.TypeUtils.getTypeElement; -import static io.microsphere.annotation.processor.util.TypeUtils.getTypeElements; import static io.microsphere.annotation.processor.util.TypeUtils.isSameType; -import static io.microsphere.annotation.processor.util.TypeUtils.isTypeElement; import static io.microsphere.annotation.processor.util.TypeUtils.ofTypeElement; import static io.microsphere.collection.CollectionUtils.isEmpty; import static io.microsphere.collection.CollectionUtils.size; import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY; -import static io.microsphere.lang.function.Predicates.and; import static io.microsphere.lang.function.Streams.filterAll; import static io.microsphere.util.ArrayUtils.isNotEmpty; import static io.microsphere.util.ClassLoaderUtils.resolveClass; @@ -92,7 +89,7 @@ static List getAnnotations(AnnotatedConstruct annotatedConstru if (annotatedConstruct == null || annotationClassName == null) { return emptyList(); } - return findAnnotations(annotatedConstruct, annotation -> matchesAnnotationType(annotation, annotationClassName)); + return findAnnotations(annotatedConstruct, annotation -> matchesAnnotationClassName(annotation, annotationClassName)); } static List getAllAnnotations(TypeMirror type) { @@ -134,7 +131,7 @@ static List getAllAnnotations(Element element, CharSequence an if (element == null || annotationClassName == null) { return emptyList(); } - return findAllAnnotations(element, annotation -> matchesAnnotationType(annotation, annotationClassName)); + return findAllAnnotations(element, annotation -> matchesAnnotationClassName(annotation, annotationClassName)); } static List getAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType) { @@ -169,7 +166,7 @@ static AnnotationMirror findAnnotation(Element element, CharSequence annotationC if (element == null || annotationClassName == null) { return null; } - List annotations = findAllAnnotations(element, annotation -> matchesAnnotationType(annotation, annotationClassName)); + List annotations = findAllAnnotations(element, annotation -> matchesAnnotationClassName(annotation, annotationClassName)); return isEmpty(annotations) ? null : annotations.get(0); } @@ -242,21 +239,39 @@ static List findAllAnnotations(TypeElement element, Predicate< if (element == null) { return emptyList(); } - return filterAnnotations(element, true, annotationFilters); + List typeElements = getAllTypeElements(element); + + List annotations = typeElements.stream() + .map(AnnotationUtils::getAnnotations) + .flatMap(Collection::stream) + .collect(toList()); + + if (isNotEmpty(annotationFilters)) { + annotations = filterAll(annotations, annotationFilters); + } + + return isEmpty(annotations) ? emptyList() : annotations; } static List findAllAnnotations(Element element, Predicate... annotationFilters) { if (element == null) { return emptyList(); } - return filterAnnotations(element, true, annotationFilters); + + TypeElement typeElement = ofTypeElement(element); + + if (typeElement == null) { + return findAnnotations(element, annotationFilters); + } + + return findAllAnnotations(typeElement, annotationFilters); } static List findAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType, Predicate... annotationFilters) { if (processingEnv == null || annotatedType == null) { return emptyList(); } - return annotatedType == null ? emptyList() : findAllAnnotations(processingEnv, annotatedType.getTypeName(), annotationFilters); + return findAllAnnotations(processingEnv, annotatedType.getTypeName(), annotationFilters); } static List findAllAnnotations(ProcessingEnvironment processingEnv, CharSequence annotatedTypeName, Predicate... annotationFilters) { @@ -266,34 +281,14 @@ static List findAllAnnotations(ProcessingEnvironment processin return findAllAnnotations(getTypeElement(processingEnv, annotatedTypeName), annotationFilters); } - - static List filterAnnotations(Element element, boolean all, Predicate... annotationFilters) { - if (isTypeElement(element)) { - return filterAnnotations((TypeElement) element, all, annotationFilters); - } - return findAnnotations(element, annotationFilters); - } - - static List filterAnnotations(TypeElement typeElement, boolean all, Predicate... annotationFilters) { - List typeElements = all ? getAllTypeElements(typeElement) : getTypeElements(typeElement); - - List annotations = typeElements.stream() - .map(AnnotationUtils::getAnnotations) - .flatMap(Collection::stream) - .filter(and(annotationFilters)) - .collect(toList()); - - return isEmpty(annotations) ? emptyList() : annotations; - } - - static boolean matchesAnnotationType(AnnotationMirror annotationMirror, Type annotationType) { + static boolean matchesAnnotationClass(AnnotationMirror annotationMirror, Type annotationType) { if (annotationMirror == null || annotationType == null) { return false; } - return matchesAnnotationType(annotationMirror, annotationType.getTypeName()); + return matchesAnnotationClassName(annotationMirror, annotationType.getTypeName()); } - static boolean matchesAnnotationType(AnnotationMirror annotationMirror, CharSequence annotationClassName) { + static boolean matchesAnnotationClassName(AnnotationMirror annotationMirror, CharSequence annotationClassName) { if (annotationMirror == null || annotationClassName == null) { return false; } From 202d48d8463ecec8af8e1a0dff6ca84191fbbc28 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 12:48:06 +0800 Subject: [PATCH 026/180] Update AnnotationUtilsTest.java --- .../processor/util/AnnotationUtilsTest.java | 92 +++++++++++++++---- 1 file changed, 74 insertions(+), 18 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java index 6eaa29171..7815c689c 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import javax.lang.model.element.AnnotationMirror; @@ -38,7 +39,9 @@ import javax.xml.ws.ServiceMode; import java.io.Serializable; import java.lang.annotation.Annotation; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Target; import java.util.List; @@ -52,7 +55,7 @@ import static io.microsphere.annotation.processor.util.AnnotationUtils.getAttribute; import static io.microsphere.annotation.processor.util.AnnotationUtils.getValue; import static io.microsphere.annotation.processor.util.AnnotationUtils.isAnnotationPresent; -import static io.microsphere.annotation.processor.util.AnnotationUtils.matchesAnnotationType; +import static io.microsphere.annotation.processor.util.AnnotationUtils.matchesAnnotationClassName; import static io.microsphere.annotation.processor.util.FieldUtils.findField; import static io.microsphere.annotation.processor.util.MethodUtils.findMethod; import static io.microsphere.annotation.processor.util.MethodUtils.getAllDeclaredMethods; @@ -84,7 +87,7 @@ public void testGetAnnotation() { @Test public void testGetAnnotationWithClassName() { - asserGetAnnotation(Service.class.getName()); + asserGetAnnotation("org.springframework.stereotype.Service"); } @Test @@ -136,15 +139,15 @@ public void testGetAnnotationsWithAnnotationClassOnNotFound() { @Test public void testGetAnnotationsWithAnnotationClassName() { - assertGetAnnotations(Service.class.getName()); - assertGetAnnotations(ServiceMode.class.getName()); + assertGetAnnotations("org.springframework.stereotype.Service"); + assertGetAnnotations("javax.xml.ws.ServiceMode"); } @Test public void testGetAnnotationsWithAnnotationClassNameOnNull() { assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, NULL_STRING).isEmpty()); assertTrue(getAnnotations(testTypeElement, NULL_STRING).isEmpty()); - assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, Service.class.getName()).isEmpty()); + assertTrue(getAnnotations(NULL_ANNOTATED_CONSTRUCT, "org.springframework.stereotype.Service").isEmpty()); } @Test @@ -197,10 +200,10 @@ public void testGetAllAnnotationsWithAnnotationClassOnNull() { @Test public void testGetAllAnnotationsWithAnnotationClassName() { - List annotations = getAllAnnotations(testTypeElement, Override.class.getName()); + List annotations = getAllAnnotations(testTypeElement, "java.lang.Override"); assertEquals(0, annotations.size()); - annotations = getAllAnnotations(testTypeMirror, Service.class.getName()); + annotations = getAllAnnotations(testTypeMirror, "org.springframework.stereotype.Service"); assertEquals(1, annotations.size()); } @@ -209,8 +212,8 @@ public void testGetAllAnnotationsWithAnnotationClassNameOnNull() { assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT, NULL_STRING)); assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR, NULL_STRING)); - assertTrue(getAllAnnotations(NULL_ELEMENT, Service.class.getName()).isEmpty()); - assertTrue(getAllAnnotations(NULL_TYPE_MIRROR, Service.class.getName()).isEmpty()); + assertTrue(getAllAnnotations(NULL_ELEMENT, "org.springframework.stereotype.Service").isEmpty()); + assertTrue(getAllAnnotations(NULL_TYPE_MIRROR, "org.springframework.stereotype.Service").isEmpty()); assertSame(emptyList(), getAllAnnotations(testTypeElement, NULL_STRING)); assertSame(emptyList(), getAllAnnotations(testTypeMirror, NULL_STRING)); @@ -257,7 +260,7 @@ public void testFindMetaAnnotationWithAnnotationClassOnNotFound() { @Test public void testFindMetaAnnotationWithAnnotationClassNameOnNotFound() { - assertNull(findMetaAnnotation(testTypeElement, Service.class.getName())); + assertNull(findMetaAnnotation(testTypeElement, "org.springframework.stereotype.Service")); } @Test @@ -270,7 +273,7 @@ public void testFindMetaAnnotationWithAnnotationClassOnNull() { @Test public void testFindMetaAnnotationWithAnnotationClassName() { getAllDeclaredMethods(getTypeElement(TestService.class)).forEach(method -> { - assertFindMetaAnnotation(method, HttpMethod.class.getName()); + assertFindMetaAnnotation(method, "javax.ws.rs.HttpMethod"); }); } @@ -347,9 +350,58 @@ public void testFindAllAnnotationsWithField() { assertSame(emptyList(), annotations); } + @Test + public void testFindAllAnnotationsWithTypeMirrorOnNull() { + assertSame(emptyList(), findAllAnnotations(NULL_TYPE_MIRROR, alwaysTrue())); + assertSame(emptyList(), findAllAnnotations(NULL_TYPE_MIRROR, alwaysFalse())); + } + + @Test + public void testFindAllAnnotationsWithTypeElementOnNull() { + assertSame(emptyList(), findAllAnnotations(NULL_TYPE_ELEMENT, alwaysTrue())); + assertSame(emptyList(), findAllAnnotations(NULL_TYPE_ELEMENT, alwaysFalse())); + } + @Test public void testFindAllAnnotationsWithElementOnNull() { assertSame(emptyList(), findAllAnnotations(NULL_ELEMENT, alwaysTrue())); + assertSame(emptyList(), findAllAnnotations(NULL_ELEMENT, alwaysFalse())); + } + + @Test + public void testFindAllAnnotationsOnNull() { + assertSame(emptyList(), findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class, alwaysTrue())); + assertSame(emptyList(), findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class, alwaysTrue())); + assertSame(emptyList(), findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, "org.springframework.stereotype.Service", alwaysFalse())); + assertSame(emptyList(), findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, "org.springframework.stereotype.Service", alwaysFalse())); + assertSame(emptyList(), findAllAnnotations(processingEnv, NULL_TYPE, alwaysTrue())); + assertSame(emptyList(), findAllAnnotations(processingEnv, NULL_TYPE, alwaysFalse())); + assertSame(emptyList(), findAllAnnotations(processingEnv, NULL_STRING, alwaysTrue())); + assertSame(emptyList(), findAllAnnotations(processingEnv, NULL_STRING, alwaysFalse())); + } + + @Test + public void testMatchesAnnotationClass() { + AnnotationMirror annotation = findAnnotation(testTypeElement, Service.class); + assertTrue(AnnotationUtils.matchesAnnotationClass(annotation, Service.class)); + } + + @Test + public void testMatchesAnnotationClassOnNull() { + assertFalse(AnnotationUtils.matchesAnnotationClass(NULL_ANNOTATION_MIRROR, Service.class)); + assertFalse(AnnotationUtils.matchesAnnotationClass(findAnnotation(testTypeElement, Service.class), NULL_CLASS)); + } + + @Test + public void testMatchesAnnotationClassName() { + AnnotationMirror annotation = findAnnotation(testTypeElement, "org.springframework.stereotype.Service"); + assertTrue(matchesAnnotationClassName(annotation, "org.springframework.stereotype.Service")); + } + + @Test + public void testMatchesAnnotationClassNameOnNull() { + assertFalse(matchesAnnotationClassName(NULL_ANNOTATION_MIRROR, "org.springframework.stereotype.Service")); + assertFalse(matchesAnnotationClassName(findAnnotation(testTypeElement, "org.springframework.stereotype.Service"), NULL_STRING)); } @Test @@ -382,8 +434,10 @@ public void testGetValue() { @Test public void testIsAnnotationPresentOnAnnotationClass() { assertTrue(isAnnotationPresent(testTypeElement, Service.class)); + assertTrue(isAnnotationPresent(testTypeElement, Component.class)); assertTrue(isAnnotationPresent(testTypeElement, ServiceMode.class)); - assertTrue(isAnnotationPresent(testTypeElement, Path.class)); + assertTrue(isAnnotationPresent(testTypeElement, Inherited.class)); + assertTrue(isAnnotationPresent(testTypeElement, Documented.class)); } @Test @@ -395,8 +449,10 @@ public void testIsAnnotationPresentOnAnnotationClassOnNull() { @Test public void testIsAnnotationPresentOnAnnotationClassName() { assertTrue(isAnnotationPresent(testTypeElement, "org.springframework.stereotype.Service")); + assertTrue(isAnnotationPresent(testTypeElement, "org.springframework.stereotype.Component")); assertTrue(isAnnotationPresent(testTypeElement, "javax.xml.ws.ServiceMode")); - assertTrue(isAnnotationPresent(testTypeElement, "javax.ws.rs.Path")); + assertTrue(isAnnotationPresent(testTypeElement, "java.lang.annotation.Inherited")); + assertTrue(isAnnotationPresent(testTypeElement, "java.lang.annotation.Documented")); } @Test @@ -468,12 +524,12 @@ private void assertGetAnnotations(String annotationClassName) { assertAnnotation(annotations.get(0), annotationClassName); } - private void assertAnnotation(AnnotationMirror annotationMirror, Class annotationClass) { - assertTrue(matchesAnnotationType(annotationMirror, annotationClass)); - assertAnnotation(annotationMirror, annotationClass.getName()); + private void assertAnnotation(AnnotationMirror annotation, Class annotationClass) { + assertTrue(AnnotationUtils.matchesAnnotationClass(annotation, annotationClass)); + assertAnnotation(annotation, annotationClass.getName()); } - private void assertAnnotation(AnnotationMirror annotationMirror, String annotationClassName) { - assertEquals(annotationMirror.getAnnotationType().toString(), annotationClassName); + private void assertAnnotation(AnnotationMirror annotation, String annotationClassName) { + assertEquals(annotation.getAnnotationType().toString(), annotationClassName); } } From 6d21d28fb7e96b4cd23d0c56684bab014c1c2575 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 13:00:32 +0800 Subject: [PATCH 027/180] Update TypeUtils.java --- .../io/microsphere/annotation/processor/util/TypeUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java index 6018e81e0..88eabbf29 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java @@ -323,7 +323,7 @@ static List findTypeElements(TypeElement type, return emptyList(); } assertNoNullElements(typeFilters, () -> "Any element of 'typeFilters' array must not be null"); - return type == null ? emptyList() : typeElementFinder(type, includeSelf, includeHierarchicalTypes, includeSuperclass, includeSuperInterfaces).findTypes(typeFilters); + return typeElementFinder(type, includeSelf, includeHierarchicalTypes, includeSuperclass, includeSuperInterfaces).findTypes(typeFilters); } static DeclaredType getDeclaredTypeOfSuperclass(Element typeElement) { From 0f92718878840d636fcadf810440a3d6b1bbe684 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 13:00:34 +0800 Subject: [PATCH 028/180] Update TypeUtilsTest.java --- .../processor/util/TypeUtilsTest.java | 409 +++++++++--------- 1 file changed, 211 insertions(+), 198 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java index 7a7e00ba0..b3fc6c31c 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java @@ -94,6 +94,7 @@ import static io.microsphere.lang.function.Predicates.alwaysFalse; import static io.microsphere.lang.function.Predicates.alwaysTrue; import static io.microsphere.reflect.TypeUtils.getTypeNames; +import static io.microsphere.util.ArrayUtils.EMPTY_STRING_ARRAY; import static io.microsphere.util.ArrayUtils.combine; import static io.microsphere.util.ArrayUtils.length; import static io.microsphere.util.ArrayUtils.ofArray; @@ -391,14 +392,14 @@ public void testOfTypeMirrors() { @Test public void testOfTypeMirrorsOnNull() { - assertTrue(ofTypeMirrors(EMPTY_ELEMENT_ARRAY).isEmpty()); - assertTrue(ofTypeMirrors(NULL_COLLECTION).isEmpty()); + assertEmptyList(ofTypeMirrors(EMPTY_ELEMENT_ARRAY)); + assertEmptyList(ofTypeMirrors(NULL_COLLECTION)); } @Test public void testOfTypeMirrorsOnEmpty() { - assertTrue(ofTypeMirrors(EMPTY_ELEMENT_ARRAY).isEmpty()); - assertTrue(ofTypeMirrors(emptyList()).isEmpty()); + assertEmptyList(ofTypeMirrors(EMPTY_ELEMENT_ARRAY)); + assertEmptyList(ofTypeMirrors(emptyList())); } @Test @@ -408,14 +409,14 @@ public void testOfTypeElements() { @Test public void testOfTypeElementsOnNull() { - assertTrue(ofTypeElements(NULL_TYPE_MIRROR_ARRAY).isEmpty()); - assertTrue(ofTypeElements(NULL_COLLECTION).isEmpty()); + assertEmptyList(ofTypeElements(NULL_TYPE_MIRROR_ARRAY)); + assertEmptyList(ofTypeElements(NULL_COLLECTION)); } @Test public void testOfTypeElementsOnEmpty() { - assertTrue(ofTypeElements(EMPTY_TYPE_MIRROR_ARRAY).isEmpty()); - assertTrue(ofTypeElements(emptyList()).isEmpty()); + assertEmptyList(ofTypeElements(EMPTY_TYPE_MIRROR_ARRAY)); + assertEmptyList(ofTypeElements(emptyList())); } @Test @@ -431,13 +432,13 @@ public void testOfDeclaredTypesWithFilter() { @Test public void testOfDeclaredTypesOnNull() { - assertTrue(ofDeclaredTypes(NULL_ELEMENT_ARRAY).isEmpty()); - assertTrue(ofDeclaredTypes(NULL_COLLECTION).isEmpty()); + assertEmptyList(ofDeclaredTypes(NULL_ELEMENT_ARRAY)); + assertEmptyList(ofDeclaredTypes(NULL_COLLECTION)); } @Test public void testOfDeclaredTypesOnEmpty() { - assertTrue(ofDeclaredTypes(emptyList()).isEmpty()); + assertEmptyList(ofDeclaredTypes(emptyList())); } @Test @@ -467,7 +468,7 @@ public void testGetAllTypeElementsOfSuperclasses() { @Test public void testGetAllTypeElementsOfSuperclassesOnNull() { - assertTrue(getAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT).isEmpty()); + assertEmptyList(getAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT)); } @Test @@ -478,7 +479,7 @@ public void testGetTypeElementsOfInterfaces() { @Test public void testGetTypeElementsOfInterfacesOnNull() { - assertTrue(getTypeElementsOfInterfaces(NULL_TYPE_ELEMENT).isEmpty()); + assertEmptyList(getTypeElementsOfInterfaces(NULL_TYPE_ELEMENT)); } @Test @@ -489,7 +490,7 @@ public void testGetAllTypeElementsOfInterfaces() { @Test public void testGetAllTypeElementsOfInterfacesOnNull() { - assertTrue(getAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT).isEmpty()); + assertEmptyList(getAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT)); } @Test @@ -500,7 +501,7 @@ public void testGetAllTypeElements() { @Test public void testGetAllTypeElementsOnNull() { - assertTrue(getAllTypeElements(NULL_TYPE_ELEMENT).isEmpty()); + assertEmptyList(getAllTypeElements(NULL_TYPE_ELEMENT)); } @Test @@ -562,7 +563,7 @@ public void testGetTypeElements() { // false true false false : nothing typeElements = TypeUtils.getTypeElements(testTypeElement, false, true, false, false); assertTypeElements(typeElements); - assertSame(emptyList(), typeElements); + assertEmptyList(typeElements); // false false true true : super class + super interfaces typeElements = TypeUtils.getTypeElements(testTypeElement, false, false, true, true); @@ -581,30 +582,30 @@ public void testGetTypeElements() { // false false false false : nothing typeElements = TypeUtils.getTypeElements(testTypeElement, false, false, false, false); assertTypeElements(typeElements); - assertSame(emptyList(), typeElements); + assertEmptyList(typeElements); } @Test public void testGetTypeElementsOnNull() { - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, true, true, true).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, true, true, false).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, true, false, true).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, true, false, false).isEmpty()); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, true, true, true)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, true, true, false)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, true, false, true)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, true, false, false)); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, false, true, true).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, true, false).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, false, true).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, false, false).isEmpty()); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, true, false, true, true)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, true, false)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, false, true)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, false, false)); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, true, true, true).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, true, true, false).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, true, false, true).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, true, false, false).isEmpty()); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, true, true, true)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, true, true, false)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, true, false, true)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, true, false, false)); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, true, true).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, true, false).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, false, true).isEmpty()); - assertTrue(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, false, false).isEmpty()); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, true, true)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, true, false)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, false, true)); + assertEmptyList(TypeUtils.getTypeElements(NULL_TYPE_ELEMENT, false, false, false, false)); } @Test @@ -613,13 +614,13 @@ public void testFindAllTypeElementsOfSuperclasses() { assertTypeElements(typeElements, ALL_SUPER_CLASSES); assertEquals(getAllTypeElementsOfSuperclasses(testTypeElement), typeElements); - assertSame(emptyList(), findAllTypeElementsOfSuperclasses(testTypeElement, alwaysFalse())); + assertEmptyList(findAllTypeElementsOfSuperclasses(testTypeElement, alwaysFalse())); } @Test public void testFindAllTypeElementsOfSuperclassesOnNull() { - assertSame(emptyList(), findAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT, alwaysFalse())); + assertEmptyList(findAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT, alwaysTrue())); + assertEmptyList(findAllTypeElementsOfSuperclasses(NULL_TYPE_ELEMENT, alwaysFalse())); } @Test @@ -628,13 +629,13 @@ public void testFindAllTypeElementsOfInterfaces() { assertTypeElements(typeElements, ALL_SUPER_INTERFACES); assertEquals(getAllTypeElementsOfInterfaces(testTypeElement), typeElements); - assertSame(emptyList(), findAllTypeElementsOfInterfaces(testTypeElement, alwaysFalse())); + assertEmptyList(findAllTypeElementsOfInterfaces(testTypeElement, alwaysFalse())); } @Test public void testFindAllTypeElementsOfInterfacesOnNull() { - assertSame(emptyList(), findAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysFalse())); + assertEmptyList(findAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysTrue())); + assertEmptyList(findAllTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysFalse())); } @Test @@ -643,13 +644,13 @@ public void testFindTypeElementsOfInterfaces() { assertTypeElements(typeElements, SUPER_INTERFACES); assertEquals(getTypeElementsOfInterfaces(testTypeElement), typeElements); - assertSame(emptyList(), findTypeElementsOfInterfaces(testTypeElement, alwaysFalse())); + assertEmptyList(findTypeElementsOfInterfaces(testTypeElement, alwaysFalse())); } @Test public void testFindTypeElementsOfInterfacesOnNull() { - assertSame(emptyList(), findTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysFalse())); + assertEmptyList(findTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysTrue())); + assertEmptyList(findTypeElementsOfInterfaces(NULL_TYPE_ELEMENT, alwaysFalse())); } @Test @@ -705,7 +706,7 @@ public void testFindTypeElements() { // false true false false : nothing typeElements = findTypeElements(testTypeElement, false, true, false, false, alwaysTrue()); assertTypeElements(typeElements); - assertSame(emptyList(), typeElements); + assertEmptyList(typeElements); // false false true true : super types typeElements = findTypeElements(testTypeElement, false, false, true, true, alwaysTrue()); @@ -724,7 +725,7 @@ public void testFindTypeElements() { // false false false false : nothing typeElements = findTypeElements(testTypeElement, false, false, false, false, alwaysTrue()); assertTypeElements(typeElements); - assertSame(emptyList(), typeElements); + assertEmptyList(typeElements); } @Test @@ -755,8 +756,8 @@ public void testGetDeclaredTypesOfInterfaces() { @Test public void testGetDeclaredTypesOfInterfacesOnNull() { - assertTrue(getDeclaredTypesOfInterfaces(NULL_ELEMENT).isEmpty()); - assertTrue(getDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR).isEmpty()); + assertEmptyList(getDeclaredTypesOfInterfaces(NULL_ELEMENT)); + assertEmptyList(getDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR)); } @Test @@ -767,8 +768,8 @@ public void testGetAllDeclaredTypesOfSuperclasses() { @Test public void testGetAllDeclaredTypesOfSuperclassesOnNull() { - assertTrue(getAllDeclaredTypesOfSuperclasses(NULL_ELEMENT).isEmpty()); - assertTrue(getAllDeclaredTypesOfSuperclasses(NULL_TYPE_MIRROR).isEmpty()); + assertEmptyList(getAllDeclaredTypesOfSuperclasses(NULL_ELEMENT)); + assertEmptyList(getAllDeclaredTypesOfSuperclasses(NULL_TYPE_MIRROR)); } @Test @@ -779,8 +780,8 @@ public void testGetAllDeclaredTypesOfInterfaces() { @Test public void testGetAllDeclaredTypesOfInterfacesOnNull() { - assertTrue(getAllDeclaredTypesOfInterfaces(NULL_ELEMENT).isEmpty()); - assertTrue(getAllDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR).isEmpty()); + assertEmptyList(getAllDeclaredTypesOfInterfaces(NULL_ELEMENT)); + assertEmptyList(getAllDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR)); } @Test @@ -791,8 +792,8 @@ public void testGetAllDeclaredTypesOfSuperTypes() { @Test public void testGetAllDeclaredTypesOfSuperTypesOnNull() { - assertTrue(getAllDeclaredTypesOfSuperTypes(NULL_ELEMENT).isEmpty()); - assertTrue(getAllDeclaredTypesOfSuperTypes(NULL_TYPE_MIRROR).isEmpty()); + assertEmptyList(getAllDeclaredTypesOfSuperTypes(NULL_ELEMENT)); + assertEmptyList(getAllDeclaredTypesOfSuperTypes(NULL_TYPE_MIRROR)); } @Test @@ -803,8 +804,8 @@ public void testGetAllDeclaredTypes() { @Test public void testGetAllDeclaredTypesOnNull() { - assertTrue(getAllDeclaredTypes(NULL_ELEMENT).isEmpty()); - assertTrue(getAllDeclaredTypes(NULL_TYPE_MIRROR).isEmpty()); + assertEmptyList(getAllDeclaredTypes(NULL_ELEMENT)); + assertEmptyList(getAllDeclaredTypes(NULL_TYPE_MIRROR)); } @Test @@ -860,7 +861,7 @@ public void testGetDeclaredTypes() { // false true false false : nothing declaredTypes = getDeclaredTypes(testTypeElement, false, true, false, false); assertDeclaredTypes(declaredTypes); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); // false false true true : super class + super interfaces declaredTypes = getDeclaredTypes(testTypeElement, false, false, true, true); @@ -879,7 +880,7 @@ public void testGetDeclaredTypes() { // false false false false : nothing declaredTypes = getDeclaredTypes(testTypeElement, false, false, false, false); assertDeclaredTypes(declaredTypes); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); } @Test @@ -911,12 +912,20 @@ public void testFindDeclaredTypesWithExcludedTypes() { @Test public void testFindDeclaredTypesWithExcludedTypesOnNull() { - assertTrue(findDeclaredTypes(NULL_ELEMENT, NULL_TYPE_ARRAY).isEmpty()); - assertTrue(findDeclaredTypes(NULL_ELEMENT, EMPTY_TYPE_ARRAY).isEmpty()); - assertTrue(findDeclaredTypes(NULL_ELEMENT, ALL_TYPES).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, NULL_TYPE_ARRAY).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, EMPTY_TYPE_ARRAY).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, ALL_TYPES).isEmpty()); + assertEmptyList(findDeclaredTypes(NULL_ELEMENT, NULL_TYPE_ARRAY)); + assertEmptyList(findDeclaredTypes(NULL_ELEMENT, EMPTY_TYPE_ARRAY)); + assertEmptyList(findDeclaredTypes(NULL_ELEMENT, ALL_TYPES)); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, NULL_TYPE_ARRAY)); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, EMPTY_TYPE_ARRAY)); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, ALL_TYPES)); + } + + @Test + public void testFindDeclaredTypesWithExcludedTypeNamesOnNull() { + assertEmptyList(findDeclaredTypes(NULL_ELEMENT, NULL_STRING_ARRAY)); + assertEmptyList(findDeclaredTypes(NULL_ELEMENT, EMPTY_STRING_ARRAY)); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, NULL_STRING_ARRAY)); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, EMPTY_STRING_ARRAY)); } @Test @@ -925,15 +934,15 @@ public void testFindDeclaredTypesOfInterfaces() { assertDeclaredTypes(declaredTypes, SUPER_INTERFACES); declaredTypes = findDeclaredTypesOfInterfaces(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); } @Test public void testFindDeclaredTypesOfInterfacesOnNull() { - assertTrue(findDeclaredTypesOfInterfaces(NULL_ELEMENT, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypesOfInterfaces(NULL_ELEMENT, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR, alwaysTrue()).isEmpty()); + assertEmptyList(findDeclaredTypesOfInterfaces(NULL_ELEMENT, alwaysTrue())); + assertEmptyList(findDeclaredTypesOfInterfaces(NULL_ELEMENT, alwaysFalse())); + assertEmptyList(findDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR, alwaysTrue())); } @Test @@ -942,15 +951,15 @@ public void testFindAllDeclaredTypesOfSuperclasses() { assertDeclaredTypes(declaredTypes, ALL_SUPER_CLASSES); declaredTypes = findAllDeclaredTypesOfSuperclasses(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); } @Test public void testFindAllDeclaredTypesOfSuperclassesOnNull() { - assertTrue(findAllDeclaredTypesOfSuperclasses(NULL_ELEMENT, alwaysTrue()).isEmpty()); - assertTrue(findAllDeclaredTypesOfSuperclasses(NULL_ELEMENT, alwaysFalse()).isEmpty()); - assertTrue(findAllDeclaredTypesOfSuperclasses(NULL_TYPE_MIRROR, alwaysTrue()).isEmpty()); - assertTrue(findAllDeclaredTypesOfSuperclasses(NULL_TYPE_MIRROR, alwaysFalse()).isEmpty()); + assertEmptyList(findAllDeclaredTypesOfSuperclasses(NULL_ELEMENT, alwaysTrue())); + assertEmptyList(findAllDeclaredTypesOfSuperclasses(NULL_ELEMENT, alwaysFalse())); + assertEmptyList(findAllDeclaredTypesOfSuperclasses(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findAllDeclaredTypesOfSuperclasses(NULL_TYPE_MIRROR, alwaysFalse())); } @Test @@ -959,15 +968,15 @@ public void testFindAllDeclaredTypesOfInterfaces() { assertDeclaredTypes(declaredTypes, ALL_SUPER_INTERFACES); declaredTypes = findAllDeclaredTypesOfInterfaces(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); } @Test public void testFindAllDeclaredTypesOfInterfacesOnNull() { - assertTrue(findAllDeclaredTypesOfInterfaces(NULL_ELEMENT, alwaysTrue()).isEmpty()); - assertTrue(findAllDeclaredTypesOfInterfaces(NULL_ELEMENT, alwaysFalse()).isEmpty()); - assertTrue(findAllDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR, alwaysTrue()).isEmpty()); - assertTrue(findAllDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR, alwaysFalse()).isEmpty()); + assertEmptyList(findAllDeclaredTypesOfInterfaces(NULL_ELEMENT, alwaysTrue())); + assertEmptyList(findAllDeclaredTypesOfInterfaces(NULL_ELEMENT, alwaysFalse())); + assertEmptyList(findAllDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findAllDeclaredTypesOfInterfaces(NULL_TYPE_MIRROR, alwaysFalse())); } @Test @@ -976,13 +985,13 @@ public void testFindAllDeclaredTypesOfSuperTypes() { assertDeclaredTypes(declaredTypes, ALL_SUPER_TYPES); declaredTypes = findAllDeclaredTypesOfSuperTypes(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); } @Test public void testFindAllDeclaredTypesOfSuperTypesOnNull() { - assertTrue(findAllDeclaredTypesOfSuperTypes(NULL_ELEMENT).isEmpty()); - assertTrue(findAllDeclaredTypesOfSuperTypes(NULL_TYPE_MIRROR).isEmpty()); + assertEmptyList(findAllDeclaredTypesOfSuperTypes(NULL_ELEMENT)); + assertEmptyList(findAllDeclaredTypesOfSuperTypes(NULL_TYPE_MIRROR)); } @Test @@ -991,15 +1000,15 @@ public void testFindAllDeclaredTypes() { assertDeclaredTypes(declaredTypes, ALL_TYPES); declaredTypes = findAllDeclaredTypes(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); } @Test public void testFindAllDeclaredTypesOnNull() { - assertTrue(findAllDeclaredTypes(NULL_ELEMENT, alwaysTrue()).isEmpty()); - assertTrue(findAllDeclaredTypes(NULL_ELEMENT, alwaysFalse()).isEmpty()); - assertTrue(findAllDeclaredTypes(NULL_TYPE_MIRROR, alwaysTrue()).isEmpty()); - assertTrue(findAllDeclaredTypes(NULL_TYPE_MIRROR, alwaysFalse()).isEmpty()); + assertEmptyList(findAllDeclaredTypes(NULL_ELEMENT, alwaysTrue())); + assertEmptyList(findAllDeclaredTypes(NULL_ELEMENT, alwaysFalse())); + assertEmptyList(findAllDeclaredTypes(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findAllDeclaredTypes(NULL_TYPE_MIRROR, alwaysFalse())); } @Test @@ -1019,12 +1028,12 @@ public void testFindAllDeclaredTypesWithExcludedTypes() { @Test public void testFindAllDeclaredTypesWithExcludedTypesOnNull() { - assertTrue(findAllDeclaredTypes(NULL_ELEMENT, NULL_TYPE_ARRAY).isEmpty()); - assertTrue(findAllDeclaredTypes(NULL_ELEMENT, EMPTY_TYPE_ARRAY).isEmpty()); - assertTrue(findAllDeclaredTypes(NULL_ELEMENT, ALL_TYPES).isEmpty()); - assertTrue(findAllDeclaredTypes(NULL_TYPE_MIRROR, NULL_TYPE_ARRAY).isEmpty()); - assertTrue(findAllDeclaredTypes(NULL_TYPE_MIRROR, EMPTY_TYPE_ARRAY).isEmpty()); - assertTrue(findAllDeclaredTypes(NULL_TYPE_MIRROR, ALL_TYPES).isEmpty()); + assertEmptyList(findAllDeclaredTypes(NULL_ELEMENT, NULL_TYPE_ARRAY)); + assertEmptyList(findAllDeclaredTypes(NULL_ELEMENT, EMPTY_TYPE_ARRAY)); + assertEmptyList(findAllDeclaredTypes(NULL_ELEMENT, ALL_TYPES)); + assertEmptyList(findAllDeclaredTypes(NULL_TYPE_MIRROR, NULL_TYPE_ARRAY)); + assertEmptyList(findAllDeclaredTypes(NULL_TYPE_MIRROR, EMPTY_TYPE_ARRAY)); + assertEmptyList(findAllDeclaredTypes(NULL_TYPE_MIRROR, ALL_TYPES)); } @Test @@ -1080,7 +1089,7 @@ public void testFindDeclaredTypes() { // false true false false : nothing declaredTypes = findDeclaredTypes(testTypeElement, false, true, false, false, alwaysTrue()); assertDeclaredTypes(declaredTypes); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); // false false true true : super class + super interfaces declaredTypes = findDeclaredTypes(testTypeElement, false, false, true, true, alwaysTrue()); @@ -1099,90 +1108,90 @@ public void testFindDeclaredTypes() { // false false false false : nothing declaredTypes = findDeclaredTypes(testTypeElement, false, false, false, false, alwaysTrue()); assertDeclaredTypes(declaredTypes); - assertSame(emptyList(), declaredTypes); + assertEmptyList(declaredTypes); } @Test public void testFindDeclaredTypesOnNull() { - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, true, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, true, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, true, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, true, true, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, true, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, true, false, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, true, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, true, false, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, false, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, false, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, false, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, false, true, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, false, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, false, false, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, false, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, false, false, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, false, true, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, true, false, true, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, false, true, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, true, false, true, true, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, false, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, false, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, true, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, false, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, false, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, true, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, true, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, true, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, true, true, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, true, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, true, false, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, true, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, true, false, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, false, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, false, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, false, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, false, true, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, false, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, false, false, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, false, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, false, false, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, true, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, false, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, false, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, true, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, true, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, true, alwaysFalse()).isEmpty()); - - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, false, alwaysFalse()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, false, alwaysTrue()).isEmpty()); - assertTrue(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, false, alwaysFalse()).isEmpty()); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, true, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, true, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, true, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, true, true, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, true, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, true, false, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, true, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, true, false, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, false, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, false, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, false, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, false, true, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, false, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, true, false, false, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, false, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, true, false, false, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, false, true, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, true, false, true, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, false, true, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, true, false, true, true, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, false, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, false, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, true, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, false, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, false, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, true, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, true, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, true, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, true, true, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, true, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, true, false, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, true, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, true, false, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, false, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, false, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, false, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, false, true, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, false, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, true, false, false, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, false, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, true, false, false, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, true, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, true, false, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, true, false, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, true, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, true, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, true, alwaysFalse())); + + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_ELEMENT, false, false, false, false, alwaysFalse())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, false, alwaysTrue())); + assertEmptyList(findDeclaredTypes(NULL_TYPE_MIRROR, false, false, false, false, alwaysFalse())); } @Test @@ -1194,7 +1203,7 @@ public void testGetTypeMirrorsOfInterfaces() { assertTypeMirrors(typeMirrors, SUPER_INTERFACES); typeMirrors = getTypeMirrorsOfInterfaces(getTypeElement(Object.class)); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = getTypeMirrorsOfInterfaces(getTypeMirror(Object.class)); assertSame(typeMirrors, typeMirrors); @@ -1203,10 +1212,10 @@ public void testGetTypeMirrorsOfInterfaces() { @Test public void testGetTypeMirrorsOfInterfacesOnNull() { List typeMirrors = getTypeMirrorsOfInterfaces(NULL_TYPE_MIRROR); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = getTypeMirrorsOfInterfaces(NULL_TYPE_ELEMENT); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); } @Test @@ -1218,16 +1227,16 @@ public void testFindTypeMirrorsOfInterfaces() { assertTypeMirrors(typeMirrors, SUPER_INTERFACES); typeMirrors = findTypeMirrorsOfInterfaces(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findTypeMirrorsOfInterfaces(testTypeElement, alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findTypeMirrorsOfInterfaces(getTypeElement(Object.class), alwaysTrue()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findTypeMirrorsOfInterfaces(getTypeElement(Object.class), alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findTypeMirrorsOfInterfaces(getTypeMirror(Object.class), alwaysTrue()); assertSame(typeMirrors, typeMirrors); @@ -1239,16 +1248,16 @@ public void testFindTypeMirrorsOfInterfaces() { @Test public void testFindTypeMirrorsOfInterfacesOnNull() { List typeMirrors = findTypeMirrorsOfInterfaces(NULL_TYPE_MIRROR, alwaysTrue()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findTypeMirrorsOfInterfaces(NULL_TYPE_ELEMENT, alwaysTrue()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findTypeMirrorsOfInterfaces(NULL_TYPE_MIRROR, alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findTypeMirrorsOfInterfaces(NULL_TYPE_ELEMENT, alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); } @Test @@ -1260,7 +1269,7 @@ public void testGetAllTypeMirrorsOfInterfaces() { assertTypeMirrors(typeMirrors, ALL_SUPER_INTERFACES); typeMirrors = getAllTypeMirrorsOfInterfaces(getTypeElement(Object.class)); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = getAllTypeMirrorsOfInterfaces(getTypeMirror(Object.class)); assertSame(typeMirrors, typeMirrors); @@ -1269,10 +1278,10 @@ public void testGetAllTypeMirrorsOfInterfaces() { @Test public void testGetAllTypeMirrorsOfInterfacesOnNull() { List typeMirrors = getAllTypeMirrorsOfInterfaces(NULL_TYPE_MIRROR); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = getAllTypeMirrorsOfInterfaces(NULL_TYPE_ELEMENT); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); } @Test @@ -1284,16 +1293,16 @@ public void testFindAllTypeMirrorsOfInterfaces() { assertTypeMirrors(typeMirrors, ALL_SUPER_INTERFACES); typeMirrors = findAllTypeMirrorsOfInterfaces(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findAllTypeMirrorsOfInterfaces(testTypeElement, alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findAllTypeMirrorsOfInterfaces(getTypeElement(Object.class), alwaysTrue()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findAllTypeMirrorsOfInterfaces(getTypeElement(Object.class), alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findAllTypeMirrorsOfInterfaces(getTypeMirror(Object.class), alwaysTrue()); assertSame(typeMirrors, typeMirrors); @@ -1305,16 +1314,16 @@ public void testFindAllTypeMirrorsOfInterfaces() { @Test public void testFindAllTypeMirrorsOfInterfacesOnNull() { List typeMirrors = findAllTypeMirrorsOfInterfaces(NULL_TYPE_MIRROR, alwaysTrue()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findAllTypeMirrorsOfInterfaces(NULL_TYPE_MIRROR, alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findAllTypeMirrorsOfInterfaces(NULL_TYPE_ELEMENT, alwaysTrue()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); typeMirrors = findAllTypeMirrorsOfInterfaces(NULL_TYPE_MIRROR, alwaysFalse()); - assertSame(emptyList(), typeMirrors); + assertEmptyList(typeMirrors); } @Test @@ -1443,9 +1452,9 @@ public void testGetTypeElementsWithProcessingEnvironment() { @Test public void testGetTypeElementsWithProcessingEnvironmentOnNull() { - assertSame(emptyList(), TypeUtils.getTypeElements(this.processingEnv, NULL_TYPE)); - assertSame(emptyList(), TypeUtils.getTypeElements(this.processingEnv, NULL_TYPE_ARRAY)); - assertSame(emptyList(), TypeUtils.getTypeElements(this.processingEnv, EMPTY_TYPE_ARRAY)); + assertEmptyList(TypeUtils.getTypeElements(this.processingEnv, NULL_TYPE)); + assertEmptyList(TypeUtils.getTypeElements(this.processingEnv, NULL_TYPE_ARRAY)); + assertEmptyList(TypeUtils.getTypeElements(this.processingEnv, EMPTY_TYPE_ARRAY)); assertGetTypeElementsOnNullProcessingEnvironment(SELF_TYPE); assertGetTypeElementsOnNullProcessingEnvironment(SUPER_CLASS); @@ -1714,7 +1723,7 @@ private void assertGetTypeElementsWithProcessingEnvironment(Type... types) { private void assertGetTypeElementsOnNullProcessingEnvironment(Type... types) { List typeElements = TypeUtils.getTypeElements(NULL_PROCESSING_ENVIRONMENT, types); - assertSame(emptyList(), typeElements); + assertEmptyList(typeElements); } private void assertGetDeclaredType(Type... types) { @@ -1801,4 +1810,8 @@ private void assertToString(Type... types) { private void assertToString(TypeMirror type) { assertEquals(type.toString(), TypeUtils.toString(type)); } + + private void assertEmptyList(List list) { + assertSame(emptyList(), list); + } } \ No newline at end of file From e31d66aed55b5550a2966e33249ec52303534565 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 14:50:30 +0800 Subject: [PATCH 029/180] Update AnnotationUtilsTest.java --- .../annotation/processor/util/AnnotationUtilsTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java index 7815c689c..874055a22 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java @@ -444,6 +444,7 @@ public void testIsAnnotationPresentOnAnnotationClass() { public void testIsAnnotationPresentOnAnnotationClassOnNull() { assertFalse(isAnnotationPresent(NULL_ELEMENT, Service.class)); assertFalse(isAnnotationPresent(testTypeElement, NULL_CLASS)); + assertFalse(isAnnotationPresent(testTypeElement, Override.class)); } @Test @@ -459,6 +460,8 @@ public void testIsAnnotationPresentOnAnnotationClassName() { public void testIsAnnotationPresentOnAnnotationClassNameOnNull() { assertFalse(isAnnotationPresent(NULL_ELEMENT, "org.springframework.stereotype.Service")); assertFalse(isAnnotationPresent(testTypeElement, NULL_STRING)); + assertFalse(isAnnotationPresent(testTypeElement, "java.lang.Override")); + } @Test From b91b0caf1d559fbd3741f475f627697c21938236 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 14:50:34 +0800 Subject: [PATCH 030/180] Update TypeUtilsTest.java --- .../processor/util/TypeUtilsTest.java | 61 ++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java index b3fc6c31c..1de421005 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java @@ -43,6 +43,7 @@ import java.util.EventListener; import java.util.List; import java.util.Set; +import java.util.concurrent.TimeUnit; import static io.microsphere.annotation.processor.util.FieldUtils.findField; import static io.microsphere.annotation.processor.util.FieldUtils.getDeclaredFields; @@ -247,11 +248,17 @@ public void testIsSameTypeOnNull() { @Test public void testIsArrayTypeOnTypeMirror() { assertIsArrayType(ArrayTypeModel.class); + + assertFalse(isArrayType(getTypeMirror(Color.class))); + assertFalse(isArrayType(getTypeMirror(ArrayTypeModel.class))); } @Test public void testIsArrayTypeOnElement() { assertIsArrayType(getTypeElement(ArrayTypeModel.class)); + + assertFalse(isArrayType(getTypeElement(Color.class))); + assertFalse(isArrayType(getTypeElement(ArrayTypeModel.class))); } @Test @@ -274,8 +281,20 @@ public void testIsEnumTypeOnNull() { @Test public void testIsClassType() { + // class assertTrue(isClassType(getTypeElement(ArrayTypeModel.class))); + assertTrue(isClassType(getDeclaredType(ArrayTypeModel.class))); + + assertTrue(isClassType(getTypeElement(Model.class))); assertTrue(isClassType(getDeclaredType(Model.class))); + + // enum + assertFalse(isClassType(getTypeElement(TimeUnit.class))); + assertFalse(isClassType(getDeclaredType(TimeUnit.class))); + + // interface + assertFalse(isClassType(getTypeElement(Serializable.class))); + assertFalse(isClassType(getDeclaredType(Serializable.class))); } @Test @@ -933,8 +952,14 @@ public void testFindDeclaredTypesOfInterfaces() { List declaredTypes = findDeclaredTypesOfInterfaces(testTypeMirror, alwaysTrue()); assertDeclaredTypes(declaredTypes, SUPER_INTERFACES); + findDeclaredTypesOfInterfaces(testTypeElement, alwaysTrue()); + assertDeclaredTypes(declaredTypes, SUPER_INTERFACES); + declaredTypes = findDeclaredTypesOfInterfaces(testTypeMirror, alwaysFalse()); assertEmptyList(declaredTypes); + + declaredTypes = findDeclaredTypesOfInterfaces(testTypeElement, alwaysFalse()); + assertEmptyList(declaredTypes); } @Test @@ -984,8 +1009,14 @@ public void testFindAllDeclaredTypesOfSuperTypes() { List declaredTypes = findAllDeclaredTypesOfSuperTypes(testTypeMirror, alwaysTrue()); assertDeclaredTypes(declaredTypes, ALL_SUPER_TYPES); + findAllDeclaredTypesOfSuperTypes(testTypeElement, alwaysTrue()); + assertDeclaredTypes(declaredTypes, ALL_SUPER_TYPES); + declaredTypes = findAllDeclaredTypesOfSuperTypes(testTypeMirror, alwaysFalse()); assertEmptyList(declaredTypes); + + declaredTypes = findAllDeclaredTypesOfSuperTypes(testTypeElement, alwaysFalse()); + assertEmptyList(declaredTypes); } @Test @@ -1016,11 +1047,15 @@ public void testFindAllDeclaredTypesWithExcludedTypes() { List declaredTypes = findAllDeclaredTypes(testTypeElement, testClass); assertDeclaredTypes(declaredTypes, ALL_SUPER_TYPES); - declaredTypes = findAllDeclaredTypes(testTypeElement, testClassName); - assertDeclaredTypes(declaredTypes, ALL_SUPER_TYPES); declaredTypes = findAllDeclaredTypes(testTypeMirror, testClass); assertDeclaredTypes(declaredTypes, ALL_SUPER_TYPES); + } + + @Test + public void testFindAllDeclaredTypesWithExcludedTypeNames() { + List declaredTypes = findAllDeclaredTypes(testTypeElement, testClassName); + assertDeclaredTypes(declaredTypes, ALL_SUPER_TYPES); declaredTypes = findAllDeclaredTypes(testTypeMirror, testClassName); assertDeclaredTypes(declaredTypes, ALL_SUPER_TYPES); @@ -1036,6 +1071,14 @@ public void testFindAllDeclaredTypesWithExcludedTypesOnNull() { assertEmptyList(findAllDeclaredTypes(NULL_TYPE_MIRROR, ALL_TYPES)); } + @Test + public void testFindAllDeclaredTypesWithExcludedTypeNamesOnNull() { + assertEmptyList(findAllDeclaredTypes(NULL_ELEMENT, NULL_STRING_ARRAY)); + assertEmptyList(findAllDeclaredTypes(NULL_ELEMENT, EMPTY_STRING_ARRAY)); + assertEmptyList(findAllDeclaredTypes(NULL_TYPE_MIRROR, NULL_STRING_ARRAY)); + assertEmptyList(findAllDeclaredTypes(NULL_TYPE_MIRROR, EMPTY_STRING_ARRAY)); + } + @Test public void testFindDeclaredTypes() { // true true true true : all types @@ -1636,11 +1679,11 @@ private void assertIsArrayType(Type type) { } private void assertIsArrayType(Element element) { - assertTrue(isArrayType(findField(element, "integers").asType())); - assertTrue(isArrayType(findField(element, "strings").asType())); - assertTrue(isArrayType(findField(element, "primitiveTypeModels").asType())); - assertTrue(isArrayType(findField(element, "models").asType())); - assertTrue(isArrayType(findField(element, "colors").asType())); + assertTrue(isArrayType(getFieldType(element, "integers"))); + assertTrue(isArrayType(getFieldType(element, "strings"))); + assertTrue(isArrayType(getFieldType(element, "primitiveTypeModels"))); + assertTrue(isArrayType(getFieldType(element, "models"))); + assertTrue(isArrayType(getFieldType(element, "colors"))); } private void assertTypeMirrors(List typeMirrors, Type... types) { @@ -1775,6 +1818,10 @@ private TypeMirror getFieldType(Type type, String fieldName) { return findField(typeMirror, fieldName).asType(); } + private TypeMirror getFieldType(Element element, String fieldName) { + return findField(element, fieldName).asType(); + } + private void assertToStringOnClasses() { assertToString(NULL_TYPE); assertToString(SELF_TYPE); From 6ea474e8416170cb1ef88d991d2c2ebccd9cbe13 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 15:01:27 +0800 Subject: [PATCH 031/180] Update ExecutableElementComparatorTest.java --- .../util/ExecutableElementComparatorTest.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/ExecutableElementComparatorTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/ExecutableElementComparatorTest.java index 9ce38cd9f..4586e3771 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/ExecutableElementComparatorTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/ExecutableElementComparatorTest.java @@ -1,6 +1,7 @@ package io.microsphere.annotation.processor.util; import io.microsphere.annotation.processor.AbstractAnnotationProcessingTest; +import io.microsphere.annotation.processor.TestService; import org.junit.jupiter.api.Test; import javax.lang.model.element.ExecutableElement; @@ -24,6 +25,7 @@ public class ExecutableElementComparatorTest extends AbstractAnnotationProcessin @Test public void testCompareOnSameMethods() { + // Object#toString() String methodName = "toString"; ExecutableElement method = getMethod(methodName); assertEquals(0, comparator.compare(method, method)); @@ -35,17 +37,32 @@ public void testCompareOnDifferentMethods() { } @Test - public void testCompareOnOverloadMethods() { + public void testCompareOnOverloadMethodsWithSameParameterCount() { // Integer#valueOf(int) | Integer#valueOf(String) TypeElement typeElement = getTypeElement(Integer.class); String methodName = "valueOf"; assertEquals(int.class.getName().compareTo(String.class.getName()), comparator.compare(findMethod(typeElement, methodName, int.class), findMethod(typeElement, methodName, String.class))); } + @Test + public void testCompareOnOverloadMethodsWithDifferentParameterCount() { + // StringBuilder#append(char[]) | StringBuilder#append(char[],int,int) + TypeElement typeElement = getTypeElement(StringBuilder.class); + String methodName = "append"; + assertEquals(-2, comparator.compare( + findMethod(typeElement, methodName, char[].class), + findMethod(typeElement, methodName, char[].class, int.class, int.class))); + } + @Test public void testCompare() { - // Object#equals - assertEquals(0, comparator.compare(getMethod("equals", Object.class), getMethod("equals", Object.class))); + // AutoCloseable#close() + assertEquals(0, comparator.compare(getMethod("close"), + findMethod(getTypeElement(AutoCloseable.class), "close"))); + + // TestService#echo(String) + assertEquals(0, comparator.compare(getMethod("echo", String.class), + findMethod(getTypeElement(TestService.class), "echo", String.class))); } @Override From 89f8bd8907b5efe0f6bf8fc425a3a38b8915f706 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 15:17:59 +0800 Subject: [PATCH 032/180] Update AbstractAnnotationProcessingTest.java --- .../processor/AbstractAnnotationProcessingTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java index e07730bb8..d32f7327c 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/AbstractAnnotationProcessingTest.java @@ -42,6 +42,8 @@ import java.util.function.Predicate; import static io.microsphere.annotation.processor.util.TypeUtils.ofDeclaredType; +import static java.util.Collections.emptyList; +import static org.junit.jupiter.api.Assertions.assertSame; /** * Abstract {@link Annotation} Processing Test case @@ -172,4 +174,8 @@ protected DeclaredType getDeclaredType(Type type) { return TypeUtils.getDeclaredType(processingEnv, type); } + protected void assertEmptyList(List list) { + assertSame(emptyList(), list); + } + } From f30462071542f8da4b38bc2034b1447a3df21214 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 15:18:01 +0800 Subject: [PATCH 033/180] Update MethodUtilsTest.java --- .../processor/util/MethodUtilsTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java index eab0a8ef6..de138cb53 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java @@ -269,13 +269,48 @@ public void testFindMethod() { assertFindMethod(type, "equals", Object.class); } + @Test + public void testFindMethodOnNotFound() { + assertNull(findMethod(testTypeElement, "notFound")); + assertNull(findMethod(testTypeElement, "notFound", String.class)); + assertNull(findMethod(testTypeElement, "notFound", "java.lang.String")); + + assertNull(findMethod(testTypeMirror, "notFound")); + assertNull(findMethod(testTypeMirror, "notFound", String.class)); + assertNull(findMethod(testTypeMirror, "notFound", "java.lang.String")); + } + @Test public void testFindMethodOnNull() { assertNull(findMethod(NULL_TYPE_ELEMENT, "toString")); + assertNull(findMethod(NULL_TYPE_ELEMENT, "toString", String.class)); + assertNull(findMethod(NULL_TYPE_ELEMENT, "toString", "java.lang.String")); + assertNull(findMethod(NULL_TYPE_ELEMENT, "toString", NULL_TYPE_ARRAY)); + assertNull(findMethod(NULL_TYPE_ELEMENT, "toString", NULL_STRING_ARRAY)); + assertNull(findMethod(NULL_TYPE_MIRROR, "toString")); + assertNull(findMethod(NULL_TYPE_MIRROR, "toString", String.class)); + assertNull(findMethod(NULL_TYPE_MIRROR, "toString", "java.lang.String")); + assertNull(findMethod(NULL_TYPE_MIRROR, "toString", NULL_TYPE_ARRAY)); + assertNull(findMethod(NULL_TYPE_MIRROR, "toString", NULL_STRING_ARRAY)); + assertNull(findMethod(testTypeElement, NULL_STRING)); + assertNull(findMethod(testTypeElement, NULL_STRING, String.class)); + assertNull(findMethod(testTypeElement, NULL_STRING, "java.lang.String")); + assertNull(findMethod(testTypeElement, NULL_STRING, NULL_TYPE_ARRAY)); + assertNull(findMethod(testTypeElement, NULL_STRING, NULL_STRING_ARRAY)); + assertNull(findMethod(testTypeMirror, NULL_STRING)); + assertNull(findMethod(testTypeMirror, NULL_STRING, String.class)); + assertNull(findMethod(testTypeMirror, NULL_STRING, "java.lang.String")); + assertNull(findMethod(testTypeMirror, NULL_STRING, NULL_TYPE_ARRAY)); + assertNull(findMethod(testTypeMirror, NULL_STRING, NULL_STRING_ARRAY)); + + assertNull(findMethod(testTypeElement, "toString", NULL_TYPE_ARRAY)); + assertNull(findMethod(testTypeElement, "toString", NULL_STRING_ARRAY)); + + assertNull(findMethod(testTypeMirror, "toString", NULL_TYPE_ARRAY)); assertNull(findMethod(testTypeMirror, "toString", NULL_STRING_ARRAY)); } From 9a4e8d49d599e84fa4802e945ab8d0798fb1c11b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 15:18:04 +0800 Subject: [PATCH 034/180] Update TypeUtilsTest.java --- .../microsphere/annotation/processor/util/TypeUtilsTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java index 1de421005..e1749de35 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java @@ -1857,8 +1857,4 @@ private void assertToString(Type... types) { private void assertToString(TypeMirror type) { assertEquals(type.toString(), TypeUtils.toString(type)); } - - private void assertEmptyList(List list) { - assertSame(emptyList(), list); - } } \ No newline at end of file From c73e07134c5e183828f82fcb177ce2dfcf1aefb2 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 15:20:25 +0800 Subject: [PATCH 035/180] Update AnnotationUtilsTest.java --- .../processor/util/AnnotationUtilsTest.java | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java index 874055a22..a79f7f5c0 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/AnnotationUtilsTest.java @@ -64,12 +64,10 @@ import static io.microsphere.util.ArrayUtils.ofArray; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; -import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -115,7 +113,7 @@ public void testGetAnnotations() { @Test public void testGetAnnotationsOnNull() { List annotations = getAnnotations(NULL_ANNOTATED_CONSTRUCT); - assertSame(emptyList(), annotations); + assertEmptyList(annotations); } @Test @@ -161,8 +159,8 @@ public void testGetAllAnnotations() { @Test public void testGetAllAnnotationsOnNull() { - assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT)); - assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR)); + assertEmptyList(getAllAnnotations(NULL_ELEMENT)); + assertEmptyList(getAllAnnotations(NULL_TYPE_MIRROR)); } @Test @@ -185,17 +183,17 @@ public void testGetAllAnnotationsWithAnnotationClass() { @Test public void testGetAllAnnotationsWithAnnotationClassOnNull() { - assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT, NULL_CLASS)); - assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR, NULL_CLASS)); - assertSame(emptyList(), getAllAnnotations(NULL_PROCESSING_ENVIRONMENT, NULL_CLASS)); + assertEmptyList(getAllAnnotations(NULL_ELEMENT, NULL_CLASS)); + assertEmptyList(getAllAnnotations(NULL_TYPE_MIRROR, NULL_CLASS)); + assertEmptyList(getAllAnnotations(NULL_PROCESSING_ENVIRONMENT, NULL_CLASS)); - assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT, Service.class)); - assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR, Service.class)); - assertSame(emptyList(), getAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class)); + assertEmptyList(getAllAnnotations(NULL_ELEMENT, Service.class)); + assertEmptyList(getAllAnnotations(NULL_TYPE_MIRROR, Service.class)); + assertEmptyList(getAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class)); - assertSame(emptyList(), getAllAnnotations(testTypeElement, NULL_CLASS)); - assertSame(emptyList(), getAllAnnotations(testTypeMirror, NULL_CLASS)); - assertSame(emptyList(), getAllAnnotations(processingEnv, NULL_CLASS)); + assertEmptyList(getAllAnnotations(testTypeElement, NULL_CLASS)); + assertEmptyList(getAllAnnotations(testTypeMirror, NULL_CLASS)); + assertEmptyList(getAllAnnotations(processingEnv, NULL_CLASS)); } @Test @@ -209,14 +207,14 @@ public void testGetAllAnnotationsWithAnnotationClassName() { @Test public void testGetAllAnnotationsWithAnnotationClassNameOnNull() { - assertSame(emptyList(), getAllAnnotations(NULL_ELEMENT, NULL_STRING)); - assertSame(emptyList(), getAllAnnotations(NULL_TYPE_MIRROR, NULL_STRING)); + assertEmptyList(getAllAnnotations(NULL_ELEMENT, NULL_STRING)); + assertEmptyList(getAllAnnotations(NULL_TYPE_MIRROR, NULL_STRING)); assertTrue(getAllAnnotations(NULL_ELEMENT, "org.springframework.stereotype.Service").isEmpty()); assertTrue(getAllAnnotations(NULL_TYPE_MIRROR, "org.springframework.stereotype.Service").isEmpty()); - assertSame(emptyList(), getAllAnnotations(testTypeElement, NULL_STRING)); - assertSame(emptyList(), getAllAnnotations(testTypeMirror, NULL_STRING)); + assertEmptyList(getAllAnnotations(testTypeElement, NULL_STRING)); + assertEmptyList(getAllAnnotations(testTypeMirror, NULL_STRING)); } @Test @@ -290,7 +288,7 @@ public void testFindAllAnnotationsWithTypeMirror() { assertEquals(3, annotations.size()); annotations = findAllAnnotations(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), annotations); + assertEmptyList(annotations); } @Test @@ -299,7 +297,7 @@ public void testFindAllAnnotationsWithTypeElement() { assertEquals(3, annotations.size()); annotations = findAllAnnotations(testTypeElement, alwaysFalse()); - assertSame(emptyList(), annotations); + assertEmptyList(annotations); } @Test @@ -347,37 +345,37 @@ public void testFindAllAnnotationsWithField() { field = findField(testTypeElement, "environment"); annotations = findAllAnnotations(field, alwaysTrue()); - assertSame(emptyList(), annotations); + assertEmptyList(annotations); } @Test public void testFindAllAnnotationsWithTypeMirrorOnNull() { - assertSame(emptyList(), findAllAnnotations(NULL_TYPE_MIRROR, alwaysTrue())); - assertSame(emptyList(), findAllAnnotations(NULL_TYPE_MIRROR, alwaysFalse())); + assertEmptyList(findAllAnnotations(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findAllAnnotations(NULL_TYPE_MIRROR, alwaysFalse())); } @Test public void testFindAllAnnotationsWithTypeElementOnNull() { - assertSame(emptyList(), findAllAnnotations(NULL_TYPE_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findAllAnnotations(NULL_TYPE_ELEMENT, alwaysFalse())); + assertEmptyList(findAllAnnotations(NULL_TYPE_ELEMENT, alwaysTrue())); + assertEmptyList(findAllAnnotations(NULL_TYPE_ELEMENT, alwaysFalse())); } @Test public void testFindAllAnnotationsWithElementOnNull() { - assertSame(emptyList(), findAllAnnotations(NULL_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findAllAnnotations(NULL_ELEMENT, alwaysFalse())); + assertEmptyList(findAllAnnotations(NULL_ELEMENT, alwaysTrue())); + assertEmptyList(findAllAnnotations(NULL_ELEMENT, alwaysFalse())); } @Test public void testFindAllAnnotationsOnNull() { - assertSame(emptyList(), findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class, alwaysTrue())); - assertSame(emptyList(), findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class, alwaysTrue())); - assertSame(emptyList(), findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, "org.springframework.stereotype.Service", alwaysFalse())); - assertSame(emptyList(), findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, "org.springframework.stereotype.Service", alwaysFalse())); - assertSame(emptyList(), findAllAnnotations(processingEnv, NULL_TYPE, alwaysTrue())); - assertSame(emptyList(), findAllAnnotations(processingEnv, NULL_TYPE, alwaysFalse())); - assertSame(emptyList(), findAllAnnotations(processingEnv, NULL_STRING, alwaysTrue())); - assertSame(emptyList(), findAllAnnotations(processingEnv, NULL_STRING, alwaysFalse())); + assertEmptyList(findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class, alwaysTrue())); + assertEmptyList(findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, Service.class, alwaysTrue())); + assertEmptyList(findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, "org.springframework.stereotype.Service", alwaysFalse())); + assertEmptyList(findAllAnnotations(NULL_PROCESSING_ENVIRONMENT, "org.springframework.stereotype.Service", alwaysFalse())); + assertEmptyList(findAllAnnotations(processingEnv, NULL_TYPE, alwaysTrue())); + assertEmptyList(findAllAnnotations(processingEnv, NULL_TYPE, alwaysFalse())); + assertEmptyList(findAllAnnotations(processingEnv, NULL_STRING, alwaysTrue())); + assertEmptyList(findAllAnnotations(processingEnv, NULL_STRING, alwaysFalse())); } @Test @@ -477,17 +475,17 @@ public void testFindAnnotations() { assertAnnotation(annotations.get(1), ServiceMode.class); annotations = findAnnotations(testTypeElement, alwaysFalse()); - assertSame(emptyList(), annotations); + assertEmptyList(annotations); } @Test public void testFindAnnotationsOnNotFound() { - assertSame(emptyList(), findAnnotations(getTypeElement(Serializable.class))); + assertEmptyList(findAnnotations(getTypeElement(Serializable.class))); } @Test public void testFindAnnotationsOnNull() { - assertSame(emptyList(), findAnnotations(NULL_ELEMENT)); + assertEmptyList(findAnnotations(NULL_ELEMENT)); } private void assertFindMetaAnnotation(Element element, Class annotationClass) { From 7871c934fa7e555a0d35298404292d7f3ab17ceb Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 15:20:27 +0800 Subject: [PATCH 036/180] Update FieldUtilsTest.java --- .../processor/util/FieldUtilsTest.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java index b0e014eba..b3eb82a6d 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/FieldUtilsTest.java @@ -50,7 +50,6 @@ import static io.microsphere.lang.function.Predicates.alwaysFalse; import static io.microsphere.lang.function.Predicates.alwaysTrue; import static io.microsphere.util.StringUtils.EMPTY_STRING; -import static java.util.Collections.emptyList; import static javax.lang.model.element.Modifier.FINAL; import static javax.lang.model.element.Modifier.PRIVATE; import static javax.lang.model.element.Modifier.PUBLIC; @@ -58,7 +57,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -162,7 +160,7 @@ public void testFindDeclaredFields() { assertModelAllFields(fields); fields = findAllDeclaredFields(type, alwaysFalse()); - assertSame(emptyList(), fields); + assertEmptyList(fields); fields = findDeclaredFields(type, f -> "f".equals(f.getSimpleName().toString())); assertEquals(1, fields.size()); @@ -171,8 +169,8 @@ public void testFindDeclaredFields() { @Test public void testFindDeclaredFieldsOnNull() { - assertSame(emptyList(), findDeclaredFields(NULL_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findDeclaredFields(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findDeclaredFields(NULL_ELEMENT, alwaysTrue())); + assertEmptyList(findDeclaredFields(NULL_TYPE_MIRROR, alwaysTrue())); } @Test @@ -183,7 +181,7 @@ public void testFindAllDeclaredFields() { assertModelAllFields(fields); fields = findAllDeclaredFields(type, alwaysFalse()); - assertSame(emptyList(), fields); + assertEmptyList(fields); fields = findAllDeclaredFields(type, f -> "f".equals(f.getSimpleName().toString())); assertEquals(1, fields.size()); @@ -192,8 +190,8 @@ public void testFindAllDeclaredFields() { @Test public void testFindAllDeclaredFieldsOnNull() { - assertSame(emptyList(), findAllDeclaredFields(NULL_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findAllDeclaredFields(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findAllDeclaredFields(NULL_ELEMENT, alwaysTrue())); + assertEmptyList(findAllDeclaredFields(NULL_TYPE_MIRROR, alwaysTrue())); } @Test @@ -208,13 +206,13 @@ public void testFilterDeclaredFields() { assertModelAllFields(fields); fields = filterDeclaredFields(type, true, alwaysFalse()); - assertSame(emptyList(), fields); + assertEmptyList(fields); fields = filterDeclaredFields(type, false, alwaysTrue()); assertModelFields(fields); fields = filterDeclaredFields(type, false, alwaysFalse()); - assertSame(emptyList(), fields); + assertEmptyList(fields); } @Test @@ -230,14 +228,14 @@ public void testFilterDeclaredFieldsOnNoDeclaredFields() { } private void assertFilterDeclaredFieldsReturningEmptyList(TypeMirror type) { - assertSame(emptyList(), filterDeclaredFields(type, true, alwaysTrue())); - assertSame(emptyList(), filterDeclaredFields(type, false, alwaysTrue())); - assertSame(emptyList(), filterDeclaredFields(type, true, alwaysFalse())); - assertSame(emptyList(), filterDeclaredFields(type, false, alwaysFalse())); - assertSame(emptyList(), filterDeclaredFields(type, true, NULL_PREDICATE_ARRAY)); - assertSame(emptyList(), filterDeclaredFields(type, false, NULL_PREDICATE_ARRAY)); - assertSame(emptyList(), filterDeclaredFields(type, true)); - assertSame(emptyList(), filterDeclaredFields(type, false)); + assertEmptyList(filterDeclaredFields(type, true, alwaysTrue())); + assertEmptyList(filterDeclaredFields(type, false, alwaysTrue())); + assertEmptyList(filterDeclaredFields(type, true, alwaysFalse())); + assertEmptyList(filterDeclaredFields(type, false, alwaysFalse())); + assertEmptyList(filterDeclaredFields(type, true, NULL_PREDICATE_ARRAY)); + assertEmptyList(filterDeclaredFields(type, false, NULL_PREDICATE_ARRAY)); + assertEmptyList(filterDeclaredFields(type, true)); + assertEmptyList(filterDeclaredFields(type, false)); } @Test @@ -335,7 +333,7 @@ public void testGetNonStaticFieldsOnNull() { public void testGetNonStaticFieldsOnEnum() { TypeElement type = getTypeElement(ElementType.class); List fields = getNonStaticFields(type); - assertSame(emptyList(), fields); + assertEmptyList(fields); } @Test From ba413517c1b5cd00112bf2cf808098793bdab582 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 15:20:31 +0800 Subject: [PATCH 037/180] Update MemberUtilsTest.java --- .../processor/util/MemberUtilsTest.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java index a22e13e61..2ad49db69 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java @@ -100,8 +100,8 @@ public void testGetDeclaredMembers() { @Test public void testGetDeclaredMembersOnNul() { - assertSame(emptyList(), getDeclaredMembers(NULL_TYPE_ELEMENT)); - assertSame(emptyList(), getDeclaredMembers(NULL_TYPE_MIRROR)); + assertEmptyList(getDeclaredMembers(NULL_TYPE_ELEMENT)); + assertEmptyList(getDeclaredMembers(NULL_TYPE_MIRROR)); } @Test @@ -111,8 +111,8 @@ public void testGetAllDeclaredMembers() { @Test public void testGetAllDeclaredMembersOnNul() { - assertSame(emptyList(), getAllDeclaredMembers(NULL_TYPE_ELEMENT)); - assertSame(emptyList(), getAllDeclaredMembers(NULL_TYPE_MIRROR)); + assertEmptyList(getAllDeclaredMembers(NULL_TYPE_ELEMENT)); + assertEmptyList(getAllDeclaredMembers(NULL_TYPE_MIRROR)); } @Test @@ -122,10 +122,10 @@ public void testFindDeclaredMembers() { @Test public void testFindDeclaredMembersOnNul() { - assertSame(emptyList(), findDeclaredMembers(NULL_TYPE_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findDeclaredMembers(NULL_TYPE_ELEMENT, alwaysFalse())); - assertSame(emptyList(), findDeclaredMembers(NULL_TYPE_MIRROR, alwaysTrue())); - assertSame(emptyList(), findDeclaredMembers(NULL_TYPE_MIRROR, alwaysFalse())); + assertEmptyList(findDeclaredMembers(NULL_TYPE_ELEMENT, alwaysTrue())); + assertEmptyList(findDeclaredMembers(NULL_TYPE_ELEMENT, alwaysFalse())); + assertEmptyList(findDeclaredMembers(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findDeclaredMembers(NULL_TYPE_MIRROR, alwaysFalse())); } @Test @@ -135,28 +135,28 @@ public void testFindAllDeclaredMembers() { @Test public void testFindAllDeclaredMembersOnNul() { - assertSame(emptyList(), findAllDeclaredMembers(NULL_TYPE_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findAllDeclaredMembers(NULL_TYPE_ELEMENT, alwaysFalse())); - assertSame(emptyList(), findAllDeclaredMembers(NULL_TYPE_MIRROR, alwaysTrue())); - assertSame(emptyList(), findAllDeclaredMembers(NULL_TYPE_MIRROR, alwaysFalse())); + assertEmptyList(findAllDeclaredMembers(NULL_TYPE_ELEMENT, alwaysTrue())); + assertEmptyList(findAllDeclaredMembers(NULL_TYPE_ELEMENT, alwaysFalse())); + assertEmptyList(findAllDeclaredMembers(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findAllDeclaredMembers(NULL_TYPE_MIRROR, alwaysFalse())); } @Test public void testFilterMembers() { - assertSame(emptyList(), filterMembers(ofList(testTypeElement), alwaysFalse())); + assertEmptyList(filterMembers(ofList(testTypeElement), alwaysFalse())); } @Test public void testFilterMembersOnNull() { - assertSame(emptyList(), filterMembers(NULL_LIST, alwaysTrue())); + assertEmptyList(filterMembers(NULL_LIST, alwaysTrue())); List methods = ofList(echoMethod); assertSame(methods, filterMembers(methods, NULL_PREDICATE_ARRAY)); } @Test public void testFilterMembersOnEmpty() { - assertSame(emptyList(), filterMembers(emptyList(), alwaysTrue())); + assertEmptyList(filterMembers(emptyList(), alwaysTrue())); List methods = ofList(echoMethod); assertSame(methods, filterMembers(methods)); } @@ -190,8 +190,8 @@ private void assertFindDeclaredMembersOfModel() { assertGetDeclaredMembersOfModel(findDeclaredMembers(type, alwaysTrue(), alwaysTrue())); assertGetDeclaredMembersOfModel(findDeclaredMembers(type.asType(), alwaysTrue())); - assertSame(emptyList(), findDeclaredMembers(type, alwaysFalse())); - assertSame(emptyList(), findDeclaredMembers(type.asType(), alwaysFalse())); + assertEmptyList(findDeclaredMembers(type, alwaysFalse())); + assertEmptyList(findDeclaredMembers(type.asType(), alwaysFalse())); } private void assertFindAllDeclaredMembersOfModel() { @@ -199,8 +199,8 @@ private void assertFindAllDeclaredMembersOfModel() { assertGetAllDeclaredMembersOfModel(findAllDeclaredMembers(type, alwaysTrue(), alwaysTrue())); assertGetAllDeclaredMembersOfModel(findAllDeclaredMembers(type.asType(), alwaysTrue())); - assertSame(emptyList(), findAllDeclaredMembers(type, alwaysFalse())); - assertSame(emptyList(), findAllDeclaredMembers(type.asType(), alwaysFalse())); + assertEmptyList(findAllDeclaredMembers(type, alwaysFalse())); + assertEmptyList(findAllDeclaredMembers(type.asType(), alwaysFalse())); } private void assertGetDeclaredMembersOfModel() { From 16a1c715cb22c1443ea3cc01222ee5494c7bf9c5 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 15:20:33 +0800 Subject: [PATCH 038/180] Update MethodUtilsTest.java --- .../processor/util/MethodUtilsTest.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java index de138cb53..325c52039 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java @@ -128,24 +128,24 @@ public void testFindDeclaredMethods() { assertEquals(2, methods.size()); methods = findDeclaredMethods(testTypeElement, alwaysFalse()); - assertSame(emptyList(), methods); + assertEmptyList(methods); methods = findDeclaredMethods(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), methods); + assertEmptyList(methods); } @Test public void testFindDeclaredMethodsOnNoMemberType() { TypeElement typeElement = getTypeElement(Serializable.class); List methods = findDeclaredMethods(typeElement, alwaysTrue()); - assertSame(emptyList(), methods); + assertEmptyList(methods); } @Test public void testFindDeclaredMethodsOnNoMethodType() { TypeElement typeElement = getTypeElement(PropertyConstants.class); List methods = findDeclaredMethods(typeElement, alwaysTrue()); - assertSame(emptyList(), methods); + assertEmptyList(methods); } @Test @@ -157,32 +157,32 @@ public void testFindAllDeclaredMethods() { assertEquals(objectMethodsSize + 14, methods.size()); methods = findAllDeclaredMethods(testTypeElement, alwaysFalse()); - assertSame(emptyList(), methods); + assertEmptyList(methods); methods = findAllDeclaredMethods(testTypeMirror, alwaysFalse()); - assertSame(emptyList(), methods); + assertEmptyList(methods); } @Test public void testFindAllDeclaredMethodsOnNoMemberType() { TypeElement typeElement = getTypeElement(Serializable.class); List methods = findAllDeclaredMethods(typeElement, alwaysTrue()); - assertSame(emptyList(), methods); + assertEmptyList(methods); } @Test public void testFindAllDeclaredMethodsOnNoMethodType() { TypeElement typeElement = getTypeElement(Constants.class); List methods = findAllDeclaredMethods(typeElement, alwaysTrue()); - assertSame(emptyList(), methods); + assertEmptyList(methods); } @Test public void testFindAllDeclaredMethodsOnNull() { - assertSame(emptyList(), findAllDeclaredMethods(NULL_TYPE_ELEMENT, alwaysTrue())); - assertSame(emptyList(), findAllDeclaredMethods(NULL_TYPE_ELEMENT, alwaysFalse())); - assertSame(emptyList(), findAllDeclaredMethods(NULL_TYPE_MIRROR, alwaysTrue())); - assertSame(emptyList(), findAllDeclaredMethods(NULL_TYPE_MIRROR, alwaysFalse())); + assertEmptyList(findAllDeclaredMethods(NULL_TYPE_ELEMENT, alwaysTrue())); + assertEmptyList(findAllDeclaredMethods(NULL_TYPE_ELEMENT, alwaysFalse())); + assertEmptyList(findAllDeclaredMethods(NULL_TYPE_MIRROR, alwaysTrue())); + assertEmptyList(findAllDeclaredMethods(NULL_TYPE_MIRROR, alwaysFalse())); } @Test @@ -193,8 +193,8 @@ public void testFindAllDeclaredMethodsWithExcludedTypes() { @Test public void testFindAllDeclaredMethodsWithExcludedTypesOnNull() { - assertSame(emptyList(), findAllDeclaredMethods(NULL_TYPE_ELEMENT, Object.class)); - assertSame(emptyList(), findAllDeclaredMethods(NULL_TYPE_MIRROR, Object.class)); + assertEmptyList(findAllDeclaredMethods(NULL_TYPE_ELEMENT, Object.class)); + assertEmptyList(findAllDeclaredMethods(NULL_TYPE_MIRROR, Object.class)); } @Test @@ -208,8 +208,8 @@ public void testFindPublicNonStaticMethods() { @Test public void testFindPublicNonStaticMethodsOnNull() { - assertSame(emptyList(), findPublicNonStaticMethods(NULL_TYPE_ELEMENT, Object.class)); - assertSame(emptyList(), findPublicNonStaticMethods(NULL_TYPE_MIRROR, Object.class)); + assertEmptyList(findPublicNonStaticMethods(NULL_TYPE_ELEMENT, Object.class)); + assertEmptyList(findPublicNonStaticMethods(NULL_TYPE_MIRROR, Object.class)); } @Test @@ -334,20 +334,20 @@ public void testFilterMethods() { @Test public void testFilterMethodsOnNull() { - assertSame(emptyList(), filterMethods(NULL_LIST, alwaysTrue())); - assertSame(emptyList(), filterMethods(NULL_LIST, NULL_PREDICATE_ARRAY)); + assertEmptyList(filterMethods(NULL_LIST, alwaysTrue())); + assertEmptyList(filterMethods(NULL_LIST, NULL_PREDICATE_ARRAY)); } @Test public void testFilterMethodsOnEmpty() { - assertSame(emptyList(), filterMethods(emptyList(), alwaysTrue())); - assertSame(emptyList(), filterMethods(emptyList(), NULL_PREDICATE_ARRAY)); + assertEmptyList(filterMethods(emptyList(), alwaysTrue())); + assertEmptyList(filterMethods(emptyList(), NULL_PREDICATE_ARRAY)); } @Test public void testFilterMethodsOnReturningEmptyList() { List methods = getDeclaredMethods(testTypeElement); - assertSame(emptyList(), filterMethods(methods, alwaysFalse())); + assertEmptyList(filterMethods(methods, alwaysFalse())); assertSame(methods, filterMethods(methods)); } @@ -389,7 +389,7 @@ public void testMatchParameterTypeNamesOnNull() { @Test public void testMatchParameterTypes() { ExecutableElement method = findMethod(testTypeElement, "toString"); - assertSame(emptyList(), getMethodParameterTypeMirrors(method)); + assertEmptyList(getMethodParameterTypeMirrors(method)); method = findMethod(testTypeElement, "equals", Object.class); List parameterTypes = getMethodParameterTypeMirrors(method); @@ -398,7 +398,7 @@ public void testMatchParameterTypes() { @Test public void testMatchParameterTypesOnNull() { - assertSame(emptyList(), getMethodParameterTypeMirrors(NULL_METHOD)); + assertEmptyList(getMethodParameterTypeMirrors(NULL_METHOD)); } @Test From 8ba61b26df3c9a35418bbb9b47cc5b43b9f26517 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 16:21:29 +0800 Subject: [PATCH 039/180] Update MethodUtils.java --- .../io/microsphere/annotation/processor/util/MethodUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MethodUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MethodUtils.java index 078004abc..189ad0f58 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MethodUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MethodUtils.java @@ -111,7 +111,6 @@ static List findAllDeclaredMethods(TypeMirror type, Type... e static List findPublicNonStaticMethods(TypeElement type, Type... excludedTypes) { return type == null ? emptyList() : findPublicNonStaticMethods(ofDeclaredType(type), excludedTypes); - } static List findPublicNonStaticMethods(TypeMirror type, Type... excludedTypes) { From 643825f48a9adcf6417078bd71100e7c10fbfd73 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 16:21:31 +0800 Subject: [PATCH 040/180] Update MethodUtilsTest.java --- .../processor/util/MethodUtilsTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java index 325c52039..3b9ae127a 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java @@ -23,6 +23,7 @@ import io.microsphere.constants.PropertyConstants; import org.junit.jupiter.api.Test; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; @@ -31,6 +32,8 @@ import java.util.List; import java.util.Set; +import static io.microsphere.annotation.processor.util.MemberUtils.getDeclaredMembers; +import static io.microsphere.annotation.processor.util.MemberUtils.isPublicNonStatic; import static io.microsphere.annotation.processor.util.MethodUtils.filterMethods; import static io.microsphere.annotation.processor.util.MethodUtils.findAllDeclaredMethods; import static io.microsphere.annotation.processor.util.MethodUtils.findDeclaredMethods; @@ -225,8 +228,24 @@ public void testIsMethodOnNull() { @Test public void testIsPublicNonStaticMethod() { - List methods = findPublicNonStaticMethods(testTypeElement, Object.class); - assertEquals(14, methods.stream().map(MethodUtils::isPublicNonStaticMethod).count()); + List members = getDeclaredMembers(testTypeElement); + for (Element member : members) { + if (member instanceof ExecutableElement) { + ExecutableElement element = (ExecutableElement) member; + switch (member.getKind()) { + case METHOD: + assertEquals(isPublicNonStaticMethod(element), isPublicNonStatic(element)); + break; + case CONSTRUCTOR: + assertFalse(isPublicNonStaticMethod(element)); + break; + } + } + } + + // Integer#valueOf(String) is a public static method + assertFalse(isPublicNonStaticMethod(findMethod(getTypeElement(Integer.class), "valueOf", String.class))); + } @Test From aa6f5f7fb67c16ae49b78ee2a98d4c62b5b45e27 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 16:23:33 +0800 Subject: [PATCH 041/180] Update MemberUtilsTest.java --- .../annotation/processor/util/MemberUtilsTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java index 2ad49db69..7ce0a6654 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MemberUtilsTest.java @@ -81,8 +81,15 @@ public void testMatchesElementKindOnNull() { @Test public void testIsPublicNonStatic() { + methodsIn(getDeclaredMembers(testTypeElement)).forEach(method -> assertTrue(isPublicNonStatic(method))); + + // Integer#valueOf(String) is a public static method + assertFalse(isPublicNonStatic(findMethod(getTypeElement(Integer.class), "valueOf", String.class))); + } + + @Test + public void testIsPublicNonStaticOnNull() { assertFalse(isPublicNonStatic(NULL_ELEMENT)); - methodsIn(getDeclaredMembers(testTypeElement.asType())).forEach(method -> assertTrue(isPublicNonStatic(method))); } @Test From 1e5e911fc65c49d084acc74efb7c7c9a14506c72 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 16:25:56 +0800 Subject: [PATCH 042/180] Update MethodUtilsTest.java --- .../annotation/processor/util/MethodUtilsTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java index 3b9ae127a..d7048f4d5 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/MethodUtilsTest.java @@ -57,6 +57,7 @@ import static io.microsphere.util.ArrayUtils.EMPTY_STRING_ARRAY; import static io.microsphere.util.ArrayUtils.ofArray; import static java.util.Collections.emptyList; +import static javax.lang.model.element.ElementKind.METHOD; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -217,8 +218,13 @@ public void testFindPublicNonStaticMethodsOnNull() { @Test public void testIsMethod() { - List methods = findPublicNonStaticMethods(testTypeElement, Object.class); - assertEquals(14, methods.stream().map(MethodUtils::isMethod).count()); + List members = getDeclaredMembers(testTypeElement); + for (Element member : members) { + if (member instanceof ExecutableElement) { + ExecutableElement element = (ExecutableElement) member; + assertEquals(METHOD == member.getKind(), isMethod(element)); + } + } } @Test From f9ad32023a87ad76b6434058c1c6f140306850df Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 16:54:25 +0800 Subject: [PATCH 043/180] Update TypeUtilsTest.java --- .../processor/util/TypeUtilsTest.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java index e1749de35..746df80e1 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java @@ -31,7 +31,6 @@ import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; @@ -47,6 +46,7 @@ import static io.microsphere.annotation.processor.util.FieldUtils.findField; import static io.microsphere.annotation.processor.util.FieldUtils.getDeclaredFields; +import static io.microsphere.annotation.processor.util.MethodUtils.findMethod; import static io.microsphere.annotation.processor.util.TypeUtils.findAllDeclaredTypes; import static io.microsphere.annotation.processor.util.TypeUtils.findAllDeclaredTypesOfInterfaces; import static io.microsphere.annotation.processor.util.TypeUtils.findAllDeclaredTypesOfSuperTypes; @@ -306,10 +306,11 @@ public void testIsClassTypeOnNull() { @Test public void testIsPrimitiveType() { TypeElement type = getTypeElement(PrimitiveTypeModel.class); - getDeclaredFields(type.asType()) - .stream() - .map(VariableElement::asType) - .forEach(t -> assertTrue(isPrimitiveType(t))); + + getDeclaredFields(type).forEach(t -> { + assertTrue(isPrimitiveType(t)); + assertTrue(isPrimitiveType(t.asType())); + }); assertFalse(isPrimitiveType(getTypeElement(ArrayTypeModel.class))); } @@ -354,6 +355,9 @@ public void testIsAnnotationTypeOnNull() { public void testIsTypeElement() { assertTrue(isTypeElement(testTypeElement)); assertTrue(isTypeElement(testTypeMirror)); + + // primitive type + assertFalse(isTypeElement(getTypeMirror(int.class))); } @Test @@ -366,11 +370,15 @@ public void testIsTypeElementOnNull() { public void testIsDeclaredType() { assertTrue(isDeclaredType(testTypeElement)); assertTrue(isDeclaredType(testTypeMirror)); - assertFalse(isDeclaredType(NULL_ELEMENT)); - assertFalse(isDeclaredType(NULL_TYPE_MIRROR)); assertFalse(isDeclaredType(types.getNullType())); assertFalse(isDeclaredType(types.getPrimitiveType(TypeKind.BYTE))); assertFalse(isDeclaredType(types.getArrayType(types.getPrimitiveType(TypeKind.BYTE)))); + + // field + assertFalse(isDeclaredType(findField(getTypeMirror(PrimitiveTypeModel.class), "z"))); + + // method + assertFalse(isDeclaredType(findMethod(testTypeElement, "close"))); } @Test From d79e0cfa1a7330bb95bc3fb94d2851d4cb483916 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:14:20 +0800 Subject: [PATCH 044/180] Update ArrayUtils.java --- .../src/main/java/io/microsphere/util/ArrayUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java index 9e39413f8..0adbe1063 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java @@ -41,7 +41,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class ArrayUtils extends BaseUtils { +public abstract class ArrayUtils { /** * An empty immutable {@code boolean} array. From 506b26433030e4aa75151e9e98da01c57bcec274 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:34 +0800 Subject: [PATCH 045/180] Update CollectionUtils.java --- .../main/java/io/microsphere/collection/CollectionUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/CollectionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/CollectionUtils.java index 6dba9bf01..eb9888ba6 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/CollectionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/CollectionUtils.java @@ -36,7 +36,7 @@ * @author Mercy * @see Collections */ -public abstract class CollectionUtils extends BaseUtils { +public abstract class CollectionUtils { public static boolean isEmpty(@Nullable Collection collection) { return collection == null || collection.isEmpty(); From 1f3ac50db328e98bff2e41c9c81b5528c5e708e0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:36 +0800 Subject: [PATCH 046/180] Update EnumerationUtils.java --- .../main/java/io/microsphere/collection/EnumerationUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java index f4a6c7991..1bdc731e3 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java @@ -29,7 +29,7 @@ * @see Collections#enumeration * @since 1.0.0 */ -public abstract class EnumerationUtils extends BaseUtils { +public abstract class EnumerationUtils { /** * Create a {@link Enumeration} instance from the specified elements From 727bc15f1e0bfc740afbe75c998f5657313c6691 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:38 +0800 Subject: [PATCH 047/180] Update ListUtils.java --- .../src/main/java/io/microsphere/collection/ListUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java index 0cd47dbb4..2bf80d21a 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java @@ -41,7 +41,7 @@ * @see List * @since 1.0.0 */ -public abstract class ListUtils extends BaseUtils { +public abstract class ListUtils { public static boolean isList(Object values) { return values instanceof List; From b0e045cdd1b732c1a646d863ff5a149a58c70d4c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:41 +0800 Subject: [PATCH 048/180] Update MapUtils.java --- .../src/main/java/io/microsphere/collection/MapUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java index bce010b05..942ca8600 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java @@ -47,7 +47,7 @@ * @see Map * @since 1.0.0 */ -public abstract class MapUtils extends BaseUtils { +public abstract class MapUtils { /** * The min load factor for {@link HashMap} or {@link Hashtable} From fbfe995a1795695e74279c59df5af8414fe62cdb Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:44 +0800 Subject: [PATCH 049/180] Update PropertiesUtils.java --- .../main/java/io/microsphere/collection/PropertiesUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java index f4d32c1b7..f3aac5713 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java @@ -32,7 +32,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class PropertiesUtils extends BaseUtils { +public abstract class PropertiesUtils { /** * Get the flatten the specified {@link Map properties} From 9c1c14c8a62493367305b252b1b7a66cd4118d45 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:50 +0800 Subject: [PATCH 050/180] Update QueueUtils.java --- .../src/main/java/io/microsphere/collection/QueueUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java index 1102a8560..d0db3a716 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java @@ -39,7 +39,7 @@ * @see Queue * @since 1.0.0 */ -public abstract class QueueUtils extends BaseUtils { +public abstract class QueueUtils { private static final Deque EMPTY_DEQUE = new EmptyDeque(); From 91fec59be21630138b2fdeab1d706275bee118b7 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:52 +0800 Subject: [PATCH 051/180] Update SetUtils.java --- .../src/main/java/io/microsphere/collection/SetUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java index ba2d4ca86..ede629ec3 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java @@ -41,7 +41,7 @@ * @see Set * @since 1.0.0 */ -public abstract class SetUtils extends BaseUtils { +public abstract class SetUtils { public static boolean isSet(@Nullable Iterable elements) { return elements instanceof Set; From efdddcce4adcc9e2a07edd74a3e4c46898d928a6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:54 +0800 Subject: [PATCH 052/180] Update FilterUtils.java --- .../src/main/java/io/microsphere/filter/FilterUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java b/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java index deb386b2e..f3a8f17aa 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java @@ -19,7 +19,7 @@ * @see FilterUtils * @since 1.0.0 */ -public abstract class FilterUtils extends BaseUtils { +public abstract class FilterUtils { private FilterUtils() { } From d7ebeb96f837c53fba018289f710be11e6904e98 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:56 +0800 Subject: [PATCH 053/180] Update MethodHandlesLookupUtils.java --- .../java/io/microsphere/invoke/MethodHandlesLookupUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java index a005062d1..044840597 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java @@ -38,7 +38,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class MethodHandlesLookupUtils extends BaseUtils { +public abstract class MethodHandlesLookupUtils { /** * {@link MethodHandle} for Not-Found From 5b0a94c75663b4a5bee99a9940f35a5cd0c91091 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:15:59 +0800 Subject: [PATCH 054/180] Update MethodHandleUtils.java --- .../src/main/java/io/microsphere/invoke/MethodHandleUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java index 9b248dcfe..089772139 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java @@ -51,7 +51,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class MethodHandleUtils extends BaseUtils { +public abstract class MethodHandleUtils { /** * A single-bit mask representing {@code module} access, From b9d1dbf56a09a484fed133c7b647b41ece642155 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:01 +0800 Subject: [PATCH 055/180] Update FileUtils.java --- .../src/main/java/io/microsphere/io/FileUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java b/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java index 3dd4c6c8d..1bbb7b211 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java @@ -23,7 +23,7 @@ * @see FileUtils * @since 1.0.0 */ -public abstract class FileUtils extends BaseUtils { +public abstract class FileUtils { /** * Resolve Relative Path From adf31b47d30d45cbb8ba7476123d65b7de20925c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:05 +0800 Subject: [PATCH 056/180] Update IOUtils.java --- .../src/main/java/io/microsphere/io/IOUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java b/microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java index 1adc3556a..5f94df6d0 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java @@ -46,7 +46,7 @@ * @see Paths * @since 1.0.0 */ -public abstract class IOUtils extends BaseUtils { +public abstract class IOUtils { private static final Logger logger = getLogger(IOUtils.class); From 51cfcfbeff13764a7b3daf3fb95e19e1cda7e3bf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:07 +0800 Subject: [PATCH 057/180] Update JmxUtils.java --- .../src/main/java/io/microsphere/management/JmxUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java b/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java index d076f721a..096381ac7 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java @@ -59,7 +59,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class JmxUtils extends BaseUtils { +public abstract class JmxUtils { private static final Logger logger = getLogger(JmxUtils.class); From 3f0f9220d520d7660c5d49f9cdfcf903f81fab06 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:09 +0800 Subject: [PATCH 058/180] Update ManagementUtils.java --- .../main/java/io/microsphere/management/ManagementUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java b/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java index 7435c46a1..6e522ab47 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java @@ -17,7 +17,7 @@ * @see ManagementUtils * @since 1.0.0 */ -public abstract class ManagementUtils extends BaseUtils { +public abstract class ManagementUtils { private static final Logger logger = getLogger(ManagementUtils.class); From 2103b2e9aee40a995e0448c758e359ec9ebe4521 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:27 +0800 Subject: [PATCH 059/180] Update CollectionUtils.java --- .../src/main/java/io/microsphere/collection/CollectionUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/CollectionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/CollectionUtils.java index eb9888ba6..8588ecd2a 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/CollectionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/CollectionUtils.java @@ -18,7 +18,6 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.annotation.Nullable; -import io.microsphere.util.BaseUtils; import java.util.AbstractSet; import java.util.Collection; From c6df2ed85544536b8fd0f28f71d386c3cddae6ad Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:29 +0800 Subject: [PATCH 060/180] Update EnumerationUtils.java --- .../main/java/io/microsphere/collection/EnumerationUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java index 1bdc731e3..32460854e 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java @@ -16,8 +16,6 @@ */ package io.microsphere.collection; -import io.microsphere.util.BaseUtils; - import java.util.Collections; import java.util.Enumeration; From afbd1070ca85ad495e6b3ed05c0ce9dcbff26d23 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:31 +0800 Subject: [PATCH 061/180] Update ListUtils.java --- .../src/main/java/io/microsphere/collection/ListUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java index 2bf80d21a..7e0d4335f 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java @@ -16,8 +16,6 @@ */ package io.microsphere.collection; -import io.microsphere.util.BaseUtils; - import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; From 762997f10ff8131e3819797e18508d0cddecee3e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:33 +0800 Subject: [PATCH 062/180] Update MapUtils.java --- .../src/main/java/io/microsphere/collection/MapUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java index 942ca8600..312d9ea92 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java @@ -17,7 +17,6 @@ package io.microsphere.collection; import io.microsphere.annotation.Nonnull; -import io.microsphere.util.BaseUtils; import java.util.Collection; import java.util.Comparator; From 520e6a0356d0b3aeffe4cd71febd467203a8e686 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:35 +0800 Subject: [PATCH 063/180] Update PropertiesUtils.java --- .../main/java/io/microsphere/collection/PropertiesUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java index f3aac5713..13b841b27 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java @@ -16,8 +16,6 @@ */ package io.microsphere.collection; -import io.microsphere.util.BaseUtils; - import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; From bb1f12e1063d3e12eb6416c56a3bcbd608320fc4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:38 +0800 Subject: [PATCH 064/180] Update QueueUtils.java --- .../src/main/java/io/microsphere/collection/QueueUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java index d0db3a716..49523b6fc 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java @@ -16,8 +16,6 @@ */ package io.microsphere.collection; -import io.microsphere.util.BaseUtils; - import java.io.Serializable; import java.util.Collection; import java.util.Deque; From 00706e2db71388345c7e93398c6949ffc211fccf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:41 +0800 Subject: [PATCH 065/180] Update SetUtils.java --- .../src/main/java/io/microsphere/collection/SetUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java index ede629ec3..7efb3fd54 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java @@ -18,7 +18,6 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.annotation.Nullable; -import io.microsphere.util.BaseUtils; import java.util.Collection; import java.util.Enumeration; From f63ffe3283df31ef26eaacd759493acf758594e2 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:44 +0800 Subject: [PATCH 066/180] Update FilterUtils.java --- .../src/main/java/io/microsphere/filter/FilterUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java b/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java index f3a8f17aa..ecc04d7ef 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/filter/FilterUtils.java @@ -4,7 +4,6 @@ package io.microsphere.filter; import io.microsphere.annotation.Nonnull; -import io.microsphere.util.BaseUtils; import java.util.ArrayList; import java.util.Iterator; From 08d05e80b0f363060d6ff2885876268159c8b2ae Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:48 +0800 Subject: [PATCH 067/180] Update MethodHandlesLookupUtils.java --- .../java/io/microsphere/invoke/MethodHandlesLookupUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java index 044840597..1d8ae8746 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java @@ -18,7 +18,6 @@ import io.microsphere.lang.function.ThrowableBiFunction; import io.microsphere.logging.Logger; -import io.microsphere.util.BaseUtils; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; From 828d419dba0f1ad4502a56b3c2767f4e5649021e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:51 +0800 Subject: [PATCH 068/180] Update MethodHandleUtils.java --- .../src/main/java/io/microsphere/invoke/MethodHandleUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java index 089772139..9ffad4c42 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java @@ -17,7 +17,6 @@ package io.microsphere.invoke; import io.microsphere.lang.function.ThrowableBiFunction; -import io.microsphere.util.BaseUtils; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; From 3200ac6375a46b828de1a0f4d64f7bb2f51855b4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:54 +0800 Subject: [PATCH 069/180] Update FileUtils.java --- .../src/main/java/io/microsphere/io/FileUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java b/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java index 1bbb7b211..00aaca817 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java @@ -3,8 +3,6 @@ */ package io.microsphere.io; -import io.microsphere.util.BaseUtils; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; From 3a6e6bf5fb99d8030f87f48b6f6ba4a38897c8ca Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:56 +0800 Subject: [PATCH 070/180] Update IOUtils.java --- .../src/main/java/io/microsphere/io/IOUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java b/microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java index 5f94df6d0..f607c9afe 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/io/IOUtils.java @@ -18,7 +18,6 @@ import io.microsphere.logging.Logger; import io.microsphere.nio.charset.CharsetUtils; -import io.microsphere.util.BaseUtils; import io.microsphere.util.SystemUtils; import java.io.Closeable; From e552029f06ec7eca0ce639a8d5e583afc03fff64 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:16:59 +0800 Subject: [PATCH 071/180] Update JmxUtils.java --- .../src/main/java/io/microsphere/management/JmxUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java b/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java index 096381ac7..6df9f9a05 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java @@ -19,7 +19,6 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.annotation.Nullable; import io.microsphere.logging.Logger; -import io.microsphere.util.BaseUtils; import javax.management.AttributeNotFoundException; import javax.management.InstanceNotFoundException; From c88a1a55b5cc39c51d390edb8c72bad3c5d6e3a6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:04 +0800 Subject: [PATCH 072/180] Update VersionUtils.java --- .../src/main/java/io/microsphere/util/VersionUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/VersionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/VersionUtils.java index e88875d55..d2492cbd7 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/VersionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/VersionUtils.java @@ -31,7 +31,7 @@ * @see Version * @since 1.0.0 */ -public abstract class VersionUtils extends BaseUtils { +public abstract class VersionUtils { /** * The latest {@link SourceVersion Java Release Version} From f7ebd228b0c37f98eba8129e2f853bf323d2b137 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:06 +0800 Subject: [PATCH 073/180] Update SystemUtils.java --- .../src/main/java/io/microsphere/util/SystemUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/SystemUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/SystemUtils.java index 29872f391..9b039953d 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/SystemUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/SystemUtils.java @@ -28,7 +28,7 @@ * @see System * @since 1.0.0 */ -public abstract class SystemUtils extends BaseUtils { +public abstract class SystemUtils { private static final Logger logger = getLogger(SystemUtils.class); From 9f8b1ba93df306d0cc4d9355256de05877f6bddf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:08 +0800 Subject: [PATCH 074/180] Update StringUtils.java --- .../src/main/java/io/microsphere/util/StringUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java index fe6ae7f6a..ebed77c6e 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java @@ -28,7 +28,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class StringUtils extends BaseUtils { +public abstract class StringUtils { public final static String EMPTY = ""; From 5d18e087837add799cdaef431ee0ecc6d9a2acfc Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:10 +0800 Subject: [PATCH 075/180] Update StackTraceUtils.java --- .../src/main/java/io/microsphere/util/StackTraceUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/StackTraceUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/StackTraceUtils.java index 8a58ae2d2..5ddd2d0c1 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/StackTraceUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/StackTraceUtils.java @@ -41,7 +41,7 @@ * @see StackTraceElement * @since 1.0.0 */ -public abstract class StackTraceUtils extends BaseUtils { +public abstract class StackTraceUtils { private static final Class TYPE = StackTraceUtils.class; From 7161320f4cf42a106db45630a239f79c4113b06e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:12 +0800 Subject: [PATCH 076/180] Update ShutdownHookUtils.java --- .../src/main/java/io/microsphere/util/ShutdownHookUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ShutdownHookUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ShutdownHookUtils.java index 52da280f7..c02135abc 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ShutdownHookUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ShutdownHookUtils.java @@ -43,7 +43,7 @@ * @see java.lang.ApplicationShutdownHooks * @since 1.0.0 */ -public abstract class ShutdownHookUtils extends BaseUtils { +public abstract class ShutdownHookUtils { private static final Logger logger = getLogger(ShutdownHookUtils.class); From bf5175e0c71124708f12ec8a0f731004bdac605b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:15 +0800 Subject: [PATCH 077/180] Update ServiceLoaderUtils.java --- .../src/main/java/io/microsphere/util/ServiceLoaderUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ServiceLoaderUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ServiceLoaderUtils.java index 534f5698b..0fa79ca3e 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ServiceLoaderUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ServiceLoaderUtils.java @@ -27,7 +27,7 @@ * @see ServiceLoader * @since 1.0.0 */ -public abstract class ServiceLoaderUtils extends BaseUtils { +public abstract class ServiceLoaderUtils { private static final Logger logger = getLogger(ServiceLoaderUtils.class); From 5411c435601078af4f145027f6d077eefaeafecf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:24 +0800 Subject: [PATCH 078/180] Update PropertyResourceBundleUtils.java --- .../java/io/microsphere/util/PropertyResourceBundleUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java index cb18ea424..7422a8997 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java @@ -21,7 +21,7 @@ * @see PropertyResourceBundle * @since 1.0.0 */ -public abstract class PropertyResourceBundleUtils extends BaseUtils { +public abstract class PropertyResourceBundleUtils { /** * The property name of encoding for {@link PropertyResourceBundle} From 8d1e9a19aed587902d738fc8d9d58dcadd8d4fd6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:26 +0800 Subject: [PATCH 079/180] Update JarUtils.java --- .../src/main/java/io/microsphere/util/jar/JarUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/jar/JarUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/jar/JarUtils.java index 605d450fe..30161bde4 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/jar/JarUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/jar/JarUtils.java @@ -6,7 +6,6 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.constants.ProtocolConstants; import io.microsphere.filter.JarEntryFilter; -import io.microsphere.util.BaseUtils; import java.io.File; import java.io.FileOutputStream; @@ -42,7 +41,7 @@ * @see JarFile * @since 1.0.0 */ -public abstract class JarUtils extends BaseUtils { +public abstract class JarUtils { /** * Create a {@link JarFile} from specified {@link URL} of {@link JarFile} From 0968fef9d0c8d3c4f7d1635895d60d6c72a4f7f8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:28 +0800 Subject: [PATCH 080/180] Update ExceptionUtils.java --- .../src/main/java/io/microsphere/util/ExceptionUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ExceptionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ExceptionUtils.java index 47da0d60c..6cdd96701 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ExceptionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ExceptionUtils.java @@ -29,7 +29,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class ExceptionUtils extends BaseUtils { +public abstract class ExceptionUtils { /** *

Gets the stack trace from a Throwable as a String.

From 7caa6efd67071c6e8e4540749cf4c4f1790063f1 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:29 +0800 Subject: [PATCH 081/180] Update ClassUtils.java --- .../src/main/java/io/microsphere/util/ClassUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java index 85aaac00e..8c94f1660 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java @@ -77,7 +77,7 @@ * @see ClassUtils * @since 1.0.0 */ -public abstract class ClassUtils extends BaseUtils { +public abstract class ClassUtils { private final static Logger logger = getLogger(ClassUtils.class); From 104f48ce79fc5f46c917b12db0ba1562c21fef2e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:32 +0800 Subject: [PATCH 082/180] Update ClassPathUtils.java --- .../src/main/java/io/microsphere/util/ClassPathUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java index 66ea79538..b3bca198a 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java @@ -29,7 +29,7 @@ * @see ClassPathUtils * @since 1.0.0 */ -public abstract class ClassPathUtils extends BaseUtils { +public abstract class ClassPathUtils { protected static final RuntimeMXBean runtimeMXBean = getRuntimeMXBean(); From dc86eb68b74a31a1edc73fd59ab118483d0344d8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:35 +0800 Subject: [PATCH 083/180] Update ClassLoaderUtils.java --- .../src/main/java/io/microsphere/util/ClassLoaderUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java index 183917d45..082de853b 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java @@ -65,7 +65,7 @@ * @see ClassLoader * @since 1.0.0 */ -public abstract class ClassLoaderUtils extends BaseUtils { +public abstract class ClassLoaderUtils { private static final Logger logger = getLogger(ClassLoaderUtils.class); From 611453787f7367864bda928734e64c3c50868850 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:37 +0800 Subject: [PATCH 084/180] Update Assert.java --- .../src/main/java/io/microsphere/util/Assert.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/Assert.java b/microsphere-java-core/src/main/java/io/microsphere/util/Assert.java index 25f2f3d93..d842ec794 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/Assert.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/Assert.java @@ -41,7 +41,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class Assert extends BaseUtils { +public abstract class Assert { /** * Assert a boolean expression, throwing an {@code IllegalArgumentException} From f5980acc8573456083deb68eaaedd65be800b541 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:40 +0800 Subject: [PATCH 085/180] Update AnnotationUtils.java --- .../src/main/java/io/microsphere/util/AnnotationUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java index 2bb23f561..58881a23b 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java @@ -61,7 +61,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class AnnotationUtils extends BaseUtils { +public abstract class AnnotationUtils { public final static List> NATIVE_ANNOTATION_TYPES = ofList( Target.class, From 4763c5753c2520179fb13e2ca32de90d6932ecc7 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:43 +0800 Subject: [PATCH 086/180] Update FormatUtils.java --- .../src/main/java/io/microsphere/text/FormatUtils.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java b/microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java index 7023ceb6a..1621ed797 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java @@ -1,7 +1,5 @@ package io.microsphere.text; -import io.microsphere.util.BaseUtils; - import static io.microsphere.util.StringUtils.isBlank; /** @@ -10,7 +8,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class FormatUtils extends BaseUtils { +public abstract class FormatUtils { public static final String DEFAULT_PLACEHOLDER = "{}"; From 2c02f9e0125f97ba8f78267fcf00ff90625b4f7a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:46 +0800 Subject: [PATCH 087/180] Update TypeUtils.java --- .../src/main/java/io/microsphere/reflect/TypeUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/TypeUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/TypeUtils.java index e01c6ae4d..9930774d1 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/TypeUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/TypeUtils.java @@ -19,7 +19,6 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.annotation.Nullable; import io.microsphere.reflect.generics.TypeArgument; -import io.microsphere.util.BaseUtils; import io.microsphere.util.ClassUtils; import java.lang.reflect.GenericArrayType; @@ -60,7 +59,7 @@ * * @since 1.0.0 */ -public abstract class TypeUtils extends BaseUtils { +public abstract class TypeUtils { public static final Predicate NON_OBJECT_TYPE_FILTER = t -> t != null && !isObjectType(t); From a14a741d56d1c7d09089fb957dc452cae0a6389d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:49 +0800 Subject: [PATCH 088/180] Update ReflectionUtils.java --- .../src/main/java/io/microsphere/reflect/ReflectionUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java index 0e670cb55..709f4b797 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java @@ -4,7 +4,6 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.annotation.Nullable; import io.microsphere.logging.Logger; -import io.microsphere.util.BaseUtils; import java.lang.reflect.Array; import java.lang.reflect.Constructor; @@ -37,7 +36,7 @@ * @see ConstructorUtils * @since 1.0.0 */ -public abstract class ReflectionUtils extends BaseUtils { +public abstract class ReflectionUtils { /** * Current Type From 25a949aa7035ecc90851f278023931882d3721c0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:52 +0800 Subject: [PATCH 089/180] Update ProxyUtils.java --- .../src/main/java/io/microsphere/reflect/ProxyUtils.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/ProxyUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/ProxyUtils.java index ef53cda7d..4a909a8e2 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/ProxyUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/ProxyUtils.java @@ -16,8 +16,6 @@ */ package io.microsphere.reflect; -import io.microsphere.util.BaseUtils; - import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.List; @@ -39,7 +37,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class ProxyUtils extends BaseUtils { +public abstract class ProxyUtils { /** *
    From 0fe84b060ca6c57d3c5522450121eb91f3d84cb8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:54 +0800 Subject: [PATCH 090/180] Update MethodUtils.java --- .../src/main/java/io/microsphere/reflect/MethodUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java index e9e27c93c..39e83b7e4 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java @@ -18,7 +18,6 @@ import io.microsphere.annotation.Nullable; import io.microsphere.logging.Logger; -import io.microsphere.util.BaseUtils; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; @@ -65,7 +64,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class MethodUtils extends BaseUtils { +public abstract class MethodUtils { private static final Logger logger = getLogger(MethodUtils.class); From 2fa84cb55f90da88da9cc24740c2cb2990382420 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:17:57 +0800 Subject: [PATCH 091/180] Update MemberUtils.java --- .../src/main/java/io/microsphere/reflect/MemberUtils.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MemberUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MemberUtils.java index 94fd4cec2..5a168c59b 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MemberUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MemberUtils.java @@ -16,8 +16,6 @@ */ package io.microsphere.reflect; -import io.microsphere.util.BaseUtils; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Member; @@ -30,7 +28,7 @@ * * @since 1.0.0 */ -public abstract class MemberUtils extends BaseUtils { +public abstract class MemberUtils { /** * The {@link Predicate} reference to {@link #isStatic(Member)} From a751cfc87badc282608e24ea52b22c0d922bd098 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:18:00 +0800 Subject: [PATCH 092/180] Update FieldUtils.java --- .../src/main/java/io/microsphere/reflect/FieldUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java index 83e83650b..952bcd6a3 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java @@ -17,7 +17,6 @@ package io.microsphere.reflect; import io.microsphere.logging.Logger; -import io.microsphere.util.BaseUtils; import java.lang.reflect.Field; import java.util.LinkedHashSet; @@ -41,7 +40,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class FieldUtils extends BaseUtils { +public abstract class FieldUtils { private static final Logger logger = getLogger(FieldUtils.class); From 59b8524549e73d4af8d4bdc9a07e6b07ea1a97b4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:18:03 +0800 Subject: [PATCH 093/180] Update ExecutableUtils.java --- .../src/main/java/io/microsphere/reflect/ExecutableUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/ExecutableUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/ExecutableUtils.java index bad7bcbac..462df4968 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/ExecutableUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/ExecutableUtils.java @@ -20,7 +20,6 @@ import io.microsphere.lang.function.ThrowableFunction; import io.microsphere.lang.function.ThrowableSupplier; import io.microsphere.logging.Logger; -import io.microsphere.util.BaseUtils; import java.lang.reflect.Constructor; import java.lang.reflect.Executable; @@ -40,7 +39,7 @@ * @see Executable * @since 1.0.0 */ -public abstract class ExecutableUtils extends BaseUtils { +public abstract class ExecutableUtils { private static final Logger logger = getLogger(ExecutableUtils.class); From 85703c545cc50a4df1dbb419d135537a2d622244 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:18:07 +0800 Subject: [PATCH 094/180] Update ConstructorUtils.java --- .../src/main/java/io/microsphere/reflect/ConstructorUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/ConstructorUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/ConstructorUtils.java index c8e1f807a..cf08c525e 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/ConstructorUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/ConstructorUtils.java @@ -17,7 +17,6 @@ package io.microsphere.reflect; import io.microsphere.logging.Logger; -import io.microsphere.util.BaseUtils; import java.lang.reflect.Constructor; import java.util.List; @@ -37,7 +36,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class ConstructorUtils extends BaseUtils { +public abstract class ConstructorUtils { private static final Logger logger = getLogger(ConstructorUtils.class); From ddcb06d477f4bb9737745e19268c18231103a675 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:18:10 +0800 Subject: [PATCH 095/180] Update AccessibleObjectUtils.java --- .../java/io/microsphere/reflect/AccessibleObjectUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/AccessibleObjectUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/AccessibleObjectUtils.java index 9e805bacb..e436edbd5 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/AccessibleObjectUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/AccessibleObjectUtils.java @@ -17,7 +17,6 @@ package io.microsphere.reflect; import io.microsphere.logging.Logger; -import io.microsphere.util.BaseUtils; import java.lang.invoke.MethodHandle; import java.lang.reflect.AccessibleObject; @@ -39,7 +38,7 @@ * @see AccessibleObject * @since 1.0.0 */ -public abstract class AccessibleObjectUtils extends BaseUtils { +public abstract class AccessibleObjectUtils { private static final Logger logger = getLogger(AccessibleObjectUtils.class); From f212221dc38da35ba5c540ffeac0d0bba4bac126 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:18:12 +0800 Subject: [PATCH 096/180] Update CharsetUtils.java --- .../main/java/io/microsphere/nio/charset/CharsetUtils.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/nio/charset/CharsetUtils.java b/microsphere-java-core/src/main/java/io/microsphere/nio/charset/CharsetUtils.java index fc03d1736..6f4721b65 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/nio/charset/CharsetUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/nio/charset/CharsetUtils.java @@ -16,8 +16,6 @@ */ package io.microsphere.nio.charset; -import io.microsphere.util.BaseUtils; - import java.nio.charset.Charset; import static java.nio.charset.Charset.defaultCharset; @@ -29,7 +27,7 @@ * @see Charset * @since 1.0.0 */ -public abstract class CharsetUtils extends BaseUtils { +public abstract class CharsetUtils { /** * The default charset looks up from the JDK system property "file.encoding" From 308c90c3e4dbfc5d8c0c0f1c7e26ae8948393585 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:18:15 +0800 Subject: [PATCH 097/180] Update URLUtils.java --- .../src/main/java/io/microsphere/net/URLUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 576e33445..216839d31 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -6,7 +6,6 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.logging.Logger; import io.microsphere.util.ArrayUtils; -import io.microsphere.util.BaseUtils; import java.io.File; import java.io.IOException; @@ -75,7 +74,7 @@ * @see URLDecoder * @since 1.0.0 */ -public abstract class URLUtils extends BaseUtils { +public abstract class URLUtils { private static final Logger logger = getLogger(URLUtils.class); From 3da87b97b9f2970220eb21a1897222d94c0117ea Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 17:18:17 +0800 Subject: [PATCH 098/180] Update ManagementUtils.java --- .../src/main/java/io/microsphere/management/ManagementUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java b/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java index 6e522ab47..4a492676b 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java @@ -3,7 +3,6 @@ import io.microsphere.logging.Logger; import io.microsphere.process.ProcessIdResolver; -import io.microsphere.util.BaseUtils; import java.util.List; From 28cd2436554a8fc53ebbb5595b93839b3b3eaf15 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 21:14:04 +0800 Subject: [PATCH 099/180] Update TypeUtils.java --- .../java/io/microsphere/annotation/processor/util/TypeUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java index 88eabbf29..e5d9c48f3 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java @@ -110,7 +110,6 @@ static boolean isSameType(TypeMirror type, CharSequence typeName) { return Objects.equals(valueOf(type), valueOf(typeName)); } - static boolean isArrayType(TypeMirror type) { return type != null && ARRAY == type.getKind(); } From 5fc80f4008c2e1700b4751413a983767c20f9f62 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 21:14:10 +0800 Subject: [PATCH 100/180] Create DelegatingDeque.java --- .../collection/DelegatingDeque.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/collection/DelegatingDeque.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/DelegatingDeque.java b/microsphere-java-core/src/test/java/io/microsphere/collection/DelegatingDeque.java new file mode 100644 index 000000000..454926ba0 --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/DelegatingDeque.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.microsphere.collection; + +import java.util.Deque; +import java.util.Iterator; + +import static io.microsphere.collection.ListUtils.newLinkedList; +import static io.microsphere.collection.Lists.ofList; + +/** + * Delegating {@link Deque} + * + * @author Mercy + * @see AbstractDeque + * @since 1.0.0 + */ +public class DelegatingDeque extends AbstractDeque { + + private final Deque delegate; + + public DelegatingDeque(Deque delegate) { + this.delegate = delegate; + } + + @Override + public Iterator iterator() { + return delegate.iterator(); + } + + @Override + public Iterator descendingIterator() { + return delegate.descendingIterator(); + } + + @Override + public boolean offerFirst(E e) { + return false; + } + + @Override + public boolean offerLast(E e) { + return false; + } + + @Override + public E pollFirst() { + return delegate.pollFirst(); + } + + @Override + public E pollLast() { + return delegate.pollLast(); + } + + @Override + public E getFirst() { + return delegate.getFirst(); + } + + @Override + public E getLast() { + return delegate.getLast(); + } + + @Override + public boolean removeLastOccurrence(Object o) { + return delegate.removeLastOccurrence(o); + } + + @Override + public int size() { + return 0; + } +} From c4302809db3778cbbfed4f3ff2fe3c86a223826b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 21:14:13 +0800 Subject: [PATCH 101/180] Update AbstractDequeTest.java --- .../collection/AbstractDequeTest.java | 63 +++---------------- 1 file changed, 7 insertions(+), 56 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/AbstractDequeTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/AbstractDequeTest.java index 0ccd8d0df..85849e0b1 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/AbstractDequeTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/AbstractDequeTest.java @@ -1,9 +1,8 @@ package io.microsphere.collection; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.Deque; -import java.util.Iterator; import java.util.NoSuchElementException; import static io.microsphere.collection.ListUtils.newLinkedList; @@ -22,60 +21,12 @@ */ public class AbstractDequeTest { - private final AbstractDeque deque = new AbstractDeque() { - - private final Deque values = newLinkedList(ofList("a")); - - @Override - public Iterator iterator() { - return values.iterator(); - } - - @Override - public Iterator descendingIterator() { - return values.descendingIterator(); - } - - @Override - public boolean offerFirst(String s) { - return false; - } - - @Override - public boolean offerLast(String s) { - return false; - } - - @Override - public String pollFirst() { - return values.pollFirst(); - } - - @Override - public String pollLast() { - return values.pollLast(); - } - - @Override - public String getFirst() { - return values.getFirst(); - } - - @Override - public String getLast() { - return values.getLast(); - } - - @Override - public boolean removeLastOccurrence(Object o) { - return values.removeLastOccurrence(o); - } - - @Override - public int size() { - return 0; - } - }; + private AbstractDeque deque; + + @BeforeEach + public void init() { + this.deque = new DelegatingDeque(newLinkedList(ofList("a"))); + } @Test public void testAddFirst() { From f407980ba0db2a614832379e4a84b37fd7d88d2a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 21:27:52 +0800 Subject: [PATCH 102/180] Update ThrowableActionTest.java --- .../lang/function/ThrowableActionTest.java | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableActionTest.java b/microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableActionTest.java index 95db8eda1..77819bb0b 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableActionTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableActionTest.java @@ -16,6 +16,7 @@ */ package io.microsphere.lang.function; +import io.microsphere.AbstractTestCase; import org.junit.jupiter.api.Test; import static io.microsphere.lang.function.ThrowableAction.execute; @@ -26,26 +27,46 @@ * * @since 1.0.0 */ -public class ThrowableActionTest { +public class ThrowableActionTest extends AbstractTestCase { - private static final ThrowableAction action = () -> { + private final ThrowableAction action = () -> { + logger.trace("ThrowableAction#execute()"); + }; + + private final ThrowableAction exceptionalAction = () -> { throw new Exception("Test"); }; @Test - public void testExecute0() { - assertThrows(Exception.class, action::execute); + public void testExecute() throws Throwable { + action.execute(); + assertThrows(Exception.class, exceptionalAction::execute); + } + + @Test + public void testExecuteWithThrowableAction() { + execute(action); + assertThrows(RuntimeException.class, () -> execute(exceptionalAction)); } @Test - public void testExecute1() { - assertThrows(RuntimeException.class, () -> execute(action)); + public void testExecuteWithThrowableActionOnNull() { + assertThrows(NullPointerException.class, () -> execute(null)); } @Test - public void testExecute2() { - assertThrows(RuntimeException.class, () -> execute(action, e -> { + public void testExecuteWithThrowableActionAndConsumer() { + execute(action, e -> { + }); + + assertThrows(RuntimeException.class, () -> execute(exceptionalAction, e -> { throw new RuntimeException(e); })); } + + @Test + public void testExecuteWithThrowableActionAndConsumerOnNull() { + assertThrows(IllegalArgumentException.class, () -> execute(null, e -> { + })); + } } From 16726841eec004efb243060af3272038478eebcf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 21:28:13 +0800 Subject: [PATCH 103/180] Update CharsetUtilsTest.java --- .../java/io/microsphere/nio/charset/CharsetUtilsTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java index 69154b9b3..6dde54978 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java @@ -5,7 +5,9 @@ import java.nio.charset.StandardCharsets; import static io.microsphere.nio.charset.CharsetUtils.DEFAULT_CHARSET; +import static io.microsphere.util.ClassUtils.isAbstractClass; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link CharsetUtils} Test @@ -15,6 +17,12 @@ * @since 1.0.0 */ public class CharsetUtilsTest { + + @Test + public void testClass() { + assertTrue(isAbstractClass(CharsetUtils.class)); + } + @Test public void testConstants() { assertEquals(StandardCharsets.UTF_8, DEFAULT_CHARSET); From e0e7dab8c8841fe3b2cd21c7203181ee32587ddc Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 29 Mar 2025 21:31:17 +0800 Subject: [PATCH 104/180] Update EnumerationUtilsTest.java --- .../microsphere/collection/EnumerationUtilsTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationUtilsTest.java index 2fc43ada8..363f1b362 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationUtilsTest.java @@ -21,6 +21,7 @@ import java.util.Enumeration; import java.util.NoSuchElementException; +import static io.microsphere.collection.EnumerationUtils.of; import static io.microsphere.collection.EnumerationUtils.ofEnums; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -37,9 +38,17 @@ */ public class EnumerationUtilsTest { + @Test + public void testOf() { + assertEnumeration(of("A", "B", "C")); + } + @Test public void testOfEnums() { - Enumeration e = ofEnums("A", "B", "C"); + assertEnumeration(ofEnums("A", "B", "C")); + } + + private static void assertEnumeration(Enumeration e) { assertNotNull(e); assertTrue(e.hasMoreElements()); From b6adfd683b1c870120e1b93e83c396e6d4e8a3fd Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Tue, 1 Apr 2025 11:10:45 +0800 Subject: [PATCH 105/180] Update Compiler.java --- .../io/microsphere/annotation/processor/Compiler.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/Compiler.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/Compiler.java index fda33704d..22e0dbb6e 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/Compiler.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/Compiler.java @@ -20,12 +20,12 @@ import javax.annotation.processing.Processor; import javax.tools.JavaCompiler; +import javax.tools.JavaCompiler.CompilationTask; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; import java.io.File; import java.io.IOException; import java.net.URL; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -39,6 +39,7 @@ import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.util.ClassUtils.getTypeName; import static io.microsphere.util.StringUtils.substringBefore; +import static java.util.Collections.singleton; import static javax.tools.StandardLocation.CLASS_OUTPUT; import static javax.tools.StandardLocation.SOURCE_OUTPUT; import static javax.tools.ToolProvider.getSystemJavaCompiler; @@ -73,8 +74,8 @@ public Compiler(File defaultSourceDirectory, File targetDirectory) throws IOExce this.sourcePaths = newLinkedHashSet(defaultSourceDirectory); this.javaCompiler = getSystemJavaCompiler(); this.javaFileManager = javaCompiler.getStandardFileManager(null, null, null); - this.javaFileManager.setLocation(CLASS_OUTPUT, Collections.singleton(targetDirectory)); - this.javaFileManager.setLocation(SOURCE_OUTPUT, Collections.singleton(targetDirectory)); + this.javaFileManager.setLocation(CLASS_OUTPUT, singleton(targetDirectory)); + this.javaFileManager.setLocation(SOURCE_OUTPUT, singleton(targetDirectory)); } public Compiler sourcePaths(File... sourcePaths) { @@ -191,7 +192,7 @@ static String resolveJavaSourceFileRelativePath(Class sourceClass) { } public boolean compile(Class... sourceClasses) { - JavaCompiler.CompilationTask task = javaCompiler.getTask(null, this.javaFileManager, null, + CompilationTask task = javaCompiler.getTask(null, this.javaFileManager, null, ofList("-parameters", "-Xlint:unchecked", "-nowarn", "-Xlint:deprecation"), // null, null, getJavaFileObjects(sourceClasses)); From 2967afc630d579b9483c657cde6ebc824c7c34c7 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Tue, 1 Apr 2025 11:42:02 +0800 Subject: [PATCH 106/180] Update TypeUtilsTest.java --- .../processor/util/TypeUtilsTest.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java index 746df80e1..ce381e963 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java @@ -43,6 +43,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; import static io.microsphere.annotation.processor.util.FieldUtils.findField; import static io.microsphere.annotation.processor.util.FieldUtils.getDeclaredFields; @@ -355,6 +356,7 @@ public void testIsAnnotationTypeOnNull() { public void testIsTypeElement() { assertTrue(isTypeElement(testTypeElement)); assertTrue(isTypeElement(testTypeMirror)); + assertTrue(isTypeElement(getFieldType(testTypeElement, "context"))); // primitive type assertFalse(isTypeElement(getTypeMirror(int.class))); @@ -755,6 +757,13 @@ public void testFindTypeElements() { assertEmptyList(typeElements); } + @Test + public void testFindTypeElementsOnNullFilterElement() { + assertThrows(IllegalArgumentException.class, + () -> findTypeElements(testTypeElement, true, true, true, true, new Predicate[]{null})); + } + + @Test public void testGetDeclaredTypeOfSuperclass() { DeclaredType superDeclaredType = getDeclaredTypeOfSuperclass(testTypeMirror); @@ -1687,11 +1696,11 @@ private void assertIsArrayType(Type type) { } private void assertIsArrayType(Element element) { - assertTrue(isArrayType(getFieldType(element, "integers"))); - assertTrue(isArrayType(getFieldType(element, "strings"))); - assertTrue(isArrayType(getFieldType(element, "primitiveTypeModels"))); - assertTrue(isArrayType(getFieldType(element, "models"))); - assertTrue(isArrayType(getFieldType(element, "colors"))); + assertTrue(isArrayType(findField(element, "integers"))); + assertTrue(isArrayType(findField(element, "strings"))); + assertTrue(isArrayType(findField(element, "primitiveTypeModels"))); + assertTrue(isArrayType(findField(element, "models"))); + assertTrue(isArrayType(findField(element, "colors"))); } private void assertTypeMirrors(List typeMirrors, Type... types) { From 2379ae821d1df0e3fc52bbdfebf752a199b65f0e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Tue, 1 Apr 2025 21:02:12 +0800 Subject: [PATCH 107/180] Create CharSequenceUtils.java --- .../microsphere/util/CharSequenceUtils.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java new file mode 100644 index 000000000..03ba9edde --- /dev/null +++ b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java @@ -0,0 +1,23 @@ +package io.microsphere.util; + +/** + * The utilities class for {@link CharSequence} + * + * @author Mercy + * @see CharSequence + * @since 1.0.0 + */ +public class CharSequenceUtils { + + public static int length(CharSequence value) { + return value == null ? 0 : value.length(); + } + + public static boolean isEmpty(CharSequence value) { + return length(value) == 0; + } + + public static boolean isNotEmpty(CharSequence value) { + return length(value) > 0; + } +} From 1590e72e9158da5b38c5a09e3bd4b292e4d1c35e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Tue, 1 Apr 2025 21:02:15 +0800 Subject: [PATCH 108/180] Create CharSequenceUtilsTest.java --- .../util/CharSequenceUtilsTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java new file mode 100644 index 000000000..84df4947b --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java @@ -0,0 +1,54 @@ +package io.microsphere.util; + +import org.junit.jupiter.api.Test; + +import static io.microsphere.constants.SymbolConstants.SPACE; +import static io.microsphere.util.CharSequenceUtils.isEmpty; +import static io.microsphere.util.CharSequenceUtils.isNotEmpty; +import static io.microsphere.util.CharSequenceUtils.length; +import static org.junit.jupiter.api.Assertions.*; + +/** + * {@link CharSequenceUtils} Test + * + * @author Mercy + * @see CharSequenceUtils + * @since 1.0.0 + */ +public class CharSequenceUtilsTest { + + static final String TEST_EMPTY_STRING = ""; + + static final String TEST_BLANK_STRING = SPACE; + + static final String TEST_CSV_STRING = "a,b,c"; + + static final String TEST_STRING = "testing"; + + @Test + public void testLength() { + assertEquals(0, length(null)); + assertEquals(0, length(TEST_EMPTY_STRING)); + assertEquals(1, length(TEST_BLANK_STRING)); + assertEquals(5, length(TEST_CSV_STRING)); + assertEquals(7, length(TEST_STRING)); + } + + @Test + public void testIsEmpty() { + assertTrue(isEmpty(null)); + assertTrue(isEmpty(TEST_EMPTY_STRING)); + assertFalse(isEmpty(TEST_BLANK_STRING)); + assertFalse(isEmpty(TEST_CSV_STRING)); + assertFalse(isEmpty(TEST_STRING)); + } + + @Test + public void testIsNotEmpty() { + assertFalse(isNotEmpty(null)); + assertFalse(isNotEmpty(TEST_EMPTY_STRING)); + assertTrue(isNotEmpty(TEST_BLANK_STRING)); + assertTrue(isNotEmpty(TEST_CSV_STRING)); + assertTrue(isNotEmpty(TEST_STRING)); + } +} \ No newline at end of file From 7f7db691ad4e3c19a9373a12a0acda0c04662350 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Tue, 1 Apr 2025 21:02:17 +0800 Subject: [PATCH 109/180] Update StringUtils.java --- .../main/java/io/microsphere/util/StringUtils.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java index ebed77c6e..1eb34089c 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java @@ -28,7 +28,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class StringUtils { +public abstract class StringUtils extends CharSequenceUtils { public final static String EMPTY = ""; @@ -36,18 +36,6 @@ public abstract class StringUtils { public static final String[] EMPTY_STRING_ARRAY = ArrayUtils.EMPTY_STRING_ARRAY; - public static int length(String value) { - return value == null ? 0 : value.length(); - } - - public static boolean isEmpty(String value) { - return length(value) == 0; - } - - public static boolean isNotEmpty(String value) { - return length(value) > 0; - } - public static boolean isBlank(String value) { int length = length(value); if (length < 1) { From 7b68b5714a5065dfa03b737d9b833f6e06107744 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Tue, 1 Apr 2025 21:02:19 +0800 Subject: [PATCH 110/180] Update StringUtilsTest.java --- .../java/io/microsphere/util/StringUtilsTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java index e9ae1436a..e76130734 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java @@ -9,6 +9,10 @@ import static io.microsphere.constants.SymbolConstants.SPACE_CHAR; import static io.microsphere.constants.SymbolConstants.VERTICAL_BAR; import static io.microsphere.util.ArrayUtils.ofArray; +import static io.microsphere.util.CharSequenceUtilsTest.TEST_BLANK_STRING; +import static io.microsphere.util.CharSequenceUtilsTest.TEST_CSV_STRING; +import static io.microsphere.util.CharSequenceUtilsTest.TEST_EMPTY_STRING; +import static io.microsphere.util.CharSequenceUtilsTest.TEST_STRING; import static io.microsphere.util.StringUtils.EMPTY; import static io.microsphere.util.StringUtils.EMPTY_STRING; import static io.microsphere.util.StringUtils.EMPTY_STRING_ARRAY; @@ -43,14 +47,6 @@ */ public class StringUtilsTest { - private static final String TEST_EMPTY_STRING = ""; - - private static final String TEST_BLANK_STRING = SPACE; - - private static final String TEST_CSV_STRING = "a,b,c"; - - private static final String TEST_STRING = "testing"; - @Test public void testConstants() { From e23eb6d245ea319039627153077a7b92a9815406 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Tue, 1 Apr 2025 21:03:21 +0800 Subject: [PATCH 111/180] Update CharSequenceUtilsTest.java --- .../test/java/io/microsphere/util/CharSequenceUtilsTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java index 84df4947b..8802cdf4e 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java @@ -6,7 +6,9 @@ import static io.microsphere.util.CharSequenceUtils.isEmpty; import static io.microsphere.util.CharSequenceUtils.isNotEmpty; import static io.microsphere.util.CharSequenceUtils.length; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link CharSequenceUtils} Test From 0a75c6fd10cbc442d2ee271f5f1be3e5eda64938 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Tue, 1 Apr 2025 21:03:26 +0800 Subject: [PATCH 112/180] Update DelegatingDeque.java --- .../test/java/io/microsphere/collection/DelegatingDeque.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/DelegatingDeque.java b/microsphere-java-core/src/test/java/io/microsphere/collection/DelegatingDeque.java index 454926ba0..c8c39d86f 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/DelegatingDeque.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/DelegatingDeque.java @@ -19,9 +19,6 @@ import java.util.Deque; import java.util.Iterator; -import static io.microsphere.collection.ListUtils.newLinkedList; -import static io.microsphere.collection.Lists.ofList; - /** * Delegating {@link Deque} * From 2b581dac1ff5c7349a0d2b06d39697539bcdd003 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 09:27:38 +0800 Subject: [PATCH 113/180] Update BeanProperty.java --- .../src/main/java/io/microsphere/beans/BeanProperty.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/beans/BeanProperty.java b/microsphere-java-core/src/main/java/io/microsphere/beans/BeanProperty.java index b63b13890..04d8b398d 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/beans/BeanProperty.java +++ b/microsphere-java-core/src/main/java/io/microsphere/beans/BeanProperty.java @@ -93,10 +93,10 @@ public boolean equals(Object o) { @Override public int hashCode() { - int result = name != null ? name.hashCode() : 0; + int result = name.hashCode(); result = 31 * result + (value != null ? value.hashCode() : 0); - result = 31 * result + (beanClass != null ? beanClass.hashCode() : 0); - result = 31 * result + (descriptor != null ? descriptor.hashCode() : 0); + result = 31 * result + beanClass.hashCode(); + result = 31 * result + descriptor.hashCode(); return result; } From 558a84f31e8a411102056e2bb455a86e90e8f57b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 09:27:41 +0800 Subject: [PATCH 114/180] Update BeanPropertyTest.java --- .../microsphere/beans/BeanPropertyTest.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/beans/BeanPropertyTest.java b/microsphere-java-core/src/test/java/io/microsphere/beans/BeanPropertyTest.java index 953ef32de..a82a9e3cd 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/beans/BeanPropertyTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/beans/BeanPropertyTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static io.microsphere.beans.BeanProperty.of; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -57,7 +58,7 @@ public void setBeanProperty(BeanProperty beanProperty) { @BeforeEach public void init() { - beanProperty = BeanProperty.of(this, "value"); + beanProperty = of(this, "value"); } @Test @@ -84,19 +85,40 @@ public void testPropertyDescriptor() { @Test public void testEquals() { + assertEquals(this.beanProperty, this.beanProperty); + assertEquals(this.beanProperty, of(this, "value")); + + // test "null" assertFalse(this.beanProperty.equals(null)); + + // test different type assertFalse(this.beanProperty.equals("test")); - assertNotEquals(this.beanProperty, BeanProperty.of(this, "beanProperty")); - assertEquals(this.beanProperty, BeanProperty.of(this, "value")); + + // test different property name + assertNotEquals(this.beanProperty, of(this, "beanProperty")); + + // test different property value + BeanPropertyTest bean = new BeanPropertyTest(); + bean.value = TEST_VALUE + TEST_VALUE; + assertNotEquals(this.beanProperty, of(bean, "value")); + + bean = new BeanPropertyTest() { + }; + assertNotEquals(this.beanProperty, of(bean, "value")); + } @Test public void testHashCode() { - assertEquals(this.beanProperty.hashCode(), BeanProperty.of(this, "value").hashCode()); + assertEquals(this.beanProperty.hashCode(), of(this, "value").hashCode()); + + BeanPropertyTest bean = new BeanPropertyTest(); + bean.value = null; + assertNotEquals(beanProperty.hashCode(), of(bean, "value").hashCode()); } @Test public void testToString() { - assertNotNull(beanProperty.toString()); + assertEquals(beanProperty.toString(), of(this, "value").toString()); } } From 76d3bcb068479ac8ac98223bf8f84a7102535655 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:15:28 +0800 Subject: [PATCH 115/180] Update StringUtils.java --- .../java/io/microsphere/util/StringUtils.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java index 1eb34089c..88c489b8d 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java @@ -19,6 +19,7 @@ import java.util.StringTokenizer; import static io.microsphere.util.ArrayUtils.asArray; +import static java.lang.Character.isDigit; import static java.lang.Character.isWhitespace; import static java.lang.String.valueOf; @@ -397,4 +398,38 @@ public static String substringAfterLast(String str, String separator) { } return str.substring(pos + separator.length()); } + + /** + *

    Checks if the String contains only unicode digits. + * A decimal point is not a unicode digit and returns false.

    + * + *

    null will return false. + * An empty String (length()=0) will return true.

    + * + *
    +     * StringUtils.isNumeric(null)   = false
    +     * StringUtils.isNumeric("")     = true
    +     * StringUtils.isNumeric("  ")   = false
    +     * StringUtils.isNumeric("123")  = true
    +     * StringUtils.isNumeric("12 3") = false
    +     * StringUtils.isNumeric("ab2c") = false
    +     * StringUtils.isNumeric("12-3") = false
    +     * StringUtils.isNumeric("12.3") = false
    +     * 
    + * + * @param str the String to check, may be null + * @return true if only contains digits, and is non-null + */ + public static boolean isNumeric(String str) { + int sz = length(str); + if (sz == 0) { + return false; + } + for (int i = 0; i < sz; i++) { + if (isDigit(str.charAt(i)) == false) { + return false; + } + } + return true; + } } From d06f7f1f3aba4cdfad9823e188e4795f06acca74 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:15:31 +0800 Subject: [PATCH 116/180] Update StringUtilsTest.java --- .../java/io/microsphere/util/StringUtilsTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java index e76130734..8a3bf79ad 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java @@ -22,6 +22,7 @@ import static io.microsphere.util.StringUtils.isEmpty; import static io.microsphere.util.StringUtils.isNotBlank; import static io.microsphere.util.StringUtils.isNotEmpty; +import static io.microsphere.util.StringUtils.isNumeric; import static io.microsphere.util.StringUtils.length; import static io.microsphere.util.StringUtils.replace; import static io.microsphere.util.StringUtils.split; @@ -270,4 +271,16 @@ public void testSubstringAfterLast() { assertEquals("c", substringAfterLast(TEST_CSV_STRING, COMMA)); assertEquals(TEST_EMPTY_STRING, substringAfterLast(TEST_CSV_STRING, "c")); } + + @Test + public void testIsNumeric() { + assertFalse(isNumeric(null)); + assertFalse(isNumeric(TEST_EMPTY_STRING)); + assertFalse(isNumeric(TEST_CSV_STRING)); + assertFalse(isNumeric(TEST_EMPTY_STRING)); + assertTrue(isNumeric("1")); + assertTrue(isNumeric("12")); + assertTrue(isNumeric("123")); + assertFalse(isNumeric("12a")); + } } \ No newline at end of file From ef943ac1104270f61a34341133976978a4b13177 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:15:38 +0800 Subject: [PATCH 117/180] Update ProcessIdResolver.java --- .../io/microsphere/process/ProcessIdResolver.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/process/ProcessIdResolver.java b/microsphere-java-core/src/main/java/io/microsphere/process/ProcessIdResolver.java index 7917284bc..cf168b1c0 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/process/ProcessIdResolver.java +++ b/microsphere-java-core/src/main/java/io/microsphere/process/ProcessIdResolver.java @@ -27,6 +27,18 @@ */ public interface ProcessIdResolver extends Prioritized { + /** + * The unknown process id + */ + long UNKNOWN_PROCESS_ID = -1L; + + /** + * Whether supports to resolve the process id or not? + * + * @return true if supports, otherwise false + */ + boolean supports(); + /** * Resolve the current process id * From 69a5bd3afc04b5786c6b52617ada6022dd0f5cb6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:15:48 +0800 Subject: [PATCH 118/180] Update ModernProcessIdResolver.java --- .../process/ModernProcessIdResolver.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/process/ModernProcessIdResolver.java b/microsphere-java-core/src/main/java/io/microsphere/process/ModernProcessIdResolver.java index d9586c3b1..2fea05c0e 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/process/ModernProcessIdResolver.java +++ b/microsphere-java-core/src/main/java/io/microsphere/process/ModernProcessIdResolver.java @@ -40,22 +40,16 @@ public class ModernProcessIdResolver implements ProcessIdResolver { private static final Class PROCESS_HANDLE_CLASS = resolveClass(PROCESS_HANDLE_CLASS_NAME); @Override - public Long current() { - if (PROCESS_HANDLE_CLASS == null) { - return null; - } + public boolean supports() { + return PROCESS_HANDLE_CLASS != null; + } - Long pid = null; - try { - Object processHandle = invokeStaticMethod(PROCESS_HANDLE_CLASS, "current"); - pid = invokeMethod(processHandle, PROCESS_HANDLE_CLASS, "pid"); - if (logger.isTraceEnabled()) { - logger.trace("The PID was resolved from the method 'java.lang.ProcessHandle#pid()' : {}", pid); - } - } catch (Throwable e) { - if (logger.isTraceEnabled()) { - logger.trace("It's failed to invoke method 'java.lang.ProcessHandle#pid()'", e); - } + @Override + public Long current() { + Object processHandle = invokeStaticMethod(PROCESS_HANDLE_CLASS, "current"); + Long pid = invokeMethod(processHandle, PROCESS_HANDLE_CLASS, "pid"); + if (logger.isTraceEnabled()) { + logger.trace("The PID was resolved from the method 'java.lang.ProcessHandle#pid()' : {}", pid); } return pid; } From d40bc4e29dcc7dde220e32af7cc3ee0623f677ad Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:15:51 +0800 Subject: [PATCH 119/180] Update ClassicProcessIdResolver.java --- .../process/ClassicProcessIdResolver.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/process/ClassicProcessIdResolver.java b/microsphere-java-core/src/main/java/io/microsphere/process/ClassicProcessIdResolver.java index e560fc3f9..77f6c48a4 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/process/ClassicProcessIdResolver.java +++ b/microsphere-java-core/src/main/java/io/microsphere/process/ClassicProcessIdResolver.java @@ -18,11 +18,10 @@ import io.microsphere.logging.Logger; -import java.lang.management.RuntimeMXBean; - import static io.microsphere.constants.SymbolConstants.AT; import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.management.JmxUtils.getRuntimeMXBean; +import static io.microsphere.util.StringUtils.isNumeric; import static io.microsphere.util.StringUtils.substringBefore; import static java.lang.Long.valueOf; @@ -37,19 +36,20 @@ public class ClassicProcessIdResolver implements ProcessIdResolver { private static final Logger logger = getLogger(ClassicProcessIdResolver.class); + private static final String runtimeName = getRuntimeMXBean().getName(); + + private static final String processIdValue = substringBefore(runtimeName, AT); + + @Override + public boolean supports() { + return isNumeric(processIdValue); + } + @Override public Long current() { - RuntimeMXBean runtimeMXBean = getRuntimeMXBean(); - String name = runtimeMXBean.getName(); - Long processId = null; - try { - String processIdValue = substringBefore(name, AT); - processId = valueOf(processIdValue); - if (logger.isTraceEnabled()) { - logger.trace("The PID was resolved from the method 'java.lang.management.RuntimeMXBean#getName()' = {} : {}", name, processId); - } - } catch (Throwable e) { - logger.warn("The PID can't be resolved from the method 'java.lang.management.RuntimeMXBean#getName()' = {} : {}", name, e); + Long processId = valueOf(processIdValue); + if (logger.isTraceEnabled()) { + logger.trace("The PID was resolved from the method 'java.lang.management.RuntimeMXBean#getName()' = {} : {}", runtimeName, processId); } return processId; } From 36157a42a184e4759ac25db5e7e69f9e446f5dee Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:15:53 +0800 Subject: [PATCH 120/180] Update VirtualMachineProcessIdResolverTest.java --- .../process/VirtualMachineProcessIdResolverTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/process/VirtualMachineProcessIdResolverTest.java b/microsphere-java-core/src/test/java/io/microsphere/process/VirtualMachineProcessIdResolverTest.java index 46e01ed69..d99da0b56 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/process/VirtualMachineProcessIdResolverTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/process/VirtualMachineProcessIdResolverTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link VirtualMachineProcessIdResolver} Test @@ -22,6 +23,11 @@ public void init() { this.resolver = new VirtualMachineProcessIdResolver(); } + @Test + public void testSupports() { + assertTrue(resolver.supports()); + } + @Test public void testCurrent() { assertNotNull(resolver.current()); From 0ede5d44c37ef8e80b51249a6b7c2079b87a4a79 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:15:59 +0800 Subject: [PATCH 121/180] Update ModernProcessIdResolverTest.java --- .../process/ModernProcessIdResolverTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java b/microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java index 15f4270f1..7bfbfa649 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java @@ -3,8 +3,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static io.microsphere.util.VersionUtils.CURRENT_JAVA_VERSION; +import static io.microsphere.util.Version.Operator.GE; import static io.microsphere.util.VersionUtils.JAVA_VERSION_9; +import static io.microsphere.util.VersionUtils.testCurrentJavaVersion; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -20,14 +21,21 @@ public class ModernProcessIdResolverTest { private ModernProcessIdResolver resolver; + private static final boolean isGEJava9 = testCurrentJavaVersion(GE, JAVA_VERSION_9); + @BeforeEach public void init() { resolver = new ModernProcessIdResolver(); } + @Test + public void testSupports() { + assertEquals(isGEJava9, resolver.supports()); + } + @Test public void testCurrent() { - if (JAVA_VERSION_9.le(CURRENT_JAVA_VERSION)) { + if (isGEJava9) { assertNotNull(resolver.current()); } else { assertNull(resolver.current()); From 858440160a4b544d20f6595e49f1f8f87f696369 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:16:04 +0800 Subject: [PATCH 122/180] Update ClassicProcessIdResolverTest.java --- .../microsphere/process/ClassicProcessIdResolverTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/process/ClassicProcessIdResolverTest.java b/microsphere-java-core/src/test/java/io/microsphere/process/ClassicProcessIdResolverTest.java index b2be62b03..95f526304 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/process/ClassicProcessIdResolverTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/process/ClassicProcessIdResolverTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link ClassicProcessIdResolver} Test @@ -22,6 +23,11 @@ public void init() { resolver = new ClassicProcessIdResolver(); } + @Test + public void testSupports() { + assertTrue(resolver.supports()); + } + @Test public void testCurrent() { assertNotNull(resolver.current()); From c2c75abbdab3f977800a3527c385fb1aebefa1bc Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:16:11 +0800 Subject: [PATCH 123/180] Update ManagementUtils.java --- .../microsphere/management/ManagementUtils.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java b/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java index 4a492676b..951625e72 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java @@ -7,6 +7,7 @@ import java.util.List; import static io.microsphere.logging.LoggerFactory.getLogger; +import static io.microsphere.process.ProcessIdResolver.UNKNOWN_PROCESS_ID; import static io.microsphere.util.ServiceLoaderUtils.loadServicesList; /** @@ -20,21 +21,29 @@ public abstract class ManagementUtils { private static final Logger logger = getLogger(ManagementUtils.class); - static final int UNKNOWN_PROCESS_ID = -1; - static final long currentProcessId = resolveCurrentProcessId(); private static long resolveCurrentProcessId() { List resolvers = loadServicesList(ProcessIdResolver.class); Long processId = null; for (ProcessIdResolver resolver : resolvers) { - if ((processId = resolver.current()) != null) { - break; + if (resolver.supports()) { + if ((processId = resolver.current()) != null) { + log(resolver, processId); + break; + } } } return processId == null ? UNKNOWN_PROCESS_ID : processId; } + static void log(ProcessIdResolver resolver, Long processId) { + if (logger.isTraceEnabled()) { + logger.trace("The process id was resolved by ProcessIdResolver[class : '{}' , priority : {}] successfully : {}", + resolver.getClass().getName(), resolver.getPriority(), processId); + } + } + /** * Get the process ID of current JVM * From 717775d14da653dbc25ca4fc74a212d69a0d2515 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:16:15 +0800 Subject: [PATCH 124/180] Update VirtualMachineProcessIdResolver.java --- .../VirtualMachineProcessIdResolver.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/process/VirtualMachineProcessIdResolver.java b/microsphere-java-core/src/main/java/io/microsphere/process/VirtualMachineProcessIdResolver.java index 59d8a3fb6..79875fb2a 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/process/VirtualMachineProcessIdResolver.java +++ b/microsphere-java-core/src/main/java/io/microsphere/process/VirtualMachineProcessIdResolver.java @@ -19,11 +19,14 @@ import io.microsphere.logging.Logger; import java.lang.management.RuntimeMXBean; +import java.lang.reflect.Field; import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.management.JmxUtils.getRuntimeMXBean; +import static io.microsphere.reflect.FieldUtils.findField; import static io.microsphere.reflect.FieldUtils.getFieldValue; import static io.microsphere.reflect.MethodUtils.invokeMethod; +import static java.lang.Long.valueOf; /** * {@link ProcessIdResolver} class for SUN JVM @@ -48,20 +51,25 @@ public class VirtualMachineProcessIdResolver implements ProcessIdResolver { */ final static String GET_PROCESS_ID_METHOD_NAME = "getProcessId"; + /** + * The {@link Field} of "jvm" + */ + final static Field JVM_FIELD = findField(getRuntimeMXBean(), JVM_FIELD_NAME); + + @Override + public boolean supports() { + return JVM_FIELD != null; + } + @Override public Long current() { - Integer processId = null; - try { - RuntimeMXBean runtimeMXBean = getRuntimeMXBean(); - Object jvm = getFieldValue(runtimeMXBean, JVM_FIELD_NAME); - processId = invokeMethod(jvm, GET_PROCESS_ID_METHOD_NAME); - if (logger.isTraceEnabled()) { - logger.trace("The PID was resolved from the native method 'sun.management.VMManagementImpl#getProcessId()' : {}", processId); - } - } catch (Throwable e) { - logger.warn("It's failed to invoke the native method 'sun.management.VMManagementImpl#getProcessId()'", e); + RuntimeMXBean runtimeMXBean = getRuntimeMXBean(); + Object jvm = getFieldValue(runtimeMXBean, JVM_FIELD); + Integer processId = invokeMethod(jvm, GET_PROCESS_ID_METHOD_NAME); + if (logger.isTraceEnabled()) { + logger.trace("The PID was resolved from the native method 'sun.management.VMManagementImpl#getProcessId()' : {}", processId); } - return Long.valueOf(processId.longValue()); + return valueOf(processId.longValue()); } @Override From 681c6654577823d1dba5524530a545b9b7eda258 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:16:19 +0800 Subject: [PATCH 125/180] Update ManagementUtilsTest.java --- .../microsphere/management/ManagementUtilsTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java index cfd97d4c1..0053c5af3 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java @@ -1,9 +1,14 @@ package io.microsphere.management; import io.microsphere.AbstractTestCase; +import io.microsphere.process.ProcessIdResolver; import org.junit.jupiter.api.Test; +import java.util.List; + import static io.microsphere.management.ManagementUtils.getCurrentProcessId; +import static io.microsphere.process.ProcessIdResolver.UNKNOWN_PROCESS_ID; +import static io.microsphere.util.ServiceLoaderUtils.loadServicesList; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -21,4 +26,12 @@ public void testGetCurrentProcessId() { assertTrue(currentProcessId > 0); } + @Test + public void testLog() { + List resolvers = loadServicesList(ProcessIdResolver.class); + for(ProcessIdResolver resolver : resolvers){ + ManagementUtils.log(resolver, UNKNOWN_PROCESS_ID); + } + } + } From 7a925a3430316ef0c88eb8c7108c0b326b77517b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:18:55 +0800 Subject: [PATCH 126/180] Update ModernProcessIdResolverTest.java --- .../io/microsphere/process/ModernProcessIdResolverTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java b/microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java index 7bfbfa649..67e1e4045 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/process/ModernProcessIdResolverTest.java @@ -8,7 +8,7 @@ import static io.microsphere.util.VersionUtils.testCurrentJavaVersion; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link ModernProcessIdResolver} Test @@ -38,7 +38,7 @@ public void testCurrent() { if (isGEJava9) { assertNotNull(resolver.current()); } else { - assertNull(resolver.current()); + assertThrows(NullPointerException.class, resolver::current); } } From f40cd6f9c678d9917ab3ed226c7c7ab551475e36 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:23:49 +0800 Subject: [PATCH 127/180] Update CharSequenceUtils.java --- .../src/main/java/io/microsphere/util/CharSequenceUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java index 03ba9edde..0eba5f750 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java @@ -7,7 +7,7 @@ * @see CharSequence * @since 1.0.0 */ -public class CharSequenceUtils { +public abstract class CharSequenceUtils { public static int length(CharSequence value) { return value == null ? 0 : value.length(); From 4dee102c7a6fb7604de2b81082679d29b270ecde Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:34:02 +0800 Subject: [PATCH 128/180] Update CharSequenceUtils.java --- .../src/main/java/io/microsphere/util/CharSequenceUtils.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java index 0eba5f750..067d8bfa4 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java @@ -9,6 +9,9 @@ */ public abstract class CharSequenceUtils { + private CharSequenceUtils() { + } + public static int length(CharSequence value) { return value == null ? 0 : value.length(); } From dfa78609bea462342624a899e36fdbdc9d2280d0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:34:41 +0800 Subject: [PATCH 129/180] Update CharSequenceUtils.java --- .../src/main/java/io/microsphere/util/CharSequenceUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java index 067d8bfa4..f4e01e1a2 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java @@ -9,7 +9,7 @@ */ public abstract class CharSequenceUtils { - private CharSequenceUtils() { + CharSequenceUtils() { } public static int length(CharSequence value) { From f04670503bce4acc2ecae5570c0ea805ca0b190a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:34:42 +0800 Subject: [PATCH 130/180] Update StringUtils.java --- .../src/main/java/io/microsphere/util/StringUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java index 88c489b8d..8ce73b35e 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java @@ -37,6 +37,10 @@ public abstract class StringUtils extends CharSequenceUtils { public static final String[] EMPTY_STRING_ARRAY = ArrayUtils.EMPTY_STRING_ARRAY; + private StringUtils() { + super(); + } + public static boolean isBlank(String value) { int length = length(value); if (length < 1) { From 93c4871fd14ed161324d13cf44891fc7aac7f226 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:43:16 +0800 Subject: [PATCH 131/180] Update BaseUtilsTest.java --- .../src/test/java/io/microsphere/util/BaseUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/BaseUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/BaseUtilsTest.java index 70751b3b4..b7e1ed176 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/BaseUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/BaseUtilsTest.java @@ -14,7 +14,7 @@ public class BaseUtilsTest { @Test - public void test() { + public void testConstructor() { assertThrows(IllegalStateException.class, () -> new BaseUtils(){}); } From af1fd01bb092f5a7afcbe3d420551fa29fce3b02 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:44:16 +0800 Subject: [PATCH 132/180] Update CharsetUtils.java --- .../main/java/io/microsphere/nio/charset/CharsetUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/nio/charset/CharsetUtils.java b/microsphere-java-core/src/main/java/io/microsphere/nio/charset/CharsetUtils.java index 6f4721b65..fc03d1736 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/nio/charset/CharsetUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/nio/charset/CharsetUtils.java @@ -16,6 +16,8 @@ */ package io.microsphere.nio.charset; +import io.microsphere.util.BaseUtils; + import java.nio.charset.Charset; import static java.nio.charset.Charset.defaultCharset; @@ -27,7 +29,7 @@ * @see Charset * @since 1.0.0 */ -public abstract class CharsetUtils { +public abstract class CharsetUtils extends BaseUtils { /** * The default charset looks up from the JDK system property "file.encoding" From 985ea13e7c443619cd927137445f40477c01dc9f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:44:19 +0800 Subject: [PATCH 133/180] Update CharsetUtilsTest.java --- .../java/io/microsphere/nio/charset/CharsetUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java index 6dde54978..7f1394ae4 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/nio/charset/CharsetUtilsTest.java @@ -7,6 +7,7 @@ import static io.microsphere.nio.charset.CharsetUtils.DEFAULT_CHARSET; import static io.microsphere.util.ClassUtils.isAbstractClass; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -18,6 +19,11 @@ */ public class CharsetUtilsTest { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new CharsetUtils(){}); + } + @Test public void testClass() { assertTrue(isAbstractClass(CharsetUtils.class)); From 7e39eb661767c0b55cc68096a71532555aa47e9f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:45:51 +0800 Subject: [PATCH 134/180] Update CharSequenceUtils.java --- .../src/main/java/io/microsphere/util/CharSequenceUtils.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java index f4e01e1a2..54e4bbb59 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/CharSequenceUtils.java @@ -7,10 +7,7 @@ * @see CharSequence * @since 1.0.0 */ -public abstract class CharSequenceUtils { - - CharSequenceUtils() { - } +public abstract class CharSequenceUtils extends BaseUtils { public static int length(CharSequence value) { return value == null ? 0 : value.length(); From 094dc40ab4e26775559848de5cbee10ba4f64676 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:45:53 +0800 Subject: [PATCH 135/180] Update CharSequenceUtilsTest.java --- .../java/io/microsphere/util/CharSequenceUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java index 8802cdf4e..cb9f1177e 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/CharSequenceUtilsTest.java @@ -8,6 +8,7 @@ import static io.microsphere.util.CharSequenceUtils.length; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -27,6 +28,11 @@ public class CharSequenceUtilsTest { static final String TEST_STRING = "testing"; + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new CharSequenceUtils(){}); + } + @Test public void testLength() { assertEquals(0, length(null)); From f05842ab9d095d13c54dd3d0d515ea044ecdc85b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:47:50 +0800 Subject: [PATCH 136/180] Update EnumerationUtils.java --- .../main/java/io/microsphere/collection/EnumerationUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java index 32460854e..f4a6c7991 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/EnumerationUtils.java @@ -16,6 +16,8 @@ */ package io.microsphere.collection; +import io.microsphere.util.BaseUtils; + import java.util.Collections; import java.util.Enumeration; @@ -27,7 +29,7 @@ * @see Collections#enumeration * @since 1.0.0 */ -public abstract class EnumerationUtils { +public abstract class EnumerationUtils extends BaseUtils { /** * Create a {@link Enumeration} instance from the specified elements From c90eff739a3452a31522a0b3c24aa1c6e48cc523 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:47:53 +0800 Subject: [PATCH 137/180] Update EnumerationUtilsTest.java --- .../java/io/microsphere/collection/EnumerationUtilsTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationUtilsTest.java index 363f1b362..a2fdb0d55 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/EnumerationUtilsTest.java @@ -38,6 +38,11 @@ */ public class EnumerationUtilsTest { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new EnumerationUtils(){}); + } + @Test public void testOf() { assertEnumeration(of("A", "B", "C")); From 8f775fa4fc7ca138e8073e8b7d1632f1d450efcf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:49:40 +0800 Subject: [PATCH 138/180] Update FileUtils.java --- .../src/main/java/io/microsphere/io/FileUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java b/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java index 00aaca817..3dd4c6c8d 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/io/FileUtils.java @@ -3,6 +3,8 @@ */ package io.microsphere.io; +import io.microsphere.util.BaseUtils; + import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -21,7 +23,7 @@ * @see FileUtils * @since 1.0.0 */ -public abstract class FileUtils { +public abstract class FileUtils extends BaseUtils { /** * Resolve Relative Path From f022aca3504a2d5a8604a9bbdcfe1a058d07ccce Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:49:42 +0800 Subject: [PATCH 139/180] Update FileUtilsTest.java --- .../src/test/java/io/microsphere/io/FileUtilsTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/io/FileUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/io/FileUtilsTest.java index a54b53ec0..af6846c5f 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/io/FileUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/io/FileUtilsTest.java @@ -41,6 +41,11 @@ public class FileUtilsTest extends AbstractTestCase { private final File packageDirectory = new File(packageResource.getFile()); + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new FileUtils(){}); + } + @Test public void testResolveRelativePath() throws Exception { assertEquals("/io/FileUtilsTest.class", resolveRelativePath(packageDirectory, classFile)); From 7efd13c1b56dc29294329f436a983f7f0f235020 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:50:37 +0800 Subject: [PATCH 140/180] Update ManagementUtils.java --- .../main/java/io/microsphere/management/ManagementUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java b/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java index 951625e72..91b2a9fb0 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/management/ManagementUtils.java @@ -3,6 +3,7 @@ import io.microsphere.logging.Logger; import io.microsphere.process.ProcessIdResolver; +import io.microsphere.util.BaseUtils; import java.util.List; @@ -17,7 +18,7 @@ * @see ManagementUtils * @since 1.0.0 */ -public abstract class ManagementUtils { +public abstract class ManagementUtils extends BaseUtils { private static final Logger logger = getLogger(ManagementUtils.class); From 77f55340e05480b0325ba60609b339adea9aa61b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:50:44 +0800 Subject: [PATCH 141/180] Update ManagementUtilsTest.java --- .../java/io/microsphere/management/ManagementUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java index 0053c5af3..5b403ec6b 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/management/ManagementUtilsTest.java @@ -9,6 +9,7 @@ import static io.microsphere.management.ManagementUtils.getCurrentProcessId; import static io.microsphere.process.ProcessIdResolver.UNKNOWN_PROCESS_ID; import static io.microsphere.util.ServiceLoaderUtils.loadServicesList; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -20,6 +21,11 @@ */ public class ManagementUtilsTest extends AbstractTestCase { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new ManagementUtils(){}); + } + @Test public void testGetCurrentProcessId() { long currentProcessId = getCurrentProcessId(); From 83a2bee46b812a7ee4e7adda11e8e915950e32f3 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:52:14 +0800 Subject: [PATCH 142/180] Update ReflectionUtils.java --- .../src/main/java/io/microsphere/reflect/ReflectionUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java index 709f4b797..0e670cb55 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java @@ -4,6 +4,7 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.annotation.Nullable; import io.microsphere.logging.Logger; +import io.microsphere.util.BaseUtils; import java.lang.reflect.Array; import java.lang.reflect.Constructor; @@ -36,7 +37,7 @@ * @see ConstructorUtils * @since 1.0.0 */ -public abstract class ReflectionUtils { +public abstract class ReflectionUtils extends BaseUtils { /** * Current Type From de2d966b3991e80695fa39625148d587932c8cef Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:52:22 +0800 Subject: [PATCH 143/180] Update ReflectionUtilsTest.java --- .../java/io/microsphere/reflect/ReflectionUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/reflect/ReflectionUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/reflect/ReflectionUtilsTest.java index fdd71b033..c57129b2b 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/reflect/ReflectionUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/reflect/ReflectionUtilsTest.java @@ -19,6 +19,7 @@ import static io.microsphere.reflect.ReflectionUtils.toList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link ReflectionUtils} Test @@ -29,6 +30,11 @@ */ public class ReflectionUtilsTest extends AbstractTestCase { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new ReflectionUtils() {}); + } + @Test public void testGetCallerClassX() throws Exception { Class expectedClass = ReflectionUtilsTest.class; From 45e60455e719fef06c046030cb6ffc30b8eb4ce4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:56:21 +0800 Subject: [PATCH 144/180] Update PropertiesUtils.java --- .../main/java/io/microsphere/collection/PropertiesUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java index 13b841b27..f4d32c1b7 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java @@ -16,6 +16,8 @@ */ package io.microsphere.collection; +import io.microsphere.util.BaseUtils; + import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; @@ -30,7 +32,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class PropertiesUtils { +public abstract class PropertiesUtils extends BaseUtils { /** * Get the flatten the specified {@link Map properties} From 3fa47f8c0fe08e8f5cddf81e0a6dbe66b8636448 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:56:24 +0800 Subject: [PATCH 145/180] Update PropertiesUtilsTest.java --- .../java/io/microsphere/collection/PropertiesUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/PropertiesUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/PropertiesUtilsTest.java index c0a8bbbf6..63e08b8b9 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/PropertiesUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/PropertiesUtilsTest.java @@ -23,6 +23,7 @@ import static io.microsphere.collection.MapUtils.ofMap; import static io.microsphere.collection.PropertiesUtils.flatProperties; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link PropertiesUtils} Test @@ -32,6 +33,11 @@ */ public class PropertiesUtilsTest { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new PropertiesUtils() {}); + } + @Test public void testFlatProperties() { Map level3Properties = ofMap("f", "F"); From a870e29cb8db11ffaa376fc8f6ad486007ae5c62 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:57:27 +0800 Subject: [PATCH 146/180] Update AccessibleObjectUtils.java --- .../java/io/microsphere/reflect/AccessibleObjectUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/AccessibleObjectUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/AccessibleObjectUtils.java index e436edbd5..9e805bacb 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/AccessibleObjectUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/AccessibleObjectUtils.java @@ -17,6 +17,7 @@ package io.microsphere.reflect; import io.microsphere.logging.Logger; +import io.microsphere.util.BaseUtils; import java.lang.invoke.MethodHandle; import java.lang.reflect.AccessibleObject; @@ -38,7 +39,7 @@ * @see AccessibleObject * @since 1.0.0 */ -public abstract class AccessibleObjectUtils { +public abstract class AccessibleObjectUtils extends BaseUtils { private static final Logger logger = getLogger(AccessibleObjectUtils.class); From b419c34e1600eb1bb94bf17931086e9a4dcb18c2 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:57:29 +0800 Subject: [PATCH 147/180] Update AccessibleObjectUtilsTest.java --- .../io/microsphere/reflect/AccessibleObjectUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/reflect/AccessibleObjectUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/reflect/AccessibleObjectUtilsTest.java index 31b23cfb6..a39a7ca4f 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/reflect/AccessibleObjectUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/reflect/AccessibleObjectUtilsTest.java @@ -31,6 +31,7 @@ import static io.microsphere.reflect.MethodUtils.findMethod; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -58,6 +59,11 @@ public class AccessibleObjectUtilsTest { */ private static final Constructor abstractProcessorConstructor = findConstructor(AbstractProcessor.class); + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new AccessibleObjectUtils() {}); + } + @Test public void testSetAccessible() { for (Method method : methods) { From 9f13e619d8d4ef1769548c28c8abca31cfac577b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:58:41 +0800 Subject: [PATCH 148/180] Update MemberUtils.java --- .../src/main/java/io/microsphere/reflect/MemberUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MemberUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MemberUtils.java index 5a168c59b..94fd4cec2 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MemberUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MemberUtils.java @@ -16,6 +16,8 @@ */ package io.microsphere.reflect; +import io.microsphere.util.BaseUtils; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Member; @@ -28,7 +30,7 @@ * * @since 1.0.0 */ -public abstract class MemberUtils { +public abstract class MemberUtils extends BaseUtils { /** * The {@link Predicate} reference to {@link #isStatic(Member)} From b57410247e994c085e144b8c5f1c1cd6ad09d23f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 11:58:44 +0800 Subject: [PATCH 149/180] Update MemberUtilsTest.java --- .../test/java/io/microsphere/reflect/MemberUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/reflect/MemberUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/reflect/MemberUtilsTest.java index 7993aead4..5659f0935 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/reflect/MemberUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/reflect/MemberUtilsTest.java @@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -33,6 +34,11 @@ */ public class MemberUtilsTest { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new MemberUtils() {}); + } + @Test public void testSTATIC_METHOD_PREDICATE() { assertTrue(STATIC_MEMBER_PREDICATE.test(findMethod(ReflectionTest.class, "staticMethod"))); From ac51a9f9999b573b0880e1cb172c7d65b3f82ffe Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:01:34 +0800 Subject: [PATCH 150/180] Update FieldUtils.java --- .../src/main/java/io/microsphere/reflect/FieldUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java index 952bcd6a3..83e83650b 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java @@ -17,6 +17,7 @@ package io.microsphere.reflect; import io.microsphere.logging.Logger; +import io.microsphere.util.BaseUtils; import java.lang.reflect.Field; import java.util.LinkedHashSet; @@ -40,7 +41,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class FieldUtils { +public abstract class FieldUtils extends BaseUtils { private static final Logger logger = getLogger(FieldUtils.class); From e9f5048b2cef34a43526ca9cdcce5fb7509b46f0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:01:38 +0800 Subject: [PATCH 151/180] Update FieldUtilsTest.java --- .../src/test/java/io/microsphere/reflect/FieldUtilsTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/reflect/FieldUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/reflect/FieldUtilsTest.java index 282a3c554..e16892019 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/reflect/FieldUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/reflect/FieldUtilsTest.java @@ -58,6 +58,11 @@ public class FieldUtilsTest { public void destroy() { ReflectionTest.staticField = "staticField"; } + + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new FieldUtils() {}); + } @Test public void testFindFieldOnObject() { From 07f95013aff8253fef5076ec8c9ed6a9efdc27df Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:02:53 +0800 Subject: [PATCH 152/180] Update ClassLoaderUtils.java --- .../src/main/java/io/microsphere/util/ClassLoaderUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java index 082de853b..183917d45 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java @@ -65,7 +65,7 @@ * @see ClassLoader * @since 1.0.0 */ -public abstract class ClassLoaderUtils { +public abstract class ClassLoaderUtils extends BaseUtils { private static final Logger logger = getLogger(ClassLoaderUtils.class); From ae19a4055eaa42c0b45471bee6a99220aeb2e9b2 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:02:56 +0800 Subject: [PATCH 153/180] Update ClassLoaderUtilsTest.java --- .../test/java/io/microsphere/util/ClassLoaderUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java index d20007ab2..efa560e2d 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java @@ -65,6 +65,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -98,6 +99,11 @@ public static void afterAll() { setVerbose(verbose); } + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new ClassLoaderUtils() {}); + } + @Test public void testFields() throws Exception { From 4780e7b0efbe9eb848eb3be3c7f10d65141f4cef Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:03:47 +0800 Subject: [PATCH 154/180] Update PropertyResourceBundleUtils.java --- .../java/io/microsphere/util/PropertyResourceBundleUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java index 7422a8997..cb18ea424 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/PropertyResourceBundleUtils.java @@ -21,7 +21,7 @@ * @see PropertyResourceBundle * @since 1.0.0 */ -public abstract class PropertyResourceBundleUtils { +public abstract class PropertyResourceBundleUtils extends BaseUtils { /** * The property name of encoding for {@link PropertyResourceBundle} From 92e7754f44656f5444927c4c8ddaf873155c8656 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:03:51 +0800 Subject: [PATCH 155/180] Update PropertyResourceBundleUtilsTest.java --- .../microsphere/util/PropertyResourceBundleUtilsTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/PropertyResourceBundleUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/PropertyResourceBundleUtilsTest.java index 39eaeb6dc..06d6d50e8 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/PropertyResourceBundleUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/PropertyResourceBundleUtilsTest.java @@ -15,12 +15,13 @@ import static io.microsphere.util.SystemUtils.FILE_ENCODING; import static java.util.Locale.ROOT; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link PropertyResourceBundleUtils} {@link Test} * * @author Mercy - * @see PropertyResourceBundleUtilsTest + * @see PropertyResourceBundleUtils * @since 1.0.0 */ public class PropertyResourceBundleUtilsTest { @@ -31,6 +32,11 @@ public class PropertyResourceBundleUtilsTest { private static final String TEST_ENCODING = DEFAULT_ENCODING; + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new PropertyResourceBundleUtils() {}); + } + @Test public void testConstants() { assertEquals("java.util.PropertyResourceBundle.encoding", DEFAULT_ENCODING_PROPERTY_NAME); From e22f61418419ae4ef1dfcd5b7e3e9834d3787c6c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:04:36 +0800 Subject: [PATCH 156/180] Update FormatUtils.java --- .../src/main/java/io/microsphere/text/FormatUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java b/microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java index 1621ed797..7023ceb6a 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java @@ -1,5 +1,7 @@ package io.microsphere.text; +import io.microsphere.util.BaseUtils; + import static io.microsphere.util.StringUtils.isBlank; /** @@ -8,7 +10,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class FormatUtils { +public abstract class FormatUtils extends BaseUtils { public static final String DEFAULT_PLACEHOLDER = "{}"; From 96062e78fc3133a2cdce00a1de8079cc618f7475 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:04:38 +0800 Subject: [PATCH 157/180] Update FormatUtilsTest.java --- .../src/test/java/io/microsphere/text/FormatUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/text/FormatUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/text/FormatUtilsTest.java index 40b26c5f1..8b4c80fcb 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/text/FormatUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/text/FormatUtilsTest.java @@ -21,6 +21,7 @@ import static io.microsphere.text.FormatUtils.format; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link FormatUtils} Test @@ -30,6 +31,11 @@ */ public class FormatUtilsTest { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new FormatUtils() {}); + } + @Test public void testFormat() { assertNull(format(null)); From 2ee0787fb6776a1cca092fce06114dd027478abb Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:06:25 +0800 Subject: [PATCH 158/180] Update MethodHandlesLookupUtils.java --- .../java/io/microsphere/invoke/MethodHandlesLookupUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java index 1d8ae8746..a005062d1 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java @@ -18,6 +18,7 @@ import io.microsphere.lang.function.ThrowableBiFunction; import io.microsphere.logging.Logger; +import io.microsphere.util.BaseUtils; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -37,7 +38,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class MethodHandlesLookupUtils { +public abstract class MethodHandlesLookupUtils extends BaseUtils { /** * {@link MethodHandle} for Not-Found From 0d9025dd777e220bd0ef7be73c5d30911b21aa26 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 12:06:28 +0800 Subject: [PATCH 159/180] Update MethodHandlesLookupUtilsTest.java --- .../io/microsphere/invoke/MethodHandlesLookupUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/invoke/MethodHandlesLookupUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/invoke/MethodHandlesLookupUtilsTest.java index 24c4b6885..5430fed6f 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/invoke/MethodHandlesLookupUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/invoke/MethodHandlesLookupUtilsTest.java @@ -26,6 +26,7 @@ import static io.microsphere.util.ArrayUtils.EMPTY_CLASS_ARRAY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link MethodHandlesLookupUtils} Test @@ -35,6 +36,11 @@ */ public class MethodHandlesLookupUtilsTest { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new MethodHandlesLookupUtils() {}); + } + @Test public void testFindPublicVirtual() throws Throwable { MethodHandle methodHandle = findPublicVirtual(String.class, "length"); From d97a6f39b842f79081cf31d2b422021064372353 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 14:58:04 +0800 Subject: [PATCH 160/180] Update URLUtils.java --- .../src/main/java/io/microsphere/net/URLUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 216839d31..576e33445 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -6,6 +6,7 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.logging.Logger; import io.microsphere.util.ArrayUtils; +import io.microsphere.util.BaseUtils; import java.io.File; import java.io.IOException; @@ -74,7 +75,7 @@ * @see URLDecoder * @since 1.0.0 */ -public abstract class URLUtils { +public abstract class URLUtils extends BaseUtils { private static final Logger logger = getLogger(URLUtils.class); From c0d324860f4003baec6c476eded87844f06e096a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 14:58:07 +0800 Subject: [PATCH 161/180] Update URLUtilsTest.java --- .../src/test/java/io/microsphere/net/URLUtilsTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index 9a512fc87..2b54667d0 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -117,6 +117,11 @@ public void after() { clearURLStreamHandlerFactory(); } + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new URLUtils() {}); + } + @Test public void testOfURL() throws MalformedURLException { assertEquals(new URL(userDirURLString), ofURL(userDirURLString)); From 7d0741f9edc5aba892d367676dc3d046f920f823 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 14:59:03 +0800 Subject: [PATCH 162/180] Update QueueUtils.java --- .../src/main/java/io/microsphere/collection/QueueUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java index 49523b6fc..1102a8560 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java @@ -16,6 +16,8 @@ */ package io.microsphere.collection; +import io.microsphere.util.BaseUtils; + import java.io.Serializable; import java.util.Collection; import java.util.Deque; @@ -37,7 +39,7 @@ * @see Queue * @since 1.0.0 */ -public abstract class QueueUtils { +public abstract class QueueUtils extends BaseUtils { private static final Deque EMPTY_DEQUE = new EmptyDeque(); From 76f0e03f693d2a1a8297f539d89577b24ff79853 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 14:59:05 +0800 Subject: [PATCH 163/180] Update QueueUtilsTest.java --- .../test/java/io/microsphere/collection/QueueUtilsTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/QueueUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/QueueUtilsTest.java index 9c8c342f6..e353a104c 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/QueueUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/QueueUtilsTest.java @@ -34,6 +34,11 @@ * @since 1.0.0 */ public class QueueUtilsTest { + + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new QueueUtils() {}); + } @Test public void testIsQueue() { From e1f6d4bbb8d19becc617ffec50d1960974ed7e68 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:00:50 +0800 Subject: [PATCH 164/180] Update ExceptionUtils.java --- .../src/main/java/io/microsphere/util/ExceptionUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ExceptionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ExceptionUtils.java index 6cdd96701..47da0d60c 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ExceptionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ExceptionUtils.java @@ -29,7 +29,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class ExceptionUtils { +public abstract class ExceptionUtils extends BaseUtils { /** *

    Gets the stack trace from a Throwable as a String.

    From 9ca90930c1da6b85d59a29ca63c1071ffadc87d8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:00:54 +0800 Subject: [PATCH 165/180] Update ExceptionUtilsTest.java --- .../test/java/io/microsphere/util/ExceptionUtilsTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/ExceptionUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/ExceptionUtilsTest.java index f8768cbbb..ef7ad71c2 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/ExceptionUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/ExceptionUtilsTest.java @@ -39,6 +39,11 @@ */ public class ExceptionUtilsTest { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new ExceptionUtils() {}); + } + @Test public void testGetStackTrace() { String stackTrace = getStackTrace(new RuntimeException("Hello,World")); From bd08234fe9f240eafcda9759380b4936cac5f26d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:02:12 +0800 Subject: [PATCH 166/180] Update SystemUtils.java --- .../src/main/java/io/microsphere/util/SystemUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/SystemUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/SystemUtils.java index 9b039953d..29872f391 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/SystemUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/SystemUtils.java @@ -28,7 +28,7 @@ * @see System * @since 1.0.0 */ -public abstract class SystemUtils { +public abstract class SystemUtils extends BaseUtils { private static final Logger logger = getLogger(SystemUtils.class); From 322adb42bea332b7b051ab1a957f97edff294826 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:02:16 +0800 Subject: [PATCH 167/180] Update SystemUtilsTest.java --- .../src/test/java/io/microsphere/util/SystemUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java index d7c633a59..e7035c535 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java @@ -90,6 +90,7 @@ import static java.lang.System.getProperty; import static javax.lang.model.SourceVersion.latest; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link SystemUtils} Test @@ -133,6 +134,11 @@ private static Field[] findIsJavaVersionFields() { .toArray(Field[]::new); } + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new SystemUtils() {}); + } + @Test public void testSystemPropertyKeys() { assertEquals("java.version", JAVA_VERSION_PROPERTY_KEY); From a20ccae230031a0e8b6fa0f95a4e5f1f0329746d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:04:14 +0800 Subject: [PATCH 168/180] Update MethodHandleUtils.java --- .../src/main/java/io/microsphere/invoke/MethodHandleUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java index 9ffad4c42..9b248dcfe 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java @@ -17,6 +17,7 @@ package io.microsphere.invoke; import io.microsphere.lang.function.ThrowableBiFunction; +import io.microsphere.util.BaseUtils; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -50,7 +51,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class MethodHandleUtils { +public abstract class MethodHandleUtils extends BaseUtils { /** * A single-bit mask representing {@code module} access, From f40b30d7f88e87e32e1530458700193b55d18df4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:04:16 +0800 Subject: [PATCH 169/180] Update MethodHandleUtilsTest.java --- .../java/io/microsphere/invoke/MethodHandleUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/invoke/MethodHandleUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/invoke/MethodHandleUtilsTest.java index 178297af2..1cd1996b1 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/invoke/MethodHandleUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/invoke/MethodHandleUtilsTest.java @@ -27,6 +27,7 @@ import static io.microsphere.invoke.MethodHandlesLookupUtils.NOT_FOUND_METHOD_HANDLE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link MethodHandleUtils} Test @@ -36,6 +37,11 @@ */ public class MethodHandleUtilsTest { + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new MethodHandleUtils() {}); + } + @Test public void testLookup() { MethodHandles.Lookup lookup = lookup(String.class); From 35b9a13b12f872f302ceeac0ed8c92674dbc68d3 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:05:07 +0800 Subject: [PATCH 170/180] Update ShutdownHookUtils.java --- .../src/main/java/io/microsphere/util/ShutdownHookUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ShutdownHookUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ShutdownHookUtils.java index c02135abc..52da280f7 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ShutdownHookUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ShutdownHookUtils.java @@ -43,7 +43,7 @@ * @see java.lang.ApplicationShutdownHooks * @since 1.0.0 */ -public abstract class ShutdownHookUtils { +public abstract class ShutdownHookUtils extends BaseUtils { private static final Logger logger = getLogger(ShutdownHookUtils.class); From d64836135817d029b87e33f4109786acda90dd06 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:05:09 +0800 Subject: [PATCH 171/180] Update ShutdownHookUtilsTest.java --- .../java/io/microsphere/util/ShutdownHookUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/ShutdownHookUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/ShutdownHookUtilsTest.java index c3e1ed95b..b4cecb2cb 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/ShutdownHookUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/ShutdownHookUtilsTest.java @@ -36,6 +36,7 @@ import static io.microsphere.util.ShutdownHookUtils.shutdownHookCallbacks; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -58,6 +59,11 @@ public void destroy() { clearShutdownHookCallbacks(); } + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new ShutdownHookUtils() {}); + } + @Test public void testRegisterShutdownHook() { testFilterShutdownHookThreadsWithRemoved(); From 1456341620fe21387837110eb7401b4d0c749440 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:07:31 +0800 Subject: [PATCH 172/180] Update JmxUtils.java --- .../src/main/java/io/microsphere/management/JmxUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java b/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java index 6df9f9a05..d076f721a 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/management/JmxUtils.java @@ -19,6 +19,7 @@ import io.microsphere.annotation.Nonnull; import io.microsphere.annotation.Nullable; import io.microsphere.logging.Logger; +import io.microsphere.util.BaseUtils; import javax.management.AttributeNotFoundException; import javax.management.InstanceNotFoundException; @@ -58,7 +59,7 @@ * @author Mercy * @since 1.0.0 */ -public abstract class JmxUtils { +public abstract class JmxUtils extends BaseUtils { private static final Logger logger = getLogger(JmxUtils.class); From 49795df94702d2c36769c89b387287a07a26d40b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 15:07:34 +0800 Subject: [PATCH 173/180] Update JmxUtilsTest.java --- .../test/java/io/microsphere/management/JmxUtilsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/management/JmxUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/management/JmxUtilsTest.java index 7c7eb139c..640c3a0b8 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/management/JmxUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/management/JmxUtilsTest.java @@ -54,6 +54,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -80,6 +81,11 @@ public static void init() throws Throwable { notFoundAttributeName = "NotFound"; } + @Test + public void testConstructor() { + assertThrows(IllegalStateException.class, () -> new JmxUtils() {}); + } + @Test public void testGetClassLoadingMXBean() throws Throwable { assertPlatformMXBean(getClassLoadingMXBean(), CLASS_LOADING_MXBEAN_NAME); From e043884066e7ac3346d5d1374ff9f88c56743086 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 20:22:36 +0800 Subject: [PATCH 174/180] Update ClassLoaderUtils.java --- .../io/microsphere/util/ClassLoaderUtils.java | 91 ++++++++++++++++++- 1 file changed, 86 insertions(+), 5 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java index 183917d45..ed2caf192 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java @@ -45,6 +45,9 @@ import static io.microsphere.reflect.MethodUtils.findMethod; import static io.microsphere.reflect.MethodUtils.invokeMethod; import static io.microsphere.reflect.ReflectionUtils.getCallerClass; +import static io.microsphere.util.ArrayUtils.asArray; +import static io.microsphere.util.Assert.assertNoNullElements; +import static io.microsphere.util.Assert.assertNotNull; import static io.microsphere.util.ServiceLoaderUtils.loadServicesList; import static io.microsphere.util.StringUtils.contains; import static io.microsphere.util.StringUtils.endsWith; @@ -301,7 +304,7 @@ public static Class findLoadedClass(@Nullable ClassLoader classLoader, String * @return {@link Class} if can be loaded */ @Nullable - public static Class loadClass(@Nullable ClassLoader classLoader, @Nonnull String className) { + public static Class loadClass(@Nullable ClassLoader classLoader, @Nullable String className) { ClassLoader actualClassLoader = findClassLoader(classLoader); return doLoadClass(actualClassLoader, className); } @@ -314,7 +317,7 @@ public static Class loadClass(@Nullable ClassLoader classLoader, @Nonnull Str * @param cached the resolved class is required to be cached or not * @return {@link Class} if can be loaded */ - public static Class loadClass(@Nullable ClassLoader classLoader, String className, boolean cached) { + public static Class loadClass(@Nullable ClassLoader classLoader, @Nullable String className, boolean cached) { ClassLoader actualClassLoader = findClassLoader(classLoader); if (cached) { String cacheKey = buildCacheKey(actualClassLoader, className); @@ -323,7 +326,10 @@ public static Class loadClass(@Nullable ClassLoader classLoader, String class return doLoadClass(actualClassLoader, className); } - protected static Class doLoadClass(ClassLoader classLoader, @Nonnull String className) { + protected static Class doLoadClass(ClassLoader classLoader, String className) { + if (isBlank(className)) { + return null; + } try { return classLoader.loadClass(className); } catch (Throwable e) { @@ -683,6 +689,77 @@ public static URLClassLoader findURLClassLoader(@Nullable ClassLoader classLoade return urlClassLoader; } + /** + * Create a new instance of {@link URLClassLoader} + * + * @param urls the urls + * @return non-null {@link URLClassLoader} + * @throws IllegalArgumentException if the urls is null or contains null element + */ + @Nonnull + public static URLClassLoader newURLClassLoader(@Nonnull Iterable urls) { + return newURLClassLoader(urls, null); + } + + /** + * Create a new instance of {@link URLClassLoader} + * + * @param urls the urls + * @return non-null {@link URLClassLoader} + * @throws IllegalArgumentException if the urls is null or contains null element + */ + @Nonnull + public static URLClassLoader newURLClassLoader(@Nonnull Iterable urls, @Nullable ClassLoader classLoader) { + assertNotNull(urls, () -> "The 'urls' must not be null"); + URL[] urlsArray = asArray(urls, URL.class); + return newURLClassLoader(urlsArray, classLoader); + } + + /** + * Create a new instance of {@link URLClassLoader} + * + * @param urls the urls + * @return non-null {@link URLClassLoader} + * @throws IllegalArgumentException if the urls is null or contains null element + */ + @Nonnull + public static URLClassLoader newURLClassLoader(@Nonnull URL[] urls) { + return newURLClassLoader(urls, null); + } + + /** + * Create a new instance of {@link URLClassLoader} + * + * @param urls the urls + * @param parent the {@link ClassLoader} as parent + * @return non-null {@link URLClassLoader} + * @throws IllegalArgumentException if the urls is null or contains null element + */ + @Nonnull + public static URLClassLoader newURLClassLoader(@Nonnull URL[] urls, @Nullable ClassLoader parent) throws IllegalArgumentException { + assertNotNull(urls, () -> "The 'urls' must not be null"); + assertNoNullElements(urls, () -> "Any element of 'urls' must not be null"); + return new URLClassLoader(urls, parent); + } + + /** + * Try to find the instance of {@link URLClassLoader} from the specified {@link ClassLoader}, + * if it can't be found, it will try to find all the {@link URL} of class-paths from the specified {@link ClassLoader}, + * and then new a instance of {@link URLClassLoader} upon those urls. + * + * @param classLoader {@link ClassLoader} + * @return non-null {@link URLClassLoader} + */ + @Nonnull + public static URLClassLoader resolveURLClassLoader(@Nullable ClassLoader classLoader) { + URLClassLoader urlClassLoader = findURLClassLoader(classLoader); + if (urlClassLoader == null) { + Set urls = findAllClassPathURLs(classLoader); + urlClassLoader = newURLClassLoader(urls, classLoader); + } + return urlClassLoader; + } + /** * Return the ClassLoader from the caller class * @@ -716,12 +793,16 @@ static Class invokeFindLoadedClassMethod(ClassLoader classLoader, String clas Method findLoadedClassMethod = findMethod(ClassLoader.class, findLoadedClassMethodName, String.class); loadedClass = invokeMethod(classLoader, findLoadedClassMethod, className); } catch (Throwable e) { - logger.error("The java.lang.ClassLoader#findLoadedClasss(String) method can't be invoked in the current JVM[vendor : {} , version : {}]", - JAVA_VENDOR, JAVA_VERSION, e.getCause()); + logOnFindLoadedClassInvocationFailed(classLoader, className, e); } return loadedClass; } + static void logOnFindLoadedClassInvocationFailed(ClassLoader classLoader, String className, Throwable e) { + logger.error("The findLoadedClass(className : '{}' : String) method of java.lang.ClassLoader[{}] can't be invoked in the current JVM[vendor : {} , version : {}]", + className, classLoader, JAVA_VENDOR, JAVA_VERSION, e); + } + static String buildCacheKey(ClassLoader classLoader, String className) { String cacheKey = className + classLoader.hashCode(); return cacheKey; From 03c1f081c3b1eaf570aa3181da1d7315eb29cd99 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 20:22:40 +0800 Subject: [PATCH 175/180] Update ClassLoaderUtilsTest.java --- .../util/ClassLoaderUtilsTest.java | 157 +++++++++++++++++- 1 file changed, 153 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java index efa560e2d..c74252ee6 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java @@ -29,7 +29,10 @@ import static io.microsphere.constants.FileConstants.CLASS_EXTENSION; import static io.microsphere.management.JmxUtils.getClassLoadingMXBean; import static io.microsphere.reflect.FieldUtils.findAllDeclaredFields; +import static io.microsphere.util.ArrayUtils.EMPTY_URL_ARRAY; +import static io.microsphere.util.ArrayUtils.asArray; import static io.microsphere.util.ArrayUtils.ofArray; +import static io.microsphere.util.ClassLoaderUtils.doLoadClass; import static io.microsphere.util.ClassLoaderUtils.findAllClassPathURLs; import static io.microsphere.util.ClassLoaderUtils.findLoadedClass; import static io.microsphere.util.ClassLoaderUtils.findLoadedClasses; @@ -49,17 +52,25 @@ import static io.microsphere.util.ClassLoaderUtils.getResources; import static io.microsphere.util.ClassLoaderUtils.getTotalLoadedClassCount; import static io.microsphere.util.ClassLoaderUtils.getUnloadedClassCount; +import static io.microsphere.util.ClassLoaderUtils.invokeFindLoadedClassMethod; import static io.microsphere.util.ClassLoaderUtils.isLoadedClass; import static io.microsphere.util.ClassLoaderUtils.isPresent; import static io.microsphere.util.ClassLoaderUtils.isVerbose; import static io.microsphere.util.ClassLoaderUtils.loadClass; +import static io.microsphere.util.ClassLoaderUtils.logOnFindLoadedClassInvocationFailed; +import static io.microsphere.util.ClassLoaderUtils.newURLClassLoader; import static io.microsphere.util.ClassLoaderUtils.removeClassPathURL; +import static io.microsphere.util.ClassLoaderUtils.resolveURLClassLoader; import static io.microsphere.util.ClassLoaderUtils.setVerbose; +import static io.microsphere.util.ClassPathUtils.getClassPaths; import static io.microsphere.util.VersionUtils.JAVA_VERSION_12; import static io.microsphere.util.VersionUtils.testCurrentJavaVersion; import static java.lang.ClassLoader.getSystemClassLoader; import static java.lang.Thread.currentThread; +import static java.net.URLClassLoader.newInstance; +import static java.util.Collections.emptyList; import static java.util.Collections.emptySet; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -101,7 +112,8 @@ public static void afterAll() { @Test public void testConstructor() { - assertThrows(IllegalStateException.class, () -> new ClassLoaderUtils() {}); + assertThrows(IllegalStateException.class, () -> new ClassLoaderUtils() { + }); } @Test @@ -277,6 +289,9 @@ public void testFindLoadedClass() { type = findLoadedClass(classLoader, Double.class.getName()); assertEquals(Double.class, type); + + type = findLoadedClass(classLoader, "java/lang/String.class"); + assertNull(type); } @Test @@ -284,6 +299,35 @@ public void testLoadClass() { assertLoadClass(classLoader); } + @Test + public void testLoadClassOnNullClassLoader() { + assertLoadClass(null); + } + + @Test + public void testLoadClassOnNullClassName() { + assertNull(loadClass(this.classLoader, null)); + + assertNull(loadClass(this.classLoader, null, true)); + } + + @Test + public void testLoadClassOnBlankClassName() { + assertNull(loadClass(this.classLoader, "")); + assertNull(loadClass(this.classLoader, " ")); + + assertNull(loadClass(this.classLoader, "", true)); + assertNull(loadClass(this.classLoader, " ", true)); + } + + @Test + public void testDoLoadClassOnNull() { + assertNull(doLoadClass(null, ClassLoaderUtilsTest.class.getName())); + assertNull(doLoadClass(null, Nonnull.class.getName())); + assertNull(doLoadClass(null, String.class.getName())); + assertNull(doLoadClass(null, null)); + } + @Test public void testLoadClassOnNotFound() { assertNull(loadClass(classLoader, "io.microsphere.not.found.class")); @@ -430,7 +474,7 @@ public void testFindLoadedClassesInClassPath() { @Test public void testFindLoadedClassesInClassPaths() { - Set> allLoadedClasses = findLoadedClassesInClassPaths(classLoader, ClassPathUtils.getClassPaths()); + Set> allLoadedClasses = findLoadedClassesInClassPaths(classLoader, getClassPaths()); assertFalse(allLoadedClasses.isEmpty()); } @@ -464,10 +508,10 @@ public void testIsPresent() { @Test public void testFindURLClassLoader() { - URLClassLoader parent = URLClassLoader.newInstance(new URL[0]); + URLClassLoader parent = newInstance(EMPTY_URL_ARRAY); assertFindURLClassLoader(parent, parent); - URLClassLoader classLoader = URLClassLoader.newInstance(new URL[0], getDefaultClassLoader()); + URLClassLoader classLoader = newInstance(EMPTY_URL_ARRAY, getDefaultClassLoader()); assertFindURLClassLoader(classLoader, classLoader); SecureClassLoader secureClassLoader = new SecureClassLoader() { @@ -479,6 +523,111 @@ protected Class loadClass(String name, boolean resolve) throws ClassNotFoundE findURLClassLoader(secureClassLoader); } + @Test + public void testNewURLClassLoaderWithURLIterable() { + Set urls = findAllClassPathURLs(this.classLoader); + URLClassLoader urlClassLoader = newURLClassLoader(urls, classLoader); + assertArrayEquals(asArray(urls, URL.class), urlClassLoader.getURLs()); + } + + @Test + public void testNewURLClassLoaderWithURLIterableOnEmpty() { + URLClassLoader urlClassLoader = newURLClassLoader(emptyList(), classLoader); + assertArrayEquals(EMPTY_URL_ARRAY, urlClassLoader.getURLs()); + + urlClassLoader = newURLClassLoader(emptyList(), null); + assertArrayEquals(EMPTY_URL_ARRAY, urlClassLoader.getURLs()); + } + + @Test + public void testNewURLClassLoaderWithURLIterableOnNull() { + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader((Iterable) null, classLoader)); + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader((Iterable) null, null)); + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader((Iterable) null)); + + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader(ofList((URL) null), classLoader)); + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader(ofList((URL) null), null)); + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader(ofList((URL) null))); + } + + @Test + public void testNewURLClassLoaderWithURLArray() { + Set urls = findAllClassPathURLs(this.classLoader); + URL[] urlsArray = asArray(urls, URL.class); + + URLClassLoader urlClassLoader = newURLClassLoader(urlsArray, classLoader); + assertArrayEquals(urlsArray, urlClassLoader.getURLs()); + + urlClassLoader = newURLClassLoader(urlsArray, null); + assertArrayEquals(urlsArray, urlClassLoader.getURLs()); + + urlClassLoader = newURLClassLoader(urlsArray); + assertArrayEquals(urlsArray, urlClassLoader.getURLs()); + } + + @Test + public void testNewURLClassLoaderWithURLArrayOnEmpty() { + URLClassLoader urlClassLoader = newURLClassLoader(EMPTY_URL_ARRAY, classLoader); + assertArrayEquals(EMPTY_URL_ARRAY, urlClassLoader.getURLs()); + + urlClassLoader = newURLClassLoader(EMPTY_URL_ARRAY, null); + assertArrayEquals(EMPTY_URL_ARRAY, urlClassLoader.getURLs()); + + urlClassLoader = newURLClassLoader(EMPTY_URL_ARRAY); + assertArrayEquals(EMPTY_URL_ARRAY, urlClassLoader.getURLs()); + } + + @Test + public void testNewURLClassLoaderWithURLArrayOnNull() { + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader((URL[]) null, classLoader)); + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader((URL[]) null, null)); + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader((URL[]) null)); + + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader(ofArray((URL) null), classLoader)); + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader(ofArray((URL) null), null)); + assertThrows(IllegalArgumentException.class, () -> newURLClassLoader(ofArray((URL) null))); + } + + @Test + public void testResolveURLClassLoader() { + Set urls = findAllClassPathURLs(this.classLoader); + URLClassLoader urlClassLoader = resolveURLClassLoader(this.classLoader); + assertArrayEquals(asArray(urls, URL.class), urlClassLoader.getURLs()); + + assertSame(urlClassLoader, resolveURLClassLoader(urlClassLoader)); + } + + @Test + public void testResolveURLClassLoaderOnNull() { + Set urls = findAllClassPathURLs(getDefaultClassLoader()); + URLClassLoader urlClassLoader = resolveURLClassLoader(null); + assertArrayEquals(asArray(urls, URL.class), urlClassLoader.getURLs()); + } + + @Test + public void testInvokeFindLoadedClassMethod() { + assertInvokeFindLoadedClassMethod(ClassLoaderUtilsTest.class); + assertInvokeFindLoadedClassMethod(Nonnull.class); + assertInvokeFindLoadedClassMethod(String.class); + } + + @Test + public void testInvokeFindLoadedClassMethodOnFailed() { + assertNull(invokeFindLoadedClassMethod(null, ClassLoaderUtilsTest.class.getName())); + } + + @Test + public void testLogOnFindLoadedClassInvocationFailed() { + logOnFindLoadedClassInvocationFailed(this.classLoader, "NotFound", new Exception("For testing")); + logOnFindLoadedClassInvocationFailed(null, "NotFound", new Exception("For testing")); + logOnFindLoadedClassInvocationFailed(null, null, new Exception("For testing")); + logOnFindLoadedClassInvocationFailed(null, null, null); + } + + private void assertInvokeFindLoadedClassMethod(Class clazz) { + assertSame(clazz, invokeFindLoadedClassMethod(this.classLoader, clazz.getName())); + } + private void assertFindURLClassLoader(ClassLoader classLoader, ClassLoader expectedClassLoader) { URLClassLoader urlClassLoader = findURLClassLoader(classLoader); assertSame(expectedClassLoader, urlClassLoader); From 6b669b9953546400928de4aa0543330a6df51b98 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 20:22:47 +0800 Subject: [PATCH 176/180] Update AbstractArtifactResolver.java --- .../microsphere/classloading/AbstractArtifactResolver.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/classloading/AbstractArtifactResolver.java b/microsphere-java-core/src/main/java/io/microsphere/classloading/AbstractArtifactResolver.java index b78fccdae..4fd8a55aa 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/classloading/AbstractArtifactResolver.java +++ b/microsphere-java-core/src/main/java/io/microsphere/classloading/AbstractArtifactResolver.java @@ -13,6 +13,7 @@ import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.net.URLUtils.resolveArchiveFile; import static io.microsphere.util.ArrayUtils.isEmpty; +import static io.microsphere.util.ClassLoaderUtils.newURLClassLoader; import static java.util.Collections.emptySet; /** @@ -48,10 +49,6 @@ public int getPriority() { protected abstract void doResolve(Collection artifactSet, URLClassLoader urlClassLoader); - protected URLClassLoader newURLClassLoader(URL[] urls) { - return new URLClassLoader(urls, null); - } - protected URL resolveArtifactResourceURL(URL resourceURL) { URL url = null; try { From 08e695b592d9c7ce422aa9de087c0f4f8a950243 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 20:22:49 +0800 Subject: [PATCH 177/180] Update MavenArtifactResolver.java --- .../classloading/MavenArtifactResolver.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/classloading/MavenArtifactResolver.java b/microsphere-java-core/src/main/java/io/microsphere/classloading/MavenArtifactResolver.java index 000942078..d89ea5743 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/classloading/MavenArtifactResolver.java +++ b/microsphere-java-core/src/main/java/io/microsphere/classloading/MavenArtifactResolver.java @@ -1,7 +1,6 @@ package io.microsphere.classloading; import io.microsphere.filter.JarEntryFilter; -import io.microsphere.util.jar.JarUtils; import java.io.IOException; import java.io.InputStream; @@ -16,6 +15,7 @@ import static io.microsphere.net.URLUtils.isJarURL; import static io.microsphere.util.ClassLoaderUtils.findAllClassPathURLs; +import static io.microsphere.util.jar.JarUtils.filter; import static io.microsphere.util.jar.JarUtils.toJarFile; /** @@ -68,16 +68,16 @@ protected void doResolve(Collection artifactSet, URLClassLoader urlCla } } - private URL findMavenPomPropertiesResource(URL classPathURL, URLClassLoader urlClassLoader) throws IOException { + URL findMavenPomPropertiesResource(URL classPathURL, URLClassLoader urlClassLoader) throws IOException { if (isJarURL(classPathURL)) { return findMavenPomPropertiesResourceInJar(classPathURL, urlClassLoader); } return null; } - private URL findMavenPomPropertiesResourceInJar(URL classPathURL, URLClassLoader urlClassLoader) throws IOException { + URL findMavenPomPropertiesResourceInJar(URL classPathURL, URLClassLoader urlClassLoader) throws IOException { JarFile jarFile = toJarFile(classPathURL); - List entries = JarUtils.filter(jarFile, MAVEN_POM_PROPERTIES_FILTER); + List entries = filter(jarFile, MAVEN_POM_PROPERTIES_FILTER); if (entries.isEmpty()) { return null; } @@ -86,7 +86,7 @@ private URL findMavenPomPropertiesResourceInJar(URL classPathURL, URLClassLoader return urlClassLoader.getResource(relativePath); } - private Artifact resolveArtifactMetaInfoInMavenPomProperties(URL mavenPomPropertiesResourceURL) { + Artifact resolveArtifactMetaInfoInMavenPomProperties(URL mavenPomPropertiesResourceURL) { Artifact artifact = null; try (InputStream mavenPomPropertiesStream = mavenPomPropertiesResourceURL.openStream()) { Properties properties = new Properties(); @@ -99,7 +99,7 @@ private Artifact resolveArtifactMetaInfoInMavenPomProperties(URL mavenPomPropert return artifact; } - private Artifact resolveArtifactMetaInfoInMavenPomProperties(Properties properties, + Artifact resolveArtifactMetaInfoInMavenPomProperties(Properties properties, URL artifactResourceURL) { String groupId = properties.getProperty(GROUP_ID_PROPERTY_NAME); String artifactId = properties.getProperty(ARTIFACT_ID_PROPERTY_NAME); @@ -107,7 +107,7 @@ private Artifact resolveArtifactMetaInfoInMavenPomProperties(Properties properti return MavenArtifact.create(groupId, artifactId, version, artifactResourceURL); } - private static class MavenPomPropertiesFilter implements JarEntryFilter { + static class MavenPomPropertiesFilter implements JarEntryFilter { @Override public boolean accept(JarEntry entry) { From 2111daaa02554e52a6602c3e20e2ed42c222362c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 20:22:53 +0800 Subject: [PATCH 178/180] Update AbstractArtifactResolverTest.java --- .../microsphere/classloading/AbstractArtifactResolverTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/classloading/AbstractArtifactResolverTest.java b/microsphere-java-core/src/test/java/io/microsphere/classloading/AbstractArtifactResolverTest.java index 4c3b0168f..43a4b4d18 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/classloading/AbstractArtifactResolverTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/classloading/AbstractArtifactResolverTest.java @@ -24,7 +24,7 @@ */ public abstract class AbstractArtifactResolverTest extends AbstractTestCase { - private AbstractArtifactResolver artifactResolver; + protected A artifactResolver; @BeforeEach public void init() { From ef48c471f35d78975c7fa8a821c3110282989e86 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 20:22:56 +0800 Subject: [PATCH 179/180] Update MavenArtifactResolverTest.java --- .../MavenArtifactResolverTest.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/classloading/MavenArtifactResolverTest.java b/microsphere-java-core/src/test/java/io/microsphere/classloading/MavenArtifactResolverTest.java index 61173988b..4d71e88ff 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/classloading/MavenArtifactResolverTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/classloading/MavenArtifactResolverTest.java @@ -16,6 +16,20 @@ */ package io.microsphere.classloading; +import org.junit.jupiter.api.Test; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; + +import static io.microsphere.classloading.MavenArtifactResolver.DEFAULT_PRIORITY; +import static io.microsphere.util.ClassLoaderUtils.getClassResource; +import static io.microsphere.util.ClassLoaderUtils.resolveURLClassLoader; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + /** * {@link MavenArtifactResolver} Test * @@ -32,6 +46,32 @@ protected MavenArtifactResolver createArtifactResolver() { @Override protected int getPriority() { - return MavenArtifactResolver.DEFAULT_PRIORITY; + return DEFAULT_PRIORITY; + } + + @Test + public void testFindMavenPomPropertiesResource() throws IOException { + URLClassLoader urlClassLoader = resolveURLClassLoader(this.classLoader); + URL mavenPomPropertiesResource = mavenPomPropertiesResourceOfNonnull(urlClassLoader); + assertNotNull(mavenPomPropertiesResource); + + URL url = getClassResource(String.class); + mavenPomPropertiesResource = artifactResolver.findMavenPomPropertiesResource(url, urlClassLoader); + assertNull(mavenPomPropertiesResource); + } + + @Test + public void testResolveArtifactMetaInfoInMavenPomProperties() throws IOException { + URLClassLoader urlClassLoader = resolveURLClassLoader(this.classLoader); + URL mavenPomPropertiesResource = mavenPomPropertiesResourceOfNonnull(urlClassLoader); + + MavenArtifact artifact = (MavenArtifact) artifactResolver.resolveArtifactMetaInfoInMavenPomProperties(mavenPomPropertiesResource); + assertEquals("com.google.code.findbugs", artifact.getGroupId()); + assertEquals("jsr305", artifact.getArtifactId()); + } + + private URL mavenPomPropertiesResourceOfNonnull(URLClassLoader urlClassLoader) throws IOException { + URL url = getClassResource(Nonnull.class); + return artifactResolver.findMavenPomPropertiesResource(url, urlClassLoader); } } From 5b04a5c0ae40e3ec95d8f6e7fd5a366a2196dabf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 2 Apr 2025 20:44:12 +0800 Subject: [PATCH 180/180] Update ClassLoaderUtilsTest.java --- .../test/java/io/microsphere/util/ClassLoaderUtilsTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java index c74252ee6..58f492b1b 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java @@ -590,10 +590,8 @@ public void testNewURLClassLoaderWithURLArrayOnNull() { @Test public void testResolveURLClassLoader() { - Set urls = findAllClassPathURLs(this.classLoader); URLClassLoader urlClassLoader = resolveURLClassLoader(this.classLoader); - assertArrayEquals(asArray(urls, URL.class), urlClassLoader.getURLs()); - + assertNotNull(urlClassLoader.getURLs()); assertSame(urlClassLoader, resolveURLClassLoader(urlClassLoader)); }