10
10
import java .util .WeakHashMap ;
11
11
12
12
import top .niunaijun .blackreflection .annotation .BClass ;
13
+ import top .niunaijun .blackreflection .annotation .BClassName ;
14
+ import top .niunaijun .blackreflection .annotation .BClassNameNotProcess ;
13
15
import top .niunaijun .blackreflection .annotation .BConstructor ;
14
16
import top .niunaijun .blackreflection .annotation .BConstructorNotProcess ;
15
17
import top .niunaijun .blackreflection .annotation .BField ;
18
20
import top .niunaijun .blackreflection .annotation .BFieldSetNotProcess ;
19
21
import top .niunaijun .blackreflection .annotation .BMethodCheckNotProcess ;
20
22
import top .niunaijun .blackreflection .annotation .BParamClass ;
21
- import top .niunaijun .blackreflection .annotation .BClassName ;
22
- import top .niunaijun .blackreflection .annotation .BClassNameNotProcess ;
23
23
import top .niunaijun .blackreflection .annotation .BParamClassName ;
24
24
import top .niunaijun .blackreflection .utils .Reflector ;
25
25
@@ -36,6 +36,7 @@ public class BlackReflection {
36
36
public static boolean DEBUG = false ;
37
37
public static boolean CACHE = false ;
38
38
private static final Map <Class <?>, Object > sProxyCache = new HashMap <>();
39
+ private static final Map <Class <?>, Object > sProxyWithExceptionCache = new HashMap <>();
39
40
40
41
// key caller
41
42
private static final WeakHashMap <Object , Map <Class <?>, Object >> sCallerProxyCache = new WeakHashMap <>();
@@ -163,16 +164,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
163
164
}
164
165
});
165
166
166
- if (CACHE ) {
167
- if (caller == null ) {
168
- sProxyCache .put (clazz , o );
167
+ if (caller == null ) {
168
+ if (withException ) {
169
+ sProxyWithExceptionCache .put (clazz , o );
169
170
} else {
170
- Map <Class <?>, Object > callerClassMap = sCallerProxyCache .get (caller );
171
- if (callerClassMap == null ) {
172
- callerClassMap = new HashMap <>();
173
- sCallerProxyCache .put (caller , callerClassMap );
174
- }
175
- callerClassMap .put (clazz , o );
171
+ sProxyCache .put (clazz , o );
176
172
}
177
173
}
178
174
return (T ) o ;
@@ -183,25 +179,16 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
183
179
}
184
180
185
181
private static <T > T getProxy (Class <T > clazz , final Object caller , boolean withException ) {
186
- if (!CACHE ) {
187
- return null ;
188
- }
189
182
try {
190
- if (! withException ) {
191
- if ( caller == null ) {
192
- Object o = sProxyCache . get ( clazz );
193
- if ( o != null ) {
194
- return ( T ) o ;
195
- }
183
+ if (caller == null ) {
184
+ Object o ;
185
+ if ( withException ) {
186
+ o = sProxyWithExceptionCache . get ( clazz );
187
+ } else {
188
+ o = sProxyCache . get ( clazz );
196
189
}
197
- else {
198
- Map <Class <?>, Object > callerClassMap = sCallerProxyCache .get (caller );
199
- if (callerClassMap != null ) {
200
- Object o = callerClassMap .get (clazz );
201
- if (o != null ) {
202
- return (T ) o ;
203
- }
204
- }
190
+ if (o != null ) {
191
+ return (T ) o ;
205
192
}
206
193
}
207
194
} catch (Throwable ignore ) {
0 commit comments