Skip to content

[cs] Added option to exclude C# using directives from CPD analysis #25

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

Merged
merged 2 commits into from
Oct 26, 2015

Conversation

tiobe
Copy link

@tiobe tiobe commented Oct 23, 2015

Some of our customers complained that their duplicated code was to high because because a lot of files have duplicate using directives. For example:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Serialization;
using CommandLine;
using CommandLine.Text;

namespace TIOBE.TICS.CIL.Static.CmdLine

This duplicates cannot be prevented, because each file needs to specify its dependencies, so the 'using' directives should be ignored during duplicated code analysis. To fix this I added a option called 'ignore_usings' to the CPD CS tokenizer, which can be added by specifying the following system property on the CPD command line: '-Dignore_usings=true'.

As you can see in the diff, the 'using' directive tokens are not omitted from the token stream but replaced by a random token. This is done to prevent that we get duplication blocks that spans over the using directives. (Starts before and end afterwards.)

As you can see this pull request also contains an older commit of us. ('Extended Objective-C grammar to accept Unicode characters in identifiers' ) This commit was already merged in the 'pmd/5.4.x' branch, but unfortunately we cannot upgrade to PMD 5.4 because a lot of our customers still use Java 1.6.

If both commit are merged and released in PMD 5.3, we can use an official PMD release again instead of our own builds. Please let me know if there are changes needed before this pull request can be accepted.

Jan van Nunen added 2 commits October 23, 2015 15:46
…ysis.

To exclude C# using directives the system property 'ignore_usings=true' has to be specified on the command line with '-Dignore_usings=true'.
@buildhive
Copy link

Andreas Dangel » pmd #341 SUCCESS
This pull request looks good
(what's this?)

@adangel adangel merged commit 7be198a into adangel:pmd/5.3.x Oct 26, 2015
@adangel
Copy link
Owner

adangel commented Oct 26, 2015

Thanks for the PR.
I've extended it to have the new option "ignoreUsings" available as a commandline option, in the CPD Ant task and in the CPD GUI.

adangel pushed a commit that referenced this pull request Apr 10, 2016
@adangel adangel changed the title Added option to exclude C# using directives from CPD analysis [cs] Added option to exclude C# using directives from CPD analysis Jun 25, 2016
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.

3 participants