Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cs] CPD: Replace C# tokenizer by an Antlr-based one #2280

Merged
merged 3 commits into from
Feb 29, 2020

Conversation

maikelsteneker
Copy link
Contributor

@maikelsteneker maikelsteneker commented Feb 12, 2020

Before submitting a PR, please check that:

  • The PR is submitted against master. The PMD team will merge back to support branches as needed.
  • ./mvnw clean verify passes. This will build and test PMD, execute PMD and checkstyle rules. Check this for more info

PR Description:
This replaces the C# tokenizer by one based on Antlr, in line to how it's done for many other languages already.

This has a couple of advantages, including adding column information and fixing #2139

In order to correctly filter using directives as the previous tokenizer did, I had to extend the BaseTokenFilter class. Existing subclasses should not be impacted by this, but the new functionality might be useful for other languages as well.

Fixes #2139

When filtering tokens, the analyzeToken method can be overriden to access the current token. This can then be used to implement isLanguageSpecificDiscarding. However, it may be desirable to "look ahead" and base the decision of whether to filter or not on multiple tokens. In order to support this new use case, a new extension point analyzeTokens is provided, which not only has access to the current token, but can also iterate over the upcoming tokens.

The functionality of iterating over remaining tokens uses Guava for its implementation. Since pmd-core targets Java 7, the Android flavour of Guava is used. In order to stay consistent with pmd-apex-jorje, this has also been adjusted to the Android flavour. For PMD 7.0, the jre flavour can be used instead.
This is based on the Antlr grammar from https://github.com/antlr/grammars-v4/tree/master/csharp.

This adds column information for C# and fixes pmd#2139.
@pmd-test
Copy link

pmd-test commented Feb 12, 2020

1 Message
📖 This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@adangel adangel changed the title [C#][cpd] Replace C# tokenizer by an Antlr-based one [cs] CPD: Replace C# tokenizer by an Antlr-based one Feb 13, 2020
Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

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

Thanks, the seems to improve C# a lot.

However, I'm especially unsure about the licensing - see the comment.

pmd-apex-jorje/pom.xml Outdated Show resolved Hide resolved
pmd-core/pom.xml Outdated Show resolved Hide resolved
@adangel adangel added this to the 6.22.0 milestone Feb 29, 2020
Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

[cs] CPD doesn't understand alternate using statement syntax with C# 8.0
5 participants