Java: Simplify CompileTimeConstantExpr.getIntValue()

The changed code previously also only covered IntegerLiteral:
- Restricted to Literal
- Integral type
- != "long"
- != "char"

So the only class left which matches all of these is IntegerLiteral.
This commit is contained in:
Marcono1234
2021-10-29 14:24:30 +02:00
parent 9730021641
commit 4f59886a65

View File

@@ -304,11 +304,7 @@ class CompileTimeConstantExpr extends Expr {
int getIntValue() {
exists(IntegralType t | this.getType() = t | t.getName().toLowerCase() != "long") and
(
exists(string lit | lit = this.(Literal).getValue() |
// Don't parse `char` literal as int, instead get its code point value (see below)
not this instanceof CharacterLiteral and
result = lit.toInt()
)
result = this.(IntegerLiteral).getIntValue()
or
result = this.(CharacterLiteral).getCodePointValue()
or