为什么我收到“建议尚未应用”警告?

发布于 2024-09-30 07:04:06 字数 687 浏览 0 评论 0原文

为什么以下代码:

 pointcut callsToList() : call(* List.*(..));

 before(List l) : callsToList() && target(l) {
  System.out.println("cool");
 }

会生成以下警告:

建议定义于 org.eclipse.ajdt.examples.ListAdvice 尚未应用 [Xlint:adviceDidNotMatch]

我正在 Eclipse 中使用。我安装了eclipsespectj插件,当然我的项目是aspectj项目。

编辑:此外,我从 ajdt 插件提供的一个工作示例开始:

pointcut callsToBeginTask() : call(void IProgressMonitor.beginTask(..)); 
before() : callsToBeginTask() {
     System.out.println("cool");
};

除了这个示例在没有警告的情况下工作这一事实之外,我看不出任何区别......

Why does the following code:

 pointcut callsToList() : call(* List.*(..));

 before(List l) : callsToList() && target(l) {
  System.out.println("cool");
 }

generates the following warning:

advice defined in
org.eclipse.ajdt.examples.ListAdvice
has not been applied
[Xlint:adviceDidNotMatch]

I am working with in Eclipse. I installed eclipse aspectj plugin and of course my project is an aspectj project.

Edit: Moreover I started from a working example provided by ajdt plugin:

pointcut callsToBeginTask() : call(void IProgressMonitor.beginTask(..)); 
before() : callsToBeginTask() {
     System.out.println("cool");
};

I can't see any difference except the fact that this example works without warning ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小苏打饼 2024-10-07 07:04:06

当您希望 AspectJ 在 OSGi 环境中工作时,您必须使用 Equinox Aspects(又名 Equinox Weaving)。这是一种与 osgi 类加载器一起使用的加载时间编织形式。

本教程有点过时,但应该可以帮助您入门:

http://www.eclipse.org/equinox/incubator/aspects/equinox-aspects-quick-start.php

当您的各个方面都针对同一个项目时,您不需要 Equinox Aspects。常规的编译时编织就可以了,但是要跨越多个捆绑包/插件,这将不起作用。

When you want AspectJ to work in an OSGi environment, you must use Equinox Aspects (aka Equinox Weaving). This is a form of Load time weaving that works with osgi classloaders.

This tutorial is a little out of date, but should get you started:

http://www.eclipse.org/equinox/incubator/aspects/equinox-aspects-quick-start.php

When your aspects are all targeted within the same project, you do not need Equinox Aspects. Regular compile time weaving will do, but to span multiple bundles/plugins, this will not work.

池予 2024-10-07 07:04:06

我的猜测是,因为 List 是一个接口,并且您想要匹配对所有扩展类的调用,您必须使用以下语法:

pointcut callsToList() : call(* List+.*(..));

更新:好的,我让它与此版本一起使用:

pointcut callsToList(List list) :
    call(* java.util.List+.*(..)) && target(list);

Object around(List l) : callsToList(l) {
    // code here
}

这也有效:

before(List l) : callsToList(l) {
    // code here
}

My guess is that because List is an interface and you want to match calls to all extending Classes you would have to use this syntax:

pointcut callsToList() : call(* List+.*(..));

Update: OK, I got it to work with this version:

pointcut callsToList(List list) :
    call(* java.util.List+.*(..)) && target(list);

Object around(List l) : callsToList(l) {
    // code here
}

This also works:

before(List l) : callsToList(l) {
    // code here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文