4

我正在尝试捕获方法签名更改并在发生错误时引发错误。但是声明错误没有按预期工作

@DeclareError("call(* a.b.C.method(..)) && !call(* a.b.C.method(int))")
public static final String errorMsg= "Signature error";

这始终与对此方法的调用相匹配。

但是如果我将此切入点移动到@Before,那么除非方法签名已更改,否则它将不匹配。

关于为什么 @DeclareError 和 @Before 之间关于切入点的不同行为的任何想法?

谢谢

4

1 回答 1

2

奇怪 - 它适用于我的环境。(带有 AspectJ 插件的 Eclipse)

@Aspect
public class GetNameOverrider {

    @DeclareError("call(* a.b.C.method(..)) && !call(* a.b.C.method(int))")
    static final String errorMsg= "Signature error";
}

如果我这样做,在编译时给我一个错误:

a.b.C c = new a.b.C();
c.method(new Integer(2)); <--- no Error
c.method(2); <--- no Error
c.method("test"); <--- Error

=============================

ErrorDescription    Resource    Path    Location    Type
"Signature error"   Main.java   /Stackoverflow/src/test line 12 AspectJ Problem
于 2013-07-03T16:59:25.403 回答