net.bytebuddy.matcher.ElementMatcher.Junction Java Examples

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: BufferAlignmentAgent.java    From agrona with Apache License 2.0 6 votes vote down vote up
private static synchronized void agent(final boolean shouldRedefine, final Instrumentation instrumentation)
{
    BufferAlignmentAgent.instrumentation = instrumentation;
    // all Int methods, and all String method other than
    // XXXStringWithoutLengthXXX or getStringXXX(int, int)
    final Junction<MethodDescription> intVerifierMatcher = nameContains("Int")
        .or(nameMatches(".*String[^W].*").and(not(ElementMatchers.takesArguments(int.class, int.class))));

    alignmentTransformer = new AgentBuilder.Default(new ByteBuddy().with(TypeValidation.DISABLED))
        .with(new AgentBuilderListener())
        .disableClassFormatChanges()
        .with(shouldRedefine ?
            AgentBuilder.RedefinitionStrategy.RETRANSFORMATION : AgentBuilder.RedefinitionStrategy.DISABLED)
        .type(isSubTypeOf(DirectBuffer.class).and(not(isInterface())))
        .transform((builder, typeDescription, classLoader, module) -> builder
            .visit(to(LongVerifier.class).on(nameContains("Long")))
            .visit(to(DoubleVerifier.class).on(nameContains("Double")))
            .visit(to(IntVerifier.class).on(intVerifierMatcher))
            .visit(to(FloatVerifier.class).on(nameContains("Float")))
            .visit(to(ShortVerifier.class).on(nameContains("Short")))
            .visit(to(CharVerifier.class).on(nameContains("Char"))))
        .installOn(instrumentation);
}
 
Example #2
Source File: InstrumentationBuilder.java    From kanela with 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 #3
Source File: ImmutableProxy.java    From reflection-util with Apache License 2.0 5 votes vote down vote up
private static Junction<MethodDescription> isReadyOnlyMethod() {
	return not(isSetter())
		.and(isGetter()
			.or(isHashCode()).or(isEquals()).or(isToString()).or(isClone())
			.or(isDeclaredBy(Object.class))
			.or(isAnnotatedWith(ReadOnly.class)));
}
 
Example #4
Source File: LuaGeneration.java    From Cubes with MIT License 4 votes vote down vote up
public static Class extendClass(Class<?> extend, final LuaTable delegations, Class<?>... inherit) {
  long startTime = System.nanoTime();

  ArrayDeque<Class> toCheck = new ArrayDeque<Class>();
  toCheck.add(extend);
  toCheck.addAll(Arrays.asList(inherit));
  while (!toCheck.isEmpty()) {
    Class check = toCheck.pop();
    for (Method method : check.getDeclaredMethods()) {
      if (Modifier.isAbstract(method.getModifiers())) {
        if (delegations.get(method.getName()).isnil())
          throw new DynamicDelegationError("No delegation for abstract method " + method);
      }
    }
    check = check.getSuperclass();
    if (check != null && check != Object.class) toCheck.add(check);
  }
  
  try {
    ReceiverTypeDefinition<?> build = b.subclass(extend).implement(inherit)
            .method(not(isConstructor()).and(isAbstract())).intercept(MethodDelegation.to(new AbstractInterceptor(delegations)));
    if (!delegations.get("__new__").isnil()) {
      build = build.constructor(isConstructor()).intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(new ConstructorInterceptor(delegations))));
    }
    Junction<MethodDescription> publicMethods = not(isConstructor().or(isAbstract())).and(isPublic()).and(new ElementMatcher<MethodDescription>() {
      @Override
      public boolean matches(MethodDescription target) {
        return !delegations.get(target.getName()).isnil();
      }
    });
    build = build.method(publicMethods).intercept(MethodDelegation.to(new PublicInterceptor(delegations)));
    
    Unloaded unloaded = build.make();
    Loaded loaded = Compatibility.get().load(unloaded);
    Class c = loaded.getLoaded();
    Log.debug("Created dynamic class " + c.getName() + " in " + ((System.nanoTime() - startTime) / 1000000) + "ms");
    return c;
  } catch (Exception e) {
    Log.error("Failed to create dynamic class " + extend.getName() + " " + Arrays.toString(inherit));
    throw new CubesException("Failed to make dynamic class", e);
  }
}
 
Example #5
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 4 votes vote down vote up
public Target intercept(ElementMatcher.Junction<MethodDescription> method, Object implementation) {
    builder.withInterceptorFor(method, implementation);
    return this;
}
 
Example #6
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 4 votes vote down vote up
public Target intercept(ElementMatcher.Junction<MethodDescription> method, Class<?> implementation) {
    builder.withInterceptorFor(method, () -> implementation);
    return this;
}
 
Example #7
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param method
 * @param implementation
 * @return
 */
public Target advise(ElementMatcher.Junction<MethodDescription> method, Class<?> implementation) {
    builder.withAdvisorFor(method, () -> implementation);
    return this;
}
 
Example #8
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param method
 * @param implementation
 * @return
 */
public Target advise(ElementMatcher.Junction<MethodDescription> method, String implementation) {
    builder.withAdvisorFor(method, implementation);
    return this;
}
 
Example #9
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> takesArguments(Integer quantity) { return ElementMatchers.takesArguments(quantity);} 
Example #10
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> takesOneArgumentOf(String type) { return ElementMatchers.takesArgument(0, named(type));} 
Example #11
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> withArgument(Integer index, Class<?> type) { return ElementMatchers.takesArgument(index, type);} 
Example #12
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> withArgument(Class<?> type) { return withArgument(0, type);} 
Example #13
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> anyMethods(String... names) { return io.vavr.collection.List.of(names).map(this::method).reduce(ElementMatcher.Junction::or); } 
Example #14
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> withReturnTypes(Class<?>... types) { return io.vavr.collection.List.of(types).map(ElementMatchers::returns).reduce(ElementMatcher.Junction::or);} 
Example #15
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> methodAnnotatedWith(String annotation) { return ElementMatchers.isAnnotatedWith(named(annotation)); } 
Example #16
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> methodAnnotatedWith(Class<? extends Annotation> annotation) { return ElementMatchers.isAnnotatedWith(annotation); } 
Example #17
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public Junction<? super TypeDescription> anyTypes(String... names) { return io.vavr.collection.List.of(names).map(ElementMatchers::named).reduce(ElementMatcher.Junction::or); } 
Example #18
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> isAbstract() { return ElementMatchers.isAbstract();} 
Example #19
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> isConstructor() { return ElementMatchers.isConstructor();} 
Example #20
Source File: InstrumentationBuilder.java    From kanela with Apache License 2.0 votes vote down vote up
public ElementMatcher.Junction<MethodDescription> method(String name){ return named(name);}