diff --git a/pmd-plsql/etc/grammar/PldocAST.jjt b/pmd-plsql/etc/grammar/PldocAST.jjt index f6489df759..8d4630ca43 100644 --- a/pmd-plsql/etc/grammar/PldocAST.jjt +++ b/pmd-plsql/etc/grammar/PldocAST.jjt @@ -607,7 +607,11 @@ ASTFormalParameter FormalParameter() : ( simpleNode = ID() // the order of outer "|" is important ! - ( LOOKAHEAD(2) ( LOOKAHEAD(2) ( (|( )) (LOOKAHEAD(2) )? ) | ) )? + + ( {jjtThis.setIn(true); } )? + ( {jjtThis.setOut(true); } )? + ( {jjtThis.setNoCopy(true); } )? + ("..." | Datatype()) ( (":" "="|<_DEFAULT>) Expression() )? ) @@ -1157,8 +1161,18 @@ ASTReadPastNextOccurrence ReadPastNextOccurrence(String target) : ASTSqlStatement SqlStatement(String initiator, String terminator) : {} { - ( + | + | + | + |{jjtThis.setType(ASTSqlStatement.Type.COMMIT); } + |{jjtThis.setType(ASTSqlStatement.Type.ROLLBACK); } + |{jjtThis.setType(ASTSqlStatement.Type.SAVEPOINT); } + |{jjtThis.setType(ASTSqlStatement.Type.SET_TRANSACTION); } + |{jjtThis.setType(ASTSqlStatement.Type.LOCK_TABLE); } + |{jjtThis.setType(ASTSqlStatement.Type.MERGE); } + |) + Skip2NextTerminator(initiator, terminator) { return jjtThis ; } @@ -2658,9 +2672,9 @@ ASTOpenStatement OpenStatement() : ASTFetchStatement FetchStatement() : {} { - QualifiedName() [ ] + QualifiedName() [ {jjtThis.setBulkCollect(true); }] //MMUE 04/08/2005 (LOOKAHEAD(functionCall()) functionCall() | QualifiedName()) ("," (LOOKAHEAD(functionCall()) functionCall() | QualifiedName()))* ";" - Expression() ("," Expression())* [ Expression()] + Expression() ("," Expression())* [ Expression(){jjtThis.setLimit(true);}] // { return jjtThis ; } } diff --git a/pmd-plsql/src/main/ant/alljavacc.xml b/pmd-plsql/src/main/ant/alljavacc.xml index d5c39fe95b..7136c123c9 100644 --- a/pmd-plsql/src/main/ant/alljavacc.xml +++ b/pmd-plsql/src/main/ant/alljavacc.xml @@ -48,6 +48,7 @@ + @@ -68,6 +69,7 @@ + diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTFetchStatement.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTFetchStatement.java new file mode 100644 index 0000000000..11a9e4b206 --- /dev/null +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTFetchStatement.java @@ -0,0 +1,44 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +/* Generated By:JJTree: Do not edit this line. ASTFetchStatement.java Version 4.3 */ +/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=true,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ + +package net.sourceforge.pmd.lang.plsql.ast; + +public class ASTFetchStatement extends AbstractPLSQLNode { + private boolean bulkcollect; + private boolean limit; + + public ASTFetchStatement(int id) { + super(id); + } + + public ASTFetchStatement(PLSQLParser p, int id) { + super(p, id); + } + + void setBulkCollect(boolean bulkcollect) { + this.bulkcollect = bulkcollect; + } + + public boolean isBulkCollect() { + return this.bulkcollect; + } + + void setLimit(boolean limit) { + this.limit = limit; + } + + public boolean isLimit() { + return this.limit; + } + + /** Accept the visitor. **/ + @Override + public Object jjtAccept(PLSQLParserVisitor visitor, Object data) { + return visitor.visit(this, data); + } +} +/* JavaCC - OriginalChecksum=21460142c066935e7922d1df0416d9ce (do not edit this line) */ diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTFormalParameter.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTFormalParameter.java index 6e1b60af58..9ee9074140 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTFormalParameter.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTFormalParameter.java @@ -8,6 +8,37 @@ package net.sourceforge.pmd.lang.plsql.ast; public class ASTFormalParameter extends net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNode { + + private boolean in; + + private boolean out; + + private boolean nocopy; + + public boolean isIn() { + return this.in; + } + + public void setIn(boolean in) { + this.in = in; + } + + public boolean isOut() { + return this.out; + } + + public void setOut(boolean out) { + this.out = out; + } + + public boolean isNoCopy() { + return this.nocopy; + } + + public void setNoCopy(boolean nocopy) { + this.nocopy = nocopy; + } + public ASTFormalParameter(int id) { super(id); } diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTSqlStatement.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTSqlStatement.java new file mode 100644 index 0000000000..daf66e932c --- /dev/null +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/ASTSqlStatement.java @@ -0,0 +1,38 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +/* Generated By:JJTree: Do not edit this line. ASTSqlStatement.java Version 4.3 */ +/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=true,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ + +package net.sourceforge.pmd.lang.plsql.ast; + +public class ASTSqlStatement extends AbstractPLSQLNode { + + private Type type; + + public enum Type { COMMIT, ROLLBACK, SAVEPOINT, SET_TRANSACTION, LOCK_TABLE, MERGE } + + public ASTSqlStatement(int id) { + super(id); + } + + public ASTSqlStatement(PLSQLParser p, int id) { + super(p, id); + } + + public void setType(Type type) { + this.type = type; + } + + public Type getType() { + return this.type; + } + + /** Accept the visitor. **/ + @Override + public Object jjtAccept(PLSQLParserVisitor visitor, Object data) { + return visitor.visit(this, data); + } +} +/* JavaCC - OriginalChecksum=e5c8185ea2733334069ae5313aec7b81 (do not edit this line) */ diff --git a/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/ast/InOutNoCopyTest.java b/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/ast/InOutNoCopyTest.java new file mode 100644 index 0000000000..c8915329c6 --- /dev/null +++ b/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/ast/InOutNoCopyTest.java @@ -0,0 +1,50 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.plsql.ast; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import net.sourceforge.pmd.lang.plsql.AbstractPLSQLParserTst; + +public class InOutNoCopyTest extends AbstractPLSQLParserTst { + + @Test + public void parseInOutNoCopy() { + ASTInput input = plsql.parseResource("InOutNoCopy.pls"); + Assert.assertNotNull(input); + List params = input.findDescendantsOfType(ASTFormalParameter.class); + Assert.assertEquals(18, params.size()); + //detailed check of first 6 test cases + Assert.assertFalse(params.get(0).isIn()); + Assert.assertFalse(params.get(0).isOut()); + Assert.assertFalse(params.get(0).isNoCopy()); + Assert.assertTrue(params.get(1).isIn()); + Assert.assertFalse(params.get(1).isOut()); + Assert.assertFalse(params.get(1).isNoCopy()); + Assert.assertFalse(params.get(2).isIn()); + Assert.assertTrue(params.get(2).isOut()); + Assert.assertFalse(params.get(2).isNoCopy()); + Assert.assertTrue(params.get(3).isIn()); + Assert.assertTrue(params.get(3).isOut()); + Assert.assertFalse(params.get(3).isNoCopy()); + Assert.assertTrue(params.get(4).isIn()); + Assert.assertTrue(params.get(4).isOut()); + Assert.assertTrue(params.get(4).isNoCopy()); + Assert.assertFalse(params.get(5).isIn()); + Assert.assertTrue(params.get(5).isOut()); + Assert.assertTrue(params.get(5).isNoCopy()); + //piecemeal test of other test cases + Assert.assertFalse(params.get(11).isIn()); + Assert.assertTrue(params.get(11).isOut()); + Assert.assertTrue(params.get(11).isNoCopy()); + Assert.assertTrue(params.get(16).isIn()); + Assert.assertTrue(params.get(16).isOut()); + Assert.assertTrue(params.get(16).isNoCopy()); + } + +} diff --git a/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/InOutNoCopy.pls b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/InOutNoCopy.pls new file mode 100644 index 0000000000..012e4b97bb --- /dev/null +++ b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/InOutNoCopy.pls @@ -0,0 +1,38 @@ +create or replace procedure InOutNoCopyTest(blankParam varchar2, + inParam in integer, + outParam out varchar2, + inOutParam in out date, + inOutNoCopyParam in out nocopy clob, + outNoCpyParam out nocopy blob) +is +begin + null; +end InOutNoCopyTest; +/ + +create or replace package InOutNoCopyTestPck is + + procedure InOutNoCopyTest(blankParam varchar2, + inParam in integer, + outParam out varchar2, + inOutParam in out date, + inOutNoCopyParam in out nocopy clob, + outNoCpyParam out nocopy blob); + +end InOutNoCopyTestPck; +/ + +create or replace package body InOutNoCopyTestPck is + + procedure InOutNoCopyTest(blankParam varchar2, + inParam in integer, + outParam out varchar2, + inOutParam in out date, + inOutNoCopyParam in out nocopy clob, + outNoCpyParam out nocopy blob) is + begin + null; + end; + +end InOutNoCopyTestPck; +/