Skip to content

Commit 1534b38

Browse files
committed
Java: Improve documentation regarding minus in front of numeric literals
1 parent 07ca09e commit 1534b38

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,25 +638,62 @@ class BooleanLiteral extends Literal, @booleanliteral {
638638
override string getAPrimaryQlClass() { result = "BooleanLiteral" }
639639
}
640640

641-
/** An integer literal. For example, `23`. */
641+
/**
642+
* An integer literal. For example, `23`.
643+
*
644+
* An integer literal can never be negative except when:
645+
* - It is written in binary, octal or hexadecimal notation
646+
* - It is written in decimal notation, has the value `2147483648` and is preceded
647+
* by a minus; in this case the value of the IntegerLiteral is -2147483648 and
648+
* the preceding minus will *not* be modeled as `MinusExpr`.<br/>
649+
* In all other cases the preceding minus, if any, will be modeled as separate
650+
* `MinusExpr`.
651+
*
652+
* The last exception is necessary because `2147483648` on its own would not be
653+
* a valid integer literal (and could also not be parsed as CodeQL `int`).
654+
*/
642655
class IntegerLiteral extends Literal, @integerliteral {
643656
/** Gets the int representation of this literal. */
644657
int getIntValue() { result = getValue().toInt() }
645658

646659
override string getAPrimaryQlClass() { result = "IntegerLiteral" }
647660
}
648661

649-
/** A long literal. For example, `23l`. */
662+
/**
663+
* A long literal. For example, `23L`.
664+
*
665+
* A long literal can never be negative except when:
666+
* - It is written in binary, octal or hexadecimal notation
667+
* - It is written in decimal notation, has the value `9223372036854775808` and
668+
* is preceded by a minus; in this case the value of the LongLiteral is
669+
* -9223372036854775808 and the preceding minus will *not* be modeled as
670+
* `MinusExpr`.<br/>
671+
* In all other cases the preceding minus, if any, will be modeled as separate
672+
* `MinusExpr`.
673+
*
674+
* The last exception is necessary because `9223372036854775808` on its own
675+
* would not be a valid long literal.
676+
*/
650677
class LongLiteral extends Literal, @longliteral {
651678
override string getAPrimaryQlClass() { result = "LongLiteral" }
652679
}
653680

654-
/** A floating point literal. For example, `4.2f`. */
681+
/**
682+
* A float literal. For example, `4.2f`.
683+
*
684+
* A float literal is never negative; a preceding minus, if any, will always
685+
* be modeled as separate `MinusExpr`.
686+
*/
655687
class FloatingPointLiteral extends Literal, @floatingpointliteral {
656688
override string getAPrimaryQlClass() { result = "FloatingPointLiteral" }
657689
}
658690

659-
/** A double literal. For example, `4.2`. */
691+
/**
692+
* A double literal. For example, `4.2`.
693+
*
694+
* A double literal is never negative; a preceding minus, if any, will always
695+
* be modeled as separate `MinusExpr`.
696+
*/
660697
class DoubleLiteral extends Literal, @doubleliteral {
661698
override string getAPrimaryQlClass() { result = "DoubleLiteral" }
662699
}

0 commit comments

Comments
 (0)