Skip to content

Issue #13501: Kill mutation for MissingJavadocMethodCheck2#13561

Merged
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:MissingJavadocMethodCheck2
Aug 31, 2023
Merged

Issue #13501: Kill mutation for MissingJavadocMethodCheck2#13561
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:MissingJavadocMethodCheck2

Conversation

@Kevin222004
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 commented Aug 17, 2023

Issue #13501: Kill mutation for MissingJavadocMethodCheck2


Check :-

https://checkstyle.org/checks/javadoc/missingjavadocmethod.html#MissingJavadocMethod


Mutation

<mutation unstable="false">
<sourceFile>MissingJavadocMethodCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck</mutatedClass>
<mutatedMethod>isContentsAllowMissingJavadoc</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE</mutator>
<description>removed conditional - replaced equality check with false</description>
<lineContent>return (ast.getType() == TokenTypes.METHOD_DEF</lineContent>
</mutation>
<mutation unstable="false">
<sourceFile>MissingJavadocMethodCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck</mutatedClass>
<mutatedMethod>isContentsAllowMissingJavadoc</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF</mutator>
<description>removed conditional - replaced equality check with true</description>
<lineContent>|| ast.getType() == TokenTypes.COMPACT_CTOR_DEF)</lineContent>
</mutation>
<mutation unstable="false">
<sourceFile>MissingJavadocMethodCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck</mutatedClass>
<mutatedMethod>isContentsAllowMissingJavadoc</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE</mutator>
<description>removed conditional - replaced equality check with false</description>
<lineContent>|| ast.getType() == TokenTypes.CTOR_DEF</lineContent>
</mutation>
<mutation unstable="false">
<sourceFile>MissingJavadocMethodCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck</mutatedClass>
<mutatedMethod>shouldCheck</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF</mutator>
<description>removed conditional - replaced equality check with true</description>
<lineContent>return (excludeScope == null</lineContent>
</mutation>


Explaination

private boolean isContentsAllowMissingJavadoc(DetailAST ast) {
return (ast.getType() == TokenTypes.METHOD_DEF
|| ast.getType() == TokenTypes.CTOR_DEF
|| ast.getType() == TokenTypes.COMPACT_CTOR_DEF)
&& (getMethodsNumberOfLine(ast) <= minLineCount
|| AnnotationUtil.containsAnnotation(ast, allowedAnnotations));
}

In this all the ast.getType == .. are use less because they are the only tokens which is accepted so any token is going to be one of them because this method is called by
private boolean isMissingJavadocAllowed(final DetailAST ast) {
return allowMissingPropertyJavadoc
&& (CheckUtil.isSetterMethod(ast) || CheckUtil.isGetterMethod(ast))
|| matchesSkipRegex(ast)
|| isContentsAllowMissingJavadoc(ast);
}

in which the ast is not modified and this method is called by visitToken
public final void visitToken(DetailAST ast) {
final Scope theScope = ScopeUtil.getScope(ast);
if (shouldCheck(ast, theScope)) {
final FileContents contents = getFileContents();
final TextBlock textBlock = contents.getJavadocBefore(ast.getLineNo());
if (textBlock == null && !isMissingJavadocAllowed(ast)) {
log(ast, MSG_JAVADOC_MISSING);
}

where ast is not changing.

Second

private boolean shouldCheck(final DetailAST ast, final Scope nodeScope) {
final Scope surroundingScope = ScopeUtil.getSurroundingScope(ast);
return (excludeScope == null
|| nodeScope != excludeScope
&& surroundingScope != excludeScope)
&& nodeScope.isIn(scope)
&& surroundingScope.isIn(scope);
}

exclude == null is also useless it is accepting both null and not null if it is not null then we have condition of that in logical Operators that's exclude == null is useless


Regression

Report-1 :-

Report-2 :-


Diff Regression config: https://gist.githubusercontent.com/Kevin222004/e68ff3727846e014d16ab79850e397c9/raw/ed2a46a684de49b6e500e30c1e1a5f867c6c6695/MissingJavadocMethodCheck.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/9600f179b602d4c971bdb0a050099005/raw/360a95ed7bb60d7a0956e531199d484c4d6f6617/test-projects.properties
Report label: Regression-1

@romani
Copy link
Copy Markdown
Member

romani commented Aug 17, 2023

All javadoc Checks that are not based on AST

public class MissingJavadocMethodCheck extends AbstractCheck {

Will pass less strict review, as most of them very buggy, so extra regression is ok.
So empty regression diff report is good enough.

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

1 similar comment
@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Ok to merge

Copy link
Copy Markdown
Member

@Vyom-Yadav Vyom-Yadav left a comment

Choose a reason for hiding this comment

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

item:

Comment on lines +433 to +434
return (ast.getType() == TokenTypes.METHOD_DEF
|| ast.getType() == TokenTypes.CTOR_DEF
|| ast.getType() == TokenTypes.COMPACT_CTOR_DEF)
&& (getMethodsNumberOfLine(ast) <= minLineCount
|| AnnotationUtil.containsAnnotation(ast, allowedAnnotations));
return getMethodsNumberOfLine(ast) <= minLineCount
|| AnnotationUtil.containsAnnotation(ast, allowedAnnotations);
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.

In this all the ast.getType == .. are use less because they are the only tokens which is accepted so any token is going to be one of them because this method is called by

I see TokenTypes.ANNOTATION_FIELD_DEF in the list of accepted tokens, maybe it is a filter for that. Please see https://stackoverflow.com/a/48729302/15412365 and verify the removal.

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.

good catch, such conditions were added at 8179a34

so we need to have javadoc on record - #8497

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.
Sorry for taking too quick a decision on this pr. I have made the decision with some simple annotations. instead of ANNOTATION_FIELD_DEF

@romani romani assigned romani and unassigned Vyom-Yadav Aug 22, 2023
@romani romani self-requested a review August 22, 2023 13:03
@Kevin222004 Kevin222004 force-pushed the MissingJavadocMethodCheck2 branch from 5247e0c to bbdd034 Compare August 28, 2023 20:03
@romani
Copy link
Copy Markdown
Member

romani commented Aug 29, 2023

@Kevin222004 , please generate diff report to double prove that it is good.

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Ok to merge

@romani romani assigned rdiachenko and unassigned romani Aug 29, 2023
Copy link
Copy Markdown
Member

@rdiachenko rdiachenko left a comment

Choose a reason for hiding this comment

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

lgtm

@rdiachenko rdiachenko force-pushed the MissingJavadocMethodCheck2 branch from bbdd034 to b0261cd Compare August 30, 2023 19:43
@rdiachenko
Copy link
Copy Markdown
Member

rebased

@rdiachenko rdiachenko assigned romani and unassigned rdiachenko Aug 30, 2023
@romani romani merged commit d39e244 into checkstyle:master Aug 31, 2023
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.

4 participants