2011-12-06 12 views
1

私は長年このAOPメソッドを知っていましたが、私はAspectJを初めて使いました。 Androidアプリでこれを初めて使用しましたが、それについてはほとんど質問しません。AspectJのポイントカットアウトへの結合

私は、Javaコードを持っている:

private void mainView() { 
     ... (some code) 
     <A> 
    setContentView(R.layout.main); 
    mView = findViewById(R.id.Main_Root); 
    mView.setOnTouchListener(this); 
     <B> 
     ... (some code) 
    } 

私は、次のAspectJのコードを持っている:

public aspect mainViewTiming { 
    pointcut callSetContentViewTiming(): 
     call(* android.app.Activity.setContentView(..)) 
     && withincode(void mainView(..)) 
    ; 

    pointcut callFindViewById(): 
     call(* android.app.Activity.findViewById(..)) 
     && withincode(void mainView(..)) 
    ; 

    pointcut callSetOnTouchListener(): 
     call (* android.view.View.setOnTouchListener(..)) 
     && withincode(void mainView(..)) 
    ; 

} 

今、私の質問は、私はAspectJのを使用し、それがから実行するのにかかる時間を計算する方法ですか?

私は3つのポイントカットを持っていますが、私はそれらを組み合わせてこの効果を得る最良の方法を知りたいのですが?このリンクから、私は「CFLOW」を使用できることを学びました: http://www.eclipse.org/aspectj/doc/released/progguide/language-joinPoints.html

before(): cflow(callSetContentViewTiming()) && cflow(callFindViewById()) && callSetOnTouchListener() { 
    start = System.currentTimeMillis(); 
} 

をしかし、私はそれが正しいかどうかわからないでした。そして、ポイントカットを組み合わせる際の違いを計算するにはどうしたらいいですか?そして、「after()」のようなものがありますか?

ありがとうございました。

答えて

0

はい、「after()」があります。しかし、あなたはcflowを正しく使用しているかどうかはわかりません。 cflowは制御フローを意味します。これは、特定のポイントカットがスタック上にあるたびにヒットするポイントカットです。他のポイントカットに一致するメソッド呼び出し(メソッド呼び出しの内部、メソッド呼び出しの内部にある)の中にいるときはいつでも。

ここで必要なのは、最初のメソッド呼び出しの前にstartを設定し、最後のメソッド呼び出しの後にset endを設定することです。途中のメソッド呼び出しは無関係なので、私はそのポイントカットを削除しました。

public aspect MainViewTiming { 

    pointcut mainView() : withincode(void mainView(..)); 

    pointcut callSetContentViewTiming() : 
     call(* android.app.Activity.setContentView(..)) && mainView(); 

    pointcut callSetOnTouchListener() : 
     call (* android.view.View.setOnTouchListener(..)) && mainView(); 

    before() : callSetContentViewTiming() { 
     start = System.currentTimeMillis(); 
    } 

    after() : callSetOnTouchListener() { 
     end = System.currentTimeMillis(); 
    } 

} 

このインスタンスのインスタンスは1つだけです。