为什么在Rascal的Java AST中使用表达式“ super()”? [英] Why is the expression `super()` in the Java AST in Rascal?

查看:189
本文介绍了为什么在Rascal的Java AST中使用表达式“ super()”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

中的一个表达式Java AST声明 Expression :: super()
使用了 super()的Java表达式?

One of the expressions in the Java AST declaration is Expression::super(). For which Java expression(s) is super() used?

使用以下示例类:

import java.util.ArrayList;
import java.util.List;

public class SuperTests<T> extends ArrayList<T> {

    public SuperTests() {
        super();
    }
    public SuperTests(int capacity) {
        super(capacity);
    }

    @Override
    public void clear() {
        super.clear();
    }

    public <T extends Integer> void addSupers(List<? super T> list) {

    }
}

无赖中的AST是:

compilationUnit(
  [
    import("java.util.ArrayList")[
      @src=|project://TestThing/src/SuperTests.java|(0,27,<1,0>,<1,27>)
    ],
    import("java.util.List")[
      @src=|project://TestThing/src/SuperTests.java|(28,22,<2,0>,<2,22>)
    ]
  ],
  [class(
      "SuperTests",
      [parameterizedType(simpleType(simpleName("ArrayList")[
              @src=|project://TestThing/src/SuperTests.java|(87,9,<4,35>,<4,44>),
              @decl=|java+class:///java/util/ArrayList|,
              @typ=class(
                |java+class:///java/util/ArrayList|,
                [typeArgument(|java+typeVariable:///SuperTests/T|)])
            ]))],
      [],
      [
        constructor(
          "SuperTests",
          [],
          [],
          block([constructorCall(
                true,
                [])[
                @src=|project://TestThing/src/SuperTests.java|(128,8,<7,2>,<7,10>),
                @decl=|java+constructor:///java/util/ArrayList/ArrayList()|
              ]])[
            @src=|project://TestThing/src/SuperTests.java|(124,15,<6,21>,<8,2>)
          ])[
          @modifiers=[public()],
          @src=|project://TestThing/src/SuperTests.java|(104,35,<6,1>,<8,2>),
          @decl=|java+constructor:///SuperTests/SuperTests()|,
          @typ=constructor(
            |java+constructor:///SuperTests/SuperTests()|,
            [])
        ],
        constructor(
          "SuperTests",
          [parameter(
              int(),
              "capacity",
              0)[
              @src=|project://TestThing/src/SuperTests.java|(159,12,<9,19>,<9,31>),
              @decl=|java+parameter:///SuperTests/SuperTests(int)/capacity|,
              @typ=int()
            ]],
          [],
          block([constructorCall(
                true,
                [simpleName("capacity")[
                    @src=|project://TestThing/src/SuperTests.java|(183,8,<10,8>,<10,16>),
                    @decl=|java+parameter:///SuperTests/SuperTests(int)/capacity|,
                    @typ=int()
                  ]])[
                @src=|project://TestThing/src/SuperTests.java|(177,16,<10,2>,<10,18>),
                @decl=|java+constructor:///java/util/ArrayList/ArrayList(int)|
              ]])[
            @src=|project://TestThing/src/SuperTests.java|(173,23,<9,33>,<11,2>)
          ])[
          @modifiers=[public()],
          @src=|project://TestThing/src/SuperTests.java|(141,55,<9,1>,<11,2>),
          @decl=|java+constructor:///SuperTests/SuperTests(int)|,
          @typ=constructor(
            |java+constructor:///SuperTests/SuperTests(int)|,
            [int()])
        ],
        method(
          void(),
          "clear",
          [],
          [],
          block([expressionStatement(methodCall(
                  true,
                  "clear",
                  [])[
                  @src=|project://TestThing/src/SuperTests.java|(234,13,<15,2>,<15,15>),
                  @decl=|java+method:///java/util/ArrayList/clear()|,
                  @typ=void()
                ])[
                @src=|project://TestThing/src/SuperTests.java|(234,14,<15,2>,<15,16>)
              ]])[
            @src=|project://TestThing/src/SuperTests.java|(230,21,<14,21>,<16,2>)
          ])[
          @modifiers=[
            annotation(markerAnnotation("Override")[
                @src=|project://TestThing/src/SuperTests.java|(199,9,<13,1>,<13,10>),
                @typ=interface(
                  |java+interface:///java/lang/Override|,
                  [])
              ]),
            public()
          ],
          @src=|project://TestThing/src/SuperTests.java|(199,52,<13,1>,<16,2>),
          @decl=|java+method:///SuperTests/clear()|,
          @typ=method(
            |java+method:///SuperTests/clear()|,
            [],
            void(),
            [])
        ],
        method(
          void(),
          "addSupers",
          [parameter(
              parameterizedType(simpleType(simpleName("List")[
                    @src=|project://TestThing/src/SuperTests.java|(297,4,<18,43>,<18,47>),
                    @decl=|java+interface:///java/util/List|,
                    @typ=interface(
                      |java+interface:///java/util/List|,
                      [wildcard(super([typeArgument(|java+typeVariable:///SuperTests/addSupers(java/util/List)/T|)]))])
                  ])),
              "list",
              0)[
              @src=|project://TestThing/src/SuperTests.java|(297,20,<18,43>,<18,63>),
              @decl=|java+parameter:///SuperTests/addSupers(java.util.List)/list|,
              @typ=interface(
                |java+interface:///java/util/List|,
                [wildcard(super([typeArgument(|java+typeVariable:///SuperTests/addSupers(java/util/List)/T|)]))])
            ]],
          [],
          block([])[
            @src=|project://TestThing/src/SuperTests.java|(319,7,<18,65>,<20,2>)
          ])[
          @modifiers=[public()],
          @src=|project://TestThing/src/SuperTests.java|(255,71,<18,1>,<20,2>),
          @decl=|java+method:///SuperTests/addSupers(java.util.List)|,
          @typ=method(
            |java+method:///SuperTests/addSupers(java.util.List)|,
            [typeParameter(
                |java+typeVariable:///SuperTests/addSupers(java/util/List)/T|,
                extends([class(
                      |java+class:///java/lang/Integer|,
                      [])]))],
            void(),
            [interface(
                |java+interface:///java/util/List|,
                [wildcard(super([typeArgument(|java+typeVariable:///SuperTests/addSupers(java/util/List)/T|)]))])])
        ]
      ])[
      @modifiers=[public()],
      @src=|project://TestThing/src/SuperTests.java|(52,278,<4,0>,<23,1>),
      @decl=|java+class:///SuperTests|,
      @typ=class(
        |java+class:///SuperTests|,
        [typeParameter(
            |java+typeVariable:///SuperTests/T|,
            unbounded())])
    ]])[
  @src=|project://TestThing/src/SuperTests.java|(0,331,<1,0>,<23,2>),
  @decl=|java+compilationUnit:///src/SuperTests.java|,
  @messages=[
    warning(
      "The serializable class SuperTests does not declare a static final serialVersionUID field of type long",
      |project://TestThing/src/SuperTests.java|(65,10,<4,0>,<4,0>)),
    warning(
      "The type parameter T is hiding the type T",
      |project://TestThing/src/SuperTests.java|(263,1,<18,0>,<18,0>)),
    warning(
      "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended",
      |project://TestThing/src/SuperTests.java|(273,7,<18,0>,<18,0>))
  ]
]

它不包含 super()构造函数,不带参数。仅在通配符绑定( wildcard(super())的情况下,才会有 super(_),但是它只有一个参数,并在 lang :: java :: m3 :: TypeSymbol 模块中进行了描述。

It does not contain the super() constructor with no arguments. Only in case of the wildcard bound (wildcard(super() is there a super(_) but it has one argument and is described in the lang::java::m3::TypeSymbol module.

那么,正在发生什么事情,我是否缺少Java构造,或者关于AST中生成的内容,Rascal ADT定义是否正确?

So what is happening, is there a Java construct I'm missing, or is the Rascal ADT definition incorrect with respect to what is generated in the AST?

推荐答案

它不再用于表示任何Java表达式。在我们决定更改Java中超级构造函数调用和超级方法调用的表示方式之前,它是代码的一部分。

It isn't used to represent any Java expression anymore. It is a part of the code before we decided to change how super constructor invocation and super method invocation are represented in the Java AST in Rascal.

所有构造函数调用均由 constructorCall(bool isSuper,_)表示。值为true在t他的 isSuper 字段表示这是一个超级调用。同样,所有方法调用都由 methodCall(bool isSuper,_)表示,具有相同的逻辑。

All constructor calls are represented by constructorCall(bool isSuper, _). A value of true in the isSuper field indicates that it is a super call. Similarly, all method calls are represented by methodCall(bool isSuper,_) with the same logic.

来自 lang :: java :: m3 ::的code>通配符(_) super(_) TypeSymbol 用于表示AST和M3中使用的类型信息。

The wildcard(_) and super(_) from lang::java::m3::TypeSymbol are used to represent type information that is used in ASTs as well as M3.

这篇关于为什么在Rascal的Java AST中使用表达式“ super()”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆