*/
class MethodSignature_To_Handle_Map{
- private Map<MethodSignature ,MethodHandle> map;
- // test facilities
+ // Static test messaging
//
- private boolean test = false;
- public void test_switch(boolean test){
- if(this.test && !test){
- test_print("test messages off");
- this.test = test;
+ private static boolean test = false;
+ public static void test_switch(boolean test){
+ if (MethodSignature_To_Handle_Map.test && !test){
+ test_print("MethodSignature_To_Handle_Map:: test messages off");
}
- if( !this.test && test){
- this.test = test;
- test_print("test messages on");
+ if (!MethodSignature_To_Handle_Map.test && test){
+ test_print("MethodSignature_To_Handle_Map:: test messages on");
}
+ MethodSignature_To_Handle_Map.test = test;
}
- private void test_print(String message){
- if(test){
- System.out.println("MethodSignature_To_Handle_Map::" + message);
+ private static void test_print(String message){
+ if (test){
+ System.out.println(message);
}
}
+ // instance data
+ //
+ private Map<MethodSignature ,MethodHandle> map;
+
// field access and strings
//
private void add_entry(MethodSignature key ,MethodHandle value){
test_print
(
- "add_entry::"
- + "("
- + key
- + ","
- +value
+ "(add_entry:: " + "(key " + key + ") " + "(value " + value + ")" + ")"
);
map.put(key ,value);
}
public void add_class(Class<?> class_metadata){
try{
+ test_print("adding public methods");
add_methods_public(class_metadata);
+
+ test_print("adding private methods");
add_methods_private(class_metadata);
+
+ test_print("adding constructors");
add_constructors(class_metadata);
+
+ /*
+ test_print("adding static methods");
+ add_methods_static(class_metadata);
+ */
+
}catch(Throwable t){
- System.out.println("MethodSignature_To_Handle_Map::add_class exception:");
+ System.out.println("MethodSignature_To_Handle_Map::add_class exception: ");
t.printStackTrace();
}
}
}
}
+ public void add_methods_static(Class<?> class_metadata) {
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+
+ for (Method method : class_metadata.getDeclaredMethods()) {
+ try {
+ if (Modifier.isStatic(method.getModifiers())) { // Only static methods
+ Class<?>[] parameter_type_list = method.getParameterTypes();
+ MethodType method_type = MethodType.methodType(method.getReturnType(), parameter_type_list);
+ MethodHandle method_handle = lookup.findStatic(class_metadata, method.getName(), method_type);
+
+ MethodSignature signature = new MethodSignature(
+ method.getReturnType(),
+ class_metadata.getName(),
+ method.getName(),
+ parameter_type_list
+ );
+
+ add_entry(signature, method_handle);
+ }
+ } catch (NoSuchMethodException e) {
+ System.err.println("Skipping static method: " + method);
+ e.printStackTrace();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+
+
// methods for looking up handles
//
public MethodHandle lookup(MethodSignature s){
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
- sb.append("MethodSignature_To_Handle_Map: {").append(System.lineSeparator());
+ sb.append("MethodSignature_To_Handle_Map:{").append(System.lineSeparator());
for (Map.Entry<MethodSignature ,MethodHandle> entry : map.entrySet()){
sb.append(" ")
*/
public class Mosaic_Dispatcher{
- private MethodSignature_To_Handle_Map map;
- private Class<?> target;
- // test facilities
+ // Static test messaging
//
- private boolean test = false;
- public void test_switch(boolean test){
- if(this.test && !test){
+ private static boolean test = false;
+ public static void test_switch(boolean test){
+ if (Mosaic_Dispatcher.test && !test){
test_print("Mosaic_Dispatcher:: test messages off");
- this.test = test;
}
- if(!this.test && test){
- this.test = test;
+ if (!Mosaic_Dispatcher.test && test){
test_print("Mosaic_Dispatcher:: test messages on");
- map.test_switch(true);
+ MethodSignature_To_Handle_Map.test_switch(true);
}
+ Mosaic_Dispatcher.test = test;
}
- private void test_print(String message){
- if(test){
- System.out.println("Mosaic_Dispatcher::" + message);
+ private static void test_print(String message){
+ if (test){
+ System.out.println(message);
}
}
+ // instance data
+ //
+ private MethodSignature_To_Handle_Map map;
+ private Class<?> target;
+
+
// field access and strings
//
public Class<?> get_target(){
// construct given the class metadata for the target class
public Mosaic_Dispatcher(Class<?> target){
this.map = new MethodSignature_To_Handle_Map();
- test_switch(true);
this.target = target;
- test_print("Mosaic_Dispatcher:: mapping class from metadata:" + to_string_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();
- test_switch(true);
try{
this.target = Class.forName(fully_qualified_class_name);
- test_print("Mosaic_Dispatcher:: mapping class from name string:" + to_string_target());
+ test_print("Mosaic_Dispatcher:: mapping methods from class specified by string:" + to_string_target());
this.map.add_class(target);
}catch(ClassNotFoundException e){
throw new ClassNotFoundException("Class not found: " + fully_qualified_class_name ,e);
// Factory method to create an instance (dispatch a constructor)
public Object make(Object... arg_list){
+ test_print("Call to Mosaic_Dispatcher::make");
return dispatch_1
(
null // there is no instance passed in when calling a constructor
);
}
- @SuppressWarnings("unchecked")
+ // dispatch static methods
public <T> T dispatch
+ (
+ Class<T> return_type
+ ,String method_name
+ ,Object... arg_list
+ ){
+ test_print("Call to Mosaic_Dispatcher::dispatch for a static method.");
+ return dispatch_1
(
- Object instance
- ,Class<T> return_type
- ,String method_name
- ,Object... arg_list
- ){
- 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())
- );
- }
-
- Object result = dispatch_1(
- instance
- ,return_type
- ,method_name
- ,arg_list
- );
-
- // Handle primitive return types explicitly
- if(return_type.isPrimitive()){
- if(return_type == boolean.class) return (T) (Boolean) result;
- if(return_type == int.class) return (T) (Integer) result;
- if(return_type == double.class) return (T) (Double) result;
- if(return_type == float.class) return (T) (Float) result;
- if(return_type == long.class) return (T) (Long) result;
- if(return_type == short.class) return (T) (Short) result;
- if(return_type == byte.class) return (T) (Byte) result;
- if(return_type == char.class) return (T) (Character) result;
- }
-
- // For non-primitives, cast normally
- return return_type.cast(result);
+ null // No instance for static methods
+ ,return_type // Return type
+ ,method_name // Method name
+ ,arg_list // Argument list
+ );
}
-
- /*
+ // dispatch instance binded methods
+ @SuppressWarnings("unchecked")
public <T> T dispatch
- (
- Object instance
- ,Class<T> return_type
- ,String method_name
- ,Object... arg_list
- ){
-
+ (
+ Object instance,
+ Class<T> return_type,
+ String method_name,
+ Object... arg_list
+ ){
+ test_print("Call to Mosaic_Dispatcher::dispatch for a method bound to an instance.");
if(instance == null || !target.isInstance(instance)){
throw new IllegalArgumentException
(
- "Provided instance is not of target type: "
- + target.getName()
- + ", but received: "
+ "Provided instance is not of target type: "
+ + target.getName()
+ + ", but received: "
+ (instance == null ? "null" : instance.getClass().getName())
);
}
-
- return return_type.cast(dispatch_1(
- instance
- ,return_type
- ,method_name
- ,arg_list
- ));
+ return dispatch_1(instance, return_type, method_name, arg_list);
}
- */
- private Object dispatch_1(
- Object instance
- ,Class<?> return_type
- ,String method_name
- ,Object... arg_list
+ private <T> T dispatch_1(
+ Object instance,
+ Class<T> return_type,
+ String method_name,
+ Object... arg_list
){
try{
+ if(arg_list == null){
+ arg_list = new Object[0]; // Treat null as an empty argument list
+ }
+
// Resolve method/constructor signature
MethodSignature signature = new MethodSignature(
- return_type
- ,to_string_target()
- ,method_name
- ,arg_list
+ return_type,
+ to_string_target(),
+ method_name,
+ arg_list
);
- test_print("dispatch_1:: signature is:" + signature.toString());
+ test_print("dispatch_1:: signature key:" + signature.toString());
MethodHandle handle = map.lookup(signature);
// Unwrap Mosaic_IsPrimitive arguments
Object[] unwrapped_arg_list = new Object[arg_list.length];
for(int i = 0; i < arg_list.length; i++){
- if (arg_list[i] instanceof Mosaic_IsPrimitive){
+ if(arg_list[i] instanceof Mosaic_IsPrimitive){
unwrapped_arg_list[i] = ((Mosaic_IsPrimitive) arg_list[i]).get_value();
- } else {
+ }else{
unwrapped_arg_list[i] = arg_list[i];
}
}
- // Handle constructor vs method
+ // Handle method invocation
+ Object result;
if("<init>".equals(method_name)){
- return handle.invokeWithArguments(unwrapped_arg_list); // Constructor: no binding needed
+ result = handle.invokeWithArguments(unwrapped_arg_list); // Constructor: no binding needed
+ }else if(instance == null){
+ result = handle.invokeWithArguments(unwrapped_arg_list); // Static method
}else{
- return handle.bindTo(instance).invokeWithArguments(unwrapped_arg_list); // Method: bind instance
+ result = handle.bindTo(instance).invokeWithArguments(unwrapped_arg_list); // Instance method
}
+ // Handle primitive return types explicitly
+ if(return_type.isPrimitive()){
+ if(return_type == boolean.class) return(T)(Boolean) result;
+ if(return_type == int.class) return(T)(Integer) result;
+ if(return_type == double.class) return(T)(Double) result;
+ if(return_type == float.class) return(T)(Float) result;
+ if(return_type == long.class) return(T)(Long) result;
+ if(return_type == short.class) return(T)(Short) result;
+ if(return_type == byte.class) return(T)(Byte) result;
+ if(return_type == char.class) return(T)(Character) result;
+ }
+
+ // For non-primitives, cast normally
+ return return_type.cast(result);
+
}catch(Throwable t){
System.out.println("Mosaic_Dispatcher::dispatch exception:");
t.printStackTrace();
@Override
public String toString(){
return
- "Mosaic_Dispatcher {"
+ "Mosaic_Dispatcher{"
+ "target="
+ to_string_target()
+ " ,map="
+++ /dev/null
-package com.ReasoningTechnology.Mosaic;
-
-/*
- These are used for testing that Mosaic can be used for white box
- testing. Mosaic tests for Mosaic itself access each of these as
- part of regression. Users are welcome to also check accessing these
- when debugging any access problems that might arise.
-*/
-
-// Public class with public and private methods
-public class Mosaic_TestClasses_0 {
- public boolean a_public_method_1() {
- return true;
- }
-
- private boolean a_private_method_2() {
- return true;
- }
-
- public class PublicClass {
- public boolean a_public_method_3() {
- return true;
- }
-
- private boolean a_private_method_4() {
- return true;
- }
- }
-
- private class PrivateClass {
- public boolean a_public_method_5() {
- return true;
- }
-
- private boolean a_private_method_6() {
- return true;
- }
- }
-}
-
-// Default (package-private) class with public and private methods
-class DefaultClass {
- public boolean a_public_method_7() {
- return true;
- }
-
- private boolean a_private_method_8() {
- return true;
- }
-}
+++ /dev/null
-package com.ReasoningTechnology.Mosaic;
-
-/*
- These are used for testing that Mosaic can be used for white box
- testing. Mosaic tests for Mosaic itself access each of these as
- part of regression. Users are welcome to also check accessing these
- when debugging any access problems that might arise.
-*/
-
-// Public class with public and private methods
-public class Mosaic_TestClasses_1 {
-
- private int i;
-
- public Mosaic_TestClasses_1(){
- i = 0;
- }
-
- public Mosaic_TestClasses_1(int a){
- i = a;
- }
-
- public Mosaic_TestClasses_1(int a ,int b){
- i = a + b;
- }
-
- public int get_i() {
- return i;
- }
-
-}
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 0
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Access_0
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 IO
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 IsPrimitive
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Logger
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 MockClass_0
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test0
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_Access_0
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_IO
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_IsPrimitive
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_Logger
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_MockClass_0
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_Testbench
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Test_Util
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Testbench
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Util
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 smoke
+++ /dev/null
-import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher;
-import com.ReasoningTechnology.Mosaic.Mosaic_IsPrimitive;
-import com.ReasoningTechnology.Mosaic.Mosaic_TestClasses_0;
-import com.ReasoningTechnology.Mosaic.Mosaic_TestClasses_1;
-import com.ReasoningTechnology.Mosaic.Mosaic_Util;
-
-public class Access_0{
-
- private static Mosaic_Dispatcher dispatcher;
-
- static{
- // Initialize the dispatcher for Mosaic_TestClasses_0
- dispatcher = new Mosaic_Dispatcher(Mosaic_TestClasses_0.class);
- dispatcher.test_switch(true); // Enable test messages for debugging
- }
-
- // Test method to access the public method of the public class
- public static boolean test_publicClass_publicMethod(){
- System.out.println("\nRunning test: test_publicClass_publicMethod");
-
- Object instance = new Mosaic_TestClasses_0();
-
- boolean result = dispatcher.dispatch
- (
- instance // target instance
- ,boolean.class // return type
- ,"a_public_method_1" // method name
- );
-
- return result;
-
- }
-
- public static boolean test_make_0(){
- System.out.println("\nRunning test: test_make_0");
- Boolean[] condition_list = new Boolean[4];
- Mosaic_Util.all_set_false(condition_list);
- int i = 0;
-
- Mosaic_Dispatcher d1 = new Mosaic_Dispatcher(Mosaic_TestClasses_1.class);
-
- Mosaic_TestClasses_1 tc0 = new Mosaic_TestClasses_1();
- condition_list[i++] = tc0.get_i() == 0;
-
- Mosaic_TestClasses_1 tc1 = (Mosaic_TestClasses_1) d1.make();
- condition_list[i++] = tc1.get_i() == 0;
-
- Mosaic_TestClasses_1 tc2 = (Mosaic_TestClasses_1) d1.make(new Mosaic_IsPrimitive(7));
- condition_list[i++] = tc2.get_i() == 7;
-
- Mosaic_TestClasses_1 tc3 = (Mosaic_TestClasses_1) d1.make(new Mosaic_IsPrimitive(21) ,new Mosaic_IsPrimitive(17) );
- condition_list[i++] = tc3.get_i() == 38;
-
- return Mosaic_Util.all(condition_list);
- }
-
- // Run method to execute all tests
- public static boolean run(){
- try{
-
- // Run the individual test(s)
- boolean result = true;
- if( !test_publicClass_publicMethod() ){
- System.out.println("test_publicClass_publicMethod failed");
- result = false;
- }else{
- System.out.println("test_publicClass_publicMethod passed");
- }
- if( !test_make_0() ){
- System.out.println("test_make_0() failed");
- result = false;
- }else{
- System.out.println("test_make_0() passed");
- }
-
- return result;
-
- }catch(Exception e){
- System.out.println("Exception in test Accept_0");
- e.printStackTrace();
- return false;
- }
-
- }
-
- public static void main(String[] args){
- // Execute the run method and return its result as the exit code
- if( run() )
- System.exit(0);
- else
- System.exit(1);
- }
-
-}
import com.ReasoningTechnology.Mosaic.Mosaic_AllMethodsPublicProxy;
import com.ReasoningTechnology.Mosaic.Mosaic_IO;
import com.ReasoningTechnology.Mosaic.Mosaic_Testbench;
-import com.ReasoningTechnology.Mosaic.Mosaic_TestClasses;
+import com.ReasoningTechnology.Mosaic.TestClasses;
public class AllMethodsPublicProxy_0 {
--- /dev/null
+import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher;
+import com.ReasoningTechnology.Mosaic.Mosaic_IsPrimitive;
+import com.ReasoningTechnology.Mosaic.Mosaic_Util;
+
+import tester.TestClasses_0;
+import tester.TestClasses_1;
+
+public class Dispatch_0{
+
+ private static Mosaic_Dispatcher dispatcher;
+
+ static{
+ // Initialize the dispatcher for TestClasses_0
+ Mosaic_Dispatcher.test_switch(true);
+ dispatcher = new Mosaic_Dispatcher(TestClasses_0.class);
+ }
+
+ // Test method to access the public method of the public class
+ public static boolean test_publicClass_publicMethod(){
+ Object instance = new TestClasses_0();
+ boolean result = dispatcher.dispatch
+ (
+ instance // target instance
+ ,boolean.class // return type
+ ,"a_public_method_1" // method name
+ );
+
+ return result;
+ }
+
+ public static boolean test_make_0(){
+ Boolean[] condition_list = new Boolean[4];
+ Mosaic_Util.all_set_false(condition_list);
+ int i = 0;
+
+ Mosaic_Dispatcher d1 = new Mosaic_Dispatcher(TestClasses_1.class);
+
+ TestClasses_1 tc0 = new TestClasses_1();
+ condition_list[i++] = tc0.get_i() == 0;
+
+ TestClasses_1 tc1 = (TestClasses_1) d1.make();
+ condition_list[i++] = tc1.get_i() == 0;
+
+ TestClasses_1 tc2 = (TestClasses_1) d1.make(new Mosaic_IsPrimitive(7));
+ condition_list[i++] = tc2.get_i() == 7;
+
+ TestClasses_1 tc3 = (TestClasses_1) d1.make(new Mosaic_IsPrimitive(21) ,new Mosaic_IsPrimitive(17) );
+ condition_list[i++] = tc3.get_i() == 38;
+
+ return Mosaic_Util.all(condition_list);
+ }
+
+ // Test public static method
+ public static boolean test_publicStaticMethod_7(){
+ boolean result = dispatcher.dispatch(
+ boolean.class, // return type
+ "a_public_static_method_7" // method name
+ );
+ return result;
+ }
+
+ // Test private static method
+ public static boolean test_privateStaticMethod_9(){
+ boolean result = dispatcher.dispatch(
+ boolean.class, // return type
+ "a_private_static_method_9" // method name
+ );
+ return result;
+ }
+
+ // Extend the run method to include static method tests
+ public static boolean run(){
+ try{
+ boolean result = true;
+
+ /*
+ System.out.println("");
+ System.out.println("running test: publicClass_publicMethod");
+ if (Boolean.TRUE.equals(test_publicClass_publicMethod())){
+ System.out.println("passed");
+ }else{
+ System.out.println("FAILED");
+ result = false;
+ }
+ */
+
+ System.out.println("");
+ System.out.println("running test: make_0");
+ if (Boolean.TRUE.equals(test_make_0())){
+ System.out.println("passed");
+ }else{
+ System.out.println("FAILED");
+ result = false;
+ }
+
+ /*
+ System.out.println("");
+ System.out.println("running test: publicStaticMethod_7");
+ if (Boolean.TRUE.equals(test_publicStaticMethod_7())){
+ System.out.println("passed");
+ }else{
+ System.out.println("FAILED");
+ result = false;
+ }
+
+ System.out.println("");
+ System.out.println("running test: privateStaticMethod_9");
+ if (Boolean.TRUE.equals(test_privateStaticMethod_9())){
+ System.out.println("passed");
+ }else{
+ System.out.println("FAILED");
+ result = false;
+ }
+ */
+
+ System.out.println("");
+ return result;
+
+ }catch (Exception e){
+ System.out.println("Exception in Dispatch_0 test:");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ public static void main(String[] args){
+ // Execute the run method and return its result as the exit code
+ if( run() )
+ System.exit(0);
+ else
+ System.exit(1);
+ }
+
+}
--- /dev/null
+import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher;
+import com.ReasoningTechnology.Mosaic.Mosaic_Util;
+
+import tester.TestClasses_0;
+
+public class Dispatch_1{
+
+ private static Mosaic_Dispatcher dispatcher;
+
+ static{
+ // Initialize the dispatcher for TestClasses_0
+ dispatcher = new Mosaic_Dispatcher(TestClasses_0.class);
+ // Test messages are disabled for now
+ }
+
+ // Test public method in the public class
+ public static boolean test_publicMethod_1(){
+ Object instance = new TestClasses_0();
+ boolean result = dispatcher.dispatch(
+ instance, // target instance
+ boolean.class, // return type
+ "a_public_method_1" // method name
+ );
+ return result;
+ }
+
+ // Test private method in the public class
+ public static boolean test_privateMethod_2(){
+ Object instance = new TestClasses_0();
+ boolean result = dispatcher.dispatch(
+ instance, // target instance
+ boolean.class, // return type
+ "a_private_method_2" // method name
+ );
+ return result;
+ }
+
+ public static boolean test_nestedPublicMethod_3(){
+ try{
+
+ // Create a dispatcher for the nested public class
+ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class);
+
+ // Create an instance of the outer class
+ TestClasses_0 outer_instance = new TestClasses_0();
+
+ // Create an instance of the nested public class
+ TestClasses_0.APublicClass_01 nested_instance = outer_instance.new APublicClass_01();
+
+ // Dispatch the public method call on the nested class
+ boolean result = nested_dispatcher.dispatch(
+ nested_instance, // Target instance
+ boolean.class, // Return type
+ "a_public_method_3" // Method name
+ );
+
+ return result;
+
+ } catch (Exception e){
+ System.out.println("Exception in test_nestedPublicMethod_3");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ // Test private method in the nested public class
+ public static boolean test_nestedPrivateMethod_4(){
+
+ // Create a dispatcher for the nested public class
+ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class);
+
+ // Create an instance of the outer class
+ TestClasses_0 outer_instance = new TestClasses_0();
+
+ // Create an instance of the nested public class
+ TestClasses_0.APublicClass_01 nested_instance = outer_instance.new APublicClass_01();
+
+ boolean result = nested_dispatcher.dispatch(
+ nested_instance, // target instance
+ boolean.class, // return type
+ "a_private_method_4" // method name
+ );
+ return result;
+ }
+
+ // Test public method in the nested private class
+ public static boolean test_private_class_public_method_5(){
+
+ // Use Mosaic_Dispatch to access the private class
+ Class<?> private_class_metadata = Mosaic_Dispatch.resolve_class(
+ TestClasses_0.class ,"tester.TestClasses_0$APrivateClass_02"
+ );
+
+ // Create a dispatcher for the private class
+ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(private_class_metadata);
+
+ // Instance of the private class is created via the dispatcher
+ Object nested_instance = nested_dispatcher.make();
+
+ boolean result = nested_dispatcher.dispatch(
+ nested_instance
+ ,boolean.class
+ ,"a_public_method_5"
+ );
+
+ return result;
+ }
+
+
+ // Test public method in the nested private class
+ public static boolean test_privateClassPublicMethod_5(){
+
+ // Create a dispatcher for the nested public class
+ Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APrivateClass_02.class);
+
+ // Instance of the private class is created via the dispatcher
+ Object nested_instance = nested_dispatcher.make();
+ boolean result = nested_dispatcher.dispatch(
+ nested_instance, // target instance
+ boolean.class, // return type
+ "a_public_method_5" // method name
+ );
+ return result;
+ }
+
+ // Test private method in the nested private class
+ public static boolean test_privateClassPrivateMethod_6(){
+ Object nested_instance = dispatcher.make(
+ TestClasses_0.class,
+ "APrivateClass_02",
+ null
+ );
+ boolean result = dispatcher.dispatch(
+ nested_instance,
+ boolean.class,
+ "a_private_method_6"
+ );
+ return result;
+ }
+
+ // Run method to execute all tests
+ public static boolean run(){
+ try{
+ boolean result = true;
+
+ /*
+ System.out.println("\nRunning test: publicMethod_1");
+ if (Boolean.TRUE.equals(test_publicMethod_1())){
+ System.out.println("PASSED");
+ } else{
+ System.out.println("FAILED");
+ result = false;
+ }
+
+ System.out.println("\nRunning test: privateMethod_2");
+ if (Boolean.TRUE.equals(test_privateMethod_2())){
+ System.out.println("PASSED");
+ } else{
+ System.out.println("FAILED");
+ result = false;
+ }
+
+ System.out.println("\nRunning test: nestedPublicMethod_3");
+ if (Boolean.TRUE.equals(test_nestedPublicMethod_3())){
+ System.out.println("PASSED");
+ } else{
+ System.out.println("FAILED");
+ result = false;
+ }
+
+ System.out.println("\nRunning test: nestedPrivateMethod_4");
+ if (Boolean.TRUE.equals(test_nestedPrivateMethod_4())){
+ System.out.println("PASSED");
+ } else{
+ System.out.println("FAILED");
+ result = false;
+ }
+ */
+
+ System.out.println("\nRunning test: privateClassPublicMethod_5");
+ if (Boolean.TRUE.equals(test_privateClassPublicMethod_5())){
+ System.out.println("PASSED");
+ } else{
+ System.out.println("FAILED");
+ result = false;
+ }
+
+ System.out.println("\nRunning test: privateClassPrivateMethod_6");
+ if (Boolean.TRUE.equals(test_privateClassPrivateMethod_6())){
+ System.out.println("PASSED");
+ } else{
+ System.out.println("FAILED");
+ result = false;
+ }
+
+ return result;
+ } catch (Exception e){
+ System.out.println("Exception in Dispatch_1 test:");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ public static void main(String[] args){
+ if (run()){
+ System.exit(0);
+ } else{
+ System.exit(1);
+ }
+ }
+}
--- /dev/null
+package tester;
+
+/*
+ These are used for testing that Mosaic can be used for white box
+ testing. Mosaic tests for Mosaic itself access each of these as
+ part of regression. Users are welcome to also check accessing these
+ when debugging any access problems that might arise.
+*/
+
+// Public class with public and private methods
+public class TestClasses_0{
+ public boolean a_public_method_1(){
+ return true;
+ }
+
+ private boolean a_private_method_2(){
+ return true;
+ }
+
+ public class APublicClass_01{
+ public boolean a_public_method_3(){
+ return true;
+ }
+
+ private boolean a_private_method_4(){
+ return true;
+ }
+ }
+
+ private class APrivateClass_02{
+ public boolean a_public_method_5(){
+ return true;
+ }
+
+ private boolean a_private_method_6(){
+ return true;
+ }
+ }
+
+ /*
+ public static boolean a_public_static_method_7(){
+ return true;
+ }
+
+ private static boolean a_private_static_method_9(){
+ return true;
+ }
+ */
+
+}
+
+// Default (package-private) class with public and private methods
+class DefaultTestClass{
+ public boolean a_public_method_7(){
+ return true;
+ }
+
+ private boolean a_private_method_8(){
+ return true;
+ }
+}
--- /dev/null
+package tester;
+
+/*
+ These are used for testing that Mosaic can be used for white box
+ testing. Mosaic tests for Mosaic itself access each of these as
+ part of regression. Users are welcome to also check accessing these
+ when debugging any access problems that might arise.
+*/
+
+// Public class with public and private methods
+public class TestClasses_1 {
+
+ private int i;
+
+ public TestClasses_1(){
+ i = 0;
+ }
+
+ public TestClasses_1(int a){
+ i = a;
+ }
+
+ public TestClasses_1(int a ,int b){
+ i = a + b;
+ }
+
+ public int get_i() {
+ return i;
+ }
+
+}
--- /dev/null
+*
+!/.gitignore
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Access_0
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 IO
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 IsPrimitive
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Logger
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 MockClass_0
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Testbench
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 Util
+++ /dev/null
-#!/bin/env bash
-java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 smoke
Testbench\
MockClass_0\
IsPrimitive\
- Access_0\
+ Dispatch_0\
""
+
+# Dispatch_1\
set -x
cd $REPO_HOME/tester
+# setup a couple of test classes
+
+javac -g -d scratchpad javac🖉/TestClasses*
+
+
# Get the list of tests to compile
# wrapper is a space-separated list
list=$(list)
cd "$REPO_HOME/tester/jvm" || exit
# Get the list of test scripts in the specific order from bash_wrapper_list
-test_list=$(test_list)
-echo test_list: $test_list
+list=$(list)
+echo list: $list
# Execute each test in the specified order
-for file in $test_list; do
+for file in $list; do
echo
if [[ -x "$file" && ! -d "$file" ]]; then
echo "... Running $file"