-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
478 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...rg/pitest/mutationtest/build/intercept/staticinitializers/FunctionalInterfaceScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.pitest.mutationtest.build.intercept.staticinitializers; | ||
|
||
import org.objectweb.asm.tree.AnnotationNode; | ||
import org.pitest.bytecode.analysis.ClassTree; | ||
import org.pitest.classpath.CodeSource; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class FunctionalInterfaceScanner implements Function<CodeSource, Set<String>> { | ||
@Override | ||
public Set<String> apply(CodeSource codeSource) { | ||
return codeSource.codeTrees() | ||
.filter(this::isFunctionalInterface) | ||
.map(c -> c.rawNode().name) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
private boolean isFunctionalInterface(ClassTree classTree) { | ||
List<AnnotationNode> annotations = classTree.rawNode().visibleAnnotations; | ||
if (annotations == null) { | ||
return false; | ||
} | ||
|
||
return annotations.stream() | ||
.anyMatch(a -> a.desc.equals("Ljava/lang/FunctionalInterface;")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 49 additions & 16 deletions
65
.../mutationtest/build/intercept/staticinitializers/StaticInitializerInterceptorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,59 @@ | ||
package org.pitest.mutationtest.build.intercept.staticinitializers; | ||
|
||
import org.pitest.classpath.CodeSource; | ||
import org.pitest.mutationtest.build.InterceptorParameters; | ||
import org.pitest.mutationtest.build.MutationInterceptor; | ||
import org.pitest.mutationtest.build.MutationInterceptorFactory; | ||
import org.pitest.plugin.Feature; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
public class StaticInitializerInterceptorFactory implements MutationInterceptorFactory { | ||
|
||
@Override | ||
public String description() { | ||
return "Static initializer code detector plugin"; | ||
} | ||
|
||
@Override | ||
public MutationInterceptor createInterceptor(InterceptorParameters params) { | ||
return new StaticInitializerInterceptor(); | ||
} | ||
|
||
@Override | ||
public Feature provides() { | ||
return Feature.named("FSTATI") | ||
.withOnByDefault(true) | ||
.withDescription("Filters mutations in static initializers and code called only from them"); | ||
} | ||
private final Function<CodeSource, Set<String>> delayedExecutionTypes; | ||
|
||
public StaticInitializerInterceptorFactory() { | ||
this(new FunctionalInterfaceScanner()); | ||
} | ||
|
||
public StaticInitializerInterceptorFactory(Function<CodeSource, Set<String>> delayedExecutionTypes) { | ||
this.delayedExecutionTypes = delayedExecutionTypes.andThen(this::jdkFunctionalClasses); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Static initializer code detector plugin"; | ||
} | ||
|
||
@Override | ||
public MutationInterceptor createInterceptor(InterceptorParameters params) { | ||
Set<String> types = delayedExecutionTypes.apply(params.code()); | ||
return new StaticInitializerInterceptor(types); | ||
} | ||
|
||
@Override | ||
public Feature provides() { | ||
return Feature.named("FSTATI") | ||
.withOnByDefault(true) | ||
.withDescription("Filters mutations in static initializers and code called only from them"); | ||
} | ||
|
||
private Set<String> jdkFunctionalClasses(Set<String> existing) { | ||
Set<String> classes = new HashSet<>(existing); | ||
try (BufferedReader r = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/jdkfunctionalinterfaces.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!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
pitest-entry/src/main/resources/jdkfunctionalinterfaces.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
java/io/FileFilter | ||
java/io/FilenameFilter | ||
java/io/ObjectInputFilter | ||
java/lang/Runnable | ||
java/lang/Thread$UncaughtExceptionHandler | ||
java/nio/file/DirectoryStream$Filter | ||
java/nio/file/PathMatcher | ||
java/security/PrivilegedAction | ||
java/security/PrivilegedExceptionAction | ||
java/time/temporal/TemporalAdjuster | ||
java/time/temporal/TemporalQuery | ||
java/util/Comparator | ||
java/util/concurrent/Callable | ||
java/util/concurrent/Flow$Publisher | ||
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/regex/Pattern$CharPredicate | ||
java/util/stream/DoubleStream$DoubleMapMultiConsumer | ||
java/util/stream/IntStream$IntMapMultiConsumer | ||
java/util/stream/LongStream$LongMapMultiConsumer | ||
jdk/internal/access/JavaObjectInputStreamAccess | ||
jdk/internal/access/JavaObjectInputStreamReadString | ||
sun/net/www/protocol/http/AuthenticatorKeys$AuthenticatorKeyAccess | ||
sun/nio/ch/MembershipRegistry$ThrowingConsumer | ||
sun/security/pkcs12/PKCS12KeyStore$RetryWithZero | ||
java/awt/KeyEventDispatcher | ||
java/awt/KeyEventPostProcessor | ||
javax/management/remote/JMXConnectorFactory$ConnectorFactory | ||
com/sun/naming/internal/ObjectFactoriesFilter$FactoryInfo | ||
java/util/logging/Filter | ||
java/net/http/HttpResponse$BodyHandler | ||
jdk/internal/net/http/common/Cancelable | ||
jdk/internal/net/http/common/MinimalFuture$ExceptionalSupplier | ||
jdk/internal/net/http/common/SequentialScheduler$RestartableTask | ||
jdk/internal/net/http/frame/FramesDecoder$FrameProcessor | ||
jdk/internal/net/http/hpack/DecodingCallback | ||
jdk/internal/net/http/hpack/HPACK$BufferUpdateConsumer | ||
jdk/internal/net/http/websocket/TransportFactory | ||
java/util/prefs/PreferenceChangeListener | ||
jdk/dynalink/beans/MissingMemberHandlerFactory | ||
jdk/dynalink/linker/GuardedInvocationTransformer | ||
jdk/dynalink/linker/MethodHandleTransformer | ||
jdk/dynalink/linker/MethodTypeConversionStrategy | ||
jdk/incubator/foreign/SegmentAllocator | ||
jdk/incubator/foreign/SymbolLookup | ||
jdk/internal/foreign/abi/BindingInterpreter$LoadFunc | ||
jdk/internal/foreign/abi/BindingInterpreter$StoreFunc | ||
jdk/internal/org/jline/reader/Widget | ||
jdk/internal/org/jline/utils/Colors$Distance | ||
jdk/jpackage/internal/AppImageBundler$ParamsValidator | ||
jdk/jpackage/internal/IOUtils$XmlConsumer | ||
jdk/jpackage/internal/LibProvidersLookup$PackageLookup | ||
jdk/jpackage/internal/OverridableResource$SourceHandler |
6 changes: 6 additions & 0 deletions
6
...t-entry/src/test/java/com/example/staticinitializers/delayedexecution/CustomFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.staticinitializers.delayedexecution; | ||
|
||
@FunctionalInterface | ||
public interface CustomFunction <T, R> { | ||
R apply(T t); | ||
} |
6 changes: 6 additions & 0 deletions
6
...test/java/com/example/staticinitializers/delayedexecution/CustomFunctionNotAnnotated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.staticinitializers.delayedexecution; | ||
|
||
// NOT annotated as a functional interface | ||
public interface CustomFunctionNotAnnotated <T, R> { | ||
R apply(T t); | ||
} |
Oops, something went wrong.