/** * Creates a method handle representation of the given method. * * @param methodDescription The method ro represent. * @return A method handle representing the given method. */ public static MethodHandle of(MethodDescription methodDescription) { return new MethodHandle( HandleType.of(methodDescription), methodDescription.getDeclaringType().asRawType(), methodDescription.getInternalName(), methodDescription.getReturnType().asRawType(), methodDescription.getParameters().asTypeList().asRawTypes()); }
/** * Creates a method handle representation of the given method for an explicit special method * invocation of an otherwise virtual method. * * @param methodDescription The method ro represent. * @param typeDescription The type on which the method is to be invoked on as a special method * invocation. * @return A method handle representing the given method as special method invocation. */ public static MethodHandle ofSpecial( MethodDescription methodDescription, TypeDescription typeDescription) { if (!methodDescription.isSpecializableFor(typeDescription)) { throw new IllegalArgumentException( "Cannot specialize " + methodDescription + " for " + typeDescription); } return new MethodHandle( HandleType.ofSpecial(methodDescription), typeDescription, methodDescription.getInternalName(), methodDescription.getReturnType().asRawType(), methodDescription.getParameters().asTypeList().asRawTypes()); }
@Override @Before public void setUp() throws Exception { when(parameterList.asTypeList()).thenReturn(parameterTypes); when(instrumentedType.getSupertype()).thenReturn(superType); when(superType.getDeclaredMethods()) .thenReturn(new MethodList.Explicit(Collections.singletonList(superMethodConstructor))); when(superType.getInternalName()).thenReturn(BAR); when(superMethod.getDeclaringType()).thenReturn(superType); when(superType.getStackSize()).thenReturn(StackSize.ZERO); when(superMethod.getReturnType()).thenReturn(returnType); when(superMethod.getInternalName()).thenReturn(BAZ); when(superMethod.getDescriptor()).thenReturn(FOOBAR); when(superMethod.getParameters()).thenReturn(parameterList); when(superMethodConstructor.isConstructor()).thenReturn(true); when(superMethodConstructor.getParameters()).thenReturn(parameterList); when(superMethodConstructor.getReturnType()).thenReturn(returnType); when(superMethodConstructor.isSpecializableFor(superType)).thenReturn(true); when(superMethodConstructor.getInternalName()).thenReturn(QUXBAZ); when(superMethodConstructor.getDescriptor()).thenReturn(BAZBAR); super.setUp(); }
@Before public void setUp() throws Exception { when(methodDescription.getDeclaringType()).thenReturn(typeDescription); when(methodDescription.getReturnType()).thenReturn(returnType); when(methodDescription.getInternalName()).thenReturn(FOO); when(methodDescription.getDescriptor()).thenReturn(BAZ); when(typeDescription.getInternalName()).thenReturn(BAR); when(typeDescription.getDescriptor()).thenReturn(BAR); when(methodNameTransformer.transform(methodDescription)).thenReturn(QUX); when(otherMethodNameTransformer.transform(methodDescription)).thenReturn(FOO + BAR); when(parameterType.getStackSize()).thenReturn(StackSize.ZERO); ParameterList parameterList = ParameterList.Explicit.latent(methodDescription, Collections.singletonList(parameterType)); when(methodDescription.getParameters()).thenReturn(parameterList); }
@Override public String transform(MethodDescription methodDescription) { return String.format("%s%s", prefix, methodDescription.getInternalName()); }
@Override public String transform(MethodDescription methodDescription) { return String.format("%s$%s", methodDescription.getInternalName(), suffix); }