Skip to content

Commit 464d363

Browse files
committed
Java: Rename Block -> BlockStmt
1 parent ab90f06 commit 464d363

File tree

25 files changed

+95
-68
lines changed

25 files changed

+95
-68
lines changed

change-notes/1.26/analysis-java.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Improvements to Java analysis
2+
3+
The following changes in version 1.26 affect Java analysis in all applications.
4+
5+
## General improvements
6+
7+
## New queries
8+
9+
| **Query** | **Tags** | **Purpose** |
10+
|-----------------------------|-----------|--------------------------------------------------------------------|
11+
12+
13+
## Changes to existing queries
14+
15+
| **Query** | **Expected impact** | **Change** |
16+
|------------------------------|------------------------|-----------------------------------|
17+
18+
19+
## Changes to libraries
20+
21+
* The QL class `Block`, denoting the `{ ... }` statement, is renamed to `BlockStmt`.

java/ql/examples/snippets/emptyblock.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
import java
1111

12-
from Block blk
12+
from BlockStmt blk
1313
where blk.getNumStmt() = 0
1414
select blk

java/ql/examples/snippets/emptythen.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
import java
1414

1515
from IfStmt i
16-
where i.getThen().(Block).getNumStmt() = 0
16+
where i.getThen().(BlockStmt).getNumStmt() = 0
1717
select i

java/ql/examples/snippets/singletonblock.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
import java
1010

11-
from Block b
11+
from BlockStmt b
1212
where b.getNumStmt() = 1
1313
select b

java/ql/src/Advisory/Statements/OneStatementPerLine.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ predicate oneLineStatement(Stmt s, File f, int line, int col) {
2727
col = l.getStartColumn()
2828
) and
2929
// Exclude blocks: `{break;}` is not really a violation.
30-
not s instanceof Block and
30+
not s instanceof BlockStmt and
3131
// Exclude implicit super constructor invocations.
3232
not s instanceof SuperConstructorInvocationStmt and
3333
// Java enums are desugared to a whole bunch of generated statements.

java/ql/src/Complexity/BlockWithTooManyStatements.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class ComplexStmt extends Stmt {
2020
}
2121
}
2222

23-
from Block b, int n
23+
from BlockStmt b, int n
2424
where n = count(ComplexStmt s | s = b.getAStmt()) and n > 3
2525
select b, "Block with too many statements (" + n.toString() + " complex statements in the block)."

java/ql/src/Frameworks/Spring/Architecture/Refactoring Opportunities/UnusedBean.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class ImpureStmt extends Stmt {
5151
/**
5252
* Get any non-block stmt in the block, including those nested within blocks.
5353
*/
54-
private Stmt getANestedStmt(Block block) {
54+
private Stmt getANestedStmt(BlockStmt block) {
5555
// Any non-block statement
56-
not result instanceof Block and result = block.getAStmt()
56+
not result instanceof BlockStmt and result = block.getAStmt()
5757
or
5858
// Or any statement nested in a block
5959
result = getANestedStmt(block.getAStmt())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ predicate hasTypeTest(Variable v) {
4242
*/
4343
class ReferenceEquals extends EqualsMethod {
4444
ReferenceEquals() {
45-
exists(Block b, ReturnStmt ret, EQExpr eq |
45+
exists(BlockStmt b, ReturnStmt ret, EQExpr eq |
4646
this.getBody() = b and
4747
b.getStmt(0) = ret and
4848
ret.getResult() = eq and

java/ql/src/Likely Bugs/Statements/EmptyBlock.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import semmle.code.java.Statement
1414

1515
/** A block without statements or comments. */
16-
private Block emptyBlock() {
16+
private BlockStmt emptyBlock() {
1717
result.getNumStmt() = 0 and
1818
result.getLocation().getNumberOfCommentLines() = 0
1919
}
@@ -48,8 +48,8 @@ predicate blockParent(Stmt empty, string msg) {
4848
or
4949
empty.getParent() instanceof LoopStmt and msg = "The body of a loop should not be empty."
5050
or
51-
empty.getParent() instanceof Block and
52-
empty instanceof Block and
51+
empty.getParent() instanceof BlockStmt and
52+
empty instanceof BlockStmt and
5353
msg = "This block should not be empty."
5454
)
5555
}

java/ql/src/Likely Bugs/Statements/UseBraces.ql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import java
1515

1616
/**
1717
* A control structure for which the trailing body (the syntactically last part)
18-
* is not a `Block`. This is either an `IfStmt` or a `LoopStmt`, but not a
18+
* is not a `BlockStmt`. This is either an `IfStmt` or a `LoopStmt`, but not a
1919
* `DoStmt`, since do-while statements don't have a trailing body.
2020
*/
2121
predicate unbracedTrailingBody(Stmt ctrlStructure, Stmt trailingBody) {
22-
not trailingBody instanceof Block and
22+
not trailingBody instanceof BlockStmt and
2323
(
2424
exists(IfStmt c | c = ctrlStructure |
2525
trailingBody = c.getElse() and not trailingBody instanceof IfStmt
@@ -33,15 +33,15 @@ predicate unbracedTrailingBody(Stmt ctrlStructure, Stmt trailingBody) {
3333

3434
/*
3535
* The body of a `SwitchStmt` is a block, but it isn't represented explicitly
36-
* in the AST as a `Block`, so we have to take it into account directly in the
36+
* in the AST as a `BlockStmt`, so we have to take it into account directly in the
3737
* following two predicates.
3838
*/
3939

4040
/**
41-
* Two consecutive statements in a `Block` statement or `SwitchStmt`.
41+
* Two consecutive statements in a `BlockStmt` statement or `SwitchStmt`.
4242
*/
4343
Stmt nextInBlock(Stmt s) {
44-
exists(Block b, int i |
44+
exists(BlockStmt b, int i |
4545
b.getStmt(i) = s and
4646
b.getStmt(i + 1) = result
4747
)
@@ -52,10 +52,10 @@ Stmt nextInBlock(Stmt s) {
5252
)
5353
}
5454

55-
/** The `Stmt.getParent()` relation restricted to not pass through `Block`s or `SwitchStmt`s. */
55+
/** The `Stmt.getParent()` relation restricted to not pass through `BlockStmt`s or `SwitchStmt`s. */
5656
Stmt nonBlockParent(Stmt s) {
5757
result = s.getParent() and
58-
not result instanceof Block and
58+
not result instanceof BlockStmt and
5959
not result instanceof SwitchStmt
6060
}
6161

@@ -64,7 +64,7 @@ predicate ifElseIf(IfStmt s, IfStmt elseif) { s.getElse() = elseif }
6464

6565
/**
6666
* The statement `body` is an unbraced trailing body of a control structure and
67-
* `succ` is the next statement in the surrounding `Block` (or `SwitchStmt`).
67+
* `succ` is the next statement in the surrounding `BlockStmt` (or `SwitchStmt`).
6868
*/
6969
predicate shouldOutdent(
7070
Stmt ctrl, Stmt body, Stmt succ, int bodycol, int succcol, int bodyline, int succline
@@ -79,7 +79,7 @@ predicate shouldOutdent(
7979

8080
/**
8181
* The statement `body` is an unbraced trailing body of a control structure and
82-
* `succ` is the next statement in the surrounding `Block` (or `SwitchStmt`).
82+
* `succ` is the next statement in the surrounding `BlockStmt` (or `SwitchStmt`).
8383
* The indentation of statement `succ` is suspect because it is indented
8484
* the same way as `body` and thus visually suggests to be part of the same
8585
* syntactic scope as `body`.

0 commit comments

Comments
 (0)