/
TypeSupport.java
42 lines (34 loc) · 1.01 KB
/
TypeSupport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright (c) 2021 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.creation.bytebuddy;
import org.mockito.exceptions.base.MockitoException;
import java.lang.reflect.Method;
class TypeSupport {
static final TypeSupport INSTANCE;
static {
Method isSealed;
try {
isSealed = Class.class.getMethod("isSealed");
} catch (NoSuchMethodException ignored) {
isSealed = null;
}
INSTANCE = new TypeSupport(isSealed);
}
private final Method isSealed;
private TypeSupport(Method isSealed) {
this.isSealed = isSealed;
}
boolean isSealed(Class<?> type) {
if (isSealed == null) {
return false;
}
try {
return (boolean) isSealed.invoke(type);
} catch (Throwable t) {
throw new MockitoException(
"Failed to check if type is sealed using handle " + isSealed, t);
}
}
}