@Test @DisplayName("JavaLexed can't be used after being closed.") void cantBeUsedOutOfScope() { final var source = new TestSource(""); final var sut = new JavaLexed(source); try { } finally { sut.close(); } Assertions.assertThrows(IllegalArgumentException.class, sut::lexicalElements); }
@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); }
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); } }
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); } JavaLexed(Source source); }
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); } JavaLexed(Source source); @Override void close(); Iterable<LexicalElement> lexicalElements(); LexicalElement get(int i); LexicalElement remove(int i); void removeRange(int start, int end); int replaceWith(List<LexicalElement>... lists); int replace(MatchResult result, List<LexicalElement>... lists); int replace(int start, int end, List<LexicalElement>... lists); void add(int index, LexicalElement le); int size(); JavaLexed match(BiFunction<JavaLexed, Lexpression, LexMatcher> expression); JavaLexed find(BiFunction<JavaLexed, Lexpression, LexMatcher> expression); JavaLexed sensitivity(int sensitivity); JavaLexed fromStart(); JavaLexed fromIndex(int i); Optional<java.util.regex.MatchResult> regexGroups(final String name); List<javax0.geci.javacomparator.LexicalElement> group(final String name); MatchResult result(); }
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); } JavaLexed(Source source); @Override void close(); Iterable<LexicalElement> lexicalElements(); LexicalElement get(int i); LexicalElement remove(int i); void removeRange(int start, int end); int replaceWith(List<LexicalElement>... lists); int replace(MatchResult result, List<LexicalElement>... lists); int replace(int start, int end, List<LexicalElement>... lists); void add(int index, LexicalElement le); int size(); JavaLexed match(BiFunction<JavaLexed, Lexpression, LexMatcher> expression); JavaLexed find(BiFunction<JavaLexed, Lexpression, LexMatcher> expression); JavaLexed sensitivity(int sensitivity); JavaLexed fromStart(); JavaLexed fromIndex(int i); Optional<java.util.regex.MatchResult> regexGroups(final String name); List<javax0.geci.javacomparator.LexicalElement> group(final String name); MatchResult result();  }