@Test public void chainReflectTest() throws NoSuchMethodException, IllegalAccessException, InputException, InvocationTargetException { Method subClassGet = ReflTestClass.class.getMethod("getSubClass"); String subClassGetterName = ReflectionUtil.getMethodId(subClassGet); Method subClassGetNum = ReflTestClass.ReflSubClass.class.getMethod("get1234", int.class); String subClassGetNumName = ReflectionUtil.getMethodId(subClassGetNum); ReflTestClass instance = new ReflTestClass(1, 2, 3); String[] input = new String[]{subClassGetterName, subClassGetNumName, "5"}; ReflectionResult chainResult = chainFactory.runChain(input, instance, null); assertNotNull(chainResult.getEndingInstance()); String result = typeHandler.getOutputFor(chainResult.getEndingInstance()); assertNotNull(result); if (!CONTAINS_1234.test(result)) { System.out.println("Expected result to include 1, 2, 3, 4 Actual result below"); System.out.println(result); } if (!result.contains("5")) { System.out.println("Expected result to contain 5 Actual result below"); System.out.println(result); } assertTrue(CONTAINS_1234.test(result)); assertTrue(result.contains("5")); }
void runChain() { MethodMap reflectionMap; Object currentInstance = initialInstance; ReflectionResult result = null; Object priorInstance; Method currentMethod; Object[] methodParameters; int argsToSkip = 0; for (int i = 0; i < input.size(); i++) { String currentArg = input.get(i); if (argsToSkip > 0) { argsToSkip--; continue; } Objects.requireNonNull(currentInstance); reflectionMap = methodMapProvider.getMethodMapFor(currentInstance.getClass()); currentMethod = reflectionMap.getById(currentArg); if (currentMethod == null) { result = new ReflectionResult(ReflectionResult.Type.UNKNOWN_REFERENCE, null, "Unknown or unavailable method"); break; } List<String> stringMethodArgs = ReflectionUtil.getArgsForMethod(this.input.subList(i + 1, input.size()), currentMethod); argsToSkip = stringMethodArgs.size(); if (stringMethodArgs.size() != currentMethod.getParameterCount()) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, ReflectionUtil.getArgMismatchString(currentMethod), null); break; } priorInstance = currentInstance; try { methodParameters = typeHandler.instantiateTypes(currentMethod.getParameterTypes(), stringMethodArgs, sender); currentInstance = reflect(currentInstance, currentMethod, methodParameters); } catch (Throwable ex) { ReflectionResult.Type type = ex instanceof InputException ? ReflectionResult.Type.INPUT_ERROR : ReflectionResult.Type.UNHANDLED_EXCEPTION; Throwable cause = ex.getCause() != null ? ex.getCause() : ex; String reason = cause.getLocalizedMessage() != null ? cause.getLocalizedMessage() : cause.toString(); result = new ReflectionResult(type, null, reason, cause); break; } if (DebuggeryBase.isDebugMode()) { List<String> remainingArgs = input.subList(i, input.size()); logDebug(i, reflectionMap, priorInstance, currentInstance, currentMethod, argsToSkip, methodParameters, remainingArgs); } if (currentMethod.getReturnType() != Void.TYPE && currentInstance == null) { result = new ReflectionResult(ReflectionResult.Type.NULL_REFERENCE, null, ReflectionUtil.getFormattedMethodSignature(currentMethod) + " returned null!"); break; } if (currentMethod.getReturnType() == Void.TYPE && currentInstance == null && i + argsToSkip < input.size() - 1) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, "You provided extra args after a void return type!\n" + ReflectionUtil.getArgMismatchString(currentMethod)); break; } } if (result == null) { result = new ReflectionResult(ReflectionResult.Type.SUCCESS, currentInstance); } Objects.requireNonNull(result); this.result = result; }
ReflectionChain { void runChain() { MethodMap reflectionMap; Object currentInstance = initialInstance; ReflectionResult result = null; Object priorInstance; Method currentMethod; Object[] methodParameters; int argsToSkip = 0; for (int i = 0; i < input.size(); i++) { String currentArg = input.get(i); if (argsToSkip > 0) { argsToSkip--; continue; } Objects.requireNonNull(currentInstance); reflectionMap = methodMapProvider.getMethodMapFor(currentInstance.getClass()); currentMethod = reflectionMap.getById(currentArg); if (currentMethod == null) { result = new ReflectionResult(ReflectionResult.Type.UNKNOWN_REFERENCE, null, "Unknown or unavailable method"); break; } List<String> stringMethodArgs = ReflectionUtil.getArgsForMethod(this.input.subList(i + 1, input.size()), currentMethod); argsToSkip = stringMethodArgs.size(); if (stringMethodArgs.size() != currentMethod.getParameterCount()) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, ReflectionUtil.getArgMismatchString(currentMethod), null); break; } priorInstance = currentInstance; try { methodParameters = typeHandler.instantiateTypes(currentMethod.getParameterTypes(), stringMethodArgs, sender); currentInstance = reflect(currentInstance, currentMethod, methodParameters); } catch (Throwable ex) { ReflectionResult.Type type = ex instanceof InputException ? ReflectionResult.Type.INPUT_ERROR : ReflectionResult.Type.UNHANDLED_EXCEPTION; Throwable cause = ex.getCause() != null ? ex.getCause() : ex; String reason = cause.getLocalizedMessage() != null ? cause.getLocalizedMessage() : cause.toString(); result = new ReflectionResult(type, null, reason, cause); break; } if (DebuggeryBase.isDebugMode()) { List<String> remainingArgs = input.subList(i, input.size()); logDebug(i, reflectionMap, priorInstance, currentInstance, currentMethod, argsToSkip, methodParameters, remainingArgs); } if (currentMethod.getReturnType() != Void.TYPE && currentInstance == null) { result = new ReflectionResult(ReflectionResult.Type.NULL_REFERENCE, null, ReflectionUtil.getFormattedMethodSignature(currentMethod) + " returned null!"); break; } if (currentMethod.getReturnType() == Void.TYPE && currentInstance == null && i + argsToSkip < input.size() - 1) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, "You provided extra args after a void return type!\n" + ReflectionUtil.getArgMismatchString(currentMethod)); break; } } if (result == null) { result = new ReflectionResult(ReflectionResult.Type.SUCCESS, currentInstance); } Objects.requireNonNull(result); this.result = result; } }
ReflectionChain { void runChain() { MethodMap reflectionMap; Object currentInstance = initialInstance; ReflectionResult result = null; Object priorInstance; Method currentMethod; Object[] methodParameters; int argsToSkip = 0; for (int i = 0; i < input.size(); i++) { String currentArg = input.get(i); if (argsToSkip > 0) { argsToSkip--; continue; } Objects.requireNonNull(currentInstance); reflectionMap = methodMapProvider.getMethodMapFor(currentInstance.getClass()); currentMethod = reflectionMap.getById(currentArg); if (currentMethod == null) { result = new ReflectionResult(ReflectionResult.Type.UNKNOWN_REFERENCE, null, "Unknown or unavailable method"); break; } List<String> stringMethodArgs = ReflectionUtil.getArgsForMethod(this.input.subList(i + 1, input.size()), currentMethod); argsToSkip = stringMethodArgs.size(); if (stringMethodArgs.size() != currentMethod.getParameterCount()) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, ReflectionUtil.getArgMismatchString(currentMethod), null); break; } priorInstance = currentInstance; try { methodParameters = typeHandler.instantiateTypes(currentMethod.getParameterTypes(), stringMethodArgs, sender); currentInstance = reflect(currentInstance, currentMethod, methodParameters); } catch (Throwable ex) { ReflectionResult.Type type = ex instanceof InputException ? ReflectionResult.Type.INPUT_ERROR : ReflectionResult.Type.UNHANDLED_EXCEPTION; Throwable cause = ex.getCause() != null ? ex.getCause() : ex; String reason = cause.getLocalizedMessage() != null ? cause.getLocalizedMessage() : cause.toString(); result = new ReflectionResult(type, null, reason, cause); break; } if (DebuggeryBase.isDebugMode()) { List<String> remainingArgs = input.subList(i, input.size()); logDebug(i, reflectionMap, priorInstance, currentInstance, currentMethod, argsToSkip, methodParameters, remainingArgs); } if (currentMethod.getReturnType() != Void.TYPE && currentInstance == null) { result = new ReflectionResult(ReflectionResult.Type.NULL_REFERENCE, null, ReflectionUtil.getFormattedMethodSignature(currentMethod) + " returned null!"); break; } if (currentMethod.getReturnType() == Void.TYPE && currentInstance == null && i + argsToSkip < input.size() - 1) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, "You provided extra args after a void return type!\n" + ReflectionUtil.getArgMismatchString(currentMethod)); break; } } if (result == null) { result = new ReflectionResult(ReflectionResult.Type.SUCCESS, currentInstance); } Objects.requireNonNull(result); this.result = result; } ReflectionChain(ReflectionChainFactory factory, @NotNull String[] args,
                    @NotNull Object initialInstance, @Nullable PlatformSender<?> sender); }
ReflectionChain { void runChain() { MethodMap reflectionMap; Object currentInstance = initialInstance; ReflectionResult result = null; Object priorInstance; Method currentMethod; Object[] methodParameters; int argsToSkip = 0; for (int i = 0; i < input.size(); i++) { String currentArg = input.get(i); if (argsToSkip > 0) { argsToSkip--; continue; } Objects.requireNonNull(currentInstance); reflectionMap = methodMapProvider.getMethodMapFor(currentInstance.getClass()); currentMethod = reflectionMap.getById(currentArg); if (currentMethod == null) { result = new ReflectionResult(ReflectionResult.Type.UNKNOWN_REFERENCE, null, "Unknown or unavailable method"); break; } List<String> stringMethodArgs = ReflectionUtil.getArgsForMethod(this.input.subList(i + 1, input.size()), currentMethod); argsToSkip = stringMethodArgs.size(); if (stringMethodArgs.size() != currentMethod.getParameterCount()) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, ReflectionUtil.getArgMismatchString(currentMethod), null); break; } priorInstance = currentInstance; try { methodParameters = typeHandler.instantiateTypes(currentMethod.getParameterTypes(), stringMethodArgs, sender); currentInstance = reflect(currentInstance, currentMethod, methodParameters); } catch (Throwable ex) { ReflectionResult.Type type = ex instanceof InputException ? ReflectionResult.Type.INPUT_ERROR : ReflectionResult.Type.UNHANDLED_EXCEPTION; Throwable cause = ex.getCause() != null ? ex.getCause() : ex; String reason = cause.getLocalizedMessage() != null ? cause.getLocalizedMessage() : cause.toString(); result = new ReflectionResult(type, null, reason, cause); break; } if (DebuggeryBase.isDebugMode()) { List<String> remainingArgs = input.subList(i, input.size()); logDebug(i, reflectionMap, priorInstance, currentInstance, currentMethod, argsToSkip, methodParameters, remainingArgs); } if (currentMethod.getReturnType() != Void.TYPE && currentInstance == null) { result = new ReflectionResult(ReflectionResult.Type.NULL_REFERENCE, null, ReflectionUtil.getFormattedMethodSignature(currentMethod) + " returned null!"); break; } if (currentMethod.getReturnType() == Void.TYPE && currentInstance == null && i + argsToSkip < input.size() - 1) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, "You provided extra args after a void return type!\n" + ReflectionUtil.getArgMismatchString(currentMethod)); break; } } if (result == null) { result = new ReflectionResult(ReflectionResult.Type.SUCCESS, currentInstance); } Objects.requireNonNull(result); this.result = result; } ReflectionChain(ReflectionChainFactory factory, @NotNull String[] args,
                    @NotNull Object initialInstance, @Nullable PlatformSender<?> sender);  }
ReflectionChain { void runChain() { MethodMap reflectionMap; Object currentInstance = initialInstance; ReflectionResult result = null; Object priorInstance; Method currentMethod; Object[] methodParameters; int argsToSkip = 0; for (int i = 0; i < input.size(); i++) { String currentArg = input.get(i); if (argsToSkip > 0) { argsToSkip--; continue; } Objects.requireNonNull(currentInstance); reflectionMap = methodMapProvider.getMethodMapFor(currentInstance.getClass()); currentMethod = reflectionMap.getById(currentArg); if (currentMethod == null) { result = new ReflectionResult(ReflectionResult.Type.UNKNOWN_REFERENCE, null, "Unknown or unavailable method"); break; } List<String> stringMethodArgs = ReflectionUtil.getArgsForMethod(this.input.subList(i + 1, input.size()), currentMethod); argsToSkip = stringMethodArgs.size(); if (stringMethodArgs.size() != currentMethod.getParameterCount()) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, ReflectionUtil.getArgMismatchString(currentMethod), null); break; } priorInstance = currentInstance; try { methodParameters = typeHandler.instantiateTypes(currentMethod.getParameterTypes(), stringMethodArgs, sender); currentInstance = reflect(currentInstance, currentMethod, methodParameters); } catch (Throwable ex) { ReflectionResult.Type type = ex instanceof InputException ? ReflectionResult.Type.INPUT_ERROR : ReflectionResult.Type.UNHANDLED_EXCEPTION; Throwable cause = ex.getCause() != null ? ex.getCause() : ex; String reason = cause.getLocalizedMessage() != null ? cause.getLocalizedMessage() : cause.toString(); result = new ReflectionResult(type, null, reason, cause); break; } if (DebuggeryBase.isDebugMode()) { List<String> remainingArgs = input.subList(i, input.size()); logDebug(i, reflectionMap, priorInstance, currentInstance, currentMethod, argsToSkip, methodParameters, remainingArgs); } if (currentMethod.getReturnType() != Void.TYPE && currentInstance == null) { result = new ReflectionResult(ReflectionResult.Type.NULL_REFERENCE, null, ReflectionUtil.getFormattedMethodSignature(currentMethod) + " returned null!"); break; } if (currentMethod.getReturnType() == Void.TYPE && currentInstance == null && i + argsToSkip < input.size() - 1) { result = new ReflectionResult(ReflectionResult.Type.ARG_MISMATCH, null, "You provided extra args after a void return type!\n" + ReflectionUtil.getArgMismatchString(currentMethod)); break; } } if (result == null) { result = new ReflectionResult(ReflectionResult.Type.SUCCESS, currentInstance); } Objects.requireNonNull(result); this.result = result; } ReflectionChain(ReflectionChainFactory factory, @NotNull String[] args,
                    @NotNull Object initialInstance, @Nullable PlatformSender<?> sender);   }