All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.internal.bytecode.Interceptor Maven / Gradle / Ivy

There is a newer version: 4.13
Show newest version
package org.robolectric.internal.bytecode;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import javax.annotation.Nonnull;
import org.robolectric.util.Function;
import org.robolectric.util.ReflectionHelpers;

public abstract class Interceptor {
  private MethodRef[] methodRefs;

  public Interceptor(MethodRef... methodRefs) {
    this.methodRefs = methodRefs;
  }

  public MethodRef[] getMethodRefs() {
    return methodRefs;
  }

  abstract public Function handle(MethodSignature methodSignature);

  abstract public MethodHandle getMethodHandle(String methodName, MethodType type) throws NoSuchMethodException, IllegalAccessException;

  @Nonnull
  protected static Function returnDefaultValue(final MethodSignature methodSignature) {
    return new Function() {
      @Override
      public Object call(Class theClass, Object value, Object[] params) {
        return ReflectionHelpers.defaultValueForType(methodSignature.returnType);
      }
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy