Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5502db4

Browse files
committed
Java: Autoformat most of semmle.code.java.dataflow.
1 parent f341aa7 commit 5502db4

18 files changed

Lines changed: 1892 additions & 1275 deletions

java/ql/src/semmle/code/java/dataflow/DataFlow.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ module DataFlow {
1515
* it should be replaced by using more than one copy of the data flow library.
1616
* Four copies are available: `DataFlow` through `DataFlow4`.
1717
*/
18-
private abstract
19-
class ConfigurationRecursionPrevention extends Configuration {
18+
abstract private class ConfigurationRecursionPrevention extends Configuration {
2019
bindingset[this]
2120
ConfigurationRecursionPrevention() { any() }
2221

2322
override predicate hasFlow(Node source, Node sink) {
24-
strictcount(Node n | this.isSource(n)) < 0
25-
or
26-
strictcount(Node n | this.isSink(n)) < 0
27-
or
28-
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0
29-
or
23+
strictcount(Node n | this.isSource(n)) < 0 or
24+
strictcount(Node n | this.isSink(n)) < 0 or
25+
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0 or
3026
super.hasFlow(source, sink)
3127
}
3228
}

java/ql/src/semmle/code/java/dataflow/DataFlow2.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ module DataFlow2 {
1515
* it should be replaced by using more than one copy of the data flow library.
1616
* Four copies are available: `DataFlow` through `DataFlow4`.
1717
*/
18-
private abstract
19-
class ConfigurationRecursionPrevention extends Configuration {
18+
abstract private class ConfigurationRecursionPrevention extends Configuration {
2019
bindingset[this]
2120
ConfigurationRecursionPrevention() { any() }
2221

2322
override predicate hasFlow(Node source, Node sink) {
24-
strictcount(Node n | this.isSource(n)) < 0
25-
or
26-
strictcount(Node n | this.isSink(n)) < 0
27-
or
28-
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0
29-
or
23+
strictcount(Node n | this.isSource(n)) < 0 or
24+
strictcount(Node n | this.isSink(n)) < 0 or
25+
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0 or
3026
super.hasFlow(source, sink)
3127
}
3228
}

java/ql/src/semmle/code/java/dataflow/DataFlow3.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ module DataFlow3 {
1515
* it should be replaced by using more than one copy of the data flow library.
1616
* Four copies are available: `DataFlow` through `DataFlow4`.
1717
*/
18-
private abstract
19-
class ConfigurationRecursionPrevention extends Configuration {
18+
abstract private class ConfigurationRecursionPrevention extends Configuration {
2019
bindingset[this]
2120
ConfigurationRecursionPrevention() { any() }
2221

2322
override predicate hasFlow(Node source, Node sink) {
24-
strictcount(Node n | this.isSource(n)) < 0
25-
or
26-
strictcount(Node n | this.isSink(n)) < 0
27-
or
28-
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0
29-
or
23+
strictcount(Node n | this.isSource(n)) < 0 or
24+
strictcount(Node n | this.isSink(n)) < 0 or
25+
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0 or
3026
super.hasFlow(source, sink)
3127
}
3228
}

java/ql/src/semmle/code/java/dataflow/DataFlow4.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ module DataFlow4 {
1515
* it should be replaced by using more than one copy of the data flow library.
1616
* Four copies are available: `DataFlow` through `DataFlow4`.
1717
*/
18-
private abstract
19-
class ConfigurationRecursionPrevention extends Configuration {
18+
abstract private class ConfigurationRecursionPrevention extends Configuration {
2019
bindingset[this]
2120
ConfigurationRecursionPrevention() { any() }
2221

2322
override predicate hasFlow(Node source, Node sink) {
24-
strictcount(Node n | this.isSource(n)) < 0
25-
or
26-
strictcount(Node n | this.isSink(n)) < 0
27-
or
28-
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0
29-
or
23+
strictcount(Node n | this.isSource(n)) < 0 or
24+
strictcount(Node n | this.isSink(n)) < 0 or
25+
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0 or
3026
super.hasFlow(source, sink)
3127
}
3228
}

java/ql/src/semmle/code/java/dataflow/DataFlow5.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ module DataFlow5 {
1515
* it should be replaced by using more than one copy of the data flow library.
1616
* Four copies are available: `DataFlow` through `DataFlow4`.
1717
*/
18-
private abstract
19-
class ConfigurationRecursionPrevention extends Configuration {
18+
abstract private class ConfigurationRecursionPrevention extends Configuration {
2019
bindingset[this]
2120
ConfigurationRecursionPrevention() { any() }
2221

2322
override predicate hasFlow(Node source, Node sink) {
24-
strictcount(Node n | this.isSource(n)) < 0
25-
or
26-
strictcount(Node n | this.isSink(n)) < 0
27-
or
28-
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0
29-
or
23+
strictcount(Node n | this.isSource(n)) < 0 or
24+
strictcount(Node n | this.isSink(n)) < 0 or
25+
strictcount(Node n1, Node n2 | this.isAdditionalFlowStep(n1, n2)) < 0 or
3026
super.hasFlow(source, sink)
3127
}
3228
}

java/ql/src/semmle/code/java/dataflow/DefUse.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ private import SSA
1313
*
1414
* This is the transitive closure of `adjacentUseUseSameVar`.
1515
*/
16-
predicate useUsePairSameVar(RValue use1, RValue use2) {
17-
adjacentUseUseSameVar+(use1, use2)
18-
}
16+
predicate useUsePairSameVar(RValue use1, RValue use2) { adjacentUseUseSameVar+(use1, use2) }
1917

2018
/**
2119
* Holds if `use1` and `use2` form a use-use-pair of the same
@@ -25,9 +23,7 @@ predicate useUsePairSameVar(RValue use1, RValue use2) {
2523
*
2624
* This is the transitive closure of `adjacentUseUse`.
2725
*/
28-
predicate useUsePair(RValue use1, RValue use2) {
29-
adjacentUseUse+(use1, use2)
30-
}
26+
predicate useUsePair(RValue use1, RValue use2) { adjacentUseUse+(use1, use2) }
3127

3228
/**
3329
* Holds if there exists a path from `def` to `use` without passing through another

java/ql/src/semmle/code/java/dataflow/InstanceAccess.qll

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Provides classes and predicates for reasoning about explicit and implicit
33
* instance accesses.
44
*/
5+
56
import java
67

78
/**
@@ -35,10 +36,9 @@ private predicate implicitSetEnclosingInstanceToThis(ConstructorCall cc) {
3536
*/
3637
private RefType getEnclosing(InnerClass ic, RefType t) {
3738
exists(RefType enclosing | enclosing = ic.getEnclosingType() |
38-
if enclosing.getASourceSupertype*() = t then
39-
result = enclosing
40-
else
41-
result = getEnclosing(enclosing, t)
39+
if enclosing.getASourceSupertype*() = t
40+
then result = enclosing
41+
else result = getEnclosing(enclosing, t)
4242
)
4343
}
4444

@@ -56,9 +56,14 @@ private predicate implicitEnclosingThisCopy(ConstructorCall cc, RefType t1, RefT
5656
* Holds if an enclosing instance of the form `t.this` is accessed by `e`.
5757
*/
5858
private predicate enclosingInstanceAccess(ExprParent e, RefType t) {
59-
e.(InstanceAccess).isEnclosingInstanceAccess(t) or
60-
exists(MethodAccess ma | ma.isEnclosingMethodAccess(t) and ma = e and not exists(ma.getQualifier())) or
61-
exists(FieldAccess fa | fa.isEnclosingFieldAccess(t) and fa = e and not exists(fa.getQualifier())) or
59+
e.(InstanceAccess).isEnclosingInstanceAccess(t)
60+
or
61+
exists(MethodAccess ma |
62+
ma.isEnclosingMethodAccess(t) and ma = e and not exists(ma.getQualifier())
63+
)
64+
or
65+
exists(FieldAccess fa | fa.isEnclosingFieldAccess(t) and fa = e and not exists(fa.getQualifier()))
66+
or
6267
implicitEnclosingThisCopy(e, t, _)
6368
}
6469

@@ -70,7 +75,9 @@ private predicate enclosingInstanceAccess(ExprParent e, RefType t) {
7075
private predicate derivedInstanceAccess(ExprParent e, int i, RefType t1, RefType t2) {
7176
enclosingInstanceAccess(e, t2) and
7277
i = 0 and
73-
exists(Callable c | c = e.(Expr).getEnclosingCallable() or c = e.(Stmt).getEnclosingCallable() | t1 = c.getDeclaringType())
78+
exists(Callable c | c = e.(Expr).getEnclosingCallable() or c = e.(Stmt).getEnclosingCallable() |
79+
t1 = c.getDeclaringType()
80+
)
7481
or
7582
exists(InnerClass ic |
7683
derivedInstanceAccess(e, i - 1, ic, t2) and
@@ -82,17 +89,15 @@ private predicate derivedInstanceAccess(ExprParent e, int i, RefType t1, RefType
8289
cached
8390
private newtype TInstanceAccessExt =
8491
TExplicitInstanceAccess(InstanceAccess ia) or
85-
TThisQualifier(FieldAccess fa) {
86-
fa.isOwnFieldAccess() and not exists(fa.getQualifier())
87-
} or
92+
TThisQualifier(FieldAccess fa) { fa.isOwnFieldAccess() and not exists(fa.getQualifier()) } or
8893
TThisArgument(Call c) {
89-
c instanceof ThisConstructorInvocationStmt or
90-
c instanceof SuperConstructorInvocationStmt or
94+
c instanceof ThisConstructorInvocationStmt
95+
or
96+
c instanceof SuperConstructorInvocationStmt
97+
or
9198
c.(MethodAccess).isOwnMethodAccess() and not exists(c.getQualifier())
9299
} or
93-
TThisEnclosingInstanceCapture(ConstructorCall cc) {
94-
implicitSetEnclosingInstanceToThis(cc)
95-
} or
100+
TThisEnclosingInstanceCapture(ConstructorCall cc) { implicitSetEnclosingInstanceToThis(cc) } or
96101
TEnclosingInstanceAccess(ExprParent e, RefType t) {
97102
enclosingInstanceAccess(e, t) and not e instanceof InstanceAccess
98103
} or
@@ -125,23 +130,27 @@ class InstanceAccessExt extends TInstanceAccessExt {
125130
private string ppBase() {
126131
exists(EnclosingInstanceAccess enc | enc = this |
127132
result = enc.getQualifier().toString() + "(" + enc.getType() + ")enclosing"
128-
) or
133+
)
134+
or
129135
isOwnInstanceAccess() and result = "this"
130136
}
131137

132138
private string ppKind() {
133-
isExplicit(_) and result = " <" + getAssociatedExprOrStmt().toString() + ">" or
134-
isImplicitFieldQualifier(_) and result = " <.field>" or
135-
isImplicitMethodQualifier(_) and result = " <.method>" or
136-
isImplicitThisConstructorArgument(_) and result = " <constr(this)>" or
137-
isImplicitEnclosingInstanceCapture(_) and result = " <.new>" or
139+
isExplicit(_) and result = " <" + getAssociatedExprOrStmt().toString() + ">"
140+
or
141+
isImplicitFieldQualifier(_) and result = " <.field>"
142+
or
143+
isImplicitMethodQualifier(_) and result = " <.method>"
144+
or
145+
isImplicitThisConstructorArgument(_) and result = " <constr(this)>"
146+
or
147+
isImplicitEnclosingInstanceCapture(_) and result = " <.new>"
148+
or
138149
isImplicitEnclosingInstanceQualifier(_) and result = "."
139150
}
140151

141152
/** Gets a textual representation of this element. */
142-
string toString() {
143-
result = ppBase() + ppKind()
144-
}
153+
string toString() { result = ppBase() + ppKind() }
145154

146155
/** Gets the source location for this element. */
147156
Location getLocation() { result = getAssociatedExprOrStmt().getLocation() }
@@ -180,11 +189,9 @@ class InstanceAccessExt extends TInstanceAccessExt {
180189
* Holds if this is the implicit `this` argument of `cc`, which is either a
181190
* `ThisConstructorInvocationStmt` or a `SuperConstructorInvocationStmt`.
182191
*/
183-
predicate isImplicitThisConstructorArgument(ConstructorCall cc) {
184-
this = TThisArgument(cc)
185-
}
192+
predicate isImplicitThisConstructorArgument(ConstructorCall cc) { this = TThisArgument(cc) }
186193

187-
/** Holds if this is the implicit qualifier of `cc`.*/
194+
/** Holds if this is the implicit qualifier of `cc`. */
188195
predicate isImplicitEnclosingInstanceCapture(ConstructorCall cc) {
189196
this = TThisEnclosingInstanceCapture(cc) or
190197
this = TEnclosingInstanceAccess(cc, _)
@@ -199,31 +206,35 @@ class InstanceAccessExt extends TInstanceAccessExt {
199206
}
200207

201208
/** Holds if this is an access to an object's own instance. */
202-
predicate isOwnInstanceAccess() {
203-
not isEnclosingInstanceAccess(_)
204-
}
209+
predicate isOwnInstanceAccess() { not isEnclosingInstanceAccess(_) }
205210

206211
/** Holds if this is an access to an enclosing instance. */
207212
predicate isEnclosingInstanceAccess(RefType t) {
208-
exists(InstanceAccess ia | this = TExplicitInstanceAccess(ia) and ia.isEnclosingInstanceAccess(t)) or
209-
this = TEnclosingInstanceAccess(_, t) or
213+
exists(InstanceAccess ia |
214+
this = TExplicitInstanceAccess(ia) and ia.isEnclosingInstanceAccess(t)
215+
)
216+
or
217+
this = TEnclosingInstanceAccess(_, t)
218+
or
210219
exists(int i | this = TInstanceAccessQualifier(_, i, t, _) and i > 0)
211220
}
212221

213222
/** Gets the type of this instance access. */
214223
RefType getType() {
215-
isEnclosingInstanceAccess(result) or
224+
isEnclosingInstanceAccess(result)
225+
or
216226
isOwnInstanceAccess() and result = getEnclosingCallable().getDeclaringType()
217227
}
218228

219229
/** Gets the control flow node associated with this instance access. */
220230
ControlFlowNode getCfgNode() {
221231
exists(ExprParent e | e = getAssociatedExprOrStmt() |
222-
e instanceof Call and result = e or
223-
e instanceof InstanceAccess and result = e or
232+
e instanceof Call and result = e
233+
or
234+
e instanceof InstanceAccess and result = e
235+
or
224236
exists(FieldAccess fa | fa = e |
225-
if fa instanceof RValue then fa = result
226-
else result.(AssignExpr).getDest() = fa
237+
if fa instanceof RValue then fa = result else result.(AssignExpr).getDest() = fa
227238
)
228239
)
229240
}
@@ -232,9 +243,7 @@ class InstanceAccessExt extends TInstanceAccessExt {
232243
/**
233244
* An access to an object's own instance.
234245
*/
235-
class OwnInstanceAccess extends InstanceAccessExt {
236-
OwnInstanceAccess() { isOwnInstanceAccess() }
237-
}
246+
class OwnInstanceAccess extends InstanceAccessExt { OwnInstanceAccess() { isOwnInstanceAccess() } }
238247

239248
/**
240249
* An access to an enclosing instance.
@@ -244,13 +253,10 @@ class EnclosingInstanceAccess extends InstanceAccessExt {
244253

245254
/** Gets the implicit qualifier of this in the desugared representation. */
246255
InstanceAccessExt getQualifier() {
247-
exists(ExprParent e, int i |
248-
result = TInstanceAccessQualifier(e, i, _, _)
249-
|
250-
this = TInstanceAccessQualifier(e, i + 1, _, _) or
251-
exists(RefType t |
252-
derivedInstanceAccess(e, i + 1, t, t)
253-
|
256+
exists(ExprParent e, int i | result = TInstanceAccessQualifier(e, i, _, _) |
257+
this = TInstanceAccessQualifier(e, i + 1, _, _)
258+
or
259+
exists(RefType t | derivedInstanceAccess(e, i + 1, t, t) |
254260
this = TEnclosingInstanceAccess(e, t) or
255261
this = TExplicitInstanceAccess(e)
256262
)

0 commit comments

Comments
 (0)