diff options
Diffstat (limited to 'ex1/src/main/java/reflection/api')
| -rw-r--r-- | ex1/src/main/java/reflection/api/ReflectionInvestigator.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/ex1/src/main/java/reflection/api/ReflectionInvestigator.java b/ex1/src/main/java/reflection/api/ReflectionInvestigator.java index 27e7b44..e16d3d5 100644 --- a/ex1/src/main/java/reflection/api/ReflectionInvestigator.java +++ b/ex1/src/main/java/reflection/api/ReflectionInvestigator.java | |||
| @@ -74,9 +74,16 @@ public class ReflectionInvestigator implements Investigator { | |||
| 74 | 74 | ||
| 75 | @Override | 75 | @Override |
| 76 | public Set<String> getNamesOfAllFieldsIncludingInheritanceChain() { | 76 | public Set<String> getNamesOfAllFieldsIncludingInheritanceChain() { |
| 77 | return Stream.of(classInfo.getDeclaredFields()) | 77 | var fields = new HashSet<String>(); |
| 78 | .map(f -> f.getName()) | 78 | var cursor = classInfo; |
| 79 | .collect(Collectors.toSet()); | 79 | while (cursor != null) { |
| 80 | fields.addAll( | ||
| 81 | Stream.of(classInfo.getDeclaredFields()) | ||
| 82 | .map(f -> f.getName()) | ||
| 83 | .collect(Collectors.toSet())); | ||
| 84 | cursor = cursor.getSuperclass(); | ||
| 85 | } | ||
| 86 | return fields; | ||
| 80 | } | 87 | } |
| 81 | 88 | ||
| 82 | @Override | 89 | @Override |
| @@ -109,7 +116,7 @@ public class ReflectionInvestigator implements Investigator { | |||
| 109 | @Override | 116 | @Override |
| 110 | public Object elevateMethodAndInvoke(String name, Class<?>[] parametersTypes, Object... args) { | 117 | public Object elevateMethodAndInvoke(String name, Class<?>[] parametersTypes, Object... args) { |
| 111 | try { | 118 | try { |
| 112 | var method = classInfo.getMethod(name, parametersTypes); | 119 | var method = classInfo.getDeclaredMethod(name, parametersTypes); |
| 113 | method.setAccessible(true); | 120 | method.setAccessible(true); |
| 114 | return method.invoke(subjectInstance, args); | 121 | return method.invoke(subjectInstance, args); |
| 115 | } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { | 122 | } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { |