Skip to content

Commit

Permalink
expand list of recognised function types
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Aug 29, 2024
1 parent c0a2548 commit a7d9d90
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public StaticInitializerInterceptorFactory() {
}

public StaticInitializerInterceptorFactory(Function<CodeSource, Set<String>> delayedExecutionTypes) {
this.delayedExecutionTypes = delayedExecutionTypes.andThen(this::jdkFunctionalClasses);
this.delayedExecutionTypes = delayedExecutionTypes.andThen(this::functionalInterfaces);
}

@Override
Expand All @@ -43,17 +43,17 @@ public Feature provides() {
.withDescription("Filters mutations in static initializers and code called only from them");
}

private Set<String> jdkFunctionalClasses(Set<String> existing) {
private Set<String> functionalInterfaces(Set<String> existing) {
Set<String> classes = new HashSet<>(existing);
try (BufferedReader r = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/jdkfunctionalinterfaces.txt")))) {
try (BufferedReader r = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/functional_interfaces.txt")))) {
String line = r.readLine();
while (line != null) {
classes.add(line);
line = r.readLine();
}
return classes;
} catch (IOException e) {
throw new RuntimeException("Could not read embedded jdk class list!");
throw new RuntimeException("Could not read embedded list of functional interfaces!");
}
}
}
133 changes: 133 additions & 0 deletions pitest-entry/src/main/resources/functional_interfaces.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
java/io/FileFilter
java/io/FilenameFilter
java/io/ObjectInputFilter
java/lang/Runnable
java/util/Comparator
java/util/concurrent/Callable
java/util/function/BiConsumer
java/util/function/BiFunction
java/util/function/BiPredicate
java/util/function/BinaryOperator
java/util/function/BooleanSupplier
java/util/function/Consumer
java/util/function/DoubleBinaryOperator
java/util/function/DoubleConsumer
java/util/function/DoubleFunction
java/util/function/DoublePredicate
java/util/function/DoubleSupplier
java/util/function/DoubleToIntFunction
java/util/function/DoubleToLongFunction
java/util/function/DoubleUnaryOperator
java/util/function/Function
java/util/function/IntBinaryOperator
java/util/function/IntConsumer
java/util/function/IntFunction
java/util/function/IntPredicate
java/util/function/IntSupplier
java/util/function/IntToDoubleFunction
java/util/function/IntToLongFunction
java/util/function/IntUnaryOperator
java/util/function/LongBinaryOperator
java/util/function/LongConsumer
java/util/function/LongFunction
java/util/function/LongPredicate
java/util/function/LongSupplier
java/util/function/LongToDoubleFunction
java/util/function/LongToIntFunction
java/util/function/LongUnaryOperator
java/util/function/ObjDoubleConsumer
java/util/function/ObjIntConsumer
java/util/function/ObjLongConsumer
java/util/function/Predicate
java/util/function/Supplier
java/util/function/ToDoubleBiFunction
java/util/function/ToDoubleFunction
java/util/function/ToIntBiFunction
java/util/function/ToIntFunction
java/util/function/ToLongBiFunction
java/util/function/ToLongFunction
java/util/function/UnaryOperator
java/util/stream/DoubleStream$DoubleMapMultiConsumer
java/util/stream/IntStream$IntMapMultiConsumer
java/util/stream/LongStream$LongMapMultiConsumer
org/pitest/sequence/Match
org/apache/commons/text/lookup/BiStringLookup
org/apache/commons/text/lookup/StringLookup
org/apache/commons/lang3/Functions$FailableBiConsumer
org/apache/commons/lang3/Functions$FailableBiFunction
org/apache/commons/lang3/Functions$FailableBiPredicate
org/apache/commons/lang3/Functions$FailableCallable
org/apache/commons/lang3/Functions$FailableConsumer
org/apache/commons/lang3/Functions$FailableFunction
org/apache/commons/lang3/Functions$FailablePredicate
org/apache/commons/lang3/Functions$FailableRunnable
org/apache/commons/lang3/Functions$FailableSupplier
org/apache/commons/lang3/ThreadUtils$ThreadGroupPredicate
org/apache/commons/lang3/ThreadUtils$ThreadPredicate
org/apache/commons/lang3/function/FailableBiConsumer
org/apache/commons/lang3/function/FailableBiFunction
org/apache/commons/lang3/function/FailableBiPredicate
org/apache/commons/lang3/function/FailableBooleanSupplier
org/apache/commons/lang3/function/FailableCallable
org/apache/commons/lang3/function/FailableConsumer
org/apache/commons/lang3/function/FailableDoubleBinaryOperator
org/apache/commons/lang3/function/FailableDoubleConsumer
org/apache/commons/lang3/function/FailableDoubleFunction
org/apache/commons/lang3/function/FailableDoublePredicate
org/apache/commons/lang3/function/FailableDoubleSupplier
org/apache/commons/lang3/function/FailableDoubleToIntFunction
org/apache/commons/lang3/function/FailableDoubleToLongFunction
org/apache/commons/lang3/function/FailableFunction
org/apache/commons/lang3/function/FailableIntBinaryOperator
org/apache/commons/lang3/function/FailableIntConsumer
org/apache/commons/lang3/function/FailableIntFunction
org/apache/commons/lang3/function/FailableIntPredicate
org/apache/commons/lang3/function/FailableIntSupplier
org/apache/commons/lang3/function/FailableIntToDoubleFunction
org/apache/commons/lang3/function/FailableIntToLongFunction
org/apache/commons/lang3/function/FailableLongBinaryOperator
org/apache/commons/lang3/function/FailableLongConsumer
org/apache/commons/lang3/function/FailableLongFunction
org/apache/commons/lang3/function/FailableLongPredicate
org/apache/commons/lang3/function/FailableLongSupplier
org/apache/commons/lang3/function/FailableLongToDoubleFunction
org/apache/commons/lang3/function/FailableLongToIntFunction
org/apache/commons/lang3/function/FailableObjDoubleConsumer
org/apache/commons/lang3/function/FailableObjIntConsumer
org/apache/commons/lang3/function/FailableObjLongConsumer
org/apache/commons/lang3/function/FailablePredicate
org/apache/commons/lang3/function/FailableRunnable
org/apache/commons/lang3/function/FailableShortSupplier
org/apache/commons/lang3/function/FailableSupplier
org/apache/commons/lang3/function/FailableToDoubleBiFunction
org/apache/commons/lang3/function/FailableToDoubleFunction
org/apache/commons/lang3/function/FailableToIntBiFunction
org/apache/commons/lang3/function/FailableToIntFunction
org/apache/commons/lang3/function/FailableToLongBiFunction
org/apache/commons/lang3/function/FailableToLongFunction
org/apache/commons/lang3/function/ToBooleanBiFunction
org/apache/commons/lang3/function/TriFunction
com/google/errorprone/matchers/Matcher
com/google/common/base/Function
com/google/common/base/Predicate
com/google/common/base/Supplier
com/google/common/cache/RemovalListener
com/google/common/cache/Weigher
com/google/common/collect/Maps$EntryTransformer
com/google/common/util/concurrent/AsyncCallable
com/google/common/util/concurrent/AsyncFunction
com/google/common/util/concurrent/ClosingFuture$AsyncClosingCallable
com/google/common/util/concurrent/ClosingFuture$AsyncClosingFunction
com/google/common/util/concurrent/ClosingFuture$ClosingCallable
com/google/common/util/concurrent/ClosingFuture$ClosingFunction
com/google/common/util/concurrent/ClosingFuture$Combiner$AsyncCombiningCallable
com/google/common/util/concurrent/ClosingFuture$Combiner$CombiningCallable
com/google/common/util/concurrent/ClosingFuture$Combiner2$AsyncClosingFunction2
com/google/common/util/concurrent/ClosingFuture$Combiner2$ClosingFunction2
com/google/common/util/concurrent/ClosingFuture$Combiner3$AsyncClosingFunction3
com/google/common/util/concurrent/ClosingFuture$Combiner3$ClosingFunction3
com/google/common/util/concurrent/ClosingFuture$Combiner4$AsyncClosingFunction4
com/google/common/util/concurrent/ClosingFuture$Combiner4$ClosingFunction4
com/google/common/util/concurrent/ClosingFuture$Combiner5$AsyncClosingFunction5
com/google/common/util/concurrent/ClosingFuture$Combiner5$ClosingFunction5
com/google/common/util/concurrent/ClosingFuture$ValueAndCloserConsumer
94 changes: 0 additions & 94 deletions pitest-entry/src/main/resources/jdkfunctionalinterfaces.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
import org.junit.Test;
import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.classinfo.ClassByteArraySource;
import org.pitest.classinfo.ClassHash;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.ClassPath;
import org.pitest.classpath.ClassloaderByteArraySource;
import org.pitest.classpath.CodeSource;
import org.pitest.mutationtest.FixedCodeSource;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -35,17 +30,23 @@ public void recognisesFunctionalInterfaces() {
assertThat(underTest.apply(codeSourceFor(functional, not))).containsExactly("java/util/function/Function");
}

/* not a test

/*
@Test
public void wholeClassPath() throws Exception {
ClassPath cp = new ClassPath();
List<String> classes = cp.classNames().stream()
.map(n -> source.getBytes(n))
.map(b -> ClassTree.fromBytes(b.get()))
.filter(ClassTree::isInterface)
.flatMap(t -> underTest.apply(codeSourceFor(t)).stream())
.distinct()
.collect(Collectors.toList());
System.out.println(classes.stream()
.collect(Collectors.joining("\n")));
}
*/
*/

/*
// not a test and only works with java 9+
Expand Down

0 comments on commit a7d9d90

Please sign in to comment.