Skip to content

Commit 8dda4a6

Browse files
committed
tests #775
removed some not flags from some classes
1 parent 9779742 commit 8dda4a6

File tree

10 files changed

+237
-376
lines changed

10 files changed

+237
-376
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ public abstract class BinaryExpression extends ASTNodeAccessImpl implements Expr
1515

1616
private Expression leftExpression;
1717
private Expression rightExpression;
18-
private boolean not = false;
19-
20-
21-
18+
// private boolean not = false;
19+
2220
public BinaryExpression() {
2321
}
2422

@@ -38,23 +36,23 @@ public void setRightExpression(Expression expression) {
3836
rightExpression = expression;
3937
}
4038

41-
public void setNot() {
42-
not = true;
43-
}
44-
45-
public void removeNot() {
46-
not = false;
47-
}
48-
49-
public boolean isNot() {
50-
return not;
51-
}
52-
39+
// public void setNot() {
40+
// not = true;
41+
// }
42+
//
43+
// public void removeNot() {
44+
// not = false;
45+
// }
46+
//
47+
// public boolean isNot() {
48+
// return not;
49+
// }
5350
@Override
5451
public String toString() {
55-
return (not ? "NOT " : "") + getLeftExpression() + " " + getStringExpression() + " " + getRightExpression();
52+
return //(not ? "NOT " : "") +
53+
getLeftExpression() + " " + getStringExpression() + " " + getRightExpression();
5654
}
5755

5856
public abstract String getStringExpression();
59-
57+
6058
}

src/main/java/net/sf/jsqlparser/expression/operators/relational/LikeExpression.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
public class LikeExpression extends BinaryExpression {
1616

17-
//private boolean not = false;
17+
private boolean not = false;
1818
private String escape = null;
1919
private boolean caseInsensitive = false;
2020

21-
// @Override
22-
// public boolean isNot() {
23-
// return not;
24-
// }
25-
//
26-
// public void setNot(boolean b) {
27-
// not = b;
28-
// }
21+
public boolean isNot() {
22+
return not;
23+
}
24+
25+
public void setNot(boolean b) {
26+
not = b;
27+
}
28+
2929
@Override
3030
public void accept(ExpressionVisitor expressionVisitor) {
3131
expressionVisitor.visit(this);
@@ -38,7 +38,7 @@ public String getStringExpression() {
3838

3939
@Override
4040
public String toString() {
41-
String retval = super.toString();
41+
String retval = getLeftExpression() + " " + (not ? "NOT " : "") + getStringExpression() + " " + getRightExpression();
4242
if (escape != null) {
4343
retval += " ESCAPE " + "'" + escape + "'";
4444
}

src/main/java/net/sf/jsqlparser/expression/operators/relational/OldOracleJoinBinaryExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public void setOldOracleJoinSyntax(int oldOracleJoinSyntax) {
2828

2929
@Override
3030
public String toString() {
31-
return (isNot() ? "NOT " : "")
32-
+ (oraclePriorPosition == ORACLE_PRIOR_START ? "PRIOR " : "")
31+
return //(isNot() ? "NOT " : "")
32+
(oraclePriorPosition == ORACLE_PRIOR_START ? "PRIOR " : "")
3333
+ getLeftExpression()
3434
+ (oldOracleJoinSyntax == ORACLE_JOIN_RIGHT ? "(+)" : "") + " "
3535
+ getStringExpression() + " "

src/main/java/net/sf/jsqlparser/util/cnfexpression/CNFConverter.java

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
import java.util.List;
1515
import java.util.Queue;
1616
import java.util.Stack;
17-
import net.sf.jsqlparser.expression.BinaryExpression;
1817
import net.sf.jsqlparser.expression.Expression;
1918
import net.sf.jsqlparser.expression.NotExpression;
20-
import net.sf.jsqlparser.expression.operators.relational.LikeExpression;
2119

2220
public class CNFConverter {
2321

@@ -55,9 +53,8 @@ public static Expression convertToCNF(Expression expr) {
5553
}
5654

5755
/**
58-
* this method takes an expression tree and converts that into
59-
* a CNF form. Notice the 5 steps shown above will turn into
60-
* 5 different methods. For the sake of testing, I set them public.
56+
* this method takes an expression tree and converts that into a CNF form. Notice the 5 steps
57+
* shown above will turn into 5 different methods. For the sake of testing, I set them public.
6158
* return the converted expression.
6259
*
6360
* @param express the original expression tree.
@@ -82,9 +79,8 @@ private Expression convert(Expression express)
8279
}
8380

8481
/**
85-
* this is the first step that rebuild the expression tree.
86-
* Use the standard specified in the above class. Traverse the
87-
* original tree recursively and rebuild the tree from that.
82+
* this is the first step that rebuild the expression tree. Use the standard specified in the
83+
* above class. Traverse the original tree recursively and rebuild the tree from that.
8884
*
8985
* @param express the original expression tree.
9086
*/
@@ -96,9 +92,8 @@ private void reorder(Expression express) {
9692
}
9793

9894
/**
99-
* This method is used to deal with pushing not operators down.
100-
* Since it needs an extra parameter, I will create a new
101-
* method to handle this.
95+
* This method is used to deal with pushing not operators down. Since it needs an extra
96+
* parameter, I will create a new method to handle this.
10297
*/
10398
private void pushNotDown() {
10499
/* set the two temp parameters to their staring point. */
@@ -114,15 +109,12 @@ private void pushNotDown() {
114109
}
115110

116111
/**
117-
* This method is the helper function to push not operators down.
118-
* traverse the tree thoroughly, when we meet the not operator.
119-
* We only need to consider these three operators: MultiAndOperator,
120-
* MultiOrOperator, NotOperator. Handle them in a seperate way.
121-
* when we finish the traverse, the expression tree will have
122-
* all the not operators pushed as downwards as they could.
123-
* In the method, I use two global variables: temp1 and temp2
124-
* to traverse the expression tree. Notice that temp2 will always
125-
* be the parent of temp1.
112+
* This method is the helper function to push not operators down. traverse the tree thoroughly,
113+
* when we meet the not operator. We only need to consider these three operators:
114+
* MultiAndOperator, MultiOrOperator, NotOperator. Handle them in a seperate way. when we finish
115+
* the traverse, the expression tree will have all the not operators pushed as downwards as they
116+
* could. In the method, I use two global variables: temp1 and temp2 to traverse the expression
117+
* tree. Notice that temp2 will always be the parent of temp1.
126118
*
127119
* @param index the index of the children appeared in parents array.
128120
*/
@@ -149,9 +141,8 @@ private void pushNot(int index) {
149141
}
150142

151143
/**
152-
* This function mainly deals with pushing not operators down.
153-
* check the child. If it is not a logic operator(and or or).
154-
* stop at that point. Else use De Morgan law to push not downwards.
144+
* This function mainly deals with pushing not operators down. check the child. If it is not a
145+
* logic operator(and or or). stop at that point. Else use De Morgan law to push not downwards.
155146
*
156147
* @param index the index of the children appeared in parents array.
157148
*/
@@ -176,15 +167,15 @@ private void handleNot(int index) {
176167
* and connect that operator with the parent and return. */
177168
if (!(child instanceof MultiAndExpression)
178169
&& !(child instanceof MultiOrExpression)) {
179-
if (child instanceof LikeExpression) {
180-
((LikeExpression) child).setNot();
181-
} else if (child instanceof BinaryExpression) {
182-
((BinaryExpression) child).setNot();
183-
} else {
184-
child = new NotExpression(child);
185-
}
170+
// if (child instanceof LikeExpression) {
171+
// ((LikeExpression) child).setNot();
172+
// } else if (child instanceof BinaryExpression) {
173+
// ((BinaryExpression) child).setNot();
174+
// } else {
175+
child = new NotExpression(child);
176+
// }
186177
((MultipleExpression) temp2).setChild(index, child);
187-
return;
178+
// return;
188179
} else if (child instanceof MultiAndExpression) {
189180
MultiAndExpression and = (MultiAndExpression) child;
190181
List<Expression> list = new ArrayList<Expression>();
@@ -214,11 +205,10 @@ private void handleNot(int index) {
214205
}
215206

216207
/**
217-
* This method serves as dealing with the third step. It is used
218-
* to put all the adjacent same multi operators together. BFS the
219-
* tree and do it node by node. In the end we will get the tree
220-
* where all the same multi operators store in the same odd level
221-
* of the tree or in the same even level of the tree.
208+
* This method serves as dealing with the third step. It is used to put all the adjacent same
209+
* multi operators together. BFS the tree and do it node by node. In the end we will get the
210+
* tree where all the same multi operators store in the same odd level of the tree or in the
211+
* same even level of the tree.
222212
*/
223213
private void gather() {
224214
Queue<Expression> queue = new LinkedList<Expression>();
@@ -296,11 +286,10 @@ private void gather() {
296286
}
297287

298288
/**
299-
* First, BFS the tree and gather all the or operators and their parents
300-
* into a stack. Next, pop them out and push the and operators under the
301-
* or operators upwards(if there are). Do this level by level, which means
302-
* during each level we will call the gather() method to make the tree uniform.
303-
* When we move out of the stack. The expression tree shall be in CNF form.
289+
* First, BFS the tree and gather all the or operators and their parents into a stack. Next, pop
290+
* them out and push the and operators under the or operators upwards(if there are). Do this
291+
* level by level, which means during each level we will call the gather() method to make the
292+
* tree uniform. When we move out of the stack. The expression tree shall be in CNF form.
304293
*/
305294
private void pushAndUp() {
306295
Queue<Mule> queue = new LinkedList<Mule>();
@@ -346,16 +335,13 @@ private void pushAndUp() {
346335
}
347336

348337
/**
349-
* This helper function is used to deal with pushing and up:
350-
* generally, pop the top element out of the stack,
351-
* use BFS to traverse the tree and push and up.
352-
* It will case the expression tree to have the and as the new
353-
* root and multiple or as the children. Push them on the queue
354-
* and repeat the same process until the newly generated or
355-
* operator does not have any and operators in it(which means no
356-
* elements will be added into the queue). when one level is
357-
* finished, regroup the tree. Do this until the stack is empty,
358-
* the result will be the expression in CNF form.
338+
* This helper function is used to deal with pushing and up: generally, pop the top element out
339+
* of the stack, use BFS to traverse the tree and push and up. It will case the expression tree
340+
* to have the and as the new root and multiple or as the children. Push them on the queue and
341+
* repeat the same process until the newly generated or operator does not have any and operators
342+
* in it(which means no elements will be added into the queue). when one level is finished,
343+
* regroup the tree. Do this until the stack is empty, the result will be the expression in CNF
344+
* form.
359345
*
360346
* @param stack the stack stores a list of combined data.
361347
*/
@@ -412,13 +398,11 @@ private void pushAnd(Stack<Mule> stack) {
412398
}
413399

414400
/**
415-
* This is the final step of the CNF conversion: now we have the
416-
* Expression tree that has one multiple and expression with a list
417-
* of multiple or expression as the child. So we need to convert the
418-
* multiple expression back to the binary counterparts. Note the
419-
* converted tree is left inclined. Also I attach a parenthesis node
420-
* before the or expression that is attached to the and expression
421-
* to make the generated result resembles the CNF form.
401+
* This is the final step of the CNF conversion: now we have the Expression tree that has one
402+
* multiple and expression with a list of multiple or expression as the child. So we need to
403+
* convert the multiple expression back to the binary counterparts. Note the converted tree is
404+
* left inclined. Also I attach a parenthesis node before the or expression that is attached to
405+
* the and expression to make the generated result resembles the CNF form.
422406
*/
423407
private void changeBack() {
424408
if (!(root instanceof MultiAndExpression)) {

src/main/java/net/sf/jsqlparser/util/cnfexpression/CloneHelper.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import java.util.ArrayList;
1313
import java.util.List;
14-
import net.sf.jsqlparser.expression.BinaryExpression;
1514
import net.sf.jsqlparser.expression.Expression;
1615
import net.sf.jsqlparser.expression.NotExpression;
1716
import net.sf.jsqlparser.expression.Parenthesis;
@@ -35,9 +34,9 @@ public Expression modify(Expression express) {
3534
list.add(modify(and.getLeftExpression()));
3635
list.add(modify(and.getRightExpression()));
3736
MultiAndExpression result = new MultiAndExpression(list);
38-
if (and.isNot()) {
39-
return new NotExpression(result);
40-
}
37+
// if (and.isNot()) {
38+
// return new NotExpression(result);
39+
// }
4140
return result;
4241
}
4342
if (express instanceof OrExpression) {
@@ -46,18 +45,18 @@ public Expression modify(Expression express) {
4645
list.add(modify(or.getLeftExpression()));
4746
list.add(modify(or.getRightExpression()));
4847
MultiOrExpression result = new MultiOrExpression(list);
49-
if (or.isNot()) {
50-
return new NotExpression(result);
51-
}
48+
// if (or.isNot()) {
49+
// return new NotExpression(result);
50+
// }
5251
return result;
5352
}
54-
if (express instanceof BinaryExpression) {
55-
BinaryExpression binary = (BinaryExpression) express;
56-
if (binary.isNot()) {
57-
binary.removeNot();
58-
return new NotExpression(modify(binary));
59-
}
60-
}
53+
// if (express instanceof BinaryExpression) {
54+
// BinaryExpression binary = (BinaryExpression) express;
55+
// if (binary.isNot()) {
56+
// binary.removeNot();
57+
// return new NotExpression(modify(binary));
58+
// }
59+
// }
6160
return express;
6261
}
6362

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ public void visit(BitwiseLeftShift expr) {
185185
}
186186

187187
public void visitOldOracleJoinBinaryExpression(OldOracleJoinBinaryExpression expression, String operator) {
188-
if (expression.isNot()) {
189-
buffer.append(NOT);
190-
}
188+
// if (expression.isNot()) {
189+
// buffer.append(NOT);
190+
// }
191191
expression.getLeftExpression().accept(this);
192192
if (expression.getOldOracleJoinSyntax() == EqualsTo.ORACLE_JOIN_RIGHT) {
193193
buffer.append("(+)");
@@ -263,7 +263,9 @@ public void visit(JdbcParameter jdbcParameter) {
263263

264264
@Override
265265
public void visit(LikeExpression likeExpression) {
266-
visitBinaryExpression(likeExpression, likeExpression.isCaseInsensitive() ? " ILIKE " : " LIKE ");
266+
visitBinaryExpression(likeExpression,
267+
(likeExpression.isNot() ? " NOT" : "")
268+
+ (likeExpression.isCaseInsensitive() ? " ILIKE " : " LIKE "));
267269
String escape = likeExpression.getEscape();
268270
if (escape != null) {
269271
buffer.append(" ESCAPE '").append(escape).append('\'');
@@ -344,9 +346,9 @@ public void visit(Subtraction subtraction) {
344346
}
345347

346348
protected void visitBinaryExpression(BinaryExpression binaryExpression, String operator) {
347-
if (binaryExpression.isNot()) {
348-
buffer.append(NOT);
349-
}
349+
// if (binaryExpression.isNot()) {
350+
// buffer.append(NOT);
351+
// }
350352
binaryExpression.getLeftExpression().accept(this);
351353
buffer.append(operator);
352354
binaryExpression.getRightExpression().accept(this);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ Expression LikeExpression() #LikeExpression:
23122312
}
23132313
{
23142314
leftExpression=SimpleExpression()
2315-
[<K_NOT> { result.setNot(); } ] ( <K_LIKE> | <K_ILIKE> { result.setCaseInsensitive(true); } ) rightExpression=SimpleExpression()
2315+
[<K_NOT> { result.setNot(true); } ] ( <K_LIKE> | <K_ILIKE> { result.setCaseInsensitive(true); } ) rightExpression=SimpleExpression()
23162316
[<K_ESCAPE> token=<S_CHAR_LITERAL> { result.setEscape((new StringValue(token.image)).getValue()); }]
23172317
{
23182318
result.setLeftExpression(leftExpression);

src/test/java/net/sf/jsqlparser/expression/operators/relational/LikeExpressionTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*/
1010
package net.sf.jsqlparser.expression.operators.relational;
1111

12-
import static org.junit.Assert.*;
12+
import static org.junit.Assert.assertFalse;
13+
import static org.junit.Assert.assertTrue;
1314
import org.junit.Test;
1415

1516
/**
@@ -22,7 +23,7 @@ public class LikeExpressionTest {
2223
public void testLikeNotIssue660() {
2324
LikeExpression instance = new LikeExpression();
2425
assertFalse(instance.isNot());
25-
instance.setNot();
26+
instance.setNot(true);
2627
assertTrue(instance.isNot());
2728
}
2829
}

0 commit comments

Comments
 (0)