2017-10-08 7 views
1

私はintercept()中にメソッドの宣言クラスの注釈(その中の値)を取得する必要があります。ByteBuddy - )(切片内の宣言クラスの注釈を取得

@RuntimeType 
    public static Object intercept(@SuperCall Callable callable, @Origin Method method) throws Exception { 
     method.getDeclaringClass().getDeclaredAnnotation(SomeAnnotationOnClass.class); 

最後の行はnullを返します。

new AgentBuilder.Default().with(AgentBuilder.Listener.StreamWriting.toSystemOut()).type(ElementMatchers.isAnnotatedWith(SomeAnnotationOnClass.class)) 
       .transform((builder, type, clazzLoader, javaModule) -> { 
        return builder.method(ElementMatchers.any()).intercept(MethodDelegation.to(MyInterceptor.class)); 

これは動作します...注釈は存在します(クラスレベルで!)。ただし、intercept()が呼び出されたときではありません。

答えて

1

クラスファイルレベルの情報が利用可能なインスツルメンテーション中に実行される独自のバインダーを定義できます。アノテーションから一定の値を抽出することができます

class FooBinder extends ParameterBinder.ForFixedValue<Foo> 

:あなたはランタイムの保持と注釈@interface Fooを定義すると仮定すると、あなたは、いくつかを実装することができます。この値は、@Fooと注釈を付けられたインターセプタメソッドで使用できるようになります。

+0

ありがとう! AgentBuilderを使用しているときに、ParameterBinder.ForFixedValueに変換をバインドする方法に関するドキュメントはありますか? 何も見つかりませんでした。 – Reymanx

+0

javadocがあなたを助けることができるように私は何を望んでいますか?このために 'MethodDelegation.withCustomBinding()。bind(...)。to(...)'を使用しています。 –

関連する問題