Skip to content

bug: jdt 对连 + 表达式不会递归调用,而是使用 extendedOperands 方法放额外的变量 #130

Open

Description

@Guitenbay

对于 a + b + c 这种表达式
jdt 为了减少树的深度,不会将它拆开

extendedOperands 方法 jdt 官方描述:

扩展操作数是表示 L op R op R2 op R3... 形式的深度嵌套表达式的首选方式,
其中相同的运算符出现在所有操作数之间(最常见的情况是冗长的字符串连接
表达式)。 使用扩展的操作数可以防止树变得太深; 这降低了遍历此类树时
在运行时耗尽线程堆栈空间的风险。 ((a + b) + c) + d 将被翻译为:
leftOperand: a rightOperand: b extendedOperands: {c, d} operator: +

因此在 gen.java 下的 ExpressionVisitor.java 1321 行相关代码:

case ASTNode.INFIX_EXPRESSION:
    {
          InfixExpression iex = (InfixExpression) exp;

需要对此种连加情况特殊处理

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions