如何在 AspectJ 中删除/重新定义类型间声明?
我使用解析器生成器,它生成表示编程语言语法节点的 java 类,以及用于向这些类添加语义的 AspectJ 方面。 我已经扩展/更改了该语言的语法,并且我想重用旧语法的各个方面并修改/扩展它们以应对节点类的更改。
例如,一个旧的节点类及其方面:
class A {
public T a1;
public U a2;
...
}
aspect Accessors1 {
public T A.getT() {return a1;}
public U A.getU() {return a2;}
}
通过语法修改,类 A 发生以下更改:
class A {
public T a1;
public V a2;
public U a3;
...
}
我想重用 Accessors1 方面并添加另一个方面:
aspect Accessors2 {
public V A.getV() {return a2;} // new accessor for new field
public U A.getU() {return a3;} // modification of old accessor
}
我尝试了这个:
declare precedence: *2, *1;
但我仍然收到此错误: Type不匹配:无法从第一方面从 V 转换为 U
。即使不使用 Accessors1.getU(),它仍然会进行类型检查,这会导致编译失败。
为什么会这样呢?如何用新的 getU() 覆盖原来的 getU() ?有没有办法告诉 AspectJ 忽略/删除 Accessors1.getU() ?
I use parser generator, which generates java classes representing syntax nodes of a programming language, and AspectJ aspects for adding semantics to these classes.
I have extended/changed the grammar of the language and I want to reuse aspects of the old grammar and modify/extend them to cope with changes of node classes.
For example, an old node class and its aspect:
class A {
public T a1;
public U a2;
...
}
aspect Accessors1 {
public T A.getT() {return a1;}
public U A.getU() {return a2;}
}
With grammar modification, the class A is change followingly:
class A {
public T a1;
public V a2;
public U a3;
...
}
I would like to reuse the Accessors1 aspect and add another one:
aspect Accessors2 {
public V A.getV() {return a2;} // new accessor for new field
public U A.getU() {return a3;} // modification of old accessor
}
I tried this:
declare precedence: *2, *1;
But I still get this error: Type mismatch: cannot convert from V to U
from the first aspect. Even though the Accessors1.getU() is not used, it is still type-checked, which causes compilation to fail.
Why is that so? How can I override the original getU()
with the new one? Is there a way to tell AspectJ to ignore/drop the Accessors1.getU()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试在第二类中使用以下更改会怎么样:
第二个方面:
What if you try to use the following changes in second class:
And the second aspect: