Skip to content

Commit

Permalink
Issue checkstyle#12641: removes code for the design profile
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Jan 15, 2023
1 parent 6748dba commit dc9c010
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2743,6 +2743,20 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck.java</fileName>
<specifier>initialization.field.uninitialized</specifier>
<message>the default constructor does not initialize field ignoreAnnotationShortNames</message>
<lineContent>private Set&lt;String&gt; ignoreAnnotationShortNames;</lineContent>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck.java</fileName>
<specifier>initialization.field.uninitialized</specifier>
<message>the default constructor does not initialize field immutableClassShortNames</message>
<lineContent>private Set&lt;String&gt; immutableClassShortNames;</lineContent>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck.java</fileName>
<specifier>return</specifier>
Expand Down
126 changes: 0 additions & 126 deletions config/pitest-suppressions/pitest-design-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
<lineContent>packageName = &quot;&quot;;</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>FinalClassCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck</mutatedClass>
<mutatedMethod>visitToken</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to java/util/Deque::size</description>
<lineContent>extractQualifiedTypeName(ast), typeDeclarations.size(), ast);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>FinalClassCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck</mutatedClass>
Expand All @@ -36,51 +27,6 @@
<lineContent>throw new IllegalStateException(ast.toString());</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>HideUtilityClassConstructorCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck$Details</mutatedClass>
<mutatedMethod>invoke</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable hasNonPrivateStaticMethodOrField</description>
<lineContent>hasNonPrivateStaticMethodOrField = false;</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>HideUtilityClassConstructorCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck$Details</mutatedClass>
<mutatedMethod>invoke</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable hasNonStaticMethodOrField</description>
<lineContent>hasNonStaticMethodOrField = false;</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>HideUtilityClassConstructorCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck$Details</mutatedClass>
<mutatedMethod>invoke</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable hasPublicCtor</description>
<lineContent>hasPublicCtor = false;</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>InnerTypeLastCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.InnerTypeLastCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable rootClass</description>
<lineContent>private boolean rootClass = true;</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>InnerTypeLastCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.InnerTypeLastCheck</mutatedClass>
<mutatedMethod>visitToken</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/api/DetailAST::getNextSibling with receiver</description>
<lineContent>DetailAST nextSibling = ast.getNextSibling();</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>MutableExceptionCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.MutableExceptionCheck</mutatedClass>
Expand All @@ -99,60 +45,6 @@
<lineContent>child = child.getNextSibling();</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck::getClassShortNames</description>
<lineContent>getClassShortNames(DEFAULT_IGNORE_ANNOTATIONS);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck::getClassShortNames with argument</description>
<lineContent>getClassShortNames(DEFAULT_IGNORE_ANNOTATIONS);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable ignoreAnnotationShortNames</description>
<lineContent>getClassShortNames(DEFAULT_IGNORE_ANNOTATIONS);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck::getClassShortNames</description>
<lineContent>getClassShortNames(DEFAULT_IMMUTABLE_TYPES);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck::getClassShortNames with argument</description>
<lineContent>getClassShortNames(DEFAULT_IMMUTABLE_TYPES);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable immutableClassShortNames</description>
<lineContent>getClassShortNames(DEFAULT_IMMUTABLE_TYPES);</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
Expand All @@ -161,22 +53,4 @@
<description>removed call to com/puppycrawl/tools/checkstyle/api/DetailAST::getNextSibling</description>
<lineContent>child != null; child = child.getNextSibling()) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
<mutatedMethod>getCanonicalName</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/api/DetailAST::getFirstChild with receiver</description>
<lineContent>DetailAST toVisit = type.getFirstChild();</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>VisibilityModifierCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</mutatedClass>
<mutatedMethod>visitImport</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/api/DetailAST::getFirstChild with receiver</description>
<lineContent>final DetailAST type = importAst.getFirstChild();</lineContent>
</mutation>
</suppressedMutations>
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void visitToken(DetailAST ast) {
case TokenTypes.INTERFACE_DEF:
case TokenTypes.RECORD_DEF:
final TypeDeclarationDescription description = new TypeDeclarationDescription(
extractQualifiedTypeName(ast), typeDeclarations.size(), ast);
extractQualifiedTypeName(ast), 0, ast);
typeDeclarations.push(description);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,7 @@ public boolean isHasPublicCtor() {
*/
public void invoke() {
final DetailAST objBlock = ast.findFirstToken(TokenTypes.OBJBLOCK);
hasNonStaticMethodOrField = false;
hasNonPrivateStaticMethodOrField = false;
hasDefaultCtor = true;
hasPublicCtor = false;
DetailAST child = objBlock.getFirstChild();

while (child != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class InnerTypeLastCheck extends AbstractCheck {
);

/** Meet a root class. */
private boolean rootClass = true;
private boolean rootClass;

@Override
public int[] getDefaultTokens() {
Expand Down Expand Up @@ -127,7 +127,7 @@ public void visitToken(DetailAST ast) {
rootClass = false;
}
else {
DetailAST nextSibling = ast.getNextSibling();
DetailAST nextSibling = ast;
while (nextSibling != null) {
if (!ScopeUtil.isInCodeBlock(ast)
&& CLASS_MEMBER_TOKENS.get(nextSibling.getType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,10 @@ public class VisibilityModifierCheck
private Pattern publicMemberPattern = Pattern.compile("^serialVersionUID$");

/** Set of ignore annotations short names. */
private Set<String> ignoreAnnotationShortNames =
getClassShortNames(DEFAULT_IGNORE_ANNOTATIONS);
private Set<String> ignoreAnnotationShortNames;

/** Set of immutable classes short names. */
private Set<String> immutableClassShortNames =
getClassShortNames(DEFAULT_IMMUTABLE_TYPES);
private Set<String> immutableClassShortNames;

/**
* Specify annotations canonical names which ignore variables in
Expand Down Expand Up @@ -661,8 +659,7 @@ private boolean hasIgnoreAnnotation(DetailAST variableDef) {
*/
private void visitImport(DetailAST importAst) {
if (!isStarImport(importAst)) {
final DetailAST type = importAst.getFirstChild();
final String canonicalName = getCanonicalName(type);
final String canonicalName = getCanonicalName(importAst);
final String shortName = getClassShortName(canonicalName);

// If imported canonical class name is not specified as allowed immutable class,
Expand Down Expand Up @@ -825,7 +822,7 @@ private boolean isImmutableField(DetailAST variableDef) {
if (isFinalField(variableDef)) {
final DetailAST type = variableDef.findFirstToken(TokenTypes.TYPE);
final boolean isCanonicalName = isCanonicalName(type);
final String typeName = getTypeName(type, isCanonicalName);
final String typeName = getCanonicalName(type);
if (immutableClassShortNames.contains(typeName)
|| isCanonicalName && immutableClassCanonicalNames.contains(typeName)) {
final DetailAST typeArgs = getGenericTypeArgs(type, isCanonicalName);
Expand Down Expand Up @@ -885,8 +882,7 @@ private static List<String> getTypeArgsClassNames(DetailAST typeArgs) {
DetailAST type = typeArgs.findFirstToken(TokenTypes.TYPE_ARGUMENT);
DetailAST sibling;
do {
final boolean isCanonicalName = isCanonicalName(type);
final String typeName = getTypeName(type, isCanonicalName);
final String typeName = getCanonicalName(type);
typeClassNames.add(typeName);
sibling = type.getNextSibling();
type = sibling.getNextSibling();
Expand Down Expand Up @@ -921,26 +917,6 @@ private static boolean isFinalField(DetailAST variableDef) {
return modifiers.findFirstToken(TokenTypes.FINAL) != null;
}

/**
* Gets the name of type from given ast {@link TokenTypes#TYPE TYPE} node.
* If type is specified via its canonical name - canonical name will be returned,
* else - short type's name.
*
* @param type {@link TokenTypes#TYPE TYPE} node.
* @param isCanonicalName is given name canonical.
* @return String representation of given type's name.
*/
private static String getTypeName(DetailAST type, boolean isCanonicalName) {
final String typeName;
if (isCanonicalName) {
typeName = getCanonicalName(type);
}
else {
typeName = type.getFirstChild().getText();
}
return typeName;
}

/**
* Checks if current type is primitive type (int, short, float, boolean, double, etc.).
* As primitive types have special tokens for each one, such as:
Expand All @@ -963,7 +939,7 @@ private static boolean isPrimitive(DetailAST type) {
*/
private static String getCanonicalName(DetailAST type) {
final StringBuilder canonicalNameBuilder = new StringBuilder(256);
DetailAST toVisit = type.getFirstChild();
DetailAST toVisit = type;
while (toVisit != null) {
toVisit = getNextSubTreeNode(toVisit, type);
if (toVisit != null && toVisit.getType() == TokenTypes.IDENT) {
Expand Down

0 comments on commit dc9c010

Please sign in to comment.