@Test public void testCheckTypes_computedValueWithDifferentDataTypeThanQuestionIsInvalid() { Expression computed = new LiteralExpression(aTextLocation().build(), new IntegerLiteral(5)); Question question = aQuestion().withDataType(new StringType()).withComputed(computed).build(); List<Question> questions = Arrays.asList(question); Questionnaire questionnaire = aQuestionnaire().withQuestions(questions).build(); TypeChecker typeChecker = new TypeChecker(questionnaire); List<TypeValidation> validations = typeChecker.checkTypes(); assertThat(validations.toString(), validations.size(), is(1)); TypeValidation typeValidation = validations.get(0); assertThat(typeValidation.getValidationMessage(), is("Computed type integer does not match question type string")); }
public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Statement> statements = questionnaire.getStatements(); for (Statement statement : statements) { validations.addAll(statement.accept(this)); } return validations; }
TypeChecker implements ExpressionVisitor<List<TypeValidation>>, StatementVisitor<List<TypeValidation>> { public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Statement> statements = questionnaire.getStatements(); for (Statement statement : statements) { validations.addAll(statement.accept(this)); } return validations; } }
TypeChecker implements ExpressionVisitor<List<TypeValidation>>, StatementVisitor<List<TypeValidation>> { public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Statement> statements = questionnaire.getStatements(); for (Statement statement : statements) { validations.addAll(statement.accept(this)); } return validations; } TypeChecker(Questionnaire questionnaire); }
TypeChecker implements ExpressionVisitor<List<TypeValidation>>, StatementVisitor<List<TypeValidation>> { public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Statement> statements = questionnaire.getStatements(); for (Statement statement : statements) { validations.addAll(statement.accept(this)); } return validations; } TypeChecker(Questionnaire questionnaire); List<TypeValidation> checkTypes(); @Override List<TypeValidation> visit(BracedExpression bracedExpression); @Override List<TypeValidation> visit(NameExpression nameExpression); @Override List<TypeValidation> visit(UnaryExpression unaryExpression); @Override List<TypeValidation> visit(BinaryExpression binaryExpression); @Override List<TypeValidation> visit(ConditionalBlock conditionalBlock); @Override List<TypeValidation> visit(Question question); @Override List<TypeValidation> visit(LiteralExpression literalExpression); }
TypeChecker implements ExpressionVisitor<List<TypeValidation>>, StatementVisitor<List<TypeValidation>> { public List<TypeValidation> checkTypes() { List<TypeValidation> validations = new ArrayList<>(); List<Statement> statements = questionnaire.getStatements(); for (Statement statement : statements) { validations.addAll(statement.accept(this)); } return validations; } TypeChecker(Questionnaire questionnaire); List<TypeValidation> checkTypes(); @Override List<TypeValidation> visit(BracedExpression bracedExpression); @Override List<TypeValidation> visit(NameExpression nameExpression); @Override List<TypeValidation> visit(UnaryExpression unaryExpression); @Override List<TypeValidation> visit(BinaryExpression binaryExpression); @Override List<TypeValidation> visit(ConditionalBlock conditionalBlock); @Override List<TypeValidation> visit(Question question); @Override List<TypeValidation> visit(LiteralExpression literalExpression);  }