From 51e36d68b0dba2188fcb70981e45935e198486dd Mon Sep 17 00:00:00 2001 From: Kostya Date: Wed, 22 Jul 2026 09:36:57 +0000 Subject: package names --- ex1/.classpath | 57 ++++++++ ex1/.project | 34 +++++ ex1/.settings/org.eclipse.core.resources.prefs | 4 + ex1/.settings/org.eclipse.jdt.apt.core.prefs | 2 + ex1/.settings/org.eclipse.jdt.core.prefs | 9 ++ ex1/.settings/org.eclipse.m2e.core.prefs | 4 + ex1/pom.xml | 2 +- ex1/src/main/java/com/reflection/api/App.java | 10 -- .../main/java/com/reflection/api/Investigator.java | 145 --------------------- ex1/src/main/java/reflection/api/App.java | 10 ++ ex1/src/main/java/reflection/api/Investigator.java | 145 +++++++++++++++++++++ ex1/target/classes/reflection/api/App.class | Bin 0 -> 576 bytes .../classes/reflection/api/Investigator.class | Bin 0 -> 1058 bytes .../test-classes/com/reflection/api/AppTest.class | Bin 0 -> 511 bytes 14 files changed, 266 insertions(+), 156 deletions(-) create mode 100644 ex1/.classpath create mode 100644 ex1/.project create mode 100644 ex1/.settings/org.eclipse.core.resources.prefs create mode 100644 ex1/.settings/org.eclipse.jdt.apt.core.prefs create mode 100644 ex1/.settings/org.eclipse.jdt.core.prefs create mode 100644 ex1/.settings/org.eclipse.m2e.core.prefs delete mode 100644 ex1/src/main/java/com/reflection/api/App.java delete mode 100644 ex1/src/main/java/com/reflection/api/Investigator.java create mode 100644 ex1/src/main/java/reflection/api/App.java create mode 100644 ex1/src/main/java/reflection/api/Investigator.java create mode 100644 ex1/target/classes/reflection/api/App.class create mode 100644 ex1/target/classes/reflection/api/Investigator.class create mode 100644 ex1/target/test-classes/com/reflection/api/AppTest.class diff --git a/ex1/.classpath b/ex1/.classpath new file mode 100644 index 0000000..df66b20 --- /dev/null +++ b/ex1/.classpath @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ex1/.project b/ex1/.project new file mode 100644 index 0000000..421f7ec --- /dev/null +++ b/ex1/.project @@ -0,0 +1,34 @@ + + + ex1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + 1784712768512 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/ex1/.settings/org.eclipse.core.resources.prefs b/ex1/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..f9fe345 --- /dev/null +++ b/ex1/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/ex1/.settings/org.eclipse.jdt.apt.core.prefs b/ex1/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..d4313d4 --- /dev/null +++ b/ex1/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/ex1/.settings/org.eclipse.jdt.core.prefs b/ex1/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..a4e59d9 --- /dev/null +++ b/ex1/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/ex1/.settings/org.eclipse.m2e.core.prefs b/ex1/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/ex1/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/ex1/pom.xml b/ex1/pom.xml index 3962137..b8a0d5a 100644 --- a/ex1/pom.xml +++ b/ex1/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.reflection.api + reflection.api ex1 1.0-SNAPSHOT diff --git a/ex1/src/main/java/com/reflection/api/App.java b/ex1/src/main/java/com/reflection/api/App.java deleted file mode 100644 index 04cd919..0000000 --- a/ex1/src/main/java/com/reflection/api/App.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.reflection.api; - -/** - * Hello world! - */ -public class App { - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} diff --git a/ex1/src/main/java/com/reflection/api/Investigator.java b/ex1/src/main/java/com/reflection/api/Investigator.java deleted file mode 100644 index 53e4fab..0000000 --- a/ex1/src/main/java/com/reflection/api/Investigator.java +++ /dev/null @@ -1,145 +0,0 @@ -package reflection.api; - -import java.util.Set; - -public interface Investigator { - - /** - * loads in instance of a given class, which you will need to investigate through means of reflection - * and supply information on... - * - * @param anInstanceOfSomething an instance of an unknown type... - */ - void load(Object anInstanceOfSomething); - - /** - * returns the total number of the current class methods (not including the super class methods) - * the total number of methods includes all sorts of modifiers: private, public, static, protected etc. - * it does not contains constructors of any sort - * - * @return total number of methods - */ - int getTotalNumberOfMethods(); - - /** - * returns the total number of constructors that this class has. (not including the super class constructors) - * the total number of constructors includes all sorts of modifiers: private, public, protected, default etc. - * - * @return total number of constructors - */ - int getTotalNumberOfConstructors(); - - /** - * returns the total number of fields that this class has. - * the total number of fields DOES NOT include fields inherited from super class, if such exists - * and includes all fields of any type (final, static etc.) - * - * @return the total number of fields - */ - int getTotalNumberOfFields(); - - /** - * returns the names of all the interfaces that this class implements - * (and NOT the ones that are being implemented by it's ancestor in the inheritance chain) - * Note that by name I mean simple, short Name that is only the interface name, - * and not its fully qualified name including the package it is located within... - * - * @return set of interfaces names - */ - Set getAllImplementedInterfaces(); - - /** - * returns total number of constant fields (=final), of any type (private, public, static etc.) - * (not including the super class fields) - * @return total number of constant fields - */ - int getCountOfConstantFields(); - - /** - * returns total number of static methods, of any type (private, public etc.), - * that are declared on the instance itself (and not part of its inheritance chain) - * - * @return total number of static methods - */ - int getCountOfStaticMethods(); - - /** - * checks if the given class extends a super class, that is not Object (which all extend by default, implicitly) - * - * @return true if the class extends, false otherwise - */ - boolean isExtending(); - - /** - * get the name of the direct parent class - * the name of the class is the short, simple name and not the fully qualified name - * - * @return the name of the parent class. null if this class doesn't extend other class - */ - String getParentClassSimpleName(); - - /** - * checks if the given class parent is of type abstract - * - * @return true if the parent class is abstract, false otherwise (also in case the given class does not extends any other class) - */ - boolean isParentClassAbstract(); - - /** - * get all the names of all fields, including the ones coming from the inheritance chain - * all fields of any type should exists: private, public, protected, static etc. - * - * @return set of fields names - */ - Set getNamesOfAllFieldsIncludingInheritanceChain(); - - /** - * invokes a method that returns an int value, on the given instance. - * the method to invoke will be given by its name only. - * You can assume that there is exactly one such method and that - * the method is declared on the instance itself and not as part of its inheritance chain - * - * @param methodName the name of the method to invoke - * @param args the arguments to pass to the method, if such exists. - * Note: You should not use the arguments in order to extract and identify the method. - * You can do that only (and simply) by its name. - * You just need to pass the arguments AS IS to the method invocation... - * - * @return the result returned from the method invocation - */ - int invokeMethodThatReturnsInt(String methodName, Object... args); - - /** - * creates a new instance of the given class, using a specific constructor, - * to be determined by the number of given arguments. - * No worries: there will be no ambiguity, i.e. two constructors that gets in 2 arguments each one of them... - * This method should act as a standalone and without any side effects, that is, the newly created - * instance SHOULD NOT replace the original given instance. - * @param numberOfArgs number of arguments that a specific constructor has. can be 0. - * @param args arguments to pass to the constructor - * - * @return the newly created instance - */ - Object createInstance(int numberOfArgs, Object... args); - - /** - * changes access control of a method and invokes it (== invokes a private method...) - * you can assume that the method exists by it's name, and matched by the relevant parameters types. - * - * @param name name of the method to change its access modifier - * @param parametersTypes the types of parameters the method accepts - * @param args arguments to pass to the method invocation AS IS (once elevated) - * - * @return the result from the method invocation - */ - Object elevateMethodAndInvoke(String name, Class[] parametersTypes, Object... args); - - /** - * explores the inheritance chain of the object. returns a string representing the list of - * parents this class has, starting from Object, and ending at the class name. - * all classes names in the list should appear in their simple short name - * @param delimiter a string to put between each two classes in the chain (e.g. "->") - * @return a string denotes the inheritance chain. - * It can look like this (given a decimeter of "->"): Object->->...-> - */ - String getInheritanceChain(String delimiter);} diff --git a/ex1/src/main/java/reflection/api/App.java b/ex1/src/main/java/reflection/api/App.java new file mode 100644 index 0000000..04cd919 --- /dev/null +++ b/ex1/src/main/java/reflection/api/App.java @@ -0,0 +1,10 @@ +package com.reflection.api; + +/** + * Hello world! + */ +public class App { + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} diff --git a/ex1/src/main/java/reflection/api/Investigator.java b/ex1/src/main/java/reflection/api/Investigator.java new file mode 100644 index 0000000..53e4fab --- /dev/null +++ b/ex1/src/main/java/reflection/api/Investigator.java @@ -0,0 +1,145 @@ +package reflection.api; + +import java.util.Set; + +public interface Investigator { + + /** + * loads in instance of a given class, which you will need to investigate through means of reflection + * and supply information on... + * + * @param anInstanceOfSomething an instance of an unknown type... + */ + void load(Object anInstanceOfSomething); + + /** + * returns the total number of the current class methods (not including the super class methods) + * the total number of methods includes all sorts of modifiers: private, public, static, protected etc. + * it does not contains constructors of any sort + * + * @return total number of methods + */ + int getTotalNumberOfMethods(); + + /** + * returns the total number of constructors that this class has. (not including the super class constructors) + * the total number of constructors includes all sorts of modifiers: private, public, protected, default etc. + * + * @return total number of constructors + */ + int getTotalNumberOfConstructors(); + + /** + * returns the total number of fields that this class has. + * the total number of fields DOES NOT include fields inherited from super class, if such exists + * and includes all fields of any type (final, static etc.) + * + * @return the total number of fields + */ + int getTotalNumberOfFields(); + + /** + * returns the names of all the interfaces that this class implements + * (and NOT the ones that are being implemented by it's ancestor in the inheritance chain) + * Note that by name I mean simple, short Name that is only the interface name, + * and not its fully qualified name including the package it is located within... + * + * @return set of interfaces names + */ + Set getAllImplementedInterfaces(); + + /** + * returns total number of constant fields (=final), of any type (private, public, static etc.) + * (not including the super class fields) + * @return total number of constant fields + */ + int getCountOfConstantFields(); + + /** + * returns total number of static methods, of any type (private, public etc.), + * that are declared on the instance itself (and not part of its inheritance chain) + * + * @return total number of static methods + */ + int getCountOfStaticMethods(); + + /** + * checks if the given class extends a super class, that is not Object (which all extend by default, implicitly) + * + * @return true if the class extends, false otherwise + */ + boolean isExtending(); + + /** + * get the name of the direct parent class + * the name of the class is the short, simple name and not the fully qualified name + * + * @return the name of the parent class. null if this class doesn't extend other class + */ + String getParentClassSimpleName(); + + /** + * checks if the given class parent is of type abstract + * + * @return true if the parent class is abstract, false otherwise (also in case the given class does not extends any other class) + */ + boolean isParentClassAbstract(); + + /** + * get all the names of all fields, including the ones coming from the inheritance chain + * all fields of any type should exists: private, public, protected, static etc. + * + * @return set of fields names + */ + Set getNamesOfAllFieldsIncludingInheritanceChain(); + + /** + * invokes a method that returns an int value, on the given instance. + * the method to invoke will be given by its name only. + * You can assume that there is exactly one such method and that + * the method is declared on the instance itself and not as part of its inheritance chain + * + * @param methodName the name of the method to invoke + * @param args the arguments to pass to the method, if such exists. + * Note: You should not use the arguments in order to extract and identify the method. + * You can do that only (and simply) by its name. + * You just need to pass the arguments AS IS to the method invocation... + * + * @return the result returned from the method invocation + */ + int invokeMethodThatReturnsInt(String methodName, Object... args); + + /** + * creates a new instance of the given class, using a specific constructor, + * to be determined by the number of given arguments. + * No worries: there will be no ambiguity, i.e. two constructors that gets in 2 arguments each one of them... + * This method should act as a standalone and without any side effects, that is, the newly created + * instance SHOULD NOT replace the original given instance. + * @param numberOfArgs number of arguments that a specific constructor has. can be 0. + * @param args arguments to pass to the constructor + * + * @return the newly created instance + */ + Object createInstance(int numberOfArgs, Object... args); + + /** + * changes access control of a method and invokes it (== invokes a private method...) + * you can assume that the method exists by it's name, and matched by the relevant parameters types. + * + * @param name name of the method to change its access modifier + * @param parametersTypes the types of parameters the method accepts + * @param args arguments to pass to the method invocation AS IS (once elevated) + * + * @return the result from the method invocation + */ + Object elevateMethodAndInvoke(String name, Class[] parametersTypes, Object... args); + + /** + * explores the inheritance chain of the object. returns a string representing the list of + * parents this class has, starting from Object, and ending at the class name. + * all classes names in the list should appear in their simple short name + * @param delimiter a string to put between each two classes in the chain (e.g. "->") + * @return a string denotes the inheritance chain. + * It can look like this (given a decimeter of "->"): Object->->...-> + */ + String getInheritanceChain(String delimiter);} diff --git a/ex1/target/classes/reflection/api/App.class b/ex1/target/classes/reflection/api/App.class new file mode 100644 index 0000000..0cbae67 Binary files /dev/null and b/ex1/target/classes/reflection/api/App.class differ diff --git a/ex1/target/classes/reflection/api/Investigator.class b/ex1/target/classes/reflection/api/Investigator.class new file mode 100644 index 0000000..01731c6 Binary files /dev/null and b/ex1/target/classes/reflection/api/Investigator.class differ diff --git a/ex1/target/test-classes/com/reflection/api/AppTest.class b/ex1/target/test-classes/com/reflection/api/AppTest.class new file mode 100644 index 0000000..cdc15d1 Binary files /dev/null and b/ex1/target/test-classes/com/reflection/api/AppTest.class differ -- cgit v1.2.3