-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34422: Combined 'skip sequences'-related flags
The --ignore-sequences option now optionally takes an argument specifying which 'ignore sequence' strategies should be applied. Multiple strategies can be enabled by providing the option multiple times. The existing behavior of --ignore-sequences without a parameter (defaulting to 'ignore literal and identifier sequences') and --ignore-literal-sequences is preserved.
- Loading branch information
1 parent
441e91c
commit e15bffe
Showing
13 changed files
with
256 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/CpdIgnoreTypeSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
package net.sourceforge.pmd.cli.commands.typesupport.internal; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
|
||
import net.sourceforge.pmd.cpd.CPDSequenceIgnoreType; | ||
|
||
import picocli.CommandLine.ITypeConverter; | ||
import picocli.CommandLine.TypeConversionException; | ||
|
||
public class CpdIgnoreTypeSupport implements ITypeConverter<CPDSequenceIgnoreType>, Iterable<String> { | ||
|
||
@Override | ||
public Iterator<String> iterator() { | ||
return Arrays.stream(CPDSequenceIgnoreType.values()).map(CPDSequenceIgnoreType::getName).iterator(); | ||
} | ||
|
||
@Override | ||
public CPDSequenceIgnoreType convert(String s) { | ||
return Arrays.stream(CPDSequenceIgnoreType.values()) | ||
.filter(t -> t.getName().equalsIgnoreCase(s)) | ||
.findFirst() | ||
.orElseThrow(() -> new TypeConversionException("Invalid ignore option: " + s)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDSequenceIgnoreSetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
package net.sourceforge.pmd.cpd; | ||
|
||
public class CPDSequenceIgnoreSetting { | ||
private int setting = 0; | ||
|
||
public void setValue(CPDSequenceIgnoreType type, boolean value) { | ||
int index = type.ordinal(); | ||
if (value) { | ||
setting |= (1 << index); | ||
} else { | ||
setting &= ~(1 << index); | ||
} | ||
} | ||
|
||
public boolean getValue(CPDSequenceIgnoreType type) { | ||
return (setting & (1 << type.ordinal())) != 0; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDSequenceIgnoreType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
package net.sourceforge.pmd.cpd; | ||
|
||
/** | ||
* Options for skipping/ignoring tokens in CPD | ||
*/ | ||
public enum CPDSequenceIgnoreType { | ||
LITERALS("literals"), | ||
LITERALS_IDENTIFIERS("literals-identifiers"), | ||
INITIALIZATIONS("initializations"); | ||
|
||
private final String name; | ||
|
||
CPDSequenceIgnoreType(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.