AspectJ无与伦比的类型警告:如何解读?

时间:2014-10-12 19:57:56

标签: java aspectj aspectj-maven-plugin

我的目标是围绕'类型的子类的所有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;
    }
}

1 个答案:

答案 0 :(得分:2)

好的,光明恍然大悟。 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;
    }
}