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 File: HandlerMethodInstrumentation.java    From skywalking with 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 #2
Source File: Log4jLogEventInstrumentation.java    From skywalking with 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 #3
Source File: RouteStateInstrumentation.java    From skywalking with 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 #4
Source File: MotanConsumerInstrumentation.java    From skywalking with 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 #5
Source File: HttpClientInstrumentation.java    From skywalking with 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 #6
Source File: MotanProviderInstrumentation.java    From skywalking with 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 #7
Source File: ServerInstrumentation.java    From skywalking with 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 #8
Source File: NettySocketIOPluginClientInstrumentation.java    From skywalking with 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 #9
Source File: ClientCnxnInstrumentation.java    From skywalking with 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 #10
Source File: DispatcherHandlerInstrumentation.java    From skywalking with 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 #11
Source File: ExecuteInstrumentation.java    From skywalking with 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 #12
Source File: MongoDBCollectionInstrumentation.java    From skywalking with 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 #13
Source File: ExecuteInstrumentation.java    From skywalking with 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 #14
Source File: PluginFinder.java    From skywalking with 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 #15
Source File: MongoDBInstrumentation.java    From skywalking with 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 #16
Source File: AbstractControllerInstrumentation.java    From skywalking with 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 File: AsyncExecutionInterceptorInstrumentation.java    From skywalking with 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 #18
Source File: DubboInstrumentation.java    From skywalking with 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 #19
Source File: JDBCRootInvokeInstrumentation.java    From skywalking with 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 #20
Source File: NetflixFeignInstrumentation.java    From skywalking with 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 #21
Source File: RouterImplInstrumentation.java    From skywalking with 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 #22
Source File: AnnotationMatcher.java    From apm-agent-java with 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 #23
Source File: RestTemplateInstrumentation.java    From skywalking with 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;
            }
        }
    };
}
 
Example #24
Source File: SubclassDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ElementMatcher<? super MethodDescription> resolve(TypeDescription typeDescription) {
    // Casting is required by JDK 6.
    return (ElementMatcher<? super MethodDescription>) isVirtual().and(not(isFinal()))
            .and(isVisibleTo(typeDescription))
            .and(not(ignoredMethods.resolve(typeDescription)))
            .or(isDeclaredBy(typeDescription));
}
 
Example #25
Source File: Lettuce5StartSpanInstrumentation.java    From apm-agent-java with 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 #26
Source File: TracerTest.java    From garmadon with 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 File: HierarchyMatch.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public ElementMatcher.Junction buildJunction() {
    ElementMatcher.Junction junction = null;
    for (String superTypeName : parentTypes) {
        if (junction == null) {
            junction = buildSuperClassMatcher(superTypeName);
        } else {
            junction = junction.and(buildSuperClassMatcher(superTypeName));
        }
    }
    junction = junction.and(not(isInterface()));
    return junction;
}
 
Example #28
Source File: ApacheMonitorFilterInstrumentation.java    From apm-agent-java with 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 #29
Source File: ListenableFutureCallbackInstrumentation.java    From skywalking with 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 #30
Source File: SuperMethodCallOtherTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
@SuppressWarnings("unchecked")
public void testStaticMethod() throws Exception {
    when(typeDescription.getSuperClass()).thenReturn(superClass);
    when(methodDescription.isStatic()).thenReturn(true);
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(genericReturnType);
    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);
}