File tree Expand file tree Collapse file tree
src/main/java/org/leplus/sql Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import org .leplus .antlr4 .PLSQLBaseListener ;
77import 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+ */
914public 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 }
Original file line number Diff line number Diff line change 44import org .antlr .v4 .runtime .RecognitionException ;
55import 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+ */
712public class ExceptionErrorListener extends BaseErrorListener {
813
914 public ExceptionErrorListener () {
Original file line number Diff line number Diff line change 77import org .leplus .antlr4 .PLSQLLexer ;
88import org .leplus .antlr4 .PLSQLParser ;
99
10+ /** Inspects SQL statements for literal constants, using an ANTLR4 PL/SQL grammar. */
1011public 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 );
Original file line number Diff line number Diff line change 22
33import 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+ */
59public class Result implements Serializable , Comparable <Result > {
610
711 private static final long serialVersionUID = 2722874450358413200L ;
You can’t perform that action at this time.
0 commit comments