2222import static com .code_intelligence .jazzer .mutation .support .StreamSupport .toArrayOrEmpty ;
2323import static java .lang .String .format ;
2424import static java .util .Arrays .stream ;
25- import static java .util .Objects .requireNonNull ;
2625import static java .util .stream .Collectors .joining ;
2726
2827import com .code_intelligence .jazzer .mutation .api .MutatorFactory ;
4241import java .lang .reflect .AnnotatedType ;
4342import java .lang .reflect .InvocationTargetException ;
4443import java .lang .reflect .Method ;
45- import java .lang .reflect .Modifier ;
4644import java .util .Optional ;
4745
4846public final class ArgumentsMutator {
49- private final Object instance ;
5047 private final Method method ;
5148 private final ProductMutator productMutator ;
5249 private Object [] arguments ;
@@ -60,8 +57,7 @@ public final class ArgumentsMutator {
6057 */
6158 private boolean argumentsExposed ;
6259
63- private ArgumentsMutator (Object instance , Method method , ProductMutator productMutator ) {
64- this .instance = instance ;
60+ private ArgumentsMutator (Method method , ProductMutator productMutator ) {
6561 this .method = method ;
6662 this .productMutator = productMutator ;
6763 }
@@ -74,44 +70,19 @@ private static String prettyPrintMethod(Method method) {
7470 stream (method .getAnnotatedParameterTypes ()).map (Object ::toString ).collect (joining (", " )));
7571 }
7672
77- public static ArgumentsMutator forInstanceMethodOrThrow (Object instance , Method method ) {
78- return forInstanceMethod (Mutators .newFactory (), instance , method )
79- .orElseThrow (
80- () ->
81- new IllegalArgumentException (
82- "Failed to construct mutator for " + prettyPrintMethod (method )));
83- }
84-
85- public static ArgumentsMutator forStaticMethodOrThrow (Method method ) {
86- return forStaticMethod (Mutators .newFactory (), method )
73+ public static ArgumentsMutator forMethodOrThrow (Method method ) {
74+ return forMethod (Mutators .newFactory (), method )
8775 .orElseThrow (
8876 () ->
8977 new IllegalArgumentException (
9078 "Failed to construct mutator for " + prettyPrintMethod (method )));
9179 }
9280
9381 public static Optional <ArgumentsMutator > forMethod (Method method ) {
94- return forMethod (Mutators .newFactory (), null , method );
82+ return forMethod (Mutators .newFactory (), method );
9583 }
9684
97- public static Optional <ArgumentsMutator > forInstanceMethod (
98- MutatorFactory mutatorFactory , Object instance , Method method ) {
99- require (!isStatic (method ), "method must not be static" );
100- requireNonNull (instance , "instance must not be null" );
101- require (
102- method .getDeclaringClass ().isInstance (instance ),
103- format ("instance is a %s, expected %s" , instance .getClass (), method .getDeclaringClass ()));
104- return forMethod (mutatorFactory , instance , method );
105- }
106-
107- public static Optional <ArgumentsMutator > forStaticMethod (
108- MutatorFactory mutatorFactory , Method method ) {
109- require (isStatic (method ), "method must be static" );
110- return forMethod (mutatorFactory , null , method );
111- }
112-
113- public static Optional <ArgumentsMutator > forMethod (
114- MutatorFactory mutatorFactory , Object instance , Method method ) {
85+ public static Optional <ArgumentsMutator > forMethod (MutatorFactory mutatorFactory , Method method ) {
11586 require (method .getParameterCount () > 0 , "Can't fuzz method without parameters: " + method );
11687 for (AnnotatedType parameter : method .getAnnotatedParameterTypes ()) {
11788 validateAnnotationUsage (parameter );
@@ -120,18 +91,13 @@ public static Optional<ArgumentsMutator> forMethod(
12091 stream (method .getAnnotatedParameterTypes ()).map (mutatorFactory ::tryCreate ),
12192 SerializingMutator <?>[]::new )
12293 .map (MutatorCombinators ::mutateProduct )
123- .map (productMutator -> ArgumentsMutator .create (instance , method , productMutator ));
94+ .map (productMutator -> ArgumentsMutator .create (method , productMutator ));
12495 }
12596
126- private static ArgumentsMutator create (
127- Object instance , Method method , ProductMutator productMutator ) {
97+ private static ArgumentsMutator create (Method method , ProductMutator productMutator ) {
12898 method .setAccessible (true );
12999
130- return new ArgumentsMutator (instance , method , productMutator );
131- }
132-
133- private static boolean isStatic (Method method ) {
134- return Modifier .isStatic (method .getModifiers ());
100+ return new ArgumentsMutator (method , productMutator );
135101 }
136102
137103 /**
@@ -203,7 +169,7 @@ void mutate(PseudoRandom prng) {
203169 productMutator .mutateInPlace (arguments , prng );
204170 }
205171
206- public void invoke (boolean detach ) throws Throwable {
172+ public void invoke (Object instance , boolean detach ) throws Throwable {
207173 Object [] invokeArguments ;
208174 if (detach ) {
209175 invokeArguments = productMutator .detach (arguments );
0 commit comments