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

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

The 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;
  }

  public abstract Function handle(MethodSignature methodSignature);

  public abstract 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