Skip to content
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

Filter try-with-resources before filtering inlined code again #1219

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public MutationInterceptor createInterceptor(InterceptorParameters params) {
@Override
public Feature provides() {
return Feature.named("FTRYWR")
.withOrder(50)
.withOnByDefault(true)
.withDescription("Filters mutations in code generated for try with resources statements");
}
Expand Down
24 changes: 17 additions & 7 deletions pitest/src/main/java/org/pitest/plugin/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
Expand All @@ -10,38 +11,44 @@ public final class Feature implements Comparable<Feature> {

private final boolean onByDefault;
private final boolean isInternal;
private final int order;
private final String name;
private final String description;
private final List<FeatureParameter> params;

private Feature(boolean onByDefault, boolean isInternal, String name, String description, List<FeatureParameter> params) {
private Feature(boolean onByDefault, boolean isInternal, int order, String name, String description, List<FeatureParameter> params) {
this.onByDefault = onByDefault;
this.isInternal = isInternal;
this.order = order;
this.name = name;
this.description = description;
this.params = params;
}

public static Feature named(String name) {
return new Feature(false, false, name.toLowerCase(Locale.ROOT), "", Collections.emptyList());
return new Feature(false, false, 100, name.toLowerCase(Locale.ROOT), "", Collections.emptyList());
}

public Feature withOrder(int order) {
return new Feature(this.onByDefault, this.isInternal, order, this.name, this.description, this.params);
}

public Feature withOnByDefault(boolean onByDefault) {
return new Feature(onByDefault, this.isInternal, this.name, this.description, this.params);
return new Feature(onByDefault, this.isInternal, this.order, this.name, this.description, this.params);
}

public Feature asInternalFeature() {
return new Feature(this.onByDefault, true, this.name, this.description, this.params);
return new Feature(this.onByDefault, true, this.order, this.name, this.description, this.params);
}

public Feature withDescription(String description) {
return new Feature(this.onByDefault, this.isInternal, this.name, description, this.params);
return new Feature(this.onByDefault, this.isInternal, this.order, this.name, description, this.params);
}

public Feature withParameter(FeatureParameter param) {
final List<FeatureParameter> params = new ArrayList<>(this.params);
params.add(param);
return new Feature(this.onByDefault, this.isInternal, this.name, this.description, params);
return new Feature(this.onByDefault, this.isInternal, this.order, this.name, this.description, params);
}

public String name() {
Expand Down Expand Up @@ -84,6 +91,9 @@ public boolean equals(Object obj) {

@Override
public int compareTo(Feature o) {
return name.compareTo(o.name);
return Comparator
.<Feature>comparingInt(feature -> feature.order)
.thenComparing(Feature::name)
.compare(this, o);
}
}