Java Code Examples for net.bytebuddy.matcher.ElementMatcher#Junction
The following examples show how to use
net.bytebuddy.matcher.ElementMatcher#Junction .
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: PluginFinder.java From skywalking with Apache License 2.0 | 6 votes |
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 2
Source File: MethodInheritanceAnnotationMatcherTest.java From skywalking with Apache License 2.0 | 6 votes |
@Test public void testMatch() throws Exception { ElementMatcher.Junction<AnnotationSource> matcher = byMethodInheritanceAnnotationMatcher(named("org.apache.skywalking.apm.agent.core.plugin.bytebuddy.MethodInheritanceAnnotationMatcherTest$TestAnnotaion")); Assert.assertTrue(matcher.matches(new MethodDescription.ForLoadedMethod(TestBean.class.getMethod("test1", String.class)))); Assert.assertTrue(matcher.matches(new MethodDescription.ForLoadedMethod(TestBean.class.getMethod("test2", String.class)))); Assert.assertTrue(matcher.matches(new MethodDescription.ForLoadedMethod(TestBean.class.getMethod("test3", String.class)))); }
Example 3
Source File: ExecutorInstrumentation.java From opencensus-java with Apache License 2.0 | 6 votes |
private static ElementMatcher.Junction<TypeDescription> createMatcher() { // This matcher matches implementations of Executor, but excludes CurrentContextExecutor and // FixedContextExecutor from io.grpc.Context, which already propagate the context. // TODO(stschmidt): As the executor implementation itself (e.g. ThreadPoolExecutor) is // instrumented by the agent for automatic context propagation, CurrentContextExecutor could be // turned into a no-op to avoid another unneeded context propagation. Likewise, when using // FixedContextExecutor, the automatic context propagation added by the agent is unneeded. return isSubTypeOf(Executor.class) .and(not(isAbstract())) .and( not( nameStartsWith("io.grpc.Context$") .and( nameEndsWith("CurrentContextExecutor") .or(nameEndsWith("FixedContextExecutor"))))); }
Example 4
Source File: ElasticApmAgent.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Nullable private static ElementMatcher.Junction<? super TypeDescription> getTypeMatcher(@Nullable Class<?> classToInstrument, ElementMatcher<? super MethodDescription> methodMatcher, ElementMatcher.Junction<? super TypeDescription> typeMatcher) { if (classToInstrument == null) { return typeMatcher; } if (matches(classToInstrument, methodMatcher)) { // even if we have a match in this class, there could be another match in a super class //if the method matcher matches multiple methods typeMatcher = is(classToInstrument).or(typeMatcher); } return getTypeMatcher(classToInstrument.getSuperclass(), methodMatcher, typeMatcher); }
Example 5
Source File: CustomElementMatchers.java From apm-agent-java with Apache License 2.0 | 5 votes |
public static ElementMatcher.Junction<NamedElement> isInAnyPackage(Collection<String> includedPackages, ElementMatcher.Junction<NamedElement> defaultIfEmpty) { if (includedPackages.isEmpty()) { return defaultIfEmpty; } ElementMatcher.Junction<NamedElement> matcher = none(); for (String applicationPackage : includedPackages) { matcher = matcher.or(nameStartsWith(applicationPackage)); } return matcher; }
Example 6
Source File: ToStringMethod.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a new {@code toString} implementation. * * @param prefixResolver A resolver for the prefix of a {@link String} representation. * @param start A token that is added between the prefix and the first field value. * @param end A token that is added after the last field value. * @param separator A token that is added between two field values. * @param definer A token that is added between a field's name and its value. * @param ignored A filter that determines what fields to ignore. */ private ToStringMethod(PrefixResolver prefixResolver, String start, String end, String separator, String definer, ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored) { this.prefixResolver = prefixResolver; this.start = start; this.end = end; this.separator = separator; this.definer = definer; this.ignored = ignored; }
Example 7
Source File: MultiClassNameMatch.java From skywalking with Apache License 2.0 | 5 votes |
@Override public ElementMatcher.Junction buildJunction() { ElementMatcher.Junction junction = null; for (String name : matchClassNames) { if (junction == null) { junction = named(name); } else { junction = junction.or(named(name)); } } return junction; }
Example 8
Source File: InliningImplementationMatcher.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a matcher where only overridable or declared methods are matched unless those are ignored. Methods that * are declared by the target type are only matched if they are not ignored. Declared methods that are not found on the * target type are always matched. * * @param ignoredMethods A method matcher that matches any ignored method. * @param originalType The original type of the instrumentation before adding any user methods. * @return A latent method matcher that identifies any method to instrument for a rebasement or redefinition. */ protected static LatentMatcher<MethodDescription> of(LatentMatcher<? super MethodDescription> ignoredMethods, TypeDescription originalType) { ElementMatcher.Junction<MethodDescription> predefinedMethodSignatures = none(); for (MethodDescription methodDescription : originalType.getDeclaredMethods()) { ElementMatcher.Junction<MethodDescription> signature = methodDescription.isConstructor() ? isConstructor() : ElementMatchers.<MethodDescription>named(methodDescription.getName()); signature = signature.and(returns(methodDescription.getReturnType().asErasure())); signature = signature.and(takesArguments(methodDescription.getParameters().asTypeList().asErasures())); predefinedMethodSignatures = predefinedMethodSignatures.or(signature); } return new InliningImplementationMatcher(ignoredMethods, predefinedMethodSignatures); }
Example 9
Source File: InstrumentationBuilder.java From kanela with Apache License 2.0 | 4 votes |
public Target intercept(ElementMatcher.Junction<MethodDescription> method, Object implementation) { builder.withInterceptorFor(method, implementation); return this; }
Example 10
Source File: AdvisorDescription.java From kanela with Apache License 2.0 | 4 votes |
public static AdvisorDescription of(ElementMatcher.Junction<MethodDescription> methodMatcher, Class<?> advisorClass) { return new AdvisorDescription(methodMatcher, advisorClass, null); }
Example 11
Source File: KanelaAgentBuilder.java From kanela with Apache License 2.0 | 4 votes |
private ElementMatcher.Junction<NamedElement> moduleExcludes() { return nameMatches(moduleDescription.getExcludePackage()); }
Example 12
Source File: CaptureTransactionInstrumentation.java From apm-agent-java with Apache License 2.0 | 4 votes |
@Override public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() { return classLoaderCanLoadClass("co.elastic.apm.api.CaptureTransaction"); }
Example 13
Source File: InstrumentationDescription.java From kanela with Apache License 2.0 | 4 votes |
public Builder withAdvisorFor(ElementMatcher.Junction<MethodDescription> methodDescription , Supplier<Class<?>> classSupplier) { advisors.add(AdvisorDescription.of(methodDescription.and(defaultMethodElementMatcher()), classSupplier.get())); return this; }
Example 14
Source File: MethodAnnotationMatch.java From skywalking with Apache License 2.0 | 4 votes |
private ElementMatcher.Junction buildEachAnnotation(String annotationName) { return isAnnotatedWith(named(annotationName)); }
Example 15
Source File: EitherInterfaceMatch.java From skywalking with Apache License 2.0 | 4 votes |
@Override public ElementMatcher.Junction buildJunction() { return not(nameStartsWith(SPRING_PACKAGE_PREFIX)). and(hasSuperType(named(getMatchInterface()))) .and(not(hasSuperType(named(getMutexInterface())))); }
Example 16
Source File: JaxRsTransactionNameInstrumentation.java From apm-agent-java with Apache License 2.0 | 4 votes |
@Override public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() { return not(isBootstrapClassLoader()) .and(classLoaderCanLoadClass("javax.ws.rs.Path")); }
Example 17
Source File: MethodInheritanceAnnotationMatcher.java From skywalking with Apache License 2.0 | 4 votes |
public static <T extends AnnotationSource> ElementMatcher.Junction<T> byMethodInheritanceAnnotationMatcher( ElementMatcher<? super TypeDescription> matcher) { return new MethodInheritanceAnnotationMatcher(new CollectionItemMatcher<>(annotationType(matcher))); }
Example 18
Source File: InstrumentationBuilder.java From kanela with Apache License 2.0 | 4 votes |
public Target intercept(ElementMatcher.Junction<MethodDescription> method, Class<?> implementation) { builder.withInterceptorFor(method, () -> implementation); return this; }
Example 19
Source File: TypeReferenceAdjustment.java From byte-buddy with Apache License 2.0 | 2 votes |
/** * Creates a type reference adjustment. * * @param strict {@code true} if the visitor should throw an exception if a type reference cannot be located. * @param filter A filter for excluding types from type reference analysis. */ protected TypeReferenceAdjustment(boolean strict, ElementMatcher.Junction<? super TypeDescription> filter) { this.strict = strict; this.filter = filter; }
Example 20
Source File: InstrumentationBuilder.java From kanela with Apache License 2.0 | votes |
public ElementMatcher.Junction<MethodDescription> withReturnTypes(Class<?>... types) { return io.vavr.collection.List.of(types).map(ElementMatchers::returns).reduce(ElementMatcher.Junction::or);}