• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.internal.bytecode;
2 
3 import java.lang.invoke.MethodHandle;
4 import java.lang.invoke.MethodType;
5 import javax.annotation.Nonnull;
6 import org.robolectric.util.Function;
7 import org.robolectric.util.ReflectionHelpers;
8 
9 public abstract class Interceptor {
10   private MethodRef[] methodRefs;
11 
Interceptor(MethodRef... methodRefs)12   public Interceptor(MethodRef... methodRefs) {
13     this.methodRefs = methodRefs;
14   }
15 
getMethodRefs()16   public MethodRef[] getMethodRefs() {
17     return methodRefs;
18   }
19 
handle(MethodSignature methodSignature)20   abstract public Function<Object, Object> handle(MethodSignature methodSignature);
21 
getMethodHandle(String methodName, MethodType type)22   abstract public MethodHandle getMethodHandle(String methodName, MethodType type) throws NoSuchMethodException, IllegalAccessException;
23 
24   @Nonnull
returnDefaultValue(final MethodSignature methodSignature)25   protected static Function<Object, Object> returnDefaultValue(final MethodSignature methodSignature) {
26     return new Function<Object, Object>() {
27       @Override
28       public Object call(Class<?> theClass, Object value, Object[] params) {
29         return ReflectionHelpers.defaultValueForType(methodSignature.returnType);
30       }
31     };
32   }
33 }
34