static void parseExpressions(StringBuilder expressions, NameValidator nameInConditionValidator,
                                 String exceptionInfo, Set<String> createObjects, List<Statement> list,
                                 ClassHelper classHelper, String indentation) {

        for (Statement statement : list) {
            // avoid parsing the RHS value expression again as we just did it to get the maximum values in createClazz
            if (statement.keyword() == Statement.Keyword.ELSE) {
                if (!Helper.isEmpty(statement.condition()))
                    throw new IllegalArgumentException("condition must be empty but was " + statement.condition());

                expressions.append(indentation);
                if (statement.isBlock()) {
                    expressions.append("else {");
                    parseExpressions(expressions, nameInConditionValidator, exceptionInfo, createObjects, statement.doBlock(), classHelper, indentation + "  ");
                    expressions.append(indentation).append("}\n");
                } else {
                    expressions.append("else {").append(statement.operation().build(statement.value())).append("; }\n");
                }
            } else if (statement.keyword() == Statement.Keyword.ELSEIF || statement.keyword() == Statement.Keyword.IF) {
                ParseResult parseResult = ConditionalExpressionVisitor.parse(statement.condition(), nameInConditionValidator, classHelper);
                if (!parseResult.ok)
                    throw new IllegalArgumentException(exceptionInfo + " invalid condition \"" + statement.condition() + "\"" +
                            (parseResult.invalidMessage == null ? "" : ": " + parseResult.invalidMessage));
                createObjects.addAll(parseResult.guessedVariables);
                if (statement.keyword() == Statement.Keyword.ELSEIF)
                    expressions.append(indentation).append("else ");

                expressions.append(indentation);
                if (statement.isBlock()) {
                    expressions.append("if (").append(parseResult.converted).append(") {\n");
                    parseExpressions(expressions, nameInConditionValidator, exceptionInfo, createObjects, statement.doBlock(), classHelper, indentation + "  ");
                    expressions.append(indentation).append("}\n");
                } else {
                    expressions.append("if (").append(parseResult.converted).append(") {").
                            append(statement.operation().build(statement.value())).append(";}\n");
                }
            } else {
                throw new IllegalArgumentException("The statement must be either 'if', 'else_if' or 'else'");
            }
        }
    }
@Test
    public void parseConditionWithError() {
        NameValidator validVariable = s -> encodingManager.hasEncodedValue(s);

        // existing encoded value but not added
        IllegalArgumentException ret = assertThrows(IllegalArgumentException.class,
                () -> parseExpressions(new StringBuilder(),
                        validVariable, "[HERE]", new HashSet<>(),
                        Arrays.asList(If("max_weight > 10", MULTIPLY, "0")), s -> "", "")
        );
        assertTrue(ret.getMessage().startsWith("[HERE] invalid condition \"max_weight > 10\": 'max_weight' not available"), ret.getMessage());

        // invalid variable or constant (NameValidator returns false)
        ret = assertThrows(IllegalArgumentException.class,
                () -> parseExpressions(new StringBuilder(),
                        validVariable, "[HERE]", new HashSet<>(),
                        Arrays.asList(If("country == GERMANY", MULTIPLY, "0")), s -> "", ""));
        assertTrue(ret.getMessage().startsWith("[HERE] invalid condition \"country == GERMANY\": 'GERMANY' not available"), ret.getMessage());

        // not whitelisted method
        ret = assertThrows(IllegalArgumentException.class,
                () -> parseExpressions(new StringBuilder(),
                        validVariable, "[HERE]", new HashSet<>(),
                        Arrays.asList(If("edge.fetchWayGeometry().size() > 2", MULTIPLY, "0")), s -> "", ""));
        assertTrue(ret.getMessage().startsWith("[HERE] invalid condition \"edge.fetchWayGeometry().size() > 2\": size is an illegal method"), ret.getMessage());
    }