From: Thomas Walker Lynch Date: Fri, 20 Dec 2024 06:14:42 +0000 (+0000) Subject: adds field access to dispatcher, and it is passing tests X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.css?a=commitdiff_plain;h=11b35efedb26818d1cb5fc5b0d1564210880b45f;p=Mosaic adds field access to dispatcher, and it is passing tests --- diff --git "a/developer/javac\360\237\226\211/Mosaic_Dispatcher.java" "b/developer/javac\360\237\226\211/Mosaic_Dispatcher.java" index 543386d..b3b166e 100644 --- "a/developer/javac\360\237\226\211/Mosaic_Dispatcher.java" +++ "b/developer/javac\360\237\226\211/Mosaic_Dispatcher.java" @@ -18,7 +18,7 @@ import java.util.Map; 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. */ @@ -184,7 +184,7 @@ class MethodSignature_To_Handle_Map{ MethodSignature_To_Handle_Map.test = test; } private static void test_print(String message){ - if (test){ + if(test){ System.out.println(message); } } @@ -204,6 +204,17 @@ class MethodSignature_To_Handle_Map{ // 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 ( @@ -231,9 +242,9 @@ class MethodSignature_To_Handle_Map{ 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); @@ -254,7 +265,6 @@ class MethodSignature_To_Handle_Map{ } } - public void add_constructors(Class class_metadata){ try{ @@ -265,7 +275,7 @@ class MethodSignature_To_Handle_Map{ 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: with parameter types @@ -279,17 +289,62 @@ class MethodSignature_To_Handle_Map{ 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 MethodHandle + MethodHandle read_handle = private_lookup.unreflectGetter(field); + MethodSignature read_signature = new MethodSignature + ( + field_type + ,class_metadata.getName() + ,"" + ,new Class[]{} + ); + add_entry(read_signature ,read_handle); + + // Create MethodHandle + MethodHandle write_handle = private_lookup.unreflectSetter(field); + MethodSignature write_signature = new MethodSignature + ( + void.class + ,class_metadata.getName() + ,"" + ,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){ @@ -369,91 +424,112 @@ public class Mosaic_Dispatcher{ 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:: 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:: mapping methods from class specified by string: \"" + to_string_target() + "\""); + this.map.add_class(target); } // methods unique to the class // + public 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 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 void write(Object instance, String field_name, T value){ + public 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 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(); } } @@ -464,10 +540,10 @@ public class Mosaic_Dispatcher{ // Use dispatch_1 to invoke the constructor Object result = dispatch_1( - null, // no instance for constructor - void.class, // return type for signature matching - "", // constructors are always named `` in Java - arg_list + null // no instance for constructor + ,void.class // return type for signature matching + ,"" // constructors are always named `` in Java + ,arg_list ); // Cast the result to the target type @@ -509,7 +585,7 @@ public class Mosaic_Dispatcher{ + (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") diff --git "a/document\360\237\226\211/todo.txt" "b/document\360\237\226\211/todo.txt" index 584f1d0..c71e6ea 100644 --- "a/document\360\237\226\211/todo.txt" +++ "b/document\360\237\226\211/todo.txt" @@ -55,3 +55,9 @@ to the 'resource' project and plan to deprecate it. 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. diff --git "a/tester/document\360\237\226\211/build_run_transcript_2024-12-20T06:09:38Z.txt" "b/tester/document\360\237\226\211/build_run_transcript_2024-12-20T06:09:38Z.txt" new file mode 100644 index 0000000..689546b --- /dev/null +++ "b/tester/document\360\237\226\211/build_run_transcript_2024-12-20T06:09:38Z.txt" @@ -0,0 +1,220 @@ +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.(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.(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:: 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.()) (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:: 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.(int ,int)) (value MethodHandle(int,int)TestClasses_1)) +(add_entry:: (key void tester.TestClasses_1.(int)) (value MethodHandle(int)TestClasses_1)) +(add_entry:: (key void tester.TestClasses_1.()) (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.() +Call to Mosaic_Dispatcher::make +dispatch_1:: signature key:void tester.TestClasses_1.(int) +Call to Mosaic_Dispatcher::make +dispatch_1:: signature key:void tester.TestClasses_1.(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:: 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.()) (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.() +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§ +> diff --git "a/tester/javac\360\237\226\211/#Dispatch_0.java#" "b/tester/javac\360\237\226\211/#Dispatch_0.java#" deleted file mode 100644 index e69de29..0000000 diff --git "a/tester/javac\360\237\226\211/Dispatcher_2.java" "b/tester/javac\360\237\226\211/Dispatcher_2.java" index 5384d03..cb1bb97 100644 --- "a/tester/javac\360\237\226\211/Dispatcher_2.java" +++ "b/tester/javac\360\237\226\211/Dispatcher_2.java" @@ -13,7 +13,7 @@ public class Dispatcher_2{ 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(); @@ -23,7 +23,7 @@ public class Dispatcher_2{ 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(); @@ -57,8 +57,8 @@ public class Dispatcher_2{ 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(); @@ -68,8 +68,8 @@ public class Dispatcher_2{ 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(); @@ -197,4 +197,3 @@ public class Dispatcher_2{ } } } - diff --git "a/tester/javac\360\237\226\211/Dispatcher_3.java" "b/tester/javac\360\237\226\211/Dispatcher_3.java" index 99433b4..ca28d1e 100644 --- "a/tester/javac\360\237\226\211/Dispatcher_3.java" +++ "b/tester/javac\360\237\226\211/Dispatcher_3.java" @@ -1,103 +1,131 @@ 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); } diff --git "a/tester/tool\360\237\226\211/list" "b/tester/tool\360\237\226\211/list" index 48a6468..273b456 100755 --- "a/tester/tool\360\237\226\211/list" +++ "b/tester/tool\360\237\226\211/list" @@ -23,6 +23,7 @@ echo\ Dispatcher_0\ Dispatcher_1\ Dispatcher_2\ + Dispatcher_3\ "" # Dispatch_1\