我的目标是围绕'类型的子类的所有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;
}
}
答案 0 :(得分:2)
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;
}
}