3

私の目標はequals、型のサブクラスのすべてのメソッドを「回避」することです。そこで、次の側面を書きました。

私は、aspectj-maven-plugin を使用しています。すべての equals メソッドがそこにあるため、コードを依存関係の jar ファイルに織り込むように指示しています。

私は以下の報酬を受けています:

Warning:(22, 0) ajc: does not match because declaring type is java.lang.Object, if match desired use target(com.basistech.rosette.dm.BaseAttribute+) [Xlint:unmatchedSuperTypeInCall] 
Warning:(22, 0) ajc: advice defined in com.basistech.rosette.dm.AdmEquals has not been applied [Xlint:adviceDidNotMatch]

私は困惑しています。BaseAttributedeclareの階層にはたくさんの型があるequalsので、 を見てはいけませんObject。追加&&target(BaseAttribute+)しても、このエラーは解消されないようです。

私は何を見逃していますか、そして/またはこれを追跡するにはどうすればよいですか?

package com.basistech.rosette.dm;

/**
 * See if we can't make an aspect to spy on equals ...
 */
public aspect AdmEquals {
    // we would like to narrow this to subclasses ...
    boolean around(Object other): call(public boolean BaseAttribute+.equals(java.lang.Object)) && args(other) {
        boolean result = proceed(other);
        if (!result) {
            System.out.println(this);
            System.out.println(other);
            System.out.println(result);
        }
        return true;
    }
}
4

1 に答える 1

3

OK、夜明け。AspectJ の呼び出し仕様では、メソッドがオーバーライドされる場所ではなく、クラス階層のベースでメソッドが定義されている場所が記述されています。したがって、以下は必要な汚れた作業を行うことを目的としています。

public aspect AdmEquals {
    // we would like to narrow this to subclasses ...
    boolean around(Object other) : 
        call(public boolean Object.equals(java.lang.Object)) &&
        args(other) &&
        target(BaseAttribute+)
    {
        boolean result = proceed(other);
        if (!result) {
            System.out.println(this);
            System.out.println(other);
            System.out.println(result);
        }
        return true;
    }
}
于 2014-10-12T20:09:47.537 に答える