private static NodeConstructor getNodeConstructor(Inject annotation, TestClass testClass) { Class<? extends RootNode> nodeClass = annotation.value(); try { Constructor<? extends RootNode> cons = nodeClass.getConstructor(testClass.getJavaClass()); return (obj) -> { try { return cons.newInstance(obj); } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException ex) { throw new AssertionError(ex); } }; } catch (NoSuchMethodException e) { try { Constructor<? extends RootNode> cons = nodeClass.getConstructor(); return (obj) -> { try { return cons.newInstance(); } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException ex) { throw new AssertionError(ex); } }; } catch (NoSuchMethodException ex) { return null; } } }
private static NodeConstructor getNodeConstructor(Inject annotation, TestClass testClass) { Class<? extends RootNode> nodeClass = annotation.value(); try { Constructor<? extends RootNode> cons = nodeClass.getConstructor(testClass.getJavaClass()); return (obj) -> { try { return cons.newInstance(obj); } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException ex) { throw new AssertionError(ex); } }; } catch (NoSuchMethodException e) { try { Constructor<? extends RootNode> cons = nodeClass.getConstructor(); return (obj) -> { try { return cons.newInstance(); } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException ex) { throw new AssertionError(ex); } }; } catch (NoSuchMethodException ex) { return null; } } }
static void validateTestMethods(TestClass testClass, List<Throwable> errors) { List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Test.class); for (FrameworkMethod method : methods) { method.validatePublicVoid(false, errors); Annotation[][] parameterAnnotations = method.getMethod().getParameterAnnotations(); Class<?>[] parameterTypes = method.getMethod().getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { if (parameterTypes[i] == CallTarget.class) { TruffleRunner.Inject testRootNode = findRootNodeAnnotation(parameterAnnotations[i]); if (testRootNode == null) { errors.add(new Exception("CallTarget parameter of test method " + method.getName() + " should have @Inject annotation")); } else { if (getNodeConstructor(testRootNode, testClass) == null) { errors.add(new Exception("Node " + testRootNode.value().getName() + " should have a default constructor or a constructor taking a " + testClass.getName())); } } } else { errors.add(new Exception("Invalid parameter type " + parameterTypes[i].getSimpleName() + " on test method " + method.getName())); } } } } }
static void validateTestMethods(TestClass testClass, List<Throwable> errors) { List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Test.class); for (FrameworkMethod method : methods) { method.validatePublicVoid(false, errors); Annotation[][] parameterAnnotations = method.getMethod().getParameterAnnotations(); Class<?>[] parameterTypes = method.getMethod().getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { if (parameterTypes[i] == CallTarget.class) { TruffleRunner.Inject testRootNode = findRootNodeAnnotation(parameterAnnotations[i]); if (testRootNode == null) { errors.add(new Exception("CallTarget parameter of test method " + method.getName() + " should have @Inject annotation")); } else { if (getNodeConstructor(testRootNode, testClass) == null) { errors.add(new Exception("Node " + testRootNode.value().getName() + " should have a default constructor or a constructor taking a " + testClass.getName())); } } } else { errors.add(new Exception("Invalid parameter type " + parameterTypes[i].getSimpleName() + " on test method " + method.getName())); } } } } }