1

我在让我的方面正常工作时遇到了一些麻烦。出于某种原因,它们似乎仅在我对应用方面的位置非常通用时才起作用。在四个切入点/建议中,只有最后一个匹配并输出任何内容。我在这里想念什么?

public aspect VerboseAspect
{
    after(Game game) returning:
            call(* Game.addPlayer(Player))
            && target(game) {
        System.out.println("addPlayer(Player): player has been added");
    }

    after(Game game) returning:
            call(* Game.addPlayer(..))
            && target(game) {
        System.out.println("addPlayer(..): player has been added");
    }

    after(Game game) returning:
            call(* Game.*(Player))
            && target(game) {
        System.out.println("*(Player):player has been added");
    }

    after(Game game) returning:
            call(* Game.*(..))
            && target(game) {
        System.out.println("*(..):player has been added");
    }
}

Java类:

public class Game {
    public void addPlayer(Player player) {
        System.out.println("inside class");
        this.players.add(player);
    }
}

输出:

inside class
*(..):player has been added
4

1 回答 1

0

(评论,但太长了。)

您使用的是哪个版本的 AspectJ?你怎么建?蚂蚁?马文?其他?

它在 IntelliJ 中对我来说很好用;运行这个:

public static void main(String[] args) {
    Game g = new Game();
    g.addPlayer(new Player());
}

产生:

inside class
addPlayer(Player): player has been added
addPlayer(..): player has been added
*(Player):player has been added
*(..):player has been added
于 2012-07-05T01:44:25.570 回答