The envisioned use case is the 'method signature' -> handle map.
Perhaps the existing method signature in the Reflection library can
- replace this ,but most of the work done here is the formatting done
+ replace this, but most of the work done here is the formatting done
in the constructors.
*/
MethodSignature_To_Handle_Map.test = test;
}
private static void test_print(String message){
- if (test){
+ if(test){
System.out.println(message);
}
}
// methods for adding entries
//
+ public void add_class(Class<?> class_metadata){
+ test_print("MethodSignature_To_Handle_Map::add_class adding methods");
+ add_methods(class_metadata);
+
+ test_print("MethodSignature_To_Handle_Map::add_class adding constructors");
+ add_constructors(class_metadata);
+
+ test_print("MethodSignature_To_Handle_Map::add_class adding fields");
+ // add_fields(class_metadata);
+ }
+
private void add_entry(MethodSignature key ,MethodHandle value){
test_print
(
MethodHandle method_handle;
if((method.getModifiers() & Modifier.STATIC) != 0){
- method_handle = private_lookup.findStatic(class_metadata, method.getName(), method_type);
+ method_handle = private_lookup.findStatic(class_metadata ,method.getName() ,method_type);
}else{
- method_handle = private_lookup.findSpecial(class_metadata, method.getName(), method_type, class_metadata);
+ method_handle = private_lookup.findSpecial(class_metadata ,method.getName() ,method_type ,class_metadata);
}
add_entry(signature,method_handle);
}
}
-
public void add_constructors(Class<?> class_metadata){
try{
try{
Class<?>[] parameter_type_list = constructor.getParameterTypes();
- MethodType method_type = MethodType.methodType(void.class, parameter_type_list);
+ MethodType method_type = MethodType.methodType(void.class ,parameter_type_list);
MethodHandle constructor_handle = private_lookup.findConstructor(class_metadata ,method_type);
// Signature for constructors: <init> with parameter types
add_entry(signature ,constructor_handle);
}catch(IllegalAccessException|NoSuchMethodException e){
- System.err.println("Mosaic_Dispatcher::add_methods unexpectedly failed to register constructor: " + class_metadata.getName());
+ System.err.println("Mosaic_Dispatcher::add_constructors unexpectedly failed to register constructor: " + class_metadata.getName());
e.printStackTrace();
}
}
}catch(IllegalAccessException e){
- System.err.println("Mosaic_Dispatcher::add_methods unexpectedly failed to initialize lookup for class: " + class_metadata.getName());
+ System.err.println("Mosaic_Dispatcher::add_constructors unexpectedly failed to initialize lookup for class: " + class_metadata.getName());
e.printStackTrace();
}
}
+ public void add_fields(Class<?> class_metadata){
+ try{
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+ MethodHandles.Lookup private_lookup = MethodHandles.privateLookupIn(class_metadata ,lookup);
+
+ for(Field field : class_metadata.getDeclaredFields()){
+ try{
+ // Field Metadata
+ String field_name = field.getName();
+ Class<?> field_type = field.getType();
+
+ // Create <read> MethodHandle
+ MethodHandle read_handle = private_lookup.unreflectGetter(field);
+ MethodSignature read_signature = new MethodSignature
+ (
+ field_type
+ ,class_metadata.getName()
+ ,"<read:" + field_name + ">"
+ ,new Class<?>[]{}
+ );
+ add_entry(read_signature ,read_handle);
+
+ // Create <write> MethodHandle
+ MethodHandle write_handle = private_lookup.unreflectSetter(field);
+ MethodSignature write_signature = new MethodSignature
+ (
+ void.class
+ ,class_metadata.getName()
+ ,"<write:" + field_name + ">"
+ ,new Class<?>[]{field_type}
+ );
+ add_entry(write_signature ,write_handle);
+
+ }catch(IllegalAccessException e){
+ System.err.println("Mosaic_Dispatcher::add_fields unexpectedly failed to register field: " + field.getName());
+ e.printStackTrace();
+ }
+ }
+ }catch(IllegalAccessException e){
+ System.err.println("Mosaic_Dispatcher::add_fields unexpectedly failed to initialize lookup for class: " + class_metadata.getName());
+ e.printStackTrace();
+ }
+ }
+
+
// methods for looking up handles
//
public MethodHandle lookup(MethodSignature s){
public Mosaic_Dispatcher(Class<?> target){
this.map = new MethodSignature_To_Handle_Map();
this.target = target;
- test_print("Mosaic_Dispatcher:: mapping methods given class_metadata object: " + to_string_target());
- this.map.add_methods(target);
- this.map.add_constructors(target);
+ test_print("Mosaic_Dispatcher::<init> mapping methods given class_metadata object: " + to_string_target());
+ this.map.add_class(target);
}
// Constructor accepting a fully qualified class name of the target class
public Mosaic_Dispatcher(String fully_qualified_class_name) throws ClassNotFoundException{
this.map = new MethodSignature_To_Handle_Map();
this.target = Class.forName(fully_qualified_class_name);
- test_print("Mosaic_Dispatcher:: mapping methods from class specified by string: \"" + to_string_target() + "\"");
- this.map.add_methods(target);
- this.map.add_constructors(target);
+ test_print("Mosaic_Dispatcher::<init> mapping methods from class specified by string: \"" + to_string_target() + "\"");
+ this.map.add_class(target);
}
// methods unique to the class
//
+ public <T> T read(String field_name){
+ try{
+ test_print("Call to Mosaic_Dispatcher::read( field_name )");
+
+ MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(target ,MethodHandles.lookup());
+ Field field = target.getDeclaredField(field_name);
+ MethodHandle handle = lookup.unreflectGetter(field);
+ return (T) handle.invoke();
+
+ }catch(NoSuchFieldException | IllegalAccessException e){
+ System.out.println("Mosaic_Dispatcher::read of static exception:");
+ e.printStackTrace();
+ return null;
+ }catch(Throwable t){
+ System.out.println("Mosaic_Dispatcher::read of static exception:");
+ t.printStackTrace();
+ return null;
+ }
+ }
+
public <T> T read(Object instance ,String field_name){
try{
- test_print("Call to Mosaic_Dispatcher::read");
+ test_print("Call to Mosaic_Dispatcher::read(instance ,field_name)");
- // Private field lookup
MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(target ,MethodHandles.lookup());
Field field = target.getDeclaredField(field_name);
- // Access the field using the lookup handle
- MethodHandle handle;
- if((field.getModifiers() & Modifier.STATIC) != 0){
- // Static field
- handle = lookup.unreflectGetter(field);
- return (T) handle.invoke();
- }else{
- // Instance-bound field
- if(instance == null || !target.isInstance(instance)){
- throw new IllegalArgumentException
- (
- "Provided instance is not of target type: "
- + target.getName()
- + ", but received: "
- + (instance == null ? "null" : instance.getClass().getName())
- );
- }
- handle = lookup.unreflectGetter(field);
- return (T) handle.bindTo(instance).invoke();
+ if(instance == null || !target.isInstance(instance)){
+ throw new IllegalArgumentException
+ (
+ "Mosaic_Dispatcher::read provided instance is not of target type: "
+ + target.getName()
+ + ", but received: "
+ + (instance == null ? "null" : instance.getClass().getName())
+ );
}
+ MethodHandle handle = lookup.unreflectGetter(field);
+ return (T) handle.bindTo(instance).invoke();
+
}catch(NoSuchFieldException | IllegalAccessException e){
- System.out.println("Mosaic_Dispatcher::read_field exception:");
+ System.out.println("Mosaic_Dispatcher::read exception:");
e.printStackTrace();
return null;
}catch(Throwable t){
- System.out.println("Mosaic_Dispatcher::read_field exception:");
+ System.out.println("Mosaic_Dispatcher::read exception:");
t.printStackTrace();
return null;
}
}
- public <T> void write(Object instance, String field_name, T value){
+ public <T> void write(String field_name ,T value){
try{
- test_print("Call to Mosaic_Dispatcher::write");
-
- // Private field lookup
- MethodHandles.Lookup lookup=MethodHandles.privateLookupIn(target,MethodHandles.lookup());
- Field field=target.getDeclaredField(field_name);
-
- // Access the field using the lookup handle
- MethodHandle handle;
- if((field.getModifiers() & Modifier.STATIC) != 0){
- // Static field
- handle=lookup.unreflectSetter(field);
- handle.invoke(value);
- }else{
- // Instance-bound field
- if(instance == null || !target.isInstance(instance)){
- throw new IllegalArgumentException(
- "Provided instance is not of target type: "+target.getName()
- +", but received: "+(instance == null ? "null" : instance.getClass().getName())
- );
- }
- handle=lookup.unreflectSetter(field);
- handle.bindTo(instance).invoke(value);
+ test_print("Call to Mosaic_Dispatcher::write(field_name ,value)");
+
+ MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(target ,MethodHandles.lookup());
+ Field field = target.getDeclaredField(field_name);
+ MethodHandle handle = lookup.unreflectSetter(field);
+ handle.invoke(value);
+
+ }catch(NoSuchFieldException | IllegalAccessException e){
+ System.out.println("Mosaic_Dispatcher::write static field exception:");
+ e.printStackTrace();
+ }catch(Throwable t){
+ System.out.println("Mosaic_Dispatcher::write static field exception:");
+ t.printStackTrace();
+ }
+ }
+
+ public <T> void write(Object instance ,String field_name ,T value){
+ try{
+ test_print("Call to Mosaic_Dispatcher::write(instance ,field_name ,value)");
+
+ MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(target ,MethodHandles.lookup());
+ Field field = target.getDeclaredField(field_name);
+
+ if(instance == null || !target.isInstance(instance)){
+ throw new IllegalArgumentException
+ (
+ "Mosaic_Dispatcher::write provided instance is not of target type: "
+ + target.getName()
+ + ", but received: "
+ + (instance == null ? "null" : instance.getClass().getName())
+ );
}
+ MethodHandle handle = lookup.unreflectSetter(field);
+ handle.bindTo(instance).invoke(value);
+
}catch(NoSuchFieldException | IllegalAccessException e){
- System.out.println("Mosaic_Dispatcher::write_field exception:");
+ System.out.println("Mosaic_Dispatcher::write instance field exception:");
e.printStackTrace();
}catch(Throwable t){
- System.out.println("Mosaic_Dispatcher::write_field exception:");
+ System.out.println("Mosaic_Dispatcher::write instance field exception:");
t.printStackTrace();
}
}
// Use dispatch_1 to invoke the constructor
Object result = dispatch_1(
- null, // no instance for constructor
- void.class, // return type for signature matching
- "<init>", // constructors are always named `<init>` in Java
- arg_list
+ null // no instance for constructor
+ ,void.class // return type for signature matching
+ ,"<init>" // constructors are always named `<init>` in Java
+ ,arg_list
);
// Cast the result to the target type
+ (instance == null ? "null" : instance.getClass().getName())
);
}
- return dispatch_1(instance, return_type, method_name, arg_list);
+ return dispatch_1(instance ,return_type ,method_name ,arg_list);
}
@SuppressWarnings("unchecked")
FunctionSignature used with AllMethodsPublic currently does not
include the return type. It needs to have that.
+2024-12-20T06:09:38Z
+
+ For Mosaic_Dispatcher, might be best to ditch the map and do lookup
+ to get the handle upon each call to a method, as we already have to
+ do the lookup to get the information for constructing the signature
+ for lookup.
--- /dev/null
+2024-12-20T06:09:38Z[]
+Thomas-developer@Blossac§/var/user_data/Thomas-developer/Mosaic/tester§
+> clean; make; run
++ cd /var/user_data/Thomas-developer/Mosaic/tester
++ rm_na log/log.txt
+rm_na: cannot remove 'log/log.txt': No such file or directory
++ rm_na -r scratchpad/Dispatcher_0.class scratchpad/Dispatcher_1.class scratchpad/Dispatcher_2.class scratchpad/Dispatcher_3.class scratchpad/IO.class 'scratchpad/IsPrimitive$TestSuite$1TestEnum.class' 'scratchpad/IsPrimitive$TestSuite.class' scratchpad/IsPrimitive.class 'scratchpad/Logger$TestSuite.class' scratchpad/Logger.class 'scratchpad/MockClass_0$TestSuite.class' scratchpad/MockClass_0.class scratchpad/smoke.class scratchpad/Testbench.class scratchpad/tester scratchpad/Util.class
++ rm_na jvm/Dispatcher_0 jvm/Dispatcher_1 jvm/Dispatcher_2 jvm/Dispatcher_3 jvm/IO jvm/IsPrimitive jvm/Logger jvm/MockClass_0 jvm/smoke jvm/Testbench jvm/Util
++ rm_na jdwp_server/Dispatcher_0 jdwp_server/Dispatcher_1 jdwp_server/Dispatcher_2 jdwp_server/Dispatcher_3 jdwp_server/IO jdwp_server/IsPrimitive jdwp_server/Logger jdwp_server/MockClass_0 jdwp_server/smoke jdwp_server/Testbench jdwp_server/Util
++ set +x
+clean done.
+++ realpath /var/user_data/Thomas-developer/Mosaic/tester/tool🖉/make
++ script_afp=/var/user_data/Thomas-developer/Mosaic/tester/tool🖉/make
++ env_must_be=tester/tool🖉/env
++ '[' tester/tool🖉/env '!=' tester/tool🖉/env ']'
++ echo 'Compiling files...'
+Compiling files...
++ set -x
++ cd /var/user_data/Thomas-developer/Mosaic/tester
++ javac -g -d scratchpad javac🖉/TestClasses_0.java javac🖉/TestClasses_1.java javac🖉/TestClasses_2.java
+++ list
++ list='smoke Logger Util IO Testbench MockClass_0 IsPrimitive Dispatcher_0 Dispatcher_1 Dispatcher_2 Dispatcher_3'
++ for file in $list
++ javac -g -d scratchpad javac🖉/smoke.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/Logger.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/Util.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/IO.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/Testbench.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/MockClass_0.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/IsPrimitive.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/Dispatcher_0.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/Dispatcher_1.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/Dispatcher_2.java
++ for file in $list
++ javac -g -d scratchpad javac🖉/Dispatcher_3.java
++ set +x
+Making jvm scripts ...
+Making jdwp debug server scripts...
+tester/tool🖉/make done.
+list: smoke Logger Util IO Testbench MockClass_0 IsPrimitive Dispatcher_0 Dispatcher_1 Dispatcher_2 Dispatcher_3
+
+... Running smoke
+Test0 passed
+
+... Running Logger
+Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
+ at com.ReasoningTechnology.Mosaic.Mosaic_Logger.<clinit>(Mosaic_Logger.java:12)
+ at Logger$TestSuite.smoke_test_logging(Logger.java:9)
+ at Logger.main(Logger.java:21)
+Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
+ at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
+ at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
+ at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:528)
+ ... 3 more
+
+... Running Util
+Util passed
+
+... Running IO
+IO passed
+
+... Running Testbench
+Expected output: Structural problem message for dummy_invalid_return_method.
+Structural problem: dummy_invalid_return_method does not return Boolean.
+Testbench Total tests run: 3
+Testbench Total tests passed: 3
+Testbench Total tests failed: 0
+
+... Running MockClass_0
+Test failed: 'test_failure_0' reported failure.
+Structural problem: test_failure_1 does not return Boolean.
+Error: test_failure_1 has an invalid structure.
+Test failed: 'test_failure_2' threw an exception: java.lang.reflect.InvocationTargetException
+Test failed: 'test_failure_3' produced extraneous stdout.
+Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
+ at com.ReasoningTechnology.Mosaic.Mosaic_Logger.<clinit>(Mosaic_Logger.java:12)
+ at com.ReasoningTechnology.Mosaic.Mosaic_Testbench.run_test(Mosaic_Testbench.java:74)
+ at com.ReasoningTechnology.Mosaic.Mosaic_Testbench.run(Mosaic_Testbench.java:95)
+ at MockClass_0.main(MockClass_0.java:94)
+Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
+ at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
+ at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
+ at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:528)
+ ... 4 more
+
+... Running IsPrimitive
+Total tests run: 15
+Total tests passed: 15
+Total tests failed: 0
+
+... Running Dispatcher_0
+making map for TestClasses_0
+Mosaic_Dispatcher::<init> mapping methods given class_metadata object: tester.TestClasses_0
+MethodSignature_To_Handle_Map::add_class adding methods
+(add_entry:: (key boolean tester.TestClasses_0.a_public_method_1()) (value MethodHandle(TestClasses_0)boolean))
+(add_entry:: (key boolean tester.TestClasses_0.a_public_static_method_7()) (value MethodHandle()boolean))
+(add_entry:: (key boolean tester.TestClasses_0.a_private_static_method_9()) (value MethodHandle()boolean))
+(add_entry:: (key boolean tester.TestClasses_0.a_private_method_2()) (value MethodHandle(TestClasses_0)boolean))
+MethodSignature_To_Handle_Map::add_class adding constructors
+(add_entry:: (key void tester.TestClasses_0.<init>()) (value MethodHandle()TestClasses_0))
+MethodSignature_To_Handle_Map::add_class adding fields
+
+running test: publicClass_publicMethod
+Call to Mosaic_Dispatcher::dispatch for a method bound to an instance.
+dispatch_1:: signature key:boolean tester.TestClasses_0.a_public_method_1()
+passed
+
+running test: make_0
+Mosaic_Dispatcher::<init> mapping methods given class_metadata object: tester.TestClasses_1
+MethodSignature_To_Handle_Map::add_class adding methods
+(add_entry:: (key int tester.TestClasses_1.get_i()) (value MethodHandle(TestClasses_1)int))
+MethodSignature_To_Handle_Map::add_class adding constructors
+(add_entry:: (key void tester.TestClasses_1.<init>(int ,int)) (value MethodHandle(int,int)TestClasses_1))
+(add_entry:: (key void tester.TestClasses_1.<init>(int)) (value MethodHandle(int)TestClasses_1))
+(add_entry:: (key void tester.TestClasses_1.<init>()) (value MethodHandle()TestClasses_1))
+MethodSignature_To_Handle_Map::add_class adding fields
+Call to Mosaic_Dispatcher::make
+dispatch_1:: signature key:void tester.TestClasses_1.<init>()
+Call to Mosaic_Dispatcher::make
+dispatch_1:: signature key:void tester.TestClasses_1.<init>(int)
+Call to Mosaic_Dispatcher::make
+dispatch_1:: signature key:void tester.TestClasses_1.<init>(int ,int)
+passed
+
+running test: publicStaticMethod_7
+Call to Mosaic_Dispatcher::dispatch for a static method.
+dispatch_1:: signature key:boolean tester.TestClasses_0.a_public_static_method_7()
+passed
+
+running test: privateStaticMethod_9
+Call to Mosaic_Dispatcher::dispatch for a static method.
+dispatch_1:: signature key:boolean tester.TestClasses_0.a_private_static_method_9()
+passed
+
+running test: defaultClass_access
+Mosaic_Dispatcher::<init> mapping methods from class specified by string: "tester.DefaultTestClass_01"
+MethodSignature_To_Handle_Map::add_class adding methods
+(add_entry:: (key boolean tester.DefaultTestClass_01.a_public_method_7()) (value MethodHandle(DefaultTestClass_01)boolean))
+(add_entry:: (key boolean tester.DefaultTestClass_01.a_private_method_8()) (value MethodHandle(DefaultTestClass_01)boolean))
+MethodSignature_To_Handle_Map::add_class adding constructors
+(add_entry:: (key void tester.DefaultTestClass_01.<init>()) (value MethodHandle()DefaultTestClass_01))
+MethodSignature_To_Handle_Map::add_class adding fields
+Call to Mosaic_Dispatcher::make
+dispatch_1:: signature key:void tester.DefaultTestClass_01.<init>()
+Call to Mosaic_Dispatcher::dispatch for a method bound to an instance.
+dispatch_1:: signature key:boolean tester.DefaultTestClass_01.a_public_method_7()
+Call to Mosaic_Dispatcher::dispatch for a method bound to an instance.
+dispatch_1:: signature key:boolean tester.DefaultTestClass_01.a_private_method_8()
+passed
+
+
+... Running Dispatcher_1
+
+running test: publicMethod_1
+passed
+
+running test: privateMethod_2
+passed
+
+running test: nestedPublicMethod_3
+passed
+
+running test: nestedPrivateMethod_4
+passed
+
+
+... Running Dispatcher_2
+
+running test: publicStaticField
+passed
+
+running test: privateStaticField
+passed
+
+running test: publicInstanceField
+passed
+
+running test: privateInstanceField
+passed
+
+running test: writePublicStaticField
+passed
+
+running test: writePrivateStaticField
+passed
+
+running test: writePublicInstanceField
+passed
+
+running test: writePrivateInstanceField
+passed
+
+
+... Running Dispatcher_3
+
+running test: privateNestedClassPublicMethod
+passed
+
+running test: privateNestedClassPrivateMethod
+passed
+
+running test: publicNestedClassPublicMethod
+passed
+
+running test: publicNestedClassPrivateMethod
+passed
+
+
+2024-12-20T06:10:20Z[]
+Thomas-developer@Blossac§/var/user_data/Thomas-developer/Mosaic/tester§
+>
public static boolean test_publicStaticField(){
try{
- Integer value=dispatcher.read(Integer.class,"i_200");
+ Integer value=dispatcher.read("i_200");
return value != null && value == 200;
}catch(Throwable t){
t.printStackTrace();
public static boolean test_privateStaticField(){
try{
- String value=dispatcher.read(String.class,"s_201");
+ String value=dispatcher.read("s_201");
return value != null && value.equals("Static Private String");
}catch(Throwable t){
t.printStackTrace();
public static boolean test_writePublicStaticField(){
try{
- dispatcher.write(null,"i_200",300);
- Integer value=dispatcher.read(Integer.class,"i_200");
+ dispatcher.write("i_200",300);
+ Integer value=dispatcher.read("i_200");
return value != null && value == 300;
}catch(Throwable t){
t.printStackTrace();
public static boolean test_writePrivateStaticField(){
try{
- dispatcher.write(null,"s_201","New Static Private String");
- String value=dispatcher.read(String.class,"s_201");
+ dispatcher.write("s_201","New Static Private String");
+ String value=dispatcher.read("s_201");
return value != null && value.equals("New Static Private String");
}catch(Throwable t){
t.printStackTrace();
}
}
}
-
import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher;
-import com.ReasoningTechnology.Mosaic.Mosaic_Util;
import tester.TestClasses_0;
public class Dispatcher_3{
- private static Mosaic_Dispatcher dispatcher;
-
- static{
- dispatcher = new Mosaic_Dispatcher(TestClasses_0.class);
+ public static boolean test_privateNestedClassPublicMethod(){
+ try{
+ TestClasses_0 outer_instance = new TestClasses_0();
+ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher("tester.TestClasses_0$APrivateClass_02");
+ Object nested_instance = nested_dispatcher.make(new Object[]{outer_instance});
+ boolean result = nested_dispatcher.dispatch(
+ nested_instance ,
+ boolean.class ,
+ "a_public_method_5"
+ );
+ return result;
+ }catch(Throwable t){
+ System.out.println("Exception in test_privateNestedClassPublicMethod:");
+ t.printStackTrace();
+ return false;
+ }
}
- public static boolean test_privateClassPublicMethod_5(){
+ public static boolean test_privateNestedClassPrivateMethod(){
try{
- Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APrivateClass_02.class);
- Object nested_instance = nested_dispatcher.make();
- return nested_dispatcher.dispatch(nested_instance, boolean.class, "a_public_method_5");
- } catch(Exception e){
- e.printStackTrace();
+ TestClasses_0 outer_instance = new TestClasses_0();
+ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher("tester.TestClasses_0$APrivateClass_02");
+ Object nested_instance = nested_dispatcher.make(new Object[]{outer_instance});
+ boolean result = nested_dispatcher.dispatch(
+ nested_instance ,
+ boolean.class ,
+ "a_private_method_6"
+ );
+ return result;
+ }catch(Throwable t){
+ System.out.println("Exception in test_privateNestedClassPrivateMethod:");
+ t.printStackTrace();
return false;
}
}
- public static boolean test_privateClassPrivateMethod_6(){
+ public static boolean test_publicNestedClassPublicMethod(){
try{
- Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APrivateClass_02.class);
- Object nested_instance = nested_dispatcher.make();
- return nested_dispatcher.dispatch(nested_instance, boolean.class, "a_private_method_6");
- } catch(Exception e){
- e.printStackTrace();
+ TestClasses_0 outer = new TestClasses_0();
+ TestClasses_0.APublicClass_01 nested_instance = outer.new APublicClass_01();
+ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class);
+ boolean result = nested_dispatcher.dispatch(
+ nested_instance ,
+ boolean.class ,
+ "a_public_method_3"
+ );
+ return result;
+ }catch(Throwable t){
+ System.out.println("Exception in test_publicNestedClassPublicMethod:");
+ t.printStackTrace();
return false;
}
}
- public static boolean test_publicDefaultClassField() {
- try {
- Class<?> defaultClass = dispatcher.getDefaultClass(); // Assuming `getDefaultClass` exists
- Integer value = dispatcher.read(Integer.class, "d_300");
- return value != null && value == 300; // Replace 300 with initialized value
- } catch (Throwable t) {
+ public static boolean test_publicNestedClassPrivateMethod(){
+ try{
+ TestClasses_0 outer = new TestClasses_0();
+ TestClasses_0.APublicClass_01 nested_instance = outer.new APublicClass_01();
+ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class);
+ boolean result = nested_dispatcher.dispatch(
+ nested_instance ,
+ boolean.class ,
+ "a_private_method_4"
+ );
+ return result;
+ }catch(Throwable t){
+ System.out.println("Exception in test_publicNestedClassPrivateMethod:");
t.printStackTrace();
return false;
}
}
-
-
public static boolean run(){
try{
boolean result = true;
System.out.println("");
- System.out.println("running test: privateClassPublicMethod_5");
- if(Boolean.TRUE.equals(test_privateClassPublicMethod_5())){
- System.out.println("PASSED");
+ System.out.println("running test: privateNestedClassPublicMethod");
+ if(Boolean.TRUE.equals(test_privateNestedClassPublicMethod())){
+ System.out.println("passed");
}else{
System.out.println("FAILED");
result = false;
}
System.out.println("");
- System.out.println("running test: privateClassPrivateMethod_6");
- if(Boolean.TRUE.equals(test_privateClassPrivateMethod_6())){
- System.out.println("PASSED");
+ System.out.println("running test: privateNestedClassPrivateMethod");
+ if(Boolean.TRUE.equals(test_privateNestedClassPrivateMethod())){
+ System.out.println("passed");
}else{
System.out.println("FAILED");
result = false;
}
System.out.println("");
- System.out.println("running test: publicDefaultClassField");
- if(Boolean.TRUE.equals(test_publicDefaultClassField())){
- System.out.println("PASSED");
+ System.out.println("running test: publicNestedClassPublicMethod");
+ if(Boolean.TRUE.equals(test_publicNestedClassPublicMethod())){
+ System.out.println("passed");
}else{
System.out.println("FAILED");
result = false;
}
+ System.out.println("");
+ System.out.println("running test: publicNestedClassPrivateMethod");
+ if(Boolean.TRUE.equals(test_publicNestedClassPrivateMethod())){
+ System.out.println("passed");
+ }else{
+ System.out.println("FAILED");
+ result = false;
+ }
System.out.println("");
return result;
}catch(Exception e){
- System.out.println("Exception in Dispatcher_1 test:");
+ System.out.println("Exception in Dispatcher_3 test:");
e.printStackTrace();
return false;
}
}
- private static boolean logPass(){
- System.out.println("PASSED");
- return true;
- }
-
- private static boolean logFail(){
- System.out.println("FAILED");
- return false;
- }
-
public static void main(String[] args){
System.exit(run() ? 0 : 1);
}
Dispatcher_0\
Dispatcher_1\
Dispatcher_2\
+ Dispatcher_3\
""
# Dispatch_1\