我的目标是“围绕”一个类型的子类的所有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;
}
}发布于 2014-10-13 04:09:48
好了,天亮了。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;
}
}https://stackoverflow.com/questions/26329373
复制相似问题