-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCommon.qll
More file actions
45 lines (41 loc) · 1.28 KB
/
Common.qll
File metadata and controls
45 lines (41 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java
predicate mayDropThroughWithoutComment(SwitchStmt switch, Stmt switchCase) {
exists(int caseIx, SwitchCase next, int nextCaseStmtIx, Stmt lastInCase, ControlFlowNode node |
switch.getCase(caseIx) = switchCase and
switch.getCase(caseIx + 1) = next and
switch.getStmt(nextCaseStmtIx) = next and
switch.getStmt(nextCaseStmtIx - 1) = lastInCase and
lastInCase != switchCase and
node.isAfter(lastInCase) and
node.getANormalSuccessor().asStmt() = switch.getAStmt() and
not fallThroughCommented(next)
)
}
private predicate fallThroughCommented(Stmt case) {
exists(Location loc |
loc = case.getLocation() and
loc.getStartLine() = fallThroughCommentedLine(loc.getFile())
)
}
private int fallThroughCommentedLine(File f) {
exists(Location loc, JavadocText text |
loc.getFile() = f and
text.getLocation() = loc and
text.getText().toLowerCase().regexpMatch(".*falls?[ -]?(through|thru).*") and
result = loc.getStartLine() + 1
)
or
exists(int mid |
mid = fallThroughCommentedLine(f) and
not stmtLine(f) = mid and
mid < max(stmtLine(f)) and
result = mid + 1
)
}
private int stmtLine(File f) {
exists(Stmt s, Location loc |
s.getLocation() = loc and
loc.getFile() = f and
loc.getStartLine() = result
)
}