summaryrefslogtreecommitdiffstats
path: root/ex1/src/main/java/reflection/api/ReflectionInvestigator.java
blob: 2d18b342f48f62d56134ef6ced763f81f10cd00c (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package reflection.api;

import java.lang.reflect.Modifier;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ReflectionInvestigator implements Investigator {
  private Object subjectInstance;
  private Class<?> classInfo;

  public ReflectionInvestigator() {}

  @Override
  public void load(Object anInstanceOfSomething) {
    subjectInstance = anInstanceOfSomething;
    classInfo = subjectInstance.getClass();
  }

  @Override
  public int getTotalNumberOfMethods() {
    return classInfo.getDeclaredMethods().length;
  }

  @Override
  public int getTotalNumberOfConstructors() {
    return classInfo.getConstructors().length;
  }

  @Override
  public int getTotalNumberOfFields() {
    return classInfo.getFields().length;
  }

  @Override
  public Set<String> getAllImplementedInterfaces() {
    return Stream.of(classInfo.getInterfaces())
        .map(info -> info.getName())
        .collect(Collectors.toSet());
  }

  @Override
  public int getCountOfConstantFields() {
    return Stream.of(classInfo.getFields())
        .filter(f -> Modifier.isFinal(f.getModifiers()))
        .toArray()
        .length;
  }

  @Override
  public int getCountOfStaticMethods() {
    return Stream.of(classInfo.getMethods())
        .filter(m -> Modifier.isStatic(m.getModifiers()))
        .toArray()
        .length;
  }

  @Override
  public boolean isExtending() {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'isExtending'");
  }

  @Override
  public String getParentClassSimpleName() {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'getParentClassSimpleName'");
  }

  @Override
  public boolean isParentClassAbstract() {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'isParentClassAbstract'");
  }

  @Override
  public Set<String> getNamesOfAllFieldsIncludingInheritanceChain() {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException(
        "Unimplemented method 'getNamesOfAllFieldsIncludingInheritanceChain'");
  }

  @Override
  public int invokeMethodThatReturnsInt(String methodName, Object... args) {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'invokeMethodThatReturnsInt'");
  }

  @Override
  public Object createInstance(int numberOfArgs, Object... args) {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'createInstance'");
  }

  @Override
  public Object elevateMethodAndInvoke(String name, Class<?>[] parametersTypes, Object... args) {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'elevateMethodAndInvoke'");
  }

  @Override
  public String getInheritanceChain(String delimiter) {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'getInheritanceChain'");
  }
}