Skip to content

Commit 8037af6

Browse files
committed
fixes #508 including precedence
1 parent 272177a commit 8037af6

File tree

9 files changed

+125
-2
lines changed

9 files changed

+125
-2
lines changed

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
2525
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
26+
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseLeftShift;
2627
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
28+
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseRightShift;
2729
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
2830
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
2931
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
@@ -52,6 +54,10 @@
5254

5355
public interface ExpressionVisitor {
5456

57+
public void visit(BitwiseRightShift aThis);
58+
59+
public void visit(BitwiseLeftShift aThis);
60+
5561
void visit(NullValue nullValue);
5662

5763
void visit(Function function);

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@ public void visit(NotExpression notExpr) {
358358
notExpr.getExpression().accept(this);
359359
}
360360

361+
@Override
362+
public void visit(BitwiseRightShift expr) {
363+
visitBinaryExpression(expr);
364+
}
365+
366+
@Override
367+
public void visit(BitwiseLeftShift expr) {
368+
visitBinaryExpression(expr);
369+
}
370+
361371
protected void visitBinaryExpression(BinaryExpression expr) {
362372
expr.getLeftExpression().accept(this);
363373
expr.getRightExpression().accept(this);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2013 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+
package net.sf.jsqlparser.expression.operators.arithmetic;
23+
24+
import net.sf.jsqlparser.expression.BinaryExpression;
25+
import net.sf.jsqlparser.expression.ExpressionVisitor;
26+
27+
public class BitwiseLeftShift extends BinaryExpression {
28+
29+
@Override
30+
public void accept(ExpressionVisitor expressionVisitor) {
31+
expressionVisitor.visit(this);
32+
}
33+
34+
@Override
35+
public String getStringExpression() {
36+
return "<<";
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2013 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+
package net.sf.jsqlparser.expression.operators.arithmetic;
23+
24+
import net.sf.jsqlparser.expression.BinaryExpression;
25+
import net.sf.jsqlparser.expression.ExpressionVisitor;
26+
27+
public class BitwiseRightShift extends BinaryExpression {
28+
29+
@Override
30+
public void accept(ExpressionVisitor expressionVisitor) {
31+
expressionVisitor.visit(this);
32+
}
33+
34+
@Override
35+
public String getStringExpression() {
36+
return ">>";
37+
}
38+
}

src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/arithmetic.uod

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
import net.sf.jsqlparser.expression.WhenClause;
6262
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
6363
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
64+
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseLeftShift;
6465
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
66+
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseRightShift;
6567
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
6668
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
6769
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
@@ -374,6 +376,16 @@ public void visit(NotExpression notExpr) {
374376
notExpr.getExpression().accept(this);
375377
}
376378

379+
@Override
380+
public void visit(BitwiseRightShift expr) {
381+
visitBinaryExpression(expr);
382+
}
383+
384+
@Override
385+
public void visit(BitwiseLeftShift expr) {
386+
visitBinaryExpression(expr);
387+
}
388+
377389
public void visitBinaryExpression(BinaryExpression binaryExpression) {
378390
binaryExpression.getLeftExpression().accept(this);
379391
binaryExpression.getRightExpression().accept(this);

src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
import net.sf.jsqlparser.expression.WindowElement;
6363
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
6464
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
65+
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseLeftShift;
6566
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
67+
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseRightShift;
6668
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
6769
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
6870
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
@@ -196,6 +198,16 @@ public void visit(NotExpression notExpr) {
196198
notExpr.getExpression().accept(this);
197199
}
198200

201+
@Override
202+
public void visit(BitwiseRightShift expr) {
203+
visitBinaryExpression(expr, " >> ");
204+
}
205+
206+
@Override
207+
public void visit(BitwiseLeftShift expr) {
208+
visitBinaryExpression(expr, " << ");
209+
}
210+
199211
public void visitOldOracleJoinBinaryExpression(OldOracleJoinBinaryExpression expression, String operator) {
200212
if (expression.isNot()) {
201213
buffer.append(NOT);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,10 @@ Expression BitwiseAndOr():
22472247
"|" { result = new BitwiseOr(); }
22482248
|
22492249
"&" { result = new BitwiseAnd(); }
2250+
|
2251+
"<<" { result = new BitwiseLeftShift(); }
2252+
|
2253+
">>" { result = new BitwiseRightShift(); }
22502254
)
22512255

22522256
rightExpression=AdditiveExpression()

src/test/java/net/sf/jsqlparser/test/select/SelectTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,4 +2665,9 @@ public void testIssue512_2() throws JSQLParserException {
26652665
public void testIssue514() throws JSQLParserException {
26662666
assertSqlCanBeParsedAndDeparsed("SELECT listagg(c1, ';') WITHIN GROUP (PARTITION BY 1 ORDER BY 1) col FROM dual");
26672667
}
2668+
2669+
public void testIssue508LeftRightBitwiseShift() throws JSQLParserException {
2670+
assertSqlCanBeParsedAndDeparsed("SELECT 1 << 1");
2671+
assertSqlCanBeParsedAndDeparsed("SELECT 1 >> 1");
2672+
}
26682673
}

0 commit comments

Comments
 (0)