Skip to content

Commit e594e59

Browse files
committed
simple jjtree start
1 parent d9f5fef commit e594e59

File tree

5 files changed

+122
-5
lines changed

5 files changed

+122
-5
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2015 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
/*
23+
* Copyright (C) 2015 JSQLParser.
24+
*
25+
* This library is free software; you can redistribute it and/or
26+
* modify it under the terms of the GNU Lesser General Public
27+
* License as published by the Free Software Foundation; either
28+
* version 2.1 of the License, or (at your option) any later version.
29+
*
30+
* This library is distributed in the hope that it will be useful,
31+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33+
* Lesser General Public License for more details.
34+
*
35+
* You should have received a copy of the GNU Lesser General Public
36+
* License along with this library; if not, write to the Free Software
37+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
38+
* MA 02110-1301 USA
39+
*/
40+
package net.sf.jsqlparser.parser;
41+
42+
/**
43+
*
44+
* @author toben
45+
*/
46+
public interface ASTNodeAccess {
47+
SimpleNode getASTNode();
48+
void setASTNode(SimpleNode node);
49+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2015 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
/*
23+
* Copyright (C) 2015 JSQLParser.
24+
*
25+
* This library is free software; you can redistribute it and/or
26+
* modify it under the terms of the GNU Lesser General Public
27+
* License as published by the Free Software Foundation; either
28+
* version 2.1 of the License, or (at your option) any later version.
29+
*
30+
* This library is distributed in the hope that it will be useful,
31+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33+
* Lesser General Public License for more details.
34+
*
35+
* You should have received a copy of the GNU Lesser General Public
36+
* License along with this library; if not, write to the Free Software
37+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
38+
* MA 02110-1301 USA
39+
*/
40+
package net.sf.jsqlparser.parser;
41+
42+
/**
43+
*
44+
* @author toben
45+
*/
46+
public class ASTNodeAccessImpl implements ASTNodeAccess {
47+
private SimpleNode node;
48+
49+
@Override
50+
public SimpleNode getASTNode() {
51+
return node;
52+
}
53+
54+
@Override
55+
public void setASTNode(SimpleNode node) {
56+
this.node = node;
57+
}
58+
59+
}

src/main/java/net/sf/jsqlparser/schema/Column.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
package net.sf.jsqlparser.schema;
2323

2424
import net.sf.jsqlparser.expression.*;
25+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
2526

2627
/**
2728
* A column. It can have the table name it belongs to.
2829
*/
29-
public final class Column implements Expression, MultiPartName {
30+
public final class Column extends ASTNodeAccessImpl implements Expression, MultiPartName {
3031

3132
private Table table;
3233
private String columnName;

src/main/java/net/sf/jsqlparser/schema/Table.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
package net.sf.jsqlparser.schema;
2323

2424
import net.sf.jsqlparser.expression.*;
25+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
2526
import net.sf.jsqlparser.statement.select.*;
2627

2728
/**
2829
* A table. It can have an alias and the schema name it belongs to.
2930
*/
30-
public class Table implements FromItem, MultiPartName {
31+
public class Table extends ASTNodeAccessImpl implements FromItem, MultiPartName {
3132

3233
private Database database;
3334
private String schemaName;

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ import java.util.*;
8080
* The parser generated by JavaCC
8181
*/
8282
public class CCJSqlParser {
83-
83+
private void linkAST(ASTNodeAccess access, SimpleNode node) {
84+
access.setASTNode(node);
85+
node.jjtSetValue(access);
86+
}
8487
}
8588

8689
PARSER_END(CCJSqlParser)
@@ -529,7 +532,9 @@ Column Column() #Column :
529532
{
530533
final Database database = new Database(databaseName);
531534
final Table table = new Table(database, schemaName, tableName);
532-
return new Column(table, columnName);
535+
Column col = new Column(table, columnName);
536+
linkAST(col,jjtThis);
537+
return col;
533538
}
534539
}
535540

@@ -576,7 +581,9 @@ Table Table() #Table :
576581
{
577582
final Server server = new Server(serverName);
578583
final Database database = new Database(server, databaseName);
579-
return new Table(database, schemaName, tableName);
584+
Table table = new Table(database, schemaName, tableName);
585+
linkAST(table,jjtThis);
586+
return table;
580587
}
581588
}
582589

0 commit comments

Comments
 (0)