[core] Add generic visitor interface in pmd-core#2589
Conversation
Replace SideEffectingVisitor with JavaVisitor The new visitor is generic. We don't actually need the old Object->Object visitor, this could just be the new generic visitor but erased Port language level checker Move delegators Remove old accept methods Remove reduced adapter Cleanup some visitor Make ant wrapper replace old visitor completely Doc Add DeprecatedUntil700 annotation Add top interface for visitors Convert JSP visitors Checkstyle Fix java module
Generated by 🚫 Danger |
There was a problem hiding this comment.
I like the idea, that we have one visitor.
You have now converted java, jsp and scala. Which languages are left? It seems, we need to convert modelica, plsql, visualforce, velocity. These should be done in individual PRs (this PR has already 300+ changed files!!)
While looking through the java changes, I'm wondering, whether we should better concentrate on finishing the java-grammar branch, rather than doing everything in parallel. What do you think?
These changes also seem to affect (as they actually define a new part - the visitors - of the language implementing API -> https://github.com/pmd/pmd/wiki/PMD-7.0.0-API#language-implementing-api) also the ANTLR languages now - as the build is failing with swift. Could you have a look at this? Thanks!
Oh, and, you only mentioned #880 as reference, but would this change actually implement/fix #880 ?
|
Thanks for the review!
Sorry about that, I thought porting the scala module would be easy given the visitor is already generic. My bad
I had started these changes on the java-grammar branch, but I think this kind of change is better on 7.0.x. It's MUCH harder to backport something from java-grammar to 7.0.x than the reverse. Changes that help with java-grammar, but ultimately need to affect all languages, are worth implementing on 7.0.x directly I think. This is the case for this change IMO. Other changes, like changing the Parser interface to allow passing a "semantic checks" logger would also be nice to finish java-grammar. And if implemented, language properties too, though this probably needs some time.
Done
This change commits to fixing it, but doesn't fix it entirely. Since there needs to be other PRs before this is completely done, maybe we can repurpose that issue into a to-do list. |
Part of #880
Describe the PR
Refine #1446 to be more useful
In the java module: remove SideEffectingVisitor, and adds a JavaVisitor interface with the following signature:
This visitor subsumes the existing
JavaParserVisitor, which now extendsJavaVisitor<Object, Object>, and alsoSideEffectingVisitor<T>, which can be writtenJavaVisitor<T, Void>now.Doing this means we can use a single
jjtAcceptimplementation per node, and it accepts both the new generic form, and the old JavaParserVisitor (which stays for compatibility).This PR also deprecates JavaParserVisitor and JavaParserVisitorAdapter, because they're redundant and unsafe (mostly, it's unclear whether null, or the
dataparameter should be returned).The same changes were done to the JSP module to check that the javacc wrapper is up to date & language-independent
In pmd-core, this adds
AstVisitor<P, R>, to be a supertype of language-specific visitor interfaces.<P, R> R acceptVisitor(AstVisitor,P)to the Node interface, which is the "language-independentjjtAccept".jjtAcceptmethods are deprecated on language-specific interfaces, so that only that single method is depended on.@DeprecatedUntil700to further distinguish among deprecated APIs on the 7.0.x branchRelated issues
Ready?
Other languages need to have their visitor generified in order to implement AstVisitor, which I guess we can do in one PR per module, later
./mvnw clean verifypasses (checked automatically by travis)