Skip to content

[core] Add generic visitor interface in pmd-core#2589

Merged
adangel merged 14 commits into
pmd:pmd/7.0.xfrom
oowekyala:generic-visitor2
Jul 19, 2020
Merged

[core] Add generic visitor interface in pmd-core#2589
adangel merged 14 commits into
pmd:pmd/7.0.xfrom
oowekyala:generic-visitor2

Conversation

@oowekyala

@oowekyala oowekyala commented Jun 14, 2020

Copy link
Copy Markdown
Member

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:

public interface JavaVisitor<P, R> extends ... {
  R visit(JavaNode node, P param);
}

This visitor subsumes the existing JavaParserVisitor, which now extends JavaVisitor<Object, Object>, and also SideEffectingVisitor<T>, which can be written JavaVisitor<T, Void> now.

Doing this means we can use a single jjtAccept implementation 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 data parameter 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

  • an interface AstVisitor<P, R>, to be a supertype of language-specific visitor interfaces.
  • a method <P, R> R acceptVisitor(AstVisitor,P) to the Node interface, which is the "language-independent jjtAccept". jjtAccept methods are deprecated on language-specific interfaces, so that only that single method is depended on.
  • an annotation @DeprecatedUntil700 to further distinguish among deprecated APIs on the 7.0.x branch

Related 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

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by travis)
  • Added (in-code) documentation (if needed)

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
@oowekyala oowekyala added the in:ast About the AST structure or API, the parsing step label Jun 14, 2020
@oowekyala oowekyala added this to the 7.0.0 milestone Jun 14, 2020
@oowekyala oowekyala changed the title Add generic visitor interface in pmd-core [core] Add generic visitor interface in pmd-core Jun 14, 2020
@ghost

ghost commented Jun 15, 2020

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

oowekyala added a commit to oowekyala/pmd that referenced this pull request Jun 17, 2020
@adangel adangel self-requested a review June 20, 2020 13:16

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Comment thread javacc-wrapper.xml Outdated
Comment thread javacc-wrapper.xml
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java Outdated
Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java Outdated
@adangel adangel added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Jun 30, 2020
@oowekyala

Copy link
Copy Markdown
Member Author

Thanks for the review!

These should be done in individual PRs (this PR has already 300+ changed files!!)

Sorry about that, I thought porting the scala module would be easy given the visitor is already generic. My bad

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?

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.

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!

Done

Oh, and, you only mentioned #880 as reference, but would this change actually implement/fix #880 ?

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.

@oowekyala oowekyala mentioned this pull request Jul 1, 2020
10 tasks
@adangel adangel removed the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Jul 19, 2020
@adangel adangel self-assigned this Jul 19, 2020
@adangel adangel merged commit a9996ab into pmd:pmd/7.0.x Jul 19, 2020
@oowekyala oowekyala deleted the generic-visitor2 branch July 19, 2020 17:59
@oowekyala oowekyala mentioned this pull request Aug 5, 2020
4 tasks
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in:ast About the AST structure or API, the parsing step

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants