3

我的目标是“围绕”equals一个类型的子类的所有方法。所以,我写了以下方面。

我正在使用 aspectj-maven-plugin,我告诉它在依赖 jar 文件中编织代码,因为这是所有 equals 方法所在的地方。

我得到了奖励:

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]

我很困惑。BaseAttribute声明的层次结构中有很多类型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

好的,天亮了。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 回答