net.bytebuddy.description.method.MethodDescription Java Examples

The following examples show how to use net.bytebuddy.description.method.MethodDescription. 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 Project: skywalking   Author: apache   File: PreparedStatementInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named("execute").or(named("executeQuery"))
                                       .or(named("executeUpdate"))
                                       .or(named("executeLargeUpdate"));
            }

            @Override
            public String getMethodsInterceptor() {
                return SERVICE_METHOD_INTERCEPTOR;
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #2
Source Project: skywalking   Author: apache   File: ExecuteInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named("execute0");
            }

            @Override
            public String getMethodsInterceptor() {
                return EXECUTE_INTERCEPTOR_CLASS;
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #3
Source Project: byte-buddy   Author: raphw   File: AdviceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAssigningEnterPostProcessorInline() throws Exception {
    Class<?> type = new ByteBuddy()
            .redefine(PostProcessorInlineTest.class)
            .visit(Advice.withCustomMapping().with(new Advice.PostProcessor.Factory() {
                @Override
                public Advice.PostProcessor make(final MethodDescription.InDefinedShape advice, boolean exit) {
                    return new Advice.PostProcessor() {
                        @Override
                        public StackManipulation resolve(TypeDescription instrumentedType,
                                                         MethodDescription instrumentedMethod,
                                                         Assigner assigner,
                                                         Advice.ArgumentHandler argumentHandler) {
                            return new StackManipulation.Compound(
                                MethodVariableAccess.of(advice.getReturnType()).loadFrom(argumentHandler.enter()),
                                MethodVariableAccess.store(instrumentedMethod.getParameters().get(0))
                            );
                        }
                    };
                }
            }).to(PostProcessorInlineTest.class).on(named(FOO)))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(type.getDeclaredMethod(FOO, String.class).invoke(type.getDeclaredConstructor().newInstance(), BAR), is((Object) FOO));
}
 
Example #4
Source Project: skywalking   Author: apache   File: RouteStateInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
    return new ConstructorInterceptPoint[] {
            new ConstructorInterceptPoint() {
                @Override
                public ElementMatcher<MethodDescription> getConstructorMatcher() {
                    return takesArgument(8, List.class);
                }

                @Override
                public String getConstructorInterceptor() {
                    return INTERCEPT_CLASS;
                }
            }
    };
}
 
Example #5
Source Project: skywalking   Author: apache   File: TransportServiceInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
    return new ConstructorInterceptPoint[] {
        new ConstructorInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getConstructorMatcher() {
                return any();
            }

            @Override
            public String getConstructorInterceptor() {
                return ENHANCE_CLASS;
            }
        }
    };
}
 
Example #6
Source Project: byte-buddy   Author: raphw   File: MethodGraphCompilerDefaultTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericClassMultipleEvolution() throws Exception {
    TypeDescription typeDescription = TypeDescription.ForLoadedType.of(GenericClassBase.Intermediate.Inner.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
    MethodDescription.SignatureToken token = typeDescription.getDeclaredMethods().filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly().asSignatureToken();
    MethodGraph.Node node = methodGraph.locate(token);
    MethodDescription.SignatureToken firstBridgeToken = typeDescription.getSuperClass().getDeclaredMethods()
            .filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly().asDefined().asSignatureToken();
    MethodDescription.SignatureToken secondBridgeToken = typeDescription.getSuperClass().getSuperClass().getDeclaredMethods()
            .filter(isMethod()).getOnly().asDefined().asSignatureToken();
    assertThat(node, is(methodGraph.locate(firstBridgeToken)));
    assertThat(node, is(methodGraph.locate(secondBridgeToken)));
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(3));
    assertThat(node.getMethodTypes().contains(token.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(firstBridgeToken.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(secondBridgeToken.asTypeToken()), is(true));
    assertThat(node.getVisibility(), is(Visibility.PUBLIC));
}
 
Example #7
Source Project: byte-buddy   Author: raphw   File: AsmVisitorWrapper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public MethodVisitor wrap(TypeDescription instrumentedType,
                          MethodDescription instrumentedMethod,
                          MethodVisitor methodVisitor,
                          Implementation.Context implementationContext,
                          TypePool typePool,
                          int writerFlags,
                          int readerFlags) {
    for (MethodVisitorWrapper methodVisitorWrapper : methodVisitorWrappers) {
        methodVisitor = methodVisitorWrapper.wrap(instrumentedType,
                instrumentedMethod,
                methodVisitor,
                implementationContext,
                typePool,
                writerFlags,
                readerFlags);
    }
    return methodVisitor;
}
 
Example #8
Source Project: skywalking   Author: apache   File: RabbitMQConsumerInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {
        new DeclaredInstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named(ENHANCE_METHOD_DISPATCH).and(takesArgumentWithType(2, "com.rabbitmq.client.AMQP$BasicProperties"));
            }

            @Override
            public String getMethodsInterceptor() {
                return INTERCEPTOR_CLASS;
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #9
Source Project: byte-buddy   Author: raphw   File: AbstractDynamicTypeBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@JavaVersionRule.Enforce(8)
@SuppressWarnings("unchecked")
public void testTypeVariableOnTypeAnnotationClassBound() throws Exception {
    Class<? extends Annotation> typeAnnotationType = (Class<? extends Annotation>) Class.forName(TYPE_VARIABLE_NAME);
    MethodDescription.InDefinedShape value = TypeDescription.ForLoadedType.of(typeAnnotationType).getDeclaredMethods().filter(named(VALUE)).getOnly();
    Class<?> type = createPlain()
            .typeVariable(FOO, TypeDescription.Generic.Builder.rawType(Object.class)
                    .build(AnnotationDescription.Builder.ofType(typeAnnotationType).define(VALUE, INTEGER_VALUE * 2).build()))
            .annotateTypeVariable(AnnotationDescription.Builder.ofType(typeAnnotationType).define(VALUE, INTEGER_VALUE).build())
            .make()
            .load(typeAnnotationType.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
            .getLoaded();
    assertThat(type.getTypeParameters().length, is(1));
    assertThat(type.getTypeParameters()[0].getBounds().length, is(1));
    assertThat(type.getTypeParameters()[0].getBounds()[0], is((Object) Object.class));
    assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveTypeVariable(type.getTypeParameters()[0]).asList().size(), is(1));
    assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveTypeVariable(type.getTypeParameters()[0]).asList().ofType(typeAnnotationType)
            .getValue(value).resolve(Integer.class), is(INTEGER_VALUE));
    assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveTypeVariable(type.getTypeParameters()[0]).ofTypeVariableBoundType(0)
            .asList().size(), is(1));
    assertThat(TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveTypeVariable(type.getTypeParameters()[0]).ofTypeVariableBoundType(0)
            .asList().ofType(typeAnnotationType).getValue(value).resolve(Integer.class), is(INTEGER_VALUE * 2));
}
 
Example #10
Source Project: skywalking   Author: apache   File: MinimalHttpClientInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named("doExecute");
            }

            @Override
            public String getMethodsInterceptor() {
                return getInstanceMethodsInterceptor();
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #11
Source Project: skywalking   Author: apache   File: CallableInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named("execute").or(named("executeQuery")).or(named("executeUpdate"));
            }

            @Override
            public String getMethodsInterceptor() {
                return SERVICE_METHOD_INTERCEPTOR;
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #12
Source Project: skywalking   Author: apache   File: SkywalkingContinuationActivation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
    return new ConstructorInterceptPoint[] {
        new ConstructorInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getConstructorMatcher() {
                return any();
            }

            @Override
            public String getConstructorInterceptor() {
                return CONSTRUCTOR_INTERCEPTOR;
            }
        }
    };
}
 
Example #13
Source Project: byte-buddy   Author: raphw   File: AbstractDynamicTypeBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExplicitTypeInitializer() throws Exception {
    assertThat(createPlain()
            .defineField(FOO, String.class, Ownership.STATIC, Visibility.PUBLIC)
            .initializer(new ByteCodeAppender() {
                public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) {
                    return new Size(new StackManipulation.Compound(
                            new TextConstant(FOO),
                            FieldAccess.forField(instrumentedMethod.getDeclaringType().getDeclaredFields().filter(named(FOO)).getOnly()).write()
                    ).apply(methodVisitor, implementationContext).getMaximalSize(), instrumentedMethod.getStackSize());
                }
            }).make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded()
            .getDeclaredField(FOO)
            .get(null), is((Object) FOO));
}
 
Example #14
Source Project: skywalking   Author: apache   File: AbstractNutzHttpInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named(DO_SEND_METHOD_NAME);
            }

            @Override
            public String getMethodsInterceptor() {
                return DO_SEND_INTERCEPTOR;
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #15
@Test
@SuppressWarnings("unchecked")
@JavaVersionRule.Enforce(8)
public void testGenericInnerTypeAnnotationReceiverTypeOnConstructor() throws Exception {
    Class<? extends Annotation> typeAnnotation = (Class<? extends Annotation>) Class.forName(TYPE_ANNOTATION);
    MethodDescription.InDefinedShape value = TypeDescription.ForLoadedType.of(typeAnnotation).getDeclaredMethods().getOnly();
    TypeDescription.Generic receiverType = describe(Class.forName(RECEIVER_TYPE_SAMPLE + "$" + GENERIC + "$" + INNER))
            .getDeclaredMethods()
            .filter(isConstructor())
            .getOnly()
            .getReceiverType();
    assertThat(receiverType, notNullValue(TypeDescription.Generic.class));
    assertThat(receiverType.getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(receiverType.asErasure().represents(Class.forName(RECEIVER_TYPE_SAMPLE + "$" + GENERIC)), is(true));
    assertThat(receiverType.getDeclaredAnnotations().size(), is(1));
    assertThat(receiverType.getDeclaredAnnotations().isAnnotationPresent(typeAnnotation), is(true));
    assertThat(receiverType.getDeclaredAnnotations().ofType(typeAnnotation).getValue(value).resolve(Integer.class), is(10));
    assertThat(receiverType.getTypeArguments().getOnly().getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(receiverType.getTypeArguments().getOnly().getSymbol(), is(T));
    assertThat(receiverType.getTypeArguments().getOnly().getDeclaredAnnotations().size(), is(1));
    assertThat(receiverType.getTypeArguments().getOnly().getDeclaredAnnotations().isAnnotationPresent(typeAnnotation), is(true));
    assertThat(receiverType.getTypeArguments().getOnly().getDeclaredAnnotations().ofType(typeAnnotation).getValue(value).resolve(Integer.class), is(11));
    assertThat(receiverType.getOwnerType().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(receiverType.getOwnerType().represents(Class.forName(RECEIVER_TYPE_SAMPLE)), is(true));
}
 
Example #16
Source Project: skywalking   Author: apache   File: AbstractControllerInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
    return new ConstructorInterceptPoint[] {
        new ConstructorInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getConstructorMatcher() {
                return any();
            }

            @Override
            public String getConstructorInterceptor() {
                return "org.apache.skywalking.apm.plugin.spring.mvc.v5.ControllerConstructorInterceptor";
            }
        }
    };
}
 
Example #17
Source Project: skywalking   Author: apache   File: KafkaTemplateCallbackInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
    return new ConstructorInterceptPoint[] {
        new ConstructorInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getConstructorMatcher() {
                return takesArgumentWithType(0, CONSTRUCTOR_INTERCEPT_TYPE);
            }

            @Override
            public String getConstructorInterceptor() {
                return CONSTRUCTOR_INTERCEPTOR_CLASS;
            }
        }
    };
}
 
Example #18
Source Project: skywalking   Author: apache   File: HttpClientRequestImplInstrumentation.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[]{
            new InstanceMethodsInterceptPoint() {
                @Override
                public ElementMatcher<MethodDescription> getMethodsMatcher() {
                    return named("end")
                            .or(named("sendHead").and(takesArguments(1)));
                }

                @Override
                public String getMethodsInterceptor() {
                    return INTERCEPT_CLASS;
                }

                @Override
                public boolean isOverrideArgs() {
                    return false;
                }
            }
    };
}
 
Example #19
Source Project: byte-buddy   Author: raphw   File: MethodCall.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public List<ArgumentLoader> resolve(MethodDescription instrumentedMethod, MethodDescription invokedMethod) {
    if (instrumentedMethod.isStatic()) {
        throw new IllegalStateException(instrumentedMethod + " is static and cannot supply an invoker instance");
    }
    return Collections.<ArgumentLoader>singletonList(this);
}
 
Example #20
Source Project: byte-buddy   Author: raphw   File: MethodGraphCompilerDefaultTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDominantInterfaceInheritanceLeft() throws Exception {
    TypeDescription typeDescription = TypeDescription.ForLoadedType.of(AmbiguousInterfaceBase.DominantInterfaceTargetLeft.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(1));
    MethodDescription methodDescription = TypeDescription.ForLoadedType.of(AmbiguousInterfaceBase.DominantIntermediate.class)
            .getDeclaredMethods().getOnly();
    MethodGraph.Node node = methodGraph.locate(methodDescription.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(1));
    assertThat(node.getMethodTypes().contains(methodDescription.asTypeToken()), is(true));
    assertThat(node.getRepresentative(), is(methodDescription));
    assertThat(node.getVisibility(), is(methodDescription.getVisibility()));
}
 
Example #21
Source Project: byte-buddy   Author: raphw   File: MethodCallProxy.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates the precomputed method graph.
 */
@SuppressFBWarnings(value = "SE_BAD_FIELD_STORE", justification = "Precomputed method graph is not intended for serialization")
PrecomputedMethodGraph() {
    LinkedHashMap<MethodDescription.SignatureToken, MethodGraph.Node> nodes = new LinkedHashMap<MethodDescription.SignatureToken, MethodGraph.Node>();
    MethodDescription callMethod = new MethodDescription.Latent(TypeDescription.ForLoadedType.of(Callable.class),
            "call",
            Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT,
            Collections.<TypeVariableToken>emptyList(),
            TypeDescription.Generic.OBJECT,
            Collections.<ParameterDescription.Token>emptyList(),
            Collections.singletonList(TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(Exception.class)),
            Collections.<AnnotationDescription>emptyList(),
            AnnotationValue.UNDEFINED,
            TypeDescription.Generic.UNDEFINED);
    nodes.put(callMethod.asSignatureToken(), new MethodGraph.Node.Simple(callMethod));
    MethodDescription runMethod = new MethodDescription.Latent(TypeDescription.ForLoadedType.of(Runnable.class),
            "run",
            Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT,
            Collections.<TypeVariableToken>emptyList(),
            TypeDescription.Generic.VOID,
            Collections.<ParameterDescription.Token>emptyList(),
            Collections.<TypeDescription.Generic>emptyList(),
            Collections.<AnnotationDescription>emptyList(),
            AnnotationValue.UNDEFINED,
            TypeDescription.Generic.UNDEFINED);
    nodes.put(runMethod.asSignatureToken(), new MethodGraph.Node.Simple(runMethod));
    MethodGraph methodGraph = new MethodGraph.Simple(nodes);
    this.methodGraph = new MethodGraph.Linked.Delegation(methodGraph, methodGraph, Collections.<TypeDescription, MethodGraph>emptyMap());
}
 
Example #22
Source Project: byte-buddy   Author: raphw   File: FieldAccessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected StackManipulation resolve(Void unused,
                                    FieldDescription fieldDescription,
                                    TypeDescription instrumentedType,
                                    MethodDescription instrumentedMethod) {
    if (instrumentedMethod.getParameters().size() <= index) {
        throw new IllegalStateException(instrumentedMethod + " does not define a parameter with index " + index);
    } else {
        return new StackManipulation.Compound(
                MethodVariableAccess.load(instrumentedMethod.getParameters().get(index)),
                assigner.assign(instrumentedMethod.getParameters().get(index).getType(), fieldDescription.getType(), typing)
        );
    }
}
 
Example #23
Source Project: byte-buddy   Author: raphw   File: InvokeDynamic.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new abstract delegator for a dynamic method invocation where the last argument is assigned an implicit type.
 *
 * @param bootstrap           The bootstrap method or constructor.
 * @param arguments           The arguments that are provided to the bootstrap method.
 * @param invocationProvider  The target provided that identifies the method to be bootstrapped.
 * @param terminationHandler  A handler that handles the method return.
 * @param assigner            The assigner to be used.
 * @param typing              Indicates if dynamic type castings should be attempted for incompatible assignments.
 * @param fieldName           The field name.
 * @param fieldLocatorFactory The field locator factory to use.
 */
protected OfField(MethodDescription.InDefinedShape bootstrap,
                  List<?> arguments,
                  InvocationProvider invocationProvider,
                  TerminationHandler terminationHandler,
                  Assigner assigner,
                  Assigner.Typing typing,
                  String fieldName,
                  FieldLocator.Factory fieldLocatorFactory) {
    super(bootstrap, arguments, invocationProvider, terminationHandler, assigner, typing);
    this.fieldName = fieldName;
    this.fieldLocatorFactory = fieldLocatorFactory;
}
 
Example #24
Source Project: byte-buddy   Author: raphw   File: MemberSubstitution.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Binding bind(TypeDescription instrumentedType,
                    MethodDescription instrumentedMethod,
                    TypeDescription typeDescription,
                    MethodDescription methodDescription,
                    InvocationType invocationType) {
    return invocationType.matches(includeVirtualCalls, includeSuperCalls) && methodMatcher.matches(methodDescription)
            ? new Binding.Resolved(instrumentedType, instrumentedMethod, typeDescription, methodDescription, substitution)
            : Binding.Unresolved.INSTANCE;
}
 
Example #25
Source Project: lams   Author: lamsfoundation   File: EnhancerImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
static MethodDescription getterOf(FieldDescription persistentField) {
	MethodList<?> methodList = MethodGraph.Compiler.DEFAULT.compile( persistentField.getDeclaringType().asErasure() )
			.listNodes()
			.asMethodList()
			.filter( isGetter(persistentField.getName() ) );
	if ( methodList.size() == 1 ) {
		return methodList.getOnly();
	}
	else {
		return null;
	}
}
 
Example #26
Source Project: byte-buddy   Author: raphw   File: MethodGraph.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Registers a new top level method within this store.
 *
 * @param methodDescriptions The methods to register.
 * @param harmonizer         The harmonizer to use for determining method equality.
 * @return A store with the given method registered as a top-level method.
 */
protected Store<V> registerTopLevel(List<? extends MethodDescription> methodDescriptions, Harmonizer<V> harmonizer) {
    if (methodDescriptions.isEmpty()) {
        return this;
    }
    LinkedHashMap<Harmonized<V>, Entry<V>> entries = new LinkedHashMap<Harmonized<V>, Entry<V>>(this.entries);
    for (MethodDescription methodDescription : methodDescriptions) {
        Harmonized<V> key = Harmonized.of(methodDescription, harmonizer);
        Entry<V> currentEntry = entries.remove(key), extendedEntry = (currentEntry == null
                ? new Entry.Initial<V>(key)
                : currentEntry).extendBy(methodDescription, harmonizer);
        entries.put(extendedEntry.getKey(), extendedEntry);
    }
    return new Store<V>(entries);
}
 
Example #27
Source Project: kanela   Author: kamon-io   File: InstrumentationBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public Target onTypesWithMethodsAnnotatedWith(String annotationName) {
    val builder = new InstrumentationDescription.Builder();
    val target = new Target(builder);
    final ElementMatcher.Junction<MethodDescription>  methodMatcher = isAnnotatedWith(named(annotationName));
    builder.addElementMatcher(() -> defaultTypeMatcher.apply().and(failSafe(hasSuperType(declaresMethod(methodMatcher)))));
    targets.add(target);
    return target;
}
 
Example #28
Source Project: byte-buddy   Author: raphw   File: MethodGraph.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry<U> extendBy(MethodDescription methodDescription, Harmonizer<U> harmonizer) {
    return new Resolved<U>(key.extend(methodDescription.asDefined(), harmonizer),
            methodDescription,
            methodDescription.getVisibility(),
            Resolved.NOT_MADE_VISIBLE);
}
 
Example #29
Source Project: skywalking   Author: apache   File: TransportClientNodesServiceInstrumentation.java    License: Apache License 2.0 5 votes vote down vote up
@Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
    return new ConstructorInterceptPoint[] {
        new ConstructorInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getConstructorMatcher() {
                return takesArgumentWithType(1, "org.elasticsearch.transport.TransportService");
            }

            @Override
            public String getConstructorInterceptor() {
                return INTERCEPTOR_CLASS;
            }
        }
    };
}
 
Example #30
Source Project: byte-buddy   Author: raphw   File: MethodDelegationBinder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public MethodBinding bind(Implementation.Target implementationTarget,
                          MethodDescription source,
                          TerminationHandler terminationHandler,
                          MethodInvoker methodInvoker,
                          Assigner assigner) {
    return MethodBinding.Illegal.INSTANCE;
}