@Test public void testCheckTypes_questionWithBracedExpressionCanHaveValidations() { String existingQuestionName = "existingQuestion"; Question question = aQuestion().withName(existingQuestionName).withQuestionLabel("Ask me now") .withDataType(new BooleanType()).build(); String notExistingQuestionName = "notExistingQuestion"; List<Statement> statements = new ArrayList<>(); Expression leftHand = new NameExpression(aTextLocation().build(), existingQuestionName); Expression rightHand = new NameExpression(aTextLocation().build(), notExistingQuestionName); Expression binaryExpression = new BinaryExpression(aTextLocation().build(), leftHand, rightHand, new AndOperator("&&")); Expression condition = new BracedExpression(aTextLocation().build(), binaryExpression); statements.add(question); statements.add(aConditionalBlock().withCondition(condition).build()); Questionnaire questionnaire = aQuestionnaire().withStatements(statements).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("Reference to undefined question 'notExistingQuestion'")); }
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);  }