Skip to content

Commit fa1a730

Browse files
authored
Merge pull request #26 from microsphere-projects/dev
Polish #25
2 parents d339814 + 0c273c3 commit fa1a730

File tree

10 files changed

+334
-182
lines changed

10 files changed

+334
-182
lines changed

microsphere-java-core/src/main/java/io/microsphere/io/scanner/SimpleClassScanner.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.microsphere.filter.FilterUtils;
77
import io.microsphere.filter.PackageNameClassNameFilter;
88
import io.microsphere.lang.ClassDataRepository;
9-
import io.microsphere.util.ClassLoaderUtils;
109

1110
import java.io.File;
1211
import java.io.IOException;

microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java

Lines changed: 222 additions & 147 deletions
Large diffs are not rendered by default.

microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import static io.microsphere.lang.function.Streams.filterAll;
4343
import static io.microsphere.lang.function.Streams.filterFirst;
4444
import static io.microsphere.lang.function.ThrowableSupplier.execute;
45-
import static io.microsphere.reflect.MethodUtils.OBJECT_METHODS;
45+
import static io.microsphere.reflect.MethodUtils.OBJECT_PUBLIC_METHODS;
4646
import static io.microsphere.reflect.MethodUtils.overrides;
4747
import static io.microsphere.util.ArrayUtils.length;
4848
import static io.microsphere.util.ClassLoaderUtils.resolveClass;
@@ -415,7 +415,7 @@ public static boolean isCallerSensitivePresent() {
415415
private static boolean isInheritedObjectMethod(Method attributeMethod) {
416416
boolean inherited = false;
417417

418-
for (Method method : OBJECT_METHODS) {
418+
for (Method method : OBJECT_PUBLIC_METHODS) {
419419
if (overrides(attributeMethod, method)) {
420420
inherited = true;
421421
break;

microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
package io.microsphere.util;
55

6-
import io.microsphere.collection.CollectionUtils;
76
import io.microsphere.constants.FileConstants;
87
import io.microsphere.filter.ClassFileJarEntryFilter;
98
import io.microsphere.io.filter.FileExtensionFilter;
@@ -17,15 +16,10 @@
1716
import java.lang.reflect.Modifier;
1817
import java.math.BigDecimal;
1918
import java.math.BigInteger;
20-
import java.net.MalformedURLException;
21-
import java.net.URL;
22-
import java.security.CodeSource;
23-
import java.security.ProtectionDomain;
2419
import java.util.ArrayList;
2520
import java.util.Arrays;
2621
import java.util.Date;
2722
import java.util.HashMap;
28-
import java.util.LinkedHashMap;
2923
import java.util.LinkedHashSet;
3024
import java.util.LinkedList;
3125
import java.util.List;
@@ -55,8 +49,6 @@
5549
import static io.microsphere.util.ArrayUtils.isEmpty;
5650
import static io.microsphere.util.ArrayUtils.isNotEmpty;
5751
import static io.microsphere.util.ArrayUtils.length;
58-
import static io.microsphere.util.ClassPathUtils.getBootstrapClassPaths;
59-
import static io.microsphere.util.ClassPathUtils.getClassPaths;
6052
import static io.microsphere.util.StringUtils.isNotBlank;
6153
import static io.microsphere.util.StringUtils.replace;
6254
import static io.microsphere.util.StringUtils.startsWith;

microsphere-java-core/src/test/java/io/microsphere/annotation/ExperimentalTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.junit.jupiter.api.Test;
2020

21-
import static org.junit.jupiter.api.Assertions.assertEquals;
2221
import static org.junit.jupiter.api.Assertions.assertNull;
2322

2423
/**

microsphere-java-core/src/test/java/io/microsphere/lang/ClassDataRepositoryTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import io.microsphere.AbstractTestCase;
2020
import io.microsphere.reflect.ReflectionUtils;
21-
import io.microsphere.util.ClassPathUtils;
2221
import org.junit.jupiter.api.Test;
2322

2423
import javax.annotation.Nonnull;

microsphere-java-core/src/test/java/io/microsphere/lang/WrapperTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static io.microsphere.lang.Wrapper.tryUnwrap;
2222
import static org.junit.jupiter.api.Assertions.assertEquals;
2323
import static org.junit.jupiter.api.Assertions.assertNull;
24-
import static org.junit.jupiter.api.Assertions.assertTrue;
2524

2625
/**
2726
* {@link Wrapper} Test

microsphere-java-core/src/test/java/io/microsphere/reflect/MethodUtilsTest.java

Lines changed: 109 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@
1616
*/
1717
package io.microsphere.reflect;
1818

19+
import io.microsphere.util.ArrayUtils;
1920
import org.junit.jupiter.api.Test;
2021

2122
import java.lang.reflect.Method;
2223
import java.util.ArrayList;
2324
import java.util.List;
2425

26+
import static io.microsphere.reflect.MethodUtils.OBJECT_DECLARED_METHODS;
27+
import static io.microsphere.reflect.MethodUtils.OBJECT_PUBLIC_METHODS;
28+
import static io.microsphere.reflect.MethodUtils.PULIC_METHOD_PREDICATE;
2529
import static io.microsphere.reflect.MethodUtils.findMethod;
30+
import static io.microsphere.reflect.MethodUtils.getAllDeclaredMethods;
31+
import static io.microsphere.reflect.MethodUtils.getDeclaredMethods;
2632
import static io.microsphere.reflect.MethodUtils.getMethods;
2733
import static io.microsphere.reflect.MethodUtils.getSignature;
2834
import static io.microsphere.reflect.MethodUtils.invokeMethod;
2935
import static io.microsphere.reflect.MethodUtils.invokeStaticMethod;
3036
import static java.lang.Integer.valueOf;
37+
import static java.util.Collections.emptyList;
3138
import static org.junit.jupiter.api.Assertions.assertEquals;
3239

3340
/**
@@ -56,44 +63,125 @@ public void testGetSignature() {
5663
// Test two-argument Method
5764
method = findMethod(MethodUtils.class, "findMethod", Class.class, String.class, Class[].class);
5865
assertEquals("io.microsphere.reflect.MethodUtils#findMethod(java.lang.Class,java.lang.String,java.lang.Class[])", getSignature(method));
66+
}
67+
68+
@Test
69+
void testFilterMethodsFromNull() {
70+
List<Method> methods = MethodUtils.filterMethods(null, true, true);
71+
assertEquals(emptyList(), methods);
72+
73+
methods = MethodUtils.filterMethods(null, true, false);
74+
assertEquals(emptyList(), methods);
75+
76+
methods = MethodUtils.filterMethods(null, false, true);
77+
assertEquals(emptyList(), methods);
78+
79+
methods = MethodUtils.filterMethods(null, false, false);
80+
assertEquals(emptyList(), methods);
81+
82+
methods = getMethods(null);
83+
assertEquals(emptyList(), methods);
84+
}
85+
86+
@Test
87+
public void testFilterMethodsFromPrimitive() {
88+
Class<?> primitiveType = int.class;
89+
List<Method> methods = MethodUtils.filterMethods(primitiveType, true, true);
90+
assertEquals(emptyList(), methods);
91+
92+
methods = MethodUtils.filterMethods(primitiveType, true, false);
93+
assertEquals(emptyList(), methods);
94+
95+
methods = MethodUtils.filterMethods(primitiveType, false, true);
96+
assertEquals(emptyList(), methods);
97+
98+
methods = MethodUtils.filterMethods(primitiveType, false, false);
99+
assertEquals(emptyList(), methods);
100+
101+
methods = getMethods(primitiveType);
102+
assertEquals(emptyList(), methods);
103+
}
104+
105+
@Test
106+
public void testFilterMethodsFromArray() {
107+
Class<?> arrayClass = ArrayUtils.EMPTY_CLASS_ARRAY.getClass();
108+
List<Method> methods = MethodUtils.filterMethods(arrayClass, true, true);
109+
assertEquals(OBJECT_PUBLIC_METHODS, methods);
110+
111+
methods = MethodUtils.filterMethods(arrayClass, false, true);
112+
assertEquals(OBJECT_PUBLIC_METHODS, methods);
59113

114+
methods = MethodUtils.filterMethods(arrayClass, true, false);
115+
assertEquals(OBJECT_PUBLIC_METHODS, methods);
116+
117+
methods = MethodUtils.filterMethods(arrayClass, false, false);
118+
assertEquals(OBJECT_PUBLIC_METHODS, methods);
60119
}
61120

62121
@Test
63-
void testGetMethodsFromClass() {
64-
List<Method> objectMethods = getMethods(Object.class, true, true);
122+
void testFilterMethodsFromClass() {
123+
List<Method> objectMethods = MethodUtils.filterMethods(Object.class, true, true);
65124

66-
List<Method> methods = getMethods(TestClass.class, true, true);
125+
List<Method> methods = MethodUtils.filterMethods(TestClass.class, true, true);
67126
assertEquals(1 + objectMethods.size(), methods.size());
68127

69-
methods = getMethods(TestClass.class, false, true);
128+
methods = MethodUtils.filterMethods(TestClass.class, false, true);
70129
assertEquals(1, methods.size());
71130

72-
methods = getMethods(TestClass.class, false, false);
131+
methods = MethodUtils.filterMethods(TestClass.class, false, false);
73132
assertEquals(7, methods.size());
74133

75-
methods = getMethods(TestClass.class, true, false);
76-
objectMethods = getMethods(Object.class, true, false);
134+
methods = MethodUtils.filterMethods(TestClass.class, true, false);
135+
objectMethods = MethodUtils.filterMethods(Object.class, true, false);
77136

78137
assertEquals(7 + objectMethods.size(), methods.size());
79138
}
80139

81140
@Test
82-
void testGetMethodsFromInterface() {
83-
List<Method> methods = getMethods(TestInterface.class, true, true);
141+
void testFilterMethodsFromInterface() {
142+
List<Method> methods = MethodUtils.filterMethods(TestInterface.class, true, true);
84143
assertEquals(2, methods.size()); // method + useLambda
85144

86-
methods = getMethods(TestInterface.class, true, false);
87-
assertEquals(3, methods.size()); // method + useLambda + 合成的lambda方法Object[]::new
88-
// NOTE:需不需要把合成的方法计算在内? 应该是要算的
145+
methods = MethodUtils.filterMethods(TestInterface.class, true, false);
146+
assertEquals(3, methods.size()); // method + useLambda + generated lambda method by compiler
89147

90-
List<Method> subMethods = getMethods(TestSubInterface.class, false, true);
148+
List<Method> subMethods = MethodUtils.filterMethods(TestSubInterface.class, false, true);
91149
assertEquals(1, subMethods.size()); // subMethod
92150

93-
subMethods = getMethods(TestSubInterface.class, true, true);
151+
subMethods = MethodUtils.filterMethods(TestSubInterface.class, true, true);
94152
assertEquals(3, subMethods.size()); // method + useLambda + subMethod
95153
}
96154

155+
@Test
156+
public void testGetDeclaredMethods() {
157+
List<Method> methods = getDeclaredMethods(Object.class);
158+
assertEquals(OBJECT_DECLARED_METHODS, methods);
159+
160+
methods = getDeclaredMethods(Object.class, PULIC_METHOD_PREDICATE);
161+
assertEquals(OBJECT_PUBLIC_METHODS, methods);
162+
163+
methods = getDeclaredMethods(TestClass.class);
164+
assertEquals(7, methods.size());
165+
166+
methods = getDeclaredMethods(TestClass.class, PULIC_METHOD_PREDICATE);
167+
assertEquals(1, methods.size());
168+
}
169+
170+
@Test
171+
public void testGetAllDeclaredMethods() {
172+
List<Method> methods = getAllDeclaredMethods(Object.class);
173+
assertEquals(OBJECT_DECLARED_METHODS, methods);
174+
175+
methods = getAllDeclaredMethods(Object.class, PULIC_METHOD_PREDICATE);
176+
assertEquals(OBJECT_PUBLIC_METHODS, methods);
177+
178+
methods = getAllDeclaredMethods(TestClass.class);
179+
assertEquals(OBJECT_DECLARED_METHODS.size() + 7, methods.size());
180+
181+
methods = getAllDeclaredMethods(TestClass.class, PULIC_METHOD_PREDICATE);
182+
assertEquals(OBJECT_PUBLIC_METHODS.size() + 1, methods.size());
183+
}
184+
97185
@Test
98186
public void testInvokeMethod() {
99187
String test = "test";
@@ -111,6 +199,13 @@ public void testInvokeStaticMethod() {
111199
assertEquals(valueOf(0), (Integer) invokeStaticMethod(TestClass.class, "value", 0));
112200
}
113201

202+
@Test
203+
public void test() {
204+
Method[] methods = TestSubInterface.class.getDeclaredMethods();
205+
methods = TestInterface.class.getDeclaredMethods();
206+
System.out.println(methods);
207+
}
208+
114209
static class TestClass {
115210
public void method1() {
116211
}

microsphere-java-core/src/test/java/io/microsphere/util/ClassUtilsTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@
44
package io.microsphere.util;
55

66
import io.microsphere.AbstractTestCase;
7-
import io.microsphere.reflect.ReflectionUtils;
87
import org.junit.jupiter.api.Test;
98

10-
import javax.annotation.Nonnull;
11-
import java.io.IOException;
129
import java.io.Serializable;
1310
import java.lang.reflect.Array;
14-
import java.net.URL;
1511
import java.util.AbstractCollection;
1612
import java.util.Map;
17-
import java.util.Set;
1813

1914
import static io.microsphere.util.ClassUtils.arrayTypeEquals;
2015
import static io.microsphere.util.ClassUtils.concreteClassCache;
@@ -28,7 +23,6 @@
2823
import static io.microsphere.util.ClassUtils.resolveWrapperType;
2924
import static org.junit.jupiter.api.Assertions.assertEquals;
3025
import static org.junit.jupiter.api.Assertions.assertFalse;
31-
import static org.junit.jupiter.api.Assertions.assertNotNull;
3226
import static org.junit.jupiter.api.Assertions.assertNull;
3327
import static org.junit.jupiter.api.Assertions.assertTrue;
3428

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</scm>
5252

5353
<properties>
54-
<revision>0.0.7-SNAPSHOT</revision>
54+
<revision>0.0.8-SNAPSHOT</revision>
5555
</properties>
5656

5757
<modules>

0 commit comments

Comments
 (0)