Apply suggestions from code review

Co-authored-by: Chris Smowton <smowton@github.com>
This commit is contained in:
Jonathan Leitschuh
2022-03-09 10:25:05 -05:00
committed by GitHub
parent 2e8b5f743b
commit 65457cc2e2
2 changed files with 5 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
---
category: minorAnalysis
---
* Add new method `CharacterLiteral.getStringifiedValue` which attempts to compute the
`String.valueOf` compile time constant value of the expression.
* Add new method `CompileTimeConstantExpr.getStringifiedValue` which attempts to compute the
`String.valueOf` string rendering of a constant expression.

View File

@@ -201,17 +201,9 @@ class CompileTimeConstantExpr extends Expr {
result = this.(StringLiteral).getValue()
or
(
if this.(AddExpr).getAnOperand().getType() instanceof TypeString // If either operand type is already a String:
then
// Then the stringified version of the expression can be safely used as a String will be created.
result =
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringifiedValue() +
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringifiedValue()
else
// Adding two literals of primitive type will not result in a String.
result =
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringValue() +
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringValue()
this.getType() instanceof TypeString and
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringifiedValue() +
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringifiedValue()
)
or
// Ternary conditional, with compile-time constant condition.