Skip to content

PMD-3546925 PLSQL Language for PMD - #1

Merged
adangel merged 5 commits into
pmd:masterfrom
sturton:master
Jan 1, 2014
Merged

adangel merged 5 commits into
pmd:masterfrom
sturton:master

Conversation

@sturton

@sturton sturton commented Jul 23, 2012

Copy link
Copy Markdown
Contributor

Patch to:-
add Oracle PL/SQL language to PMD languages
add PL/SQL as an option to CPD

AST is derived from PLDoc parser (pldoc.sourceforge.net) 1.3.2.

The AST also covers a subset of SQL*Plus.

@ryan-gustafson

Copy link
Copy Markdown
Contributor

This integration basically dumps a fully independent JavaCC lexer into the PMD packages, but fails to (a) integrate is as a PMD Language with a LanguageVersionHandler, or (b) use the PMD common JavaCC classes.

I was going to see if I could clean up this up quickly, but I can't. The grammar is not included in the commit. This is required to maintain the code and do (b) above. It should be in the /etc/grammar directory, along with corresponding modifications to /src/main/ant/alljavacc.xml. Look very closely at how the C++ language is integrated. The PLSQL would be essentially the same.

Feel free to take a stab at this, otherwise include the grammar and I'll see when I can get to it next.

@sturton

sturton commented Aug 25, 2012

Copy link
Copy Markdown
Contributor Author

Nothing about the PL/SQL parser is quick :-( - (most of the keywords in PL/SQL are not reserved words and infrequent or edges cases have increased the parser generation time from about 3 minutes to 90 minutes.

As an example FUNCTION can be a keyword or a variable, parameter, or database table or column name.

The PL/SQL parser also combines the wonders of mixed Pl/SQL, SQL*Plus, SQL DML (SELECT,INSERT,UPDATE,DELETE.MERGE) and DDL (CREATE and DROP, etc.).

The committed code is the simplest translation of the JavaCC compiler to a JJTree equivalent, and is of immediate use for CPD.

The grammar has been committed under /etc/grammar (sturton/pmd on github).

2 versions have been committed: the first version equates to the non-Visitor version used to generate the CPD tokenizer and the second version is modified to allow the Visitor pattern and return a terminal object.

Playing with the resultant java classes, it seemed as if some of the PMD applications were Java language specific: as an example the ViewerModel class (used in bgastviewer) references the Java terminal object (ASTCompilationUnit) explicitly.

[
Modifications to the generated PLSQL AST classes (to extend from net.sourceforge.pmd.lang.ast interfaces and classes )
and altering PMD classes to reference net.sourceforge.pmd.lang.ast allowed me to get bgastviewer working
]

"
diff /Users/sturton/Development/pmd.git/pmd/src/main/java/net/sourceforge/pmd/util/viewer/model/ViewerModel.java /Users/sturton/Development/pmd-visitor.git/pmd/src/main/java/net/sourceforge/pmd/util/viewer/model/ViewerModel.java
11,12c11,13
< import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;

< import net.sourceforge.pmd.lang.java.ast.ParseException;

//import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
//import net.sourceforge.pmd.lang.java.ast.ParseException;
import net.sourceforge.pmd.lang.ast.ParseException;
38c39

< ASTCompilationUnit compilationUnit = (ASTCompilationUnit) languageVersionHandler

Node node = languageVersionHandler
40c41

< rootNode = compilationUnit;

rootNode = node;
59a61,62
System.err.println("SRT: xPath="+xPath);
System.err.println("SRT: evaluator="+evaluator);
60a64,65
System.err.println("SRT: xpath="+xpath);
System.err.println("SRT: rootNode="+rootNode);
61a67
System.err.println("SRT: evaluationResults="+evaluationResults);
stumacbook:pmd sturton$

"

On 25 Aug 2012, at 09:44, ryan-gustafson [email protected] wrote:

This integration basically dumps a fully independent JavaCC lexer into the PMD packages, but fails to (a) integrate is as a PMD Language with a LanguageVersionHandler, or (b) use the PMD common JavaCC classes.

I was going to see if I could clean up this up quickly, but I can't. The grammar is not included in the commit. This is required to maintain the code and do (b) above. It should be in the /etc/grammar directory, along with corresponding modifications to /src/main/ant/alljavacc.xml. Look very closely at how the C++ language is integrated. The PLSQL would be essentially the same.

Feel free to take a stab at this, otherwise include the grammar and I'll see when I can get to it next.

—
Reply to this email directly or view it on GitHub.

@ryan-gustafson

Copy link
Copy Markdown
Contributor

Unless you want to write PMD Rules and thus need the AST, or the tree/lexer portions of the grammar are horribly intertwined, my guess is you could remove all tree portions from the grammar, and convert this to a .jj instead of a .jjt. That's what is done for C++, it's just a lexer, no tree building (look in the lang.cpp.ast package). As is, the AST produced is utterly useless for visiting, all nodes are of the same type. It needs to go solidly one way or the other (lexer or lexer+tree), the SimpleNode partial approach isn't acceptable.

I think the Viewer is dead code (just not yet removed), the Designer is what you should be using, and it's fully dynamic to support any AST producing Language. Which if you drop AST support becomes a non-issue.

The manual mods to generated code are unnecessary, this should all be automated via Ant scripts, per my prior comment. I can get his working if we make a decision on whether we are lexing or building trees.

I thought I recall Romain commenting on licensing before (LGPL). Has that been resolved?

@sturton

sturton commented Aug 26, 2012

Copy link
Copy Markdown
Contributor Author

On 26 Aug 2012, at 10:43, ryan-gustafson [email protected] wrote:

Unless you want to write PMD Rules and thus need the AST, or the tree/lexer portions of the grammar are horribly intertwined, my guess is you could remove all tree portions from the grammar, and convert this to a .jj instead of a .jjt. That's what is done for C++, it's just a lexer, no tree building (look in the lang.cpp.ast package). As is, the AST produced is utterly useless for visiting, all nodes are of the same type. It needs to go solidly one way or the other (lexer or lexer+tree), the SimpleNode partial approach isn't acceptable.

My aspiration is to allow the greatest possible PMD functionality (rules, dead code detection etc.); one of the problems with PL/SQL are that there are few free code quality tools. TOAD and Sonar have paid versions, but that generally means thet the "DBA" has a copy and might or might not run some code quality checks.

[
We PL/SQL developers need all of the help we can get.

when others then null - The Tom Kyte Blog - Yes
http://oracle-wtf.blogspot.co.uk

]

The other benefit that I want to get out of this integration is the tree generator/Visitor combination itself, for use by anyone who thinks of a use for a functional PLSQL AST.

Without full PMD integration there is little benefit of extending beyond the PLDoc/CPD hybrids that I cobbled together:- http://pldoc.sourceforge.net/maven-site/pldoc-cpd/ and http://pldoc.sourceforge.net/maven-site/maven-cpd-plugin/index.html.

Of the 2 committed versions of PldocAST.jjt, the committed classes relate to the original (CPD only version): the separate classes have been generated but were not committed into my PMD sourcetree because I wanted to keep the Visitor implementation uncommitted until I had a working Designer (or at least a working Viewer) implementation.

I will commit the (separate) classes generated by the Visitor version.

I think the Viewer is dead code (just not yet removed), the Designer is what you should be using, and it's fully dynamic to support any AST producing Language. Which if you drop AST support becomes a non-issue.

I started with Viewer because Viewer seemed a waypoint to full integration, requiring fewer changes and so giving me a better idea of the PLSQL AST changes needed for integration

The manual mods to generated code are unnecessary, this should all be automated via Ant scripts, per my prior comment. I can get his working if we make a decision on whether we are lexing or building trees.

I thought I recall Romain commenting on licensing before (LGPL). Has that been resolved?

I emailed the PLDoc project manager (Albert Tumanov in the copyright assertions in the original PLSQL.jj file) and he is in favour of code reuse - he basically said "Tell me what you me to write and I' write it".

I don't know whether Albert has managed to get around to responding.

—
Reply to this email directly or view it on GitHub.

@sturton

sturton commented Aug 26, 2012

Copy link
Copy Markdown
Contributor Author

The AST* classes are committed to sturton/pmd, replacing the old CPD only classes.

I'm in the middle of cribbing the classes required from the Java language to get the PLSQL Scope classes.

The main problems are that the important productions are missing from the PLDoc .jjt file.

ASTMethodDeclarator
ASTVariableDeclaratorId

On 25 Aug 2012, at 09:44, ryan-gustafson [email protected] wrote:

This integration basically dumps a fully independent JavaCC lexer into the PMD packages, but fails to (a) integrate is as a PMD Language with a LanguageVersionHandler, or (b) use the PMD common JavaCC classes.

I was going to see if I could clean up this up quickly, but I can't. The grammar is not included in the commit. This is required to maintain the code and do (b) above. It should be in the /etc/grammar directory, along with corresponding modifications to /src/main/ant/alljavacc.xml. Look very closely at how the C++ language is integrated. The PLSQL would be essentially the same.

Feel free to take a stab at this, otherwise include the grammar and I'll see when I can get to it next.

—
Reply to this email directly or view it on GitHub.

@sturton

sturton commented Oct 2, 2012

Copy link
Copy Markdown
Contributor Author

Status report (sturton/pmd committed at github)
PLSQL AST modifications:-

productions amended to copy Java productions as much possible
productions return the correct type rather than just SimpleNode ()
begin and end line and column values set for each node

Designer class copied as PLSQLDesigner (because the Designer class imports Java specific classes); and these seem to be functioning
AST pane
Symbol
XPath search and search results
Rule generation

Not yet attempted:
DataFlowFacade and DataFlowHandler
TypeResolutionFacade

On 26 Aug 2012, at 10:43, ryan-gustafson [email protected] wrote:

Unless you want to write PMD Rules and thus need the AST, or the tree/lexer portions of the grammar are horribly intertwined, my guess is you could remove all tree portions from the grammar, and convert this to a .jj instead of a .jjt. That's what is done for C++, it's just a lexer, no tree building (look in the lang.cpp.ast package). As is, the AST produced is utterly useless for visiting, all nodes are of the same type. It needs to go solidly one way or the other (lexer or lexer+tree), the SimpleNode partial approach isn't acceptable.

I think the Viewer is dead code (just not yet removed), the Designer is what you should be using, and it's fully dynamic to support any AST producing Language. Which if you drop AST support becomes a non-issue.

The manual mods to generated code are unnecessary, this should all be automated via Ant scripts, per my prior comment. I can get his working if we make a decision on whether we are lexing or building trees.

I thought I recall Romain commenting on licensing before (LGPL). Has that been resolved?

—
Reply to this email directly or view it on GitHub.

@sturton

sturton commented Oct 2, 2012

Copy link
Copy Markdown
Contributor Author

Test Rule

"


"WHEN OTHERS THEN NULL" hides all errors - (Re)RAISE an exception or call RAISE_APPLICATION_ERROR



</value>
</property>
3 PROCEDURE set_new_planned (p_emp_id IN NUMBER, p_project_id IN NUMBER, p_hours IN NUMBER)
IS
BEGIN
UPDATE employee_on_activity ea
SET ea.ea_planned_hours = p_hours
WHERE
ea.ea_emp_id = p_emp_id
AND ea.ea_proj_id = p_project_id;

EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20100, 'No such employee or project');

END set_new_planned;

FUNCTION existing_planned (p_emp_id IN NUMBER, p_project_id IN NUMBER) RETURN NUMBER

IS

existing_hours NUMBER(4);

BEGIN
SELECT ea.ea_planned_hours INTO existing_hours
FROM employee_on_activity ea
WHERE
ea.ea_emp_id = p_emp_id
AND ea.ea_proj_id = p_project_id;

RETURN (existing_hours);

EXCEPTION
WHEN OTHERS THEN NULL;

END existing_planned;

END update_planned_hrs;
/
]]>

"
On 26 Aug 2012, at 10:43, ryan-gustafson [email protected] wrote:

Unless you want to write PMD Rules and thus need the AST, or the tree/lexer portions of the grammar are horribly intertwined, my guess is you could remove all tree portions from the grammar, and convert this to a .jj instead of a .jjt. That's what is done for C++, it's just a lexer, no tree building (look in the lang.cpp.ast package). As is, the AST produced is utterly useless for visiting, all nodes are of the same type. It needs to go solidly one way or the other (lexer or lexer+tree), the SimpleNode partial approach isn't acceptable.

I think the Viewer is dead code (just not yet removed), the Designer is what you should be using, and it's fully dynamic to support any AST producing Language. Which if you drop AST support becomes a non-issue.

The manual mods to generated code are unnecessary, this should all be automated via Ant scripts, per my prior comment. I can get his working if we make a decision on whether we are lexing or building trees.

I thought I recall Romain commenting on licensing before (LGPL). Has that been resolved?

—
Reply to this email directly or view it on GitHub.

@buildhive

Copy link
Copy Markdown

PMD » pmd #3 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #4 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #5 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #7 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #8 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #9 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #12 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #14 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #15 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #16 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #17 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #18 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #22 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #23 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #24 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #5 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #6 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #7 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #8 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #9 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #10 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #11 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #12 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #121 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #125 SUCCESS
This pull request looks good
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #126 SUCCESS
This pull request looks good
(what's this?)

@buildhive

Copy link
Copy Markdown

PMD » pmd #151 FAILURE
Looks like there's a problem with this pull request
(what's this?)

This was referenced Dec 22, 2013
@adangel
adangel merged commit e9d7ddd into pmd:master Jan 1, 2014
@adangel

adangel commented Jan 1, 2014

Copy link
Copy Markdown
Member

Many thanks again for the effort you have put into this - and sorry again, that it took so long. It's now finally merged into the core PMD codebase.
Also, the rules can be seen here: http://pmd.sourceforge.net/snapshot/rules/plsql/codesize.html

@sturton

sturton commented Jan 1, 2014

Copy link
Copy Markdown
Contributor Author

I'm just glad to contribute: I had experience with PLDoc's PLSQL parser and owned Tom Copeland's book, and it seemed easier/more efficient to add PLSQL into PMD, rather than to extend PLDoc with code metrics.

I know that the PLDoc project owner (Albert Tumanov) was also happy that work on PLDoc was useful outside the project.

Hopefully the work that you put into making PMD more language agnostic, will prompt more people to add languages.

jsotuyod pushed a commit that referenced this pull request Apr 8, 2018
jsotuyod pushed a commit that referenced this pull request Apr 23, 2018
adangel pushed a commit that referenced this pull request May 16, 2018
adangel pushed a commit that referenced this pull request Dec 7, 2018
adangel pushed a commit that referenced this pull request Apr 30, 2020
oowekyala pushed a commit that referenced this pull request Sep 6, 2020
adangel pushed a commit that referenced this pull request Mar 26, 2021
Add support lexical parameters in SQL*Plus scripts, allow excluding lines which the parser does not understand.
adangel pushed a commit that referenced this pull request May 12, 2023
@ghost ghost mentioned this pull request Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants