开发者

Pointcut for usage of operator "==" with specific types

is it possible to write an AspectJ pointcut that matches the usage of a specific operator with a specific type?

Some background information: I'm working on a project where we have to use a legacy Java library (pre 5.0, before the enum keyword) which comes with several "pseudo-enum" types, i.e. normal Java classes that define static constants of its own type. Those "feel" very much like enums, but using them like enums can result in an error. Therefore I'd like AspectJ to mark uses of == with objects of one of these types as an error, if that is possible. I have googled this and consulted the normally very helpful book AspectJ in actio开发者_JS百科n, but so far without success. Any help is appreciated.


== is not the same as equals(), and is implemented by the JVM, and as far as I can tell cannot be modified by aspectj. Also, I don't think that AspectJ is the correct tool for this job.

A better approach would be to implement a Checkstyle rule or similar for your project to allow you indicate these points. You could have them as errors or warnings. See Writing Checks for Checkstyle for more information.

This would require some coding, but so would the aspectJ solution.

Checkstyle has an eclipse plugin as well as a maven plugin, so you could have these errors appearing as you work in the IDE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜