@Test public void should_capture_name_of_method_called() throws Exception { final Instrumentation inst = ByteBuddyAgent.install(); final ByteBuddy bb = new ByteBuddy(); final P2<Gather.Exports, Gather.Transforms> pair = List.iterableList(TypeDescription.ForLoadedType.of(Foo.class).getDeclaredMethods()) .foldLeft(Main.gather(bb, new MockComp()), P.p(c -> TreeMap.empty(Ord.stringOrd), c -> r -> a -> a)); final Config config = ConfigFactory.empty(); pair._2() .f(config) .f(k -> pair._1().f(config).get().f(k).some()) .f(new AgentBuilder.Default(bb).with(Main.LoggerListener.DEFAULT)).installOn(inst); final Class<?> bar = getClass().getClassLoader().loadClass("ji.core.MainTest$Bar"); bar.getDeclaredMethod("baz", String.class).invoke(null, "123"); assertThat(Foo.ref().get(), is("baz")); }
@VisibleForTesting static F<P2<Exports, Transforms>, F<MethodDescription.InDefinedShape, P2<Exports, Transforms>>> gather(ByteBuddy bb, Compoundable comp) { final Export.Default export = Export.Default.of(bb); final Transform.Default transform = Transform.Default.of(bb, comp); return pair -> md -> { if (!md.isStatic()) { LOG.debug("Ignored non-static method %s", md); return pair; } if (!md.isPublic()) { LOG.debug("Ignored non-public method %s", md); return pair; } if (md.getReturnType().equals(TypeDescription.Generic.VOID)) { LOG.debug("Ignored return void method %s", md); return pair; } final Option<P2<Exports, Transforms>> exportsMayChanged = export.f(md, pair._1()).map(e -> P.p(e, pair._2())).toOption(); final Option<P2<Exports, Transforms>> transformsMayChanged = transform.f(md, pair._2()).map(t -> P.p(pair._1(), t)).toOption(); return exportsMayChanged.orElse(transformsMayChanged).orSome(() -> { LOG.debug("Ignored invalid annotated method %s", md); return pair; }); }; }
Main { @VisibleForTesting static F<P2<Exports, Transforms>, F<MethodDescription.InDefinedShape, P2<Exports, Transforms>>> gather(ByteBuddy bb, Compoundable comp) { final Export.Default export = Export.Default.of(bb); final Transform.Default transform = Transform.Default.of(bb, comp); return pair -> md -> { if (!md.isStatic()) { LOG.debug("Ignored non-static method %s", md); return pair; } if (!md.isPublic()) { LOG.debug("Ignored non-public method %s", md); return pair; } if (md.getReturnType().equals(TypeDescription.Generic.VOID)) { LOG.debug("Ignored return void method %s", md); return pair; } final Option<P2<Exports, Transforms>> exportsMayChanged = export.f(md, pair._1()).map(e -> P.p(e, pair._2())).toOption(); final Option<P2<Exports, Transforms>> transformsMayChanged = transform.f(md, pair._2()).map(t -> P.p(pair._1(), t)).toOption(); return exportsMayChanged.orElse(transformsMayChanged).orSome(() -> { LOG.debug("Ignored invalid annotated method %s", md); return pair; }); }; } }
Main { @VisibleForTesting static F<P2<Exports, Transforms>, F<MethodDescription.InDefinedShape, P2<Exports, Transforms>>> gather(ByteBuddy bb, Compoundable comp) { final Export.Default export = Export.Default.of(bb); final Transform.Default transform = Transform.Default.of(bb, comp); return pair -> md -> { if (!md.isStatic()) { LOG.debug("Ignored non-static method %s", md); return pair; } if (!md.isPublic()) { LOG.debug("Ignored non-public method %s", md); return pair; } if (md.getReturnType().equals(TypeDescription.Generic.VOID)) { LOG.debug("Ignored return void method %s", md); return pair; } final Option<P2<Exports, Transforms>> exportsMayChanged = export.f(md, pair._1()).map(e -> P.p(e, pair._2())).toOption(); final Option<P2<Exports, Transforms>> transformsMayChanged = transform.f(md, pair._2()).map(t -> P.p(pair._1(), t)).toOption(); return exportsMayChanged.orElse(transformsMayChanged).orSome(() -> { LOG.debug("Ignored invalid annotated method %s", md); return pair; }); }; } private  Main(); }
Main { @VisibleForTesting static F<P2<Exports, Transforms>, F<MethodDescription.InDefinedShape, P2<Exports, Transforms>>> gather(ByteBuddy bb, Compoundable comp) { final Export.Default export = Export.Default.of(bb); final Transform.Default transform = Transform.Default.of(bb, comp); return pair -> md -> { if (!md.isStatic()) { LOG.debug("Ignored non-static method %s", md); return pair; } if (!md.isPublic()) { LOG.debug("Ignored non-public method %s", md); return pair; } if (md.getReturnType().equals(TypeDescription.Generic.VOID)) { LOG.debug("Ignored return void method %s", md); return pair; } final Option<P2<Exports, Transforms>> exportsMayChanged = export.f(md, pair._1()).map(e -> P.p(e, pair._2())).toOption(); final Option<P2<Exports, Transforms>> transformsMayChanged = transform.f(md, pair._2()).map(t -> P.p(pair._1(), t)).toOption(); return exportsMayChanged.orElse(transformsMayChanged).orSome(() -> { LOG.debug("Ignored invalid annotated method %s", md); return pair; }); }; } private  Main(); static void premain(final String args, final Instrumentation inst); }
Main { @VisibleForTesting static F<P2<Exports, Transforms>, F<MethodDescription.InDefinedShape, P2<Exports, Transforms>>> gather(ByteBuddy bb, Compoundable comp) { final Export.Default export = Export.Default.of(bb); final Transform.Default transform = Transform.Default.of(bb, comp); return pair -> md -> { if (!md.isStatic()) { LOG.debug("Ignored non-static method %s", md); return pair; } if (!md.isPublic()) { LOG.debug("Ignored non-public method %s", md); return pair; } if (md.getReturnType().equals(TypeDescription.Generic.VOID)) { LOG.debug("Ignored return void method %s", md); return pair; } final Option<P2<Exports, Transforms>> exportsMayChanged = export.f(md, pair._1()).map(e -> P.p(e, pair._2())).toOption(); final Option<P2<Exports, Transforms>> transformsMayChanged = transform.f(md, pair._2()).map(t -> P.p(pair._1(), t)).toOption(); return exportsMayChanged.orElse(transformsMayChanged).orSome(() -> { LOG.debug("Ignored invalid annotated method %s", md); return pair; }); }; } private  Main(); static void premain(final String args, final Instrumentation inst);  }