如何在 AspectJ 中删除/重新定义类型间声明?

发布于 2024-11-14 18:35:33 字数 885 浏览 2 评论 0原文

我使用解析器生成器,它生成表示编程语言语法节点的 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 技术交流群。

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

发布评论

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

评论(1

我一直都在从未离去 2024-11-21 18:35:33

如果您尝试在第二类中使用以下更改会怎么样:

class A {
  public T a1;
  public U a2;
  public V a3;
  ...
}

第二个方面:

aspect Accessors2 {
  public V A.getV() {return a3;} // new accessor for new field
  public U A.getU() {return a2;} // modification of old accessor
}

What if you try to use the following changes in second class:

class A {
  public T a1;
  public U a2;
  public V a3;
  ...
}

And the second aspect:

aspect Accessors2 {
  public V A.getV() {return a3;} // new accessor for new field
  public U A.getU() {return a2;} // modification of old accessor
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文