Skip to content

Commit

Permalink
* Mutation testing - part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaLegeza committed Nov 28, 2023
1 parent f8af975 commit 2086d79
Showing 1 changed file with 6 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
import com.google.errorprone.BugPattern;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugChecker.MemberReferenceTreeMatcher;
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher;
import com.google.errorprone.fixes.SuggestedFixes;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.suppliers.Supplier;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MemberReferenceTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.util.List;
import reactor.core.publisher.Mono;

/**
Expand All @@ -41,9 +38,10 @@
* of the empty publisher and prematurely terminates the reactive chain from the execution. In most
* cases this is not the desired behaviour.
*
* <p>NB: Mono&lt;?>#zipWith(Mono&lt;Void>) is allowed be the Reactor API, but it is an incorrect
* usage of the API. It will be flagged by ErrorProne but the fix won't be supplied. The problem
* with the original code should be revisited and fixed in a structural manner by the developer.
* <p>NB: Mono&lt;?&gt;#zipWith(Mono&lt;Void&gt;) is allowed be the Reactor API, but it is an
* incorrect usage of the API. It will be flagged by ErrorProne but the fix won't be supplied. The
* problem with the original code should be revisited and fixed in a structural manner by the
* developer.
*/
@AutoService(BugChecker.class)
@BugPattern(
Expand All @@ -55,7 +53,7 @@
severity = ERROR,
tags = LIKELY_ERROR)
public final class MonoZipOfMonoVoidUsage extends BugChecker
implements MethodInvocationTreeMatcher, MemberReferenceTreeMatcher {
implements MethodInvocationTreeMatcher {
private static final long serialVersionUID = 1L;
private static final Supplier<Type> MONO = type(Mono.class.getName());
// Mono.empty() yields `Mono<Object>` under the hood
Expand Down Expand Up @@ -111,17 +109,6 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
.build();
}

@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
boolean dynamicMono = MONO_ZIP_AND_WITH.matches(tree, state);
boolean staticMono = STATIC_MONO_ZIP.matches(tree, state);

if (!dynamicMono && !staticMono) {
return Description.NO_MATCH;
}
return describeMatch(tree);
}

private static Matcher<MethodInvocationTree> hasArgumentOfType(Supplier<Type> type) {
return hasArgumentOfTypes(ImmutableList.of(type));
}
Expand Down Expand Up @@ -149,12 +136,7 @@ private static Matcher<MethodInvocationTree> hasArgumentOfTypes(
tree.getArguments().stream()
.anyMatch(
arg -> {
List<Type> allParams = ASTHelpers.getType(arg).allparams();
if (allParams.isEmpty()) {
return false;
}

Type argumentType = allParams.get(0);
Type argumentType = ASTHelpers.getType(arg).allparams().get(0);
return types.stream()
.map(type -> type.get(state).allparams().get(0))
.anyMatch(
Expand Down

0 comments on commit 2086d79

Please sign in to comment.