Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Guitenbay opened this issue Jun 20, 2022 · 0 comments

Comments

@Guitenbay
Copy link

对于 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;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant