• 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   public abstract Function<Object, Object> handle(MethodSignature methodSignature);
21 
getMethodHandle(String methodName, MethodType type)22   public abstract MethodHandle getMethodHandle(String methodName, MethodType type)
23       throws NoSuchMethodException, IllegalAccessException;
24 
25   @Nonnull
returnDefaultValue( final MethodSignature methodSignature)26   protected static Function<Object, Object> returnDefaultValue(
27       final MethodSignature methodSignature) {
28     return new Function<Object, Object>() {
29       @Override
30       public Object call(Class<?> theClass, Object value, Object[] params) {
31         return ReflectionHelpers.defaultValueForType(methodSignature.returnType);
32       }
33     };
34   }
35 }
36