Skip to content

Commit

Permalink
Corrected the signed expression behaviors and renamed InverseExpressi…
Browse files Browse the repository at this point in the history
…on to SignedExpression;
  • Loading branch information
Pap Lőrinc committed Jan 28, 2014
1 parent 5d151c7 commit d1e7185
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 176 deletions.
22 changes: 11 additions & 11 deletions src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
Expand Down Expand Up @@ -54,11 +54,11 @@ public interface ExpressionVisitor {

void visit(Function function);

void visit(InverseExpression inverseExpression);
void visit(SignedExpression signedExpression);

void visit(JdbcParameter jdbcParameter);
void visit(JdbcNamedParameter jdbcNamedParameter);

void visit(JdbcNamedParameter jdbcNamedParameter);

void visit(DoubleValue doubleValue);

Expand Down Expand Up @@ -137,10 +137,10 @@ public interface ExpressionVisitor {
void visit(AnalyticExpression aexpr);

void visit(ExtractExpression eexpr);

void visit(IntervalExpression iexpr);

void visit(OracleHierarchicalExpression oexpr);

void visit(RegExpMatchOperator rexpr);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,44 @@
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package net.sf.jsqlparser.expression;

/**
* It represents a "-" before an expression
* It represents a "-" or "+" before an expression
*/
public class InverseExpression implements Expression {
public class SignedExpression implements Expression {

private Expression expression;
private char sign;
private Expression expression;

public InverseExpression() {
public SignedExpression(char sign, Expression expression) {
this.sign = sign;
setExpression(expression);
}

public InverseExpression(Expression expression) {
setExpression(expression);
}
public char getSign() {
return sign;
}

public void setSign(char sign) {
this.sign = sign;
}

public Expression getExpression() {
public Expression getExpression() {
return expression;
}

Expand All @@ -47,4 +54,9 @@ public final void setExpression(Expression expression) {
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}

@Override
public String toString() {
return getSign() + expression.toString();
}
}
87 changes: 16 additions & 71 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,38 @@
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package net.sf.jsqlparser.util;

import java.util.ArrayList;
import java.util.List;
import net.sf.jsqlparser.expression.AllComparisonExpression;
import net.sf.jsqlparser.expression.AnalyticExpression;
import net.sf.jsqlparser.expression.AnyComparisonExpression;
import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.CaseExpression;
import net.sf.jsqlparser.expression.CastExpression;
import net.sf.jsqlparser.expression.DateValue;
import net.sf.jsqlparser.expression.DoubleValue;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.expression.ExtractExpression;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.IntervalExpression;
import net.sf.jsqlparser.expression.InverseExpression;
import net.sf.jsqlparser.expression.JdbcNamedParameter;
import net.sf.jsqlparser.expression.JdbcParameter;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.NullValue;
import net.sf.jsqlparser.expression.OracleHierarchicalExpression;
import net.sf.jsqlparser.expression.Parenthesis;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.TimeValue;
import net.sf.jsqlparser.expression.TimestampValue;
import net.sf.jsqlparser.expression.WhenClause;
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
import net.sf.jsqlparser.expression.operators.arithmetic.Modulo;
import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication;
import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction;
import net.sf.jsqlparser.expression.*;
import net.sf.jsqlparser.expression.operators.arithmetic.*;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.relational.Between;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
import net.sf.jsqlparser.expression.operators.relational.ItemsListVisitor;
import net.sf.jsqlparser.expression.operators.relational.LikeExpression;
import net.sf.jsqlparser.expression.operators.relational.Matches;
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.delete.Delete;
import net.sf.jsqlparser.statement.insert.Insert;
import net.sf.jsqlparser.statement.replace.Replace;
import net.sf.jsqlparser.statement.select.FromItemVisitor;
import net.sf.jsqlparser.statement.select.Join;
import net.sf.jsqlparser.statement.select.LateralSubSelect;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SelectVisitor;
import net.sf.jsqlparser.statement.select.SetOperationList;
import net.sf.jsqlparser.statement.select.SubJoin;
import net.sf.jsqlparser.statement.select.SubSelect;
import net.sf.jsqlparser.statement.select.ValuesList;
import net.sf.jsqlparser.statement.select.WithItem;
import net.sf.jsqlparser.statement.select.*;
import net.sf.jsqlparser.statement.update.Update;

import java.util.ArrayList;
import java.util.List;

/**
* Find all used tables within an select statement.
*/
Expand Down Expand Up @@ -297,8 +242,8 @@ public void visit(InExpression inExpression) {
}

@Override
public void visit(InverseExpression inverseExpression) {
inverseExpression.getExpression().accept(this);
public void visit(SignedExpression signedExpression) {
signedExpression.getExpression().accept(this);
}

@Override
Expand Down Expand Up @@ -393,7 +338,7 @@ public void visit(TimeValue timeValue) {

/*
* (non-Javadoc)
*
*
* @see net.sf.jsqlparser.expression.ExpressionVisitor#visit(net.sf.jsqlparser.expression.CaseExpression)
*/
@Override
Expand All @@ -402,7 +347,7 @@ public void visit(CaseExpression caseExpression) {

/*
* (non-Javadoc)
*
*
* @see net.sf.jsqlparser.expression.ExpressionVisitor#visit(net.sf.jsqlparser.expression.WhenClause)
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
Expand Down Expand Up @@ -159,9 +159,9 @@ public void visit(InExpression inExpression) {
}

@Override
public void visit(InverseExpression inverseExpression) {
buffer.append("-");
inverseExpression.getExpression().accept(this);
public void visit(SignedExpression signedExpression) {
buffer.append(signedExpression.getSign());
signedExpression.getExpression().accept(this);
}

@Override
Expand Down
31 changes: 16 additions & 15 deletions src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ Insert Insert():
[LOOKAHEAD(2) "(" ]
(
{ insert.setUseValues(false); }
itemsList = SubSelect()
itemsList= SubSelect()
)
[ ")" ]
)
Expand Down Expand Up @@ -419,7 +419,7 @@ Column Column():
} else {
table = new Table(null, null);
colName = name1;
}
}

return new Column(table, colName);
}
Expand Down Expand Up @@ -1585,7 +1585,7 @@ Expression PrimaryExpression():
Expression retval = null;
CastExpression castExpr = null;
Token token = null;
boolean isInverse = false;
Token sign = null;
String tmp = "";
ColDataType type = null;
}
Expand All @@ -1603,27 +1603,28 @@ Expression PrimaryExpression():

| LOOKAHEAD(ExtractExpression()) retval=ExtractExpression()

| LOOKAHEAD([ "+" | "-"] Function()) [ "+" | "-" { isInverse = true; }] retval=Function()
| LOOKAHEAD(["+" | "-"] Function()) [sign="+" | sign="-"] retval=Function()

| LOOKAHEAD([ "+" | "-"] <S_DOUBLE>) [ "+" | "-" { tmp = "-"; }] token=<S_DOUBLE> { retval = new DoubleValue(tmp+token.image); }
| LOOKAHEAD(["+" | "-"] <S_DOUBLE>) [sign="+" | sign="-"] token=<S_DOUBLE> { retval = new DoubleValue(token.image); }

| LOOKAHEAD([ "+" | "-"] <S_LONG>) [ "+" | "-" { tmp = "-"; }] token=<S_LONG> { retval = new LongValue(tmp+token.image); }
| LOOKAHEAD(["+" | "-"] <S_LONG>) [sign="+" | sign="-"] token=<S_LONG> { retval = new LongValue(token.image); }

| LOOKAHEAD(CastExpression()) [ "+" | "-" { isInverse = true; }] retval=CastExpression()
| LOOKAHEAD(["+" | "-"] CastExpression()) [sign="+" | sign="-"] retval=CastExpression()

| LOOKAHEAD(Column()) [ "+" | "-" { isInverse = true; }] retval=Column()
| LOOKAHEAD(["+" | "-"] Column()) [sign="+" | sign="-"] retval=Column()

| LOOKAHEAD(2) [ "+" | "-" { isInverse = true; }] "(" retval=PrimaryExpression() ")" {retval = new Parenthesis(retval); }
| LOOKAHEAD(2) [sign="+" | sign="-"] "(" retval=PrimaryExpression() ")" {retval = new Parenthesis(retval); }

| [sign="+" | sign="-"] "(" retval=SubSelect() ")"

| token=<S_CHAR_LITERAL> { retval = new StringValue(token.image); }

| [ "+" | "-" { isInverse = true; }] "(" retval=SubSelect() ")"

| "{d" token=<S_CHAR_LITERAL> "}" { retval = new DateValue(token.image); }
| "{d" token=<S_CHAR_LITERAL> "}" { retval = new DateValue(token.image); }

| "{t" token=<S_CHAR_LITERAL> "}" { retval = new TimeValue(token.image); }
| "{t" token=<S_CHAR_LITERAL> "}" { retval = new TimeValue(token.image); }

| "{ts" token=<S_CHAR_LITERAL> "}" { retval = new TimestampValue(token.image); }
| "{ts" token=<S_CHAR_LITERAL> "}" { retval = new TimestampValue(token.image); }

| retval = IntervalExpression()
)
Expand All @@ -1637,8 +1638,8 @@ Expression PrimaryExpression():
} ]

{
if (isInverse) {
retval = new InverseExpression(retval);
if (sign != null) {
retval = new SignedExpression(sign.image.charAt(0), retval);
}
return retval;
}
Expand Down
Loading

0 comments on commit d1e7185

Please sign in to comment.