net.bytebuddy.matcher.ElementMatcher Java Examples

The following examples show how to use net.bytebuddy.matcher.ElementMatcher. 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: DispatcherHandlerInstrumentation.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("handle");
            }

            @Override
            public String getMethodsInterceptor() {
                return "org.apache.skywalking.apm.plugin.spring.webflux.v5.DispatcherHandlerHandleMethodInterceptor";
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #2
Source Project: skywalking   Author: apache   File: ServerInstrumentation.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(ENHANCE_METHOD);
                }

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

                @Override
                public boolean isOverrideArgs() {
                    return false;
                }
            }
    };
}
 
Example #3
Source Project: skywalking   Author: apache   File: Log4jLogEventInstrumentation.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.toolkit.activation.log.log4j.v2.x.async.Log4jLogEventConstructorInterceptor";
            }
        }
    };
}
 
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: MotanProviderInstrumentation.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("call");
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #6
Source Project: skywalking   Author: apache   File: ClientCnxnInstrumentation.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("queuePacket").and(takesArgumentWithType(0, "org.apache.zookeeper.proto.RequestHeader"))
                                           .and(takesArgumentWithType(2, "org.apache.jute.Record"));
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #7
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 #8
Source Project: skywalking   Author: apache   File: MongoDBCollectionInstrumentation.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 MONGDB_METHOD_INTERCET_CLASS;
            }
        }
    };
}
 
Example #9
Source Project: skywalking   Author: apache   File: PluginFinder.java    License: Apache License 2.0 6 votes vote down vote up
public ElementMatcher<? super TypeDescription> buildMatch() {
    ElementMatcher.Junction judge = new AbstractJunction<NamedElement>() {
        @Override
        public boolean matches(NamedElement target) {
            return nameMatchDefine.containsKey(target.getActualName());
        }
    };
    judge = judge.and(not(isInterface()));
    for (AbstractClassEnhancePluginDefine define : signatureMatchDefine) {
        ClassMatch match = define.enhanceClass();
        if (match instanceof IndirectMatch) {
            judge = judge.or(((IndirectMatch) match).buildJunction());
        }
    }
    return new ProtectiveShieldMatcher(judge);
}
 
Example #10
Source Project: skywalking   Author: apache   File: MongoDBInstrumentation.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 ElementMatchers.named(METHOD_NAME);
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #11
Source Project: skywalking   Author: apache   File: JDBCRootInvokeInstrumentation.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("executeCallback");
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #12
Source Project: skywalking   Author: apache   File: NetflixFeignInstrumentation.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");
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #13
Source Project: skywalking   Author: apache   File: RouterImplInstrumentation.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 INTERCEPT_CLASS;
                }
            }
    };
}
 
Example #14
Source Project: skywalking   Author: apache   File: DubboInstrumentation.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("invoke");
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #15
Source Project: skywalking   Author: apache   File: AsyncExecutionInterceptorInstrumentation.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("doSubmit").and(takesArgumentWithType(0, "java.util.concurrent.Callable"));
            }

            @Override
            public String getMethodsInterceptor() {
                return "org.apache.skywalking.apm.plugin.spring.async.DoSubmitMethodInterceptor";
            }

            @Override
            public boolean isOverrideArgs() {
                return 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.v4.ControllerConstructorInterceptor";
            }
        }
    };
}
 
Example #17
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 #18
Source Project: skywalking   Author: apache   File: HandlerMethodInstrumentation.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(ENHANCE_METHOD);
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #19
Source Project: skywalking   Author: apache   File: MotanConsumerInstrumentation.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("call");
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #20
Source Project: skywalking   Author: apache   File: NettySocketIOPluginClientInstrumentation.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("joinRoom").or(named("leaveRoom"));
            }

            @Override
            public String getMethodsInterceptor() {
                return "org.apache.skywalking.apm.plugin.netty.socketio.NettySocketIORoomInterceptor";
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }

        }
    };
}
 
Example #21
Source Project: skywalking   Author: apache   File: HttpClientInstrumentation.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("executeMethod").and(takesArguments(3))
                                             .and(takesArgument(0, named("org.apache.commons.httpclient.HostConfiguration")))
                                             .and(takesArgument(1, named("org.apache.commons.httpclient.HttpMethod")))
                                             .and(takesArgument(2, named("org.apache.commons.httpclient.HttpState")));
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #22
Source Project: apm-agent-java   Author: elastic   File: ExecutorInstrumentation.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <ul>
 *     <li>{@link ExecutorService#invokeAll}</li>
 *     <li>{@link ExecutorService#invokeAny}</li>
 * </ul>
 */
@Override
public ElementMatcher<? super MethodDescription> getMethodMatcher() {
    return nameStartsWith("invoke")
        .and(nameEndsWith("Any").or(nameEndsWith("All")))
        .and(isPublic())
        .and(takesArgument(0, Collection.class))
        .and(isOverriddenFrom(ExecutorService.class));
}
 
Example #23
Source Project: byte-buddy   Author: raphw   File: SuperMethodCallOtherTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
@SuppressWarnings("unchecked")
public void testNoSuper() throws Exception {
    when(typeDescription.getSuperClass()).thenReturn(superClass);
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(genericReturnType);
    when(methodDescription.getDeclaringType()).thenReturn(declaringType);
    when(declaringType.getStackSize()).thenReturn(StackSize.SINGLE);
    when(returnType.getStackSize()).thenReturn(StackSize.SINGLE);
    when(rawSuperClass.getDeclaredMethods()).thenReturn(superClassMethods);
    when(superClassMethods.filter(any(ElementMatcher.class))).thenReturn(superClassMethods);
    when(implementationTarget.invokeDominant(token)).thenReturn(Implementation.SpecialMethodInvocation.Illegal.INSTANCE);
    SuperMethodCall.INSTANCE.appender(implementationTarget).apply(methodVisitor, implementationContext, methodDescription);
}
 
Example #24
Source Project: apm-agent-java   Author: elastic   File: ApacheMonitorFilterInstrumentation.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@link org.apache.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}
 */
@Override
public ElementMatcher<? super MethodDescription> getMethodMatcher() {
    return named("invoke")
        .and(takesArgument(0, named("org.apache.dubbo.rpc.Invoker")))
        .and(takesArgument(1, named("org.apache.dubbo.rpc.Invocation")))
        // makes sure we only instrument Dubbo 2.7.3+ which introduces this method
        .and(returns(named("org.apache.dubbo.rpc.Result")
            .and(declaresMethod(named("whenCompleteWithContext")
                .and(takesArgument(0, named("java.util.function.BiConsumer")))))));
}
 
Example #25
Source Project: skywalking   Author: apache   File: ListenableFutureCallbackInstrumentation.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named(SuccessCallbackInstrumentation.SUCCESS_METHOD_NAME);
            }

            @Override
            public String getMethodsInterceptor() {
                return SuccessCallbackInstrumentation.SUCCESS_CALLBACK_INTERCEPTOR;
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        },
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named(FailureCallbackInstrumentation.FAILURE_METHOD_NAME);
            }

            @Override
            public String getMethodsInterceptor() {
                return FailureCallbackInstrumentation.FAILURE_CALLBACK_INTERCEPTOR;
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #26
Source Project: garmadon   Author: criteo   File: TracerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void Tracer_should_exclude_undesired_packages(){
    ElementMatcher<NamedElement> matcher = Tracer.ignoredMatcher;

    assertThat(matcher.matches(() -> "java."), is(true));
    assertThat(matcher.matches(() -> "org.mockito"), is(true));
    assertThat(matcher.matches(() -> "sun.net."), is(true));
    assertThat(matcher.matches(() -> "com.criteo.hadoop.garmadon."), is(true));
    assertThat(matcher.matches(() -> "com.criteo.jvm."), is(true));
}
 
Example #27
Source Project: apm-agent-java   Author: elastic   File: AnnotationMatcher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test if the target has any annotations matching the annotationPattern of this matcher.
 *
 * @param target the AnnotationSource to test.
 * @return true if the target has an annotation matching the annotationPattern of this AnnotationMatcher, else false.
 * If this AnnotationMatcher was initialized with {@link #matchAll()} always returns true.
 */
public boolean matches(AnnotationSource target) {
    if (matchesAll()) {
        return true;
    }

    ElementMatcher.Junction<AnnotationSource> resultMatcher = isAnnotatedWith(CustomElementMatchers.matches(wildcardMatcher));
    if (metaAnnotation) {
        resultMatcher = isAnnotatedWith(resultMatcher);
    }
    return resultMatcher.matches(target);
}
 
Example #28
Source Project: skywalking   Author: apache   File: StatementInstrumentation.java    License: Apache License 2.0 5 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"))
                                       .or(named("executeBatchInternal"))
                                       .or(named("executeUpdateInternal"))
                                       .or(named("executeQuery"))
                                       .or(named("executeBatch"));
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}
 
Example #29
Source Project: apm-agent-java   Author: elastic   File: Lettuce5StartSpanInstrumentation.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ElementMatcher<? super MethodDescription> getMethodMatcher() {
    return named("dispatch")
        .and(returns(nameEndsWith("RedisCommand")))
        .and(takesArguments(1))
        .and(takesArgument(0, nameEndsWith("RedisCommand")));
}
 
Example #30
Source Project: skywalking   Author: apache   File: RestTemplateInstrumentation.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
    return new InstanceMethodsInterceptPoint[] {
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named(DO_EXECUTE_METHOD_NAME);
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        },
        new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named(CREATE_REQUEST_METHOD_NAME);
            }

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

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }
    };
}