创建构造函数的Java注释
我正在为我的自动化框架使用创建构造函数的Java注释,java,annotations,retention,Java,Annotations,Retention,我正在为我的自动化框架使用PageFactorypage对象模型。现在我必须为每个页面类创建一个构造函数。例如: public class StudentProfile { public StudentProfile (WebDriver driver) { this.driver = driver; PageFactory.initElements(driver, this); } } 但是我想创建一个自定义注释。这样我就不必为每个页面类重复
PageFactory
page对象模型。现在我必须为每个页面类创建一个构造函数。例如:
public class StudentProfile {
public StudentProfile (WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
}
但是我想创建一个自定义注释。这样我就不必为每个页面类重复一遍又一遍
@InitElements(driver)
public class StudentProfile {
// to do
}
@InitElements(driver)
public class SchoolHomePage {
// to do
}
我已经通过了以下的TUT,但不明白我将如何实现它
- 让注释可以在运行时检查。如果您想编写一个工具,例如,获取某个类的实例,并使用该类字段上编写的注释作为将该实例序列化为XML或JSON blob的指导,那么这是非常好的。它对这个用例完全不起作用;您不能只在运行时将构造函数添加到对象中并使其有用(因此,构造函数在编译时不存在,而编译时显然是您需要它们的时候)
- 在编译过程中插入注释处理器,它就可以看到它们。但是,开箱即用的API,注释处理器可以生成新文件;它不能修改现有的。因此,它也不能添加该构造函数
- 你基本上不能。注释API仅提供两种基本体: