diff options
Diffstat (limited to 'ex1/reflection/api')
| -rw-r--r-- | ex1/reflection/api/Investigator.java | 145 |
1 files changed, 0 insertions, 145 deletions
diff --git a/ex1/reflection/api/Investigator.java b/ex1/reflection/api/Investigator.java deleted file mode 100644 index 53e4fab..0000000 --- a/ex1/reflection/api/Investigator.java +++ /dev/null | |||
| @@ -1,145 +0,0 @@ | |||
| 1 | package reflection.api; | ||
| 2 | |||
| 3 | import java.util.Set; | ||
| 4 | |||
| 5 | public interface Investigator { | ||
| 6 | |||
| 7 | /** | ||
| 8 | * loads in instance of a given class, which you will need to investigate through means of reflection | ||
| 9 | * and supply information on... | ||
| 10 | * | ||
| 11 | * @param anInstanceOfSomething an instance of an unknown type... | ||
| 12 | */ | ||
| 13 | void load(Object anInstanceOfSomething); | ||
| 14 | |||
| 15 | /** | ||
| 16 | * returns the total number of the current class methods (not including the super class methods) | ||
| 17 | * the total number of methods includes all sorts of modifiers: private, public, static, protected etc. | ||
| 18 | * it does not contains constructors of any sort | ||
| 19 | * | ||
| 20 | * @return total number of methods | ||
| 21 | */ | ||
| 22 | int getTotalNumberOfMethods(); | ||
| 23 | |||
| 24 | /** | ||
| 25 | * returns the total number of constructors that this class has. (not including the super class constructors) | ||
| 26 | * the total number of constructors includes all sorts of modifiers: private, public, protected, default etc. | ||
| 27 | * | ||
| 28 | * @return total number of constructors | ||
| 29 | */ | ||
| 30 | int getTotalNumberOfConstructors(); | ||
| 31 | |||
| 32 | /** | ||
| 33 | * returns the total number of fields that this class has. | ||
| 34 | * the total number of fields DOES NOT include fields inherited from super class, if such exists | ||
| 35 | * and includes all fields of any type (final, static etc.) | ||
| 36 | * | ||
| 37 | * @return the total number of fields | ||
| 38 | */ | ||
| 39 | int getTotalNumberOfFields(); | ||
| 40 | |||
| 41 | /** | ||
| 42 | * returns the names of all the interfaces that this class implements | ||
| 43 | * (and NOT the ones that are being implemented by it's ancestor in the inheritance chain) | ||
| 44 | * Note that by name I mean simple, short Name that is only the interface name, | ||
| 45 | * and not its fully qualified name including the package it is located within... | ||
| 46 | * | ||
| 47 | * @return set of interfaces names | ||
| 48 | */ | ||
| 49 | Set<String> getAllImplementedInterfaces(); | ||
| 50 | |||
| 51 | /** | ||
| 52 | * returns total number of constant fields (=final), of any type (private, public, static etc.) | ||
| 53 | * (not including the super class fields) | ||
| 54 | * @return total number of constant fields | ||
| 55 | */ | ||
| 56 | int getCountOfConstantFields(); | ||
| 57 | |||
| 58 | /** | ||
| 59 | * returns total number of static methods, of any type (private, public etc.), | ||
| 60 | * that are declared on the instance itself (and not part of its inheritance chain) | ||
| 61 | * | ||
| 62 | * @return total number of static methods | ||
| 63 | */ | ||
| 64 | int getCountOfStaticMethods(); | ||
| 65 | |||
| 66 | /** | ||
| 67 | * checks if the given class extends a super class, that is not Object (which all extend by default, implicitly) | ||
| 68 | * | ||
| 69 | * @return true if the class extends, false otherwise | ||
| 70 | */ | ||
| 71 | boolean isExtending(); | ||
| 72 | |||
| 73 | /** | ||
| 74 | * get the name of the direct parent class | ||
| 75 | * the name of the class is the short, simple name and not the fully qualified name | ||
| 76 | * | ||
| 77 | * @return the name of the parent class. null if this class doesn't extend other class | ||
| 78 | */ | ||
| 79 | String getParentClassSimpleName(); | ||
| 80 | |||
| 81 | /** | ||
| 82 | * checks if the given class parent is of type abstract | ||
| 83 | * | ||
| 84 | * @return true if the parent class is abstract, false otherwise (also in case the given class does not extends any other class) | ||
| 85 | */ | ||
| 86 | boolean isParentClassAbstract(); | ||
| 87 | |||
| 88 | /** | ||
| 89 | * get all the names of all fields, including the ones coming from the inheritance chain | ||
| 90 | * all fields of any type should exists: private, public, protected, static etc. | ||
| 91 | * | ||
| 92 | * @return set of fields names | ||
| 93 | */ | ||
| 94 | Set<String> getNamesOfAllFieldsIncludingInheritanceChain(); | ||
| 95 | |||
| 96 | /** | ||
| 97 | * invokes a method that returns an int value, on the given instance. | ||
| 98 | * the method to invoke will be given by its name only. | ||
| 99 | * You can assume that there is exactly one such method and that | ||
| 100 | * the method is declared on the instance itself and not as part of its inheritance chain | ||
| 101 | * | ||
| 102 | * @param methodName the name of the method to invoke | ||
| 103 | * @param args the arguments to pass to the method, if such exists. | ||
| 104 | * Note: You should not use the arguments in order to extract and identify the method. | ||
| 105 | * You can do that only (and simply) by its name. | ||
| 106 | * You just need to pass the arguments AS IS to the method invocation... | ||
| 107 | * | ||
| 108 | * @return the result returned from the method invocation | ||
| 109 | */ | ||
| 110 | int invokeMethodThatReturnsInt(String methodName, Object... args); | ||
| 111 | |||
| 112 | /** | ||
| 113 | * creates a new instance of the given class, using a specific constructor, | ||
| 114 | * to be determined by the number of given arguments. | ||
| 115 | * No worries: there will be no ambiguity, i.e. two constructors that gets in 2 arguments each one of them... | ||
| 116 | * This method should act as a standalone and without any side effects, that is, the newly created | ||
| 117 | * instance SHOULD NOT replace the original given instance. | ||
| 118 | * @param numberOfArgs number of arguments that a specific constructor has. can be 0. | ||
| 119 | * @param args arguments to pass to the constructor | ||
| 120 | * | ||
| 121 | * @return the newly created instance | ||
| 122 | */ | ||
| 123 | Object createInstance(int numberOfArgs, Object... args); | ||
| 124 | |||
| 125 | /** | ||
| 126 | * changes access control of a method and invokes it (== invokes a private method...) | ||
| 127 | * you can assume that the method exists by it's name, and matched by the relevant parameters types. | ||
| 128 | * | ||
| 129 | * @param name name of the method to change its access modifier | ||
| 130 | * @param parametersTypes the types of parameters the method accepts | ||
| 131 | * @param args arguments to pass to the method invocation AS IS (once elevated) | ||
| 132 | * | ||
| 133 | * @return the result from the method invocation | ||
| 134 | */ | ||
| 135 | Object elevateMethodAndInvoke(String name, Class<?>[] parametersTypes, Object... args); | ||
| 136 | |||
| 137 | /** | ||
| 138 | * explores the inheritance chain of the object. returns a string representing the list of | ||
| 139 | * parents this class has, starting from Object, and ending at the class name. | ||
| 140 | * all classes names in the list should appear in their simple short name | ||
| 141 | * @param delimiter a string to put between each two classes in the chain (e.g. "->") | ||
| 142 | * @return a string denotes the inheritance chain. | ||
| 143 | * It can look like this (given a decimeter of "->"): Object-><class name>->...-><class name> | ||
| 144 | */ | ||
| 145 | String getInheritanceChain(String delimiter);} | ||