Java Code Examples for net.bytebuddy.description.method.MethodDescription#isVirtual()

The following examples show how to use net.bytebuddy.description.method.MethodDescription#isVirtual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public StackManipulation resolve(TypeDescription targetType,
                                 ByteCodeElement target,
                                 TypeList.Generic parameters,
                                 TypeDescription.Generic result,
                                 int freeOffset) {
    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.size() + " parameters");
    }
    for (int index = 0; index < mapped.size(); index++) {
        if (!parameters.get(index).asErasure().isAssignableTo(mapped.get(index).asErasure())) {
            throw new IllegalStateException("Cannot invoke " + methodDescription + " on parameter " + index + " of type " + parameters.get(index));
        }
    }
    return methodDescription.isVirtual()
            ? MethodInvocation.invoke(methodDescription).virtual(mapped.get(THIS_REFERENCE).asErasure())
            : MethodInvocation.invoke(methodDescription);
}
 
Example 2
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 3
Source File: MethodCall.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@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);
}
 
Example 4
Source File: MethodCall.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public StackManipulation toStackManipulation(MethodDescription invokedMethod, Implementation.Target implementationTarget) {
    if (!invokedMethod.isAccessibleTo(implementationTarget.getInstrumentedType()) || !invokedMethod.isVirtual()) {
        throw new IllegalStateException("Cannot invoke " + invokedMethod + " virtually");
    }
    return MethodInvocation.invoke(invokedMethod);
}
 
Example 5
Source File: MethodSortMatcher.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isSort(MethodDescription target) {
    return target.isVirtual();
}