ValidatorChain extends ArrayList<Validator> { public void addValueSpaceChecks(MethodSpec.Builder methodBuilder, ParameterSpec symbol, RDFSClazz range) { for (Validator validator : this) { validator.addValueSpaceCheck(methodBuilder, symbol, range); } }  void addValueSpaceChecks(MethodSpec.Builder methodBuilder, ParameterSpec symbol, RDFSClazz range); String[] getValueSpaceDefinitions(RDFSClazz range); boolean isValueSpaceConstrained(RDFSClazz range); static ValidatorChain getRDFSDefault();  }
@Test public void addValueSpaceChecks() throws Exception { ParameterSpec param = ParameterSpec.builder(ClassName.get(Object.class), "x").build(); MethodSpec method = MethodSpec.methodBuilder("foo") .addModifiers(Modifier.PUBLIC) .addParameter(param) .returns(void.class) .build(); MethodSpec.Builder methodBuilder = method.toBuilder(); Pattern notNullCheckPattern = Pattern.compile("if\\s*\\((x\\s*==\\s*null|null\\s*==\\s*x)\\)"); Pattern positiveCheckPattern = Pattern.compile("if\\s*\\((x\\s*<=\\s*0|0\\s*>=\\s*x)\\)"); ValidatorChain chain = new ValidatorChain(); chain.add(new NotNullValidator()); chain.addValueSpaceChecks(methodBuilder, param, xsdPositiveInt); String code = methodBuilder.build().code.toString(); Matcher notNullCheckMatcher = notNullCheckPattern.matcher(code); Matcher positiveCheckMatcher = positiveCheckPattern.matcher(code); assertTrue(notNullCheckMatcher.find()); assertFalse(positiveCheckMatcher.find()); chain.add(new XSDValueSpaceValidator()); chain.addValueSpaceChecks(methodBuilder, param, xsdPositiveInt); code = methodBuilder.build().code.toString(); notNullCheckMatcher = notNullCheckPattern.matcher(code); positiveCheckMatcher = positiveCheckPattern.matcher(code); assertTrue(notNullCheckMatcher.find()); assertTrue(positiveCheckMatcher.find()); assertTrue(notNullCheckMatcher.end() < positiveCheckMatcher.start()); }