Skip to content

Commit fb2d36d

Browse files
authored
Merge pull request github#15451 from Marcono1234/marcono1234/java-assignment-doc
Java: Document which assignment type is covered by which class
2 parents 0d6c141 + d8fe0f5 commit fb2d36d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,17 @@ class ArrayInit extends Expr, @arrayinit {
378378
override string getAPrimaryQlClass() { result = "ArrayInit" }
379379
}
380380

381-
/** A common super-class that represents all varieties of assignments. */
381+
/**
382+
* A common super-class that represents many varieties of assignments.
383+
*
384+
* This does not cover unary assignments such as `i++`, and initialization of
385+
* local variables at their declaration such as `int i = 0;`.
386+
*
387+
* To cover more cases of variable updates, see the classes `VariableAssign`,
388+
* `VariableUpdate` and `VarWrite`. But consider that they don't cover array
389+
* element assignments since there the assignment destination is not directly
390+
* the array variable but instead an `ArrayAccess`.
391+
*/
382392
class Assignment extends Expr, @assignment {
383393
/** Gets the destination (left-hand side) of the assignment. */
384394
Expr getDest() { result.isNthChildOf(this, 0) }
@@ -1781,6 +1791,9 @@ class VariableUpdate extends Expr {
17811791

17821792
/**
17831793
* An assignment to a variable or an initialization of the variable.
1794+
*
1795+
* This does not cover compound assignments such as `i += 1`, or unary
1796+
* assignments such as `i++`; use the class `VariableUpdate` for that.
17841797
*/
17851798
class VariableAssign extends VariableUpdate {
17861799
VariableAssign() {
@@ -1979,6 +1992,9 @@ class ExtensionReceiverAccess extends VarAccess {
19791992

19801993
/**
19811994
* A write access to a variable, which occurs as the destination of an assignment.
1995+
*
1996+
* This does not cover the initialization of local variables at their declaration,
1997+
* use the class `VariableUpdate` if you want to cover that as well.
19821998
*/
19831999
class VarWrite extends VarAccess {
19842000
VarWrite() { this.isVarWrite() }

0 commit comments

Comments
 (0)