class JavaLexed implements AutoCloseable {

    @Override
    public void close() {
        assertOpen();
        isOpen = false;
        final var lines = new ArrayList<String>();
        final var currentLine = new StringBuilder();
        for (final var lex : lexicalElements) {
            String lexeme;
            if (lex.getType() == LexicalElement.Type.CHARACTER || lex.getType() == LexicalElement.Type.STRING) {
                lexeme = lex.getOriginalLexeme();
            } else {
                lexeme = lex.getFullLexeme();
            }
            while (lexeme.contains("\n")) {
                final var nlpos = lexeme.indexOf("\n");
                final var start = lexeme.substring(0, nlpos);
                currentLine.append(start);
                lines.add(currentLine.toString());
                currentLine.delete(0, currentLine.length());
                lexeme = lexeme.substring(nlpos + 1);
            }
            currentLine.append(lexeme);
        }
        if (currentLine.length() > 0) {
            lines.add(currentLine.toString());
        }
        source.returns(lines);
    }

    public  JavaLexed(Source source);

}