Skip to content

Commit 4f5ccfd

Browse files
authored
Merge pull request github#9181 from Marcono1234/marcono1234/FloatingPointLiteral-rename
Java: Rename `FloatingPointLiteral` to `FloatLiteral`
2 parents f2e28c3 + 4e1a73f commit 4f5ccfd

File tree

9 files changed

+19
-22
lines changed

9 files changed

+19
-22
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: deprecated
3+
---
4+
* The QL class `FloatingPointLiteral` has been renamed to `FloatLiteral`.

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,20 +716,23 @@ class LongLiteral extends Literal, @longliteral {
716716
override string getAPrimaryQlClass() { result = "LongLiteral" }
717717
}
718718

719+
/** DEPRECATED: Alias for FloatLiteral */
720+
deprecated class FloatingPointLiteral = FloatLiteral;
721+
719722
/**
720723
* A float literal. For example, `4.2f`.
721724
*
722725
* A float literal is never negative; a preceding minus, if any, will always
723726
* be modeled as separate `MinusExpr`.
724727
*/
725-
class FloatingPointLiteral extends Literal, @floatingpointliteral {
728+
class FloatLiteral extends Literal, @floatingpointliteral {
726729
/**
727730
* Gets the value of this literal as CodeQL 64-bit `float`. The value will
728731
* be parsed as Java 32-bit `float` and then converted to a CodeQL `float`.
729732
*/
730733
float getFloatValue() { result = this.getValue().toFloat() }
731734

732-
override string getAPrimaryQlClass() { result = "FloatingPointLiteral" }
735+
override string getAPrimaryQlClass() { result = "FloatLiteral" }
733736
}
734737

735738
/**

java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module Private {
4949
/** Class to represent float and double literals. */
5050
class RealLiteral extends J::Literal {
5151
RealLiteral() {
52-
this instanceof J::FloatingPointLiteral or
52+
this instanceof J::FloatLiteral or
5353
this instanceof J::DoubleLiteral
5454
}
5555
}
@@ -191,7 +191,7 @@ private module Impl {
191191
/** Gets the constant `float` value of non-`ConstantIntegerExpr` expressions. */
192192
float getNonIntegerValue(Expr e) {
193193
result = e.(LongLiteral).getValue().toFloat() or
194-
result = e.(FloatingPointLiteral).getValue().toFloat() or
194+
result = e.(FloatLiteral).getValue().toFloat() or
195195
result = e.(DoubleLiteral).getValue().toFloat()
196196
}
197197

java/ql/src/Likely Bugs/Comparison/NoComparisonOnFloats.ql

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
import semmle.code.java.Type
1313
import semmle.code.java.Expr
1414

15-
// Either `float`, `double`, `Float`, or `Double`.
16-
class Floating extends Type {
17-
Floating() {
18-
exists(string s | s = this.getName().toLowerCase() |
19-
s = "float" or
20-
s = "double"
21-
)
22-
}
23-
}
24-
2515
predicate trivialLiteral(Literal e) {
2616
e.getValue() = "0.0" or
2717
e.getValue() = "0" or
@@ -61,7 +51,7 @@ predicate similarVarComparison(EqualityTest e) {
6151

6252
from EqualityTest ee
6353
where
64-
ee.getAnOperand().getType() instanceof Floating and
54+
ee.getAnOperand().getType() instanceof FloatingPointType and
6555
not ee.getAnOperand() instanceof NullLiteral and
6656
not trivialLiteral(ee.getAnOperand()) and
6757
not definedConstant(ee.getAnOperand()) and

java/ql/src/Violations of Best Practice/Magic Constants/MagicConstants.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private predicate powerOfTen(float f) {
5555
}
5656

5757
private predicate floatTrivial(Literal lit) {
58-
(lit instanceof FloatingPointLiteral or lit instanceof DoubleLiteral) and
58+
(lit instanceof FloatLiteral or lit instanceof DoubleLiteral) and
5959
exists(float f |
6060
f = lit.getValue().toFloat() and
6161
(f.abs() <= 20.0 or powerOfTen(f))

java/ql/test/kotlin/library-tests/literals/literals.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
| literals.kt:17:30:17:33 | 15 | LongLiteral |
1616
| literals.kt:18:30:18:39 | 11 | LongLiteral |
1717
| literals.kt:19:30:19:38 | 1234567 | LongLiteral |
18-
| literals.kt:20:32:20:35 | 0.0 | FloatingPointLiteral |
19-
| literals.kt:21:32:21:37 | 123.4 | FloatingPointLiteral |
20-
| literals.kt:22:32:22:38 | -123.4 | FloatingPointLiteral |
18+
| literals.kt:20:32:20:35 | 0.0 | FloatLiteral |
19+
| literals.kt:21:32:21:37 | 123.4 | FloatLiteral |
20+
| literals.kt:22:32:22:38 | -123.4 | FloatLiteral |
2121
| literals.kt:23:34:23:36 | 0.0 | DoubleLiteral |
2222
| literals.kt:24:34:24:38 | 123.4 | DoubleLiteral |
2323
| literals.kt:25:34:25:39 | -123.4 | DoubleLiteral |

java/ql/test/library-tests/fields/PrintAst.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fields/FieldTest.java:
33
# 3| 1: [Class] FieldTest
44
# 4| 4: [FieldDeclaration] float ff, ...;
55
# 4| -1: [TypeAccess] float
6-
# 4| 1: [FloatingPointLiteral] 2.3f
6+
# 4| 1: [FloatLiteral] 2.3f
77
# 5| 5: [FieldDeclaration] Object obj, ...;
88
# 5| -1: [TypeAccess] Object
99
# 5| 0: [NullLiteral] null
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import semmle.code.java.Expr
22

3-
from FloatingPointLiteral lit
3+
from FloatLiteral lit
44
select lit, lit.getValue(), lit.getFloatValue()

java/ql/test/library-tests/literals/literals-numeric/negativeNumericLiterals.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ from Literal l
44
where
55
l instanceof IntegerLiteral or
66
l instanceof LongLiteral or
7-
l instanceof FloatingPointLiteral or
7+
l instanceof FloatLiteral or
88
l instanceof DoubleLiteral
99
select l, l.getValue(), l.getParent()

0 commit comments

Comments
 (0)