|
4 | 4 |
|
5 | 5 | import java.lang.invoke.MethodType; |
6 | 6 | import java.lang.reflect.Field; |
| 7 | +import java.lang.reflect.Modifier; |
7 | 8 | import java.lang.reflect.ParameterizedType; |
8 | 9 | import java.lang.reflect.Type; |
9 | 10 |
|
@@ -36,25 +37,18 @@ public <T> Class<T> wrap(Class<T> type) { |
36 | 37 | return (Class<T>) MethodType.methodType(type).wrap().returnType(); |
37 | 38 | } |
38 | 39 |
|
39 | | - /** |
40 | | - * Checks if a field contains certain modifiers. |
41 | | - * |
42 | | - * @param field The field to check. |
43 | | - * @param contains The modifiers. |
44 | | - * @return If the field contains the modifiers. |
45 | | - */ |
46 | | - public boolean hasModifiers(Field field, int contains) { |
47 | | - return (field.getModifiers() & contains) == contains; |
| 40 | + public boolean isCompanionClass(Class<?> clazz) { |
| 41 | + if (!Modifier.isPublic(clazz.getModifiers())) return false; |
| 42 | + if (!Modifier.isStatic(clazz.getModifiers())) return false; |
| 43 | + |
| 44 | + return clazz.getSimpleName().equals("Companion"); |
48 | 45 | } |
49 | 46 |
|
50 | | - /** |
51 | | - * Checks if a class contains certain modifiers. |
52 | | - * |
53 | | - * @param clazz The class to check. |
54 | | - * @param contains The modifiers. |
55 | | - * @return If the class contains the modifiers. |
56 | | - */ |
57 | | - public boolean hasModifiers(Class<?> clazz, int contains) { |
58 | | - return (clazz.getModifiers() & contains) == contains; |
| 47 | + public boolean isCompanionField(Field field) { |
| 48 | + if (!isCompanionClass(field.getType())) return false; |
| 49 | + if (!Modifier.isStatic(field.getModifiers())) return false; |
| 50 | + if (!Modifier.isFinal(field.getModifiers())) return false; |
| 51 | + |
| 52 | + return field.getName().equals("Companion"); |
59 | 53 | } |
60 | 54 | } |
0 commit comments