@Override protected boolean isSort(MethodDescription target) { return target.isVirtual(); } },
/** * Resolves an invocation type. * * @param opcode The opcode that is used for invoking the method. * @param methodDescription The method that is being invoked. * @return The invokation type for the method given that opcode. */ protected static InvocationType of(int opcode, MethodDescription methodDescription) { switch (opcode) { case Opcodes.INVOKEVIRTUAL: case Opcodes.INVOKEINTERFACE: return InvocationType.VIRTUAL; case Opcodes.INVOKESPECIAL: return methodDescription.isVirtual() ? SUPER : OTHER; default: return OTHER; } }
/** * {@inheritDoc} */ public StackManipulation toStackManipulation(MethodDescription invokedMethod, Implementation.Target implementationTarget) { if (!invokedMethod.isVirtual()) { throw new IllegalStateException("Cannot invoke " + invokedMethod + " virtually"); } return MethodInvocation.invoke(invokedMethod); } }
/** * {@inheritDoc} */ public StackManipulation toStackManipulation(MethodDescription invokedMethod, Implementation.Target implementationTarget) { if (invokedMethod.isVirtual() && !invokedMethod.isInvokableOn(instrumentedType)) { throw new IllegalStateException("Cannot invoke " + invokedMethod + " on " + instrumentedType); } return invokedMethod.isVirtual() ? MethodInvocation.invoke(invokedMethod).virtual(instrumentedType) : MethodInvocation.invoke(invokedMethod); }
/** * {@inheritDoc} */ public StackManipulation toStackManipulation(MethodDescription invokedMethod, Implementation.Target implementationTarget) { if (!invokedMethod.isVirtual()) { throw new IllegalStateException("Cannot invoke " + invokedMethod + " virtually"); } else if (!invokedMethod.isInvokableOn(typeDescription)) { throw new IllegalStateException("Cannot invoke " + invokedMethod + " on " + typeDescription); } return MethodInvocation.invoke(invokedMethod).virtual(typeDescription); }
/** * {@inheritDoc} */ public StackManipulation resolve(TypeDescription targetType, ByteCodeElement target, TypeList.Generic parameters, TypeDescription.Generic result) { MethodDescription methodDescription = methodResolver.resolve(targetType, target, parameters, result); if (!methodDescription.isAccessibleTo(instrumentedType)) { throw new IllegalStateException(instrumentedType + " cannot access " + methodDescription); } TypeList.Generic mapped = methodDescription.isStatic() ? methodDescription.getParameters().asTypeList() : new TypeList.Generic.Explicit(CompoundList.of(methodDescription.getDeclaringType(), methodDescription.getParameters().asTypeList())); if (!methodDescription.getReturnType().asErasure().isAssignableTo(result.asErasure())) { throw new IllegalStateException("Cannot assign return value of " + methodDescription + " to " + result); } else if (mapped.size() != parameters.size()) { throw new IllegalStateException("Cannot invoke " + methodDescription + " on " + parameters); } for (int index = 0; index < mapped.size(); index++) { if (!mapped.get(index).asErasure().isAssignableTo(parameters.get(index).asErasure())) { throw new IllegalStateException("Cannot invoke " + methodDescription + " on " + parameters); } } return methodDescription.isVirtual() ? MethodInvocation.invoke(methodDescription).virtual(mapped.get(THIS_REFERENCE).asErasure()) : MethodInvocation.invoke(methodDescription); }