为什么我不能从行为实例中获取代理?

why can't i get the agent from behaviour instance?

我在 Eclipse 中使用 JADE。我尝试使用一个方面为每个执行的行为捕获 action 方法。它工作得很好,我什至得到了执行行为的实例。但是,此实例不允许我获取添加此行为的代理。因为在 http://jade.tilab.com/doc/api/jade/core/behaviours/Behaviour.html Behavior 中,我们可以知道是哪个 Agent 添加了这个行为。下图显示了我的错误

谢谢。

感谢 没有 更新问题,没有发布实际的错误消息,甚至没有从读者的视图中隐藏您的 class 的导入。 :-7

无论如何:您发布的代码应该可以工作,对我来说它在 Eclipse 中没有任何红色下划线。这里有两种切入点和建议的变体,就像你的一样,使用了丑陋的转换和 getThis() 的用法,另一种通过直接和类型安全的参数绑定更优雅:

package de.scrum_master.aspect;

import jade.core.behaviours.Behaviour;

public aspect ActionAspect {
    before() :
        execution(* Behaviour.action(..))
    {
        System.out.println(thisJoinPoint);
        Behaviour behaviour = (Behaviour) thisJoinPoint.getThis();
        behaviour.getAgent();
    }

    before(Behaviour behaviour) :
        execution(* Behaviour.action(..)) && this(behaviour)
    {
        System.out.println(thisJoinPoint);
        behaviour.getAgent();
    }
}