Skip to content

Commit 0b30498

Browse files
committed
docs: add code comments
1 parent 9bb9ca0 commit 0b30498

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎src/main/java/org/leplus/sql/ConstantListener.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import org.leplus.antlr4.PLSQLBaseListener;
77
import org.leplus.antlr4.PLSQLParser.ConstantContext;
88

9+
/**
10+
* ANTLR listener that collects the literal constants of a PL/SQL parse tree.
11+
* {@code NULL} literals are skipped, since they denote absence rather than a
12+
* value.
13+
*/
914
public class ConstantListener extends PLSQLBaseListener {
1015

1116
private static final String NULL = "NULL";
@@ -27,6 +32,9 @@ public void enterConstant(final ConstantContext ctx) {
2732
addResult(ctx);
2833
}
2934

35+
/**
36+
* @return an unmodifiable view of the constants collected so far.
37+
*/
3038
public List<Result> getResults() {
3139
return Collections.unmodifiableList(results);
3240
}

‎src/main/java/org/leplus/sql/ExceptionErrorListener.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import org.antlr.v4.runtime.RecognitionException;
55
import org.antlr.v4.runtime.Recognizer;
66

7+
/**
8+
* An ANTLR error listener that makes parsing fail fast: instead of ANTLR's
9+
* default "recover and continue", it rethrows the recognition exception on the
10+
* first syntax error.
11+
*/
712
public class ExceptionErrorListener extends BaseErrorListener {
813

914
public ExceptionErrorListener() {

‎src/main/java/org/leplus/sql/Inspector.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@
77
import org.leplus.antlr4.PLSQLLexer;
88
import org.leplus.antlr4.PLSQLParser;
99

10+
/** Inspects SQL statements for literal constants, using an ANTLR4 PL/SQL grammar. */
1011
public class Inspector {
1112

1213
public Inspector() {
1314
super();
1415
}
1516

17+
/**
18+
* Parses a SQL statement and returns the literal constants it contains, in
19+
* source order. Parsing fails fast: the first syntax error is rethrown (see
20+
* {@link ExceptionErrorListener}).
21+
*
22+
* @param sqlStatement the SQL text to inspect.
23+
* @return the constants found.
24+
*/
1625
public List<Result> findConstants(final String sqlStatement) {
1726
final PLSQLLexer lexer = new PLSQLLexer(CharStreams.fromString(sqlStatement));
1827
final CommonTokenStream tokens = new CommonTokenStream(lexer);

‎src/main/java/org/leplus/sql/Result.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import java.io.Serializable;
44

5+
/**
6+
* A literal constant found in a SQL statement: its text value and its position.
7+
* Ordered by line, then column, then value.
8+
*/
59
public class Result implements Serializable, Comparable<Result> {
610

711
private static final long serialVersionUID = 2722874450358413200L;

0 commit comments

Comments
 (0)