[plsql] Introduce new node OuterJoinExpression

This commit is contained in:
Andreas Dangel
2019-07-20 17:32:31 +02:00
parent fdb31686f0
commit 50d211eae4
6 changed files with 28 additions and 43 deletions

View File

@ -1556,13 +1556,26 @@ ASTSimpleExpression SimpleExpression() :
LOOKAHEAD(2)
( "*" | Column() ) { sb.append(token.image); }
)
[LOOKAHEAD(3) "(" "+" ")" {jjtThis.setJoinOperator(true);} ] // JoinOperator
{
jjtThis.setImage(sb.toString());
return jjtThis;
}
}
ASTOuterJoinExpression OuterJoinExpression() :
{ StringBuilder sb = new StringBuilder(); }
{
[ LOOKAHEAD(6) SchemaName() { sb.append(token.image); } "." { sb.append(token.image); } ]
[ LOOKAHEAD(4) TableName() { sb.append(token.image); } "." { sb.append(token.image); } ]
Column() { sb.append(token.image); }
"(" "+" ")"
{
jjtThis.setImage(sb.toString());
return jjtThis;
}
}
/**
* Built-in function call or a user defined function call.
* See https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/Functions.html#GUID-D079EFD3-C683-441F-977E-2C9503089982
@ -3259,7 +3272,7 @@ ASTPrimaryPrefix PrimaryPrefix() :
}
{
(
LOOKAHEAD(ID() ("." ID())* "(" "+" ")") ( simpleNode = SimpleExpression() ) { sb.append(simpleNode.getImage()); }
LOOKAHEAD(OuterJoinExpression()) ( simpleNode = OuterJoinExpression() ) { sb.append(simpleNode.getImage()); }
// Note: AnalyticClause and WithinClause are only allowed for specific functions, but this grammar allows it for all functions.
| LOOKAHEAD(FunctionName() "(") ( simpleNode = FunctionCall() [ AnalyticClause() ] [ WithinClause() ] ) { sb.append(simpleNode.getImage()); }
| LOOKAHEAD(MultiSetCondition()) simpleNode = MultiSetCondition()

View File

@ -67,7 +67,6 @@
<delete file="${target}/net/sourceforge/pmd/lang/plsql/ast/ASTRegexpLikeCondition.java" />
<delete file="${target}/net/sourceforge/pmd/lang/plsql/ast/ASTSelectIntoStatement.java" />
<delete file="${target}/net/sourceforge/pmd/lang/plsql/ast/ASTSelectStatement.java" />
<delete file="${target}/net/sourceforge/pmd/lang/plsql/ast/ASTSimpleExpression.java" />
<delete file="${target}/net/sourceforge/pmd/lang/plsql/ast/ASTSubqueryOperation.java" />
<delete file="${target}/net/sourceforge/pmd/lang/plsql/ast/ASTTriggerTimingPointSection.java" />
<delete file="${target}/net/sourceforge/pmd/lang/plsql/ast/ASTTriggerUnit.java" />

View File

@ -1,30 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.plsql.ast;
public class ASTSimpleExpression extends AbstractPLSQLNode {
private boolean joinOperator;
ASTSimpleExpression(int id) {
super(id);
}
ASTSimpleExpression(PLSQLParser p, int id) {
super(p, id);
}
@Override
public Object jjtAccept(PLSQLParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
void setJoinOperator(boolean joinOperator) {
this.joinOperator = joinOperator;
}
public boolean hasJoinOperator() {
return joinOperator;
}
}

View File

@ -1106,4 +1106,9 @@ public class PLSQLParserVisitorAdapter implements PLSQLParserVisitor {
public Object visit(ASTXMLElement node, Object data) {
return visit((PLSQLNode) node, data);
}
@Override
public Object visit(ASTOuterJoinExpression node, Object data) {
return visit((PLSQLNode) node, data);
}
}

View File

@ -1200,6 +1200,11 @@ public abstract class AbstractPLSQLRule extends AbstractRule implements PLSQLPar
return visit((PLSQLNode) node, data);
}
@Override
public Object visit(ASTOuterJoinExpression node, Object data) {
return visit((PLSQLNode) node, data);
}
/*
* Treat all Executable Code
*/

View File

@ -5,7 +5,6 @@
package net.sourceforge.pmd.lang.plsql.ast;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
@ -136,14 +135,8 @@ public class JoinClauseTest extends AbstractPLSQLParserTst {
String code = IOUtils.toString(this.getClass().getResourceAsStream("JoinOperator.pls"),
StandardCharsets.UTF_8);
ASTInput input = parsePLSQL(code);
List<ASTSimpleExpression> expressions = input.findDescendantsOfType(ASTSimpleExpression.class);
List<ASTSimpleExpression> expressionsWithJoinOperator = new ArrayList<ASTSimpleExpression>();
for (ASTSimpleExpression exp : expressions) {
if (exp.hasJoinOperator()) {
expressionsWithJoinOperator.add(exp);
}
}
Assert.assertEquals(4, expressionsWithJoinOperator.size());
Assert.assertEquals("h.opp_id", expressionsWithJoinOperator.get(3).getImage());
List<ASTOuterJoinExpression> expressions = input.findDescendantsOfType(ASTOuterJoinExpression.class);
Assert.assertEquals(4, expressions.size());
Assert.assertEquals("h.opp_id", expressions.get(3).getImage());
}
}