Skip to content

Commit

Permalink
Filter try-with-resources before filtering inlined code again
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed May 25, 2023
1 parent ccfa7e3 commit e38fd83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
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);
}
}

0 comments on commit e38fd83

Please sign in to comment.