Java Code Examples for net.bytebuddy.description.type.TypeList#size()

The following examples show how to use net.bytebuddy.description.type.TypeList#size() . 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: MethodDescription.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if this method is a bootstrap method while expecting the supplied type as a type representation.
 *
 * @param selfType The type of the bootstrap method's type representation.
 * @return {@code true} if this method is a bootstrap method assuming the supplied type representation.
 */
private boolean isBootstrap(TypeDescription selfType) {
    TypeList parameterTypes = getParameters().asTypeList().asErasures();
    switch (parameterTypes.size()) {
        case 0:
            return false;
        case 1:
            return parameterTypes.getOnly().represents(Object[].class);
        case 2:
            return JavaType.METHOD_HANDLES_LOOKUP.getTypeStub().isAssignableTo(parameterTypes.get(0))
                    && parameterTypes.get(1).represents(Object[].class);
        case 3:
            return JavaType.METHOD_HANDLES_LOOKUP.getTypeStub().isAssignableTo(parameterTypes.get(0))
                    && (parameterTypes.get(1).represents(Object.class) || parameterTypes.get(1).represents(String.class))
                    && (parameterTypes.get(2).represents(Object[].class) || parameterTypes.get(2).isAssignableFrom(selfType));
        default:
            return JavaType.METHOD_HANDLES_LOOKUP.getTypeStub().isAssignableTo(parameterTypes.get(0))
                    && (parameterTypes.get(1).represents(Object.class) || parameterTypes.get(1).represents(String.class))
                    && parameterTypes.get(2).isAssignableFrom(selfType);
    }
}
 
Example 2
Source File: MethodDescription.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if this method is a bootstrap method given the supplied arguments. This method does not implement a full check but assumes that
 * {@link MethodDescription.AbstractBase#isBootstrap(TypeDescription)} is invoked, as well.
 *
 * @param types The types of the explicit arguments that are supplied to the bootstrap method.
 * @return {@code true} if this method is a bootstrap method for the supplied arguments.
 */
private boolean isBootstrap(List<? extends TypeDefinition> types) {
    TypeList targets = getParameters().asTypeList().asErasures();
    if (targets.size() < 4) {
        return types.isEmpty() || targets.get(targets.size() - 1).represents(Object[].class);
    } else {
        Iterator<TypeDescription> iterator = targets.subList(3, targets.size()).iterator();
        for (TypeDefinition type : types) {
            if (!iterator.hasNext()) {
                return false;
            }
            TypeDescription target = iterator.next();
            if (!iterator.hasNext() && target.represents(Object[].class)) {
                return true;
            } else if (!type.asErasure().isAssignableTo(target)) {
                return false;
            }
        }
        if (iterator.hasNext()) {
            return iterator.next().represents(Object[].class) && !iterator.hasNext();
        } else {
            return true;
        }
    }
}
 
Example 3
Source File: RebaseImplementationTarget.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a special method invocation for the given method.
 *
 * @param resolvedMethod      The rebased method to be invoked.
 * @param instrumentedType    The instrumented type on which the method is to be invoked if it is non-static.
 * @param prependedParameters Any additional arguments that are to be provided to the rebased method.
 * @return A special method invocation of the rebased method.
 */
protected static Implementation.SpecialMethodInvocation of(MethodDescription resolvedMethod, TypeDescription instrumentedType, TypeList prependedParameters) {
    StackManipulation stackManipulation = resolvedMethod.isStatic()
            ? MethodInvocation.invoke(resolvedMethod)
            : MethodInvocation.invoke(resolvedMethod).special(instrumentedType);
    if (stackManipulation.isValid()) {
        List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(prependedParameters.size() + 1);
        for (TypeDescription prependedParameter : prependedParameters) {
            stackManipulations.add(DefaultValue.of(prependedParameter));
        }
        stackManipulations.add(stackManipulation);
        return new RebasedMethodInvocation(resolvedMethod, instrumentedType, new Compound(stackManipulations), prependedParameters);
    } else {
        return Illegal.INSTANCE;
    }
}
 
Example 4
Source File: JaxRsOffsetMappingFactory.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
private void findInInterfaces(TransactionAnnotationValue transactionAnnotationValue, TypeDescription classTypeDescription, String methodName) {
    TypeList interfaces = classTypeDescription.getInterfaces().asErasures();
    for (int i = 0; i < interfaces.size(); i++) {
        TypeDescription interfaceDescription = interfaces.get(i);
        getAnnotationValueFromAnnotationSource(transactionAnnotationValue, interfaceDescription, true);
        for (MethodDescription.InDefinedShape annotationMethod : interfaceDescription.getDeclaredMethods().filter(named(methodName))) {
            getAnnotationValueFromAnnotationSource(transactionAnnotationValue, annotationMethod, false);
        }
        findInInterfaces(transactionAnnotationValue, interfaceDescription, methodName);
    }
}