Java Code Examples for net.bytebuddy.description.method.ParameterList#size()

The following examples show how to use net.bytebuddy.description.method.ParameterList#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: ControllerMethodData.java    From Diorite with MIT License 6 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
protected ControllerMethodData(Controller controller, TypeDescription classType, InDefinedShape member, String name, int index)
{
    super(controller, classType, member, name, index);
    if (member.isStatic())
    {
        throw new IllegalStateException("Can't use injections on static methods! (Source: " + member.getDeclaringType().getCanonicalName() + "#" +
                                        member.getName() + " " + member.getDescriptor());
    }
    Map<Class<? extends Annotation>, ? extends Annotation> rawScopeAnnotations = controller.extractRawScopeAnnotations(member);
    Map<Class<? extends Annotation>, ? extends Annotation> rawQualifierAnnotations = controller.extractRawQualifierAnnotations(member);
    this.scopeAnnotations = controller.transformAll(this.classType, name, member, rawScopeAnnotations);
    this.qualifierAnnotations = controller.transformAll(this.classType, name, member, rawQualifierAnnotations);
    ParameterList<ParameterDescription.InDefinedShape> parameters = member.getParameters();
    org.diorite.inject.impl.data.InjectValueData<?, TypeDescription.ForLoadedType.Generic>[] values =
            new org.diorite.inject.impl.data.InjectValueData[parameters.size()];
    int i = 0;
    for (ParameterDescription.InDefinedShape param : parameters)
    {
        values[i] = controller.createValue(i, classType, param.getType(), param, Controller.fixName(param.getType(), param.getName()),
                                           rawScopeAnnotations, rawQualifierAnnotations);
        i++;
    }
    this.values = List.of(values);
}
 
Example 2
Source File: MethodCall.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves this appender to a stack manipulation.
 *
 * @param instrumentedMethod The instrumented method.
 * @param invokedMethod      The invoked method.
 * @param targetHandler      The resolved target handler to base the stack manipulation upon.
 * @return A stack manipulation that represents this method call.
 */
protected StackManipulation toStackManipulation(MethodDescription instrumentedMethod, MethodDescription invokedMethod, TargetHandler.Resolved targetHandler) {
    List<ArgumentLoader> argumentLoaders = new ArrayList<ArgumentLoader>();
    for (ArgumentLoader.ArgumentProvider argumentProvider : argumentProviders) {
        argumentLoaders.addAll(argumentProvider.resolve(instrumentedMethod, invokedMethod));
    }
    ParameterList<?> parameters = invokedMethod.getParameters();
    if (parameters.size() != argumentLoaders.size()) {
        throw new IllegalStateException(invokedMethod + " does not accept " + argumentLoaders.size() + " arguments");
    }
    Iterator<? extends ParameterDescription> parameterIterator = parameters.iterator();
    List<StackManipulation> argumentInstructions = new ArrayList<StackManipulation>(argumentLoaders.size());
    for (ArgumentLoader argumentLoader : argumentLoaders) {
        argumentInstructions.add(argumentLoader.toStackManipulation(parameterIterator.next(), assigner, typing));
    }
    return new StackManipulation.Compound(
            targetHandler.toStackManipulation(invokedMethod, assigner, typing),
            new StackManipulation.Compound(argumentInstructions),
            methodInvoker.toStackManipulation(invokedMethod, implementationTarget),
            terminationHandler.toStackManipulation(invokedMethod, instrumentedMethod, assigner, typing)
    );
}
 
Example 3
Source File: TemplateModelProxyHandler.java    From flow with Apache License 2.0 5 votes vote down vote up
private static boolean isAccessor(MethodDescription method) {
    if (method.getDeclaringType().represents(Object.class)) {
        return false;
    }
    String methodName = method.getName();
    Generic returnType = method.getReturnType();
    ParameterList<?> args = method.getParameters();

    boolean isSetter = Generic.VOID.equals(returnType) && args.size() == 1
            && ReflectTools.isSetterName(methodName);
    boolean isGetter = !Generic.VOID.equals(returnType) && args.isEmpty()
            && ReflectTools.isGetterName(methodName,
                    returnType.represents(boolean.class));
    return isSetter || isGetter;
}
 
Example 4
Source File: MethodInheritanceAnnotationMatcher.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private boolean parameterEquals(ParameterList<?> source, ParameterList<?> impl) {
    if (source.size() != impl.size()) {
        return false;
    }
    for (int i = 0; i < source.size(); i++) {
        if (!Objects.equals(source.get(i).getType(), impl.get(i).getType())) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: ArgumentTypeNameMatch.java    From skywalking with Apache License 2.0 5 votes vote down vote up
/**
 * Match the target method.
 *
 * @param target target method description.
 * @return true if matched. or false.
 */
@Override
public boolean matches(MethodDescription target) {
    ParameterList<?> parameters = target.getParameters();
    if (parameters.size() > index) {
        return parameters.get(index).getType().asErasure().getName().equals(argumentTypeName);
    }

    return false;
}
 
Example 6
Source File: MethodAttributeAppender.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a method attribute appender factory that writes all annotations that are defined for every parameter
 * of the given method.
 *
 * @param methodDescription The method from which to extract the parameter annotations.
 * @return A method attribute appender factory for an appender that writes all parameter annotations of the supplied method.
 */
public static Factory ofParameterAnnotations(MethodDescription methodDescription) {
    ParameterList<?> parameters = methodDescription.getParameters();
    List<MethodAttributeAppender.Factory> factories = new ArrayList<MethodAttributeAppender.Factory>(parameters.size());
    for (ParameterDescription parameter : parameters) {
        factories.add(new Explicit(parameter.getIndex(), parameter.getDeclaredAnnotations()));
    }
    return new Factory.Compound(factories);
}
 
Example 7
Source File: InvokeDynamic.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Resolved resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) {
    ParameterList<?> parameters = instrumentedMethod.getParameters();
    if (index >= parameters.size()) {
        throw new IllegalStateException("No parameter " + index + " for " + instrumentedMethod);
    }
    return doResolve(MethodVariableAccess.load(parameters.get(index)), parameters.get(index).getType(), assigner, typing);
}