Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup from code review feedback
  • Loading branch information
JLLeitschuh committed Mar 9, 2022
commit 363fff23585472e8f12d33027614957fe7274627
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
category: minorAnalysis
---
* Add new method `CompileTimeConstantExpr.getStringifiedValue` which attempts to compute the
* Add new predicate `CompileTimeConstantExpr.getStringifiedValue` which attempts to compute the
`String.valueOf` string rendering of a constant expression.
10 changes: 5 additions & 5 deletions java/ql/lib/semmle/code/java/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ class CompileTimeConstantExpr extends Expr {
*
* The stringified version of a compile-time constant expression is the equivalent to
* the result of calling `String.valueOf(expr)` on the expression.
*
*
* Note that this does not handle the following cases:
*
* - mathematical computations of type `long`.
* - mathematical computations of type `long`, `float`, or `double`.
*/
pragma[nomagic]
string getStringifiedValue() {
Expand Down Expand Up @@ -200,11 +200,11 @@ class CompileTimeConstantExpr extends Expr {
string getStringValue() {
result = this.(StringLiteral).getValue()
or
(
this.getType() instanceof TypeString and
this.getType() instanceof TypeString and // When the expression type is `String`
result =
// Then the resultant string is the addition of both operands stringified value, regardless of type.
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringifiedValue() +
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringifiedValue()
)
or
// Ternary conditional, with compile-time constant condition.
exists(ConditionalExpr ce, boolean condition |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semmle.code.java.Expr
import java

from CompileTimeConstantExpr constant, RefType tpe
where
Expand Down
2 changes: 1 addition & 1 deletion java/ql/test/library-tests/constants/getBooleanValue.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semmle.code.java.Variable
import java

from Variable v, CompileTimeConstantExpr init, RefType enclosing, boolean constant
where
Expand Down
2 changes: 1 addition & 1 deletion java/ql/test/library-tests/constants/getInitializer.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semmle.code.java.Variable
import java

from Variable v, Expr init, RefType enclosing
where
Expand Down
2 changes: 1 addition & 1 deletion java/ql/test/library-tests/constants/getIntValue.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semmle.code.java.Variable
import java

from Variable v, CompileTimeConstantExpr init, RefType enclosing, int constant
where
Expand Down
2 changes: 1 addition & 1 deletion java/ql/test/library-tests/constants/getStringValue.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semmle.code.java.Variable
import java

from Variable v, CompileTimeConstantExpr init, RefType enclosing, string constant
where
Expand Down
2 changes: 1 addition & 1 deletion java/ql/test/library-tests/constants/getStringified.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semmle.code.java.Variable
import java

from Variable v, CompileTimeConstantExpr init, RefType enclosing, string constant
where
Expand Down