AspectJ不是为查找类而设计的。你最好的选择是扫描类路径并使用反射。
如果您可以接受编译时信息,Eclipse AJDT插件为所有AspectJ建议提供了良好的图形信息。
但是,如果您可以忍受一些限制,您可以找到AspectJ建议的所有对象的类。
打印出用于实现MatchRule类的所有对象的类名:A液
@Aspect
public class FindSubClassesAspect {
@Pointcut("execution(demo.MatchRule+.new(..))")
public void demoPointcut() {
}
@After("demoPointcut()")
public void afterDemoPointcut(
JoinPoint joinPoint) {
FindSubClasses.addMatchRuleImplememtation(
joinPoint.getTarget().getClass().getSimpleName());
}
}
包含所有的MatchRule实现信息类:
public enum FindSubClasses {
;
private static Set<String> matchRuleImplementations =
new HashSet<String>();
public static void addMatchRuleImplememtation(String className) {
matchRuleImplementations.add(className);
}
public static Collection<String> getMatchRuleImplementations() {
return matchRuleImplementations;
}
}
一个简单的驱动程序证明该方面工作:
public class Driver {
public static void main(String[] args) {
new DefaultMatchRule();
new CustomMatchRule();
Collection<String> matchRuleImplementations =
FindSubClasses.getMatchRuleImplementations();
System.out.print("Clases that implements MatchRule: ");
for (String className : matchRuleImplementations) {
System.out.print(className + ", ");
}
}
}
执行此驱动器的输出:
Clases实现MatchRule:DefaultMatchRule,CustomMatchRule,
我希望这有助于!
你能解释一下为什么你需要这样的清单吗?除了分析代码外,我无法想象这样的理由。在所有其他情况下,您可以在使用它们的时刻横切课程。 – alehro