Java Code Examples for net.bytebuddy.description.method.ParameterDescription#InDefinedShape

The following examples show how to use net.bytebuddy.description.method.ParameterDescription#InDefinedShape . 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: SimpleMethodSignatureOffsetMappingFactory.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@Override
public Advice.OffsetMapping make(ParameterDescription.InDefinedShape target,
                                 AnnotationDescription.Loadable<SimpleMethodSignature> annotation,
                                 AdviceType adviceType) {
    return new Advice.OffsetMapping() {
        @Override
        public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner,
                              Advice.ArgumentHandler argumentHandler, Sort sort) {
            final String className = instrumentedMethod.getDeclaringType().getTypeName();
            String simpleClassName = className.substring(className.lastIndexOf('$') + 1);
            simpleClassName = simpleClassName.substring(simpleClassName.lastIndexOf('.') + 1);
            final String signature = String.format("%s#%s", simpleClassName, instrumentedMethod.getName());
            return Target.ForStackManipulation.of(signature);
        }
    };
}
 
Example 2
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 3
Source File: AnnotationValueOffsetMappingFactory.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Override
public Advice.OffsetMapping make(final ParameterDescription.InDefinedShape target,
                                 final AnnotationDescription.Loadable<AnnotationValueExtractor> annotation,
                                 final AdviceType adviceType) {
    return new Advice.OffsetMapping() {
        @Override
        public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Advice.ArgumentHandler argumentHandler, Sort sort) {
            return Target.ForStackManipulation.of(getAnnotationValue(instrumentedMethod, annotation.load()));
        }
    };
}
 
Example 4
Source File: JaxRsOffsetMappingFactory.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Override
public Advice.OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<JaxRsPath> annotation, AdviceType adviceType) {
    return new Advice.OffsetMapping() {
        @Override
        public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Advice.ArgumentHandler argumentHandler, Sort sort) {
            Object value = null;
            if (useAnnotationValueForTransactionName) {
                value = getTransactionAnnotationValueFromAnnotations(instrumentedMethod, instrumentedType);
            }
            return Target.ForStackManipulation.of(value);
        }
    };
}
 
Example 5
Source File: TypePoolDefaultLazyParameterListTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
protected ParameterList<ParameterDescription.InDefinedShape> asList(List<ParameterDescription> elements) {
    List<ParameterDescription.InDefinedShape> parameterDescriptions = new ArrayList<ParameterDescription.InDefinedShape>(elements.size());
    for (ParameterDescription element : elements) {
        parameterDescriptions.add(typePool.describe(Foo.class.getName()).resolve()
                .getDeclaredMethods()
                .filter(is(element.getDeclaringMethod()))
                .getOnly()
                .getParameters()
                .getOnly());
    }
    return new ParameterList.Explicit<ParameterDescription.InDefinedShape>(parameterDescriptions);
}
 
Example 6
Source File: BinderToConstructor.java    From Diorite with MIT License 4 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
BinderToConstructor(Controller controller, Class<? extends T> type, Constructor<?> constructor)
{
    this.controller = controller;
    Constructor<? extends T> constructor1 = (Constructor<? extends T>) constructor;
    constructor1.setAccessible(true);

    MethodDescription.ForLoadedConstructor constructorDesc = new MethodDescription.ForLoadedConstructor(constructor);
    Map<Class<? extends Annotation>, ? extends Annotation> scopeMap = controller.extractRawScopeAnnotations(constructorDesc);
    Map<Class<? extends Annotation>, ? extends Annotation> qualifierMap = controller.extractRawQualifierAnnotations(constructorDesc);

    int parameterCount = constructor.getParameterCount();
    ArrayList<ControllerInjectValueData<?>> params = new ArrayList<>(parameterCount);
    ParameterList<ParameterDescription.InDefinedShape> parameters = constructorDesc.getParameters();
    for (int i = 0; i < parameterCount; i++)
    {
        ParameterDescription.InDefinedShape param = parameters.get(i);
        ControllerInjectValueData<Object> value = controller.createValue(- 1, constructorDesc.getDeclaringType(), param.getType(), param,
                                                                         param.getName(), scopeMap, qualifierMap);
        params.add(value);
    }
    this.params = List.of(params.toArray(new ControllerInjectValueData[parameterCount]));

    this.constructor = $this ->
    {
        Object[] args = new Object[parameterCount];
        for (int i = 0; i < parameterCount; i++)
        {
            args[i] = this.params.get(i).tryToGet($this);
        }
        try
        {
            return constructor1.newInstance(args);
        }
        catch (InstantiationException | IllegalAccessException | InvocationTargetException e)
        {
            throw new RuntimeException("Can't bind value to " + constructor1.getDeclaringClass().getName() + " constructor. " +
                                       Arrays.toString(constructor1.getParameterTypes()), e);
        }
    };
}
 
Example 7
Source File: Implementation.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ParameterList<ParameterDescription.InDefinedShape> getParameters() {
    return new ParameterList.Explicit.ForTypes(this, methodDescription.getParameters().asTypeList().asRawTypes());
}
 
Example 8
Source File: Implementation.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ParameterList<ParameterDescription.InDefinedShape> getParameters() {
    return new ParameterList.Empty<ParameterDescription.InDefinedShape>();
}
 
Example 9
Source File: Implementation.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ParameterList<ParameterDescription.InDefinedShape> getParameters() {
    return new ParameterList.Explicit.ForTypes(this, Collections.singletonList(fieldDescription.getType().asRawType()));
}
 
Example 10
Source File: MethodRebaseResolver.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ParameterList<ParameterDescription.InDefinedShape> getParameters() {
    return new ParameterList.Explicit.ForTypes(this, methodDescription.getParameters().asTypeList().asRawTypes());
}
 
Example 11
Source File: MethodRebaseResolver.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ParameterList<ParameterDescription.InDefinedShape> getParameters() {
    return new ParameterList.Explicit.ForTypes(this, CompoundList.of(methodDescription.getParameters().asTypeList().asErasures(), placeholderType));
}
 
Example 12
Source File: TypePoolDefaultLazyParameterListTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
protected ParameterDescription.InDefinedShape asElement(ParameterDescription element) {
    return element.asDefined();
}
 
Example 13
Source File: ElementMatchers.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Exactly matches a given parameter as a {@link ParameterDescription} in its defined shape.
 *
 * @param parameter The parameter to match by its description
 * @param <T>       The type of the matched object.
 * @return An element matcher that exactly matches the given parameter in its defined shape.
 */
public static <T extends ParameterDescription> ElementMatcher.Junction<T> is(ParameterDescription.InDefinedShape parameter) {
    return definedParameter(new EqualityMatcher<ParameterDescription.InDefinedShape>(parameter));
}
 
Example 14
Source File: ElementMatchers.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Matches a parameter in its defined shape.
 *
 * @param matcher The matcher to apply to the matched parameter's defined shape.
 * @param <T>     The matched object's type.
 * @return A matcher that matches a matched parameter's defined shape.
 */
public static <T extends ParameterDescription> ElementMatcher.Junction<T> definedParameter(ElementMatcher<? super ParameterDescription.InDefinedShape> matcher) {
    return new DefinedShapeMatcher<T, ParameterDescription.InDefinedShape>(matcher);
}