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

Skip to content

Commit 67d1c72

Browse files
committed
Java: Autoformat libs outside semmle.code.java.
1 parent 16b29b2 commit 67d1c72

41 files changed

Lines changed: 1305 additions & 1183 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

java/ql/src/Advisory/Documentation/JavadocCommon.qll

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import java
22

33
/** Holds if the given `Javadoc` contains a minimum of a few characters of text. */
4-
private
5-
predicate acceptableDocText(Javadoc j) {
4+
private predicate acceptableDocText(Javadoc j) {
65
// Require minimum combined length of all non-tag elements.
76
sum(JavadocElement e, int toSum |
87
e = j.getAChild() and
98
not e = j.getATag(_) and
109
toSum = e.toString().length()
11-
|
10+
|
1211
toSum
1312
) >= 5
1413
}
1514

1615
/** Holds if the given `JavadocTag` contains a minimum of a few characters of text. */
17-
private
18-
predicate acceptableTag(JavadocTag t) {
16+
private predicate acceptableTag(JavadocTag t) {
1917
sum(JavadocElement e, int toSum |
2018
e = t.getAChild() and
2119
toSum = e.toString().length()
22-
|
20+
|
2321
toSum
2422
) >= 5
2523
}
@@ -31,9 +29,7 @@ class DocuRefType extends RefType {
3129
this.isPublic()
3230
}
3331

34-
predicate hasAcceptableDocText() {
35-
acceptableDocText(this.getDoc().getJavadoc())
36-
}
32+
predicate hasAcceptableDocText() { acceptableDocText(this.getDoc().getJavadoc()) }
3733
}
3834

3935
/** A public (non-getter, non-setter) `Callable` that does not override another method. */
@@ -50,12 +46,11 @@ class DocuCallable extends Callable {
5046
not this.getLocation() = this.getDeclaringType().getLocation()
5147
}
5248

53-
predicate hasAcceptableDocText() {
54-
acceptableDocText(this.getDoc().getJavadoc())
55-
}
49+
predicate hasAcceptableDocText() { acceptableDocText(this.getDoc().getJavadoc()) }
5650

5751
string toMethodOrConstructorString() {
58-
(this instanceof Method and result = "method") or
52+
(this instanceof Method and result = "method")
53+
or
5954
(this instanceof Constructor and result = "constructor")
6055
}
6156
}

java/ql/src/Architecture/Dependencies/UnusedMavenDependencies.qll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import semmle.code.xml.MavenPom
66
* within the given container (folder, jar file etc.).
77
*/
88
predicate pomDependsOnContainer(Pom f, Container g) {
9-
exists(RefType source, RefType target |
10-
source.getFile().getParentContainer*() = f.getFile().getParentContainer() and
11-
target.getFile().getParentContainer*() = g and
12-
depends(source, target)
13-
)
9+
exists(RefType source, RefType target |
10+
source.getFile().getParentContainer*() = f.getFile().getParentContainer() and
11+
target.getFile().getParentContainer*() = g and
12+
depends(source, target)
13+
)
1414
}
1515

1616
/**
1717
* Holds if the source code in the project represented by the sourcePom depends on any code
1818
* within the project represented by the targetPom.
1919
*/
2020
predicate pomDependsOnPom(Pom sourcePom, Pom targetPom) {
21-
exists(RefType source, RefType target |
22-
source.getFile().getParentContainer*() = sourcePom.getFile().getParentContainer() and
23-
target.getFile().getParentContainer*() = targetPom.getFile().getParentContainer() and
24-
depends(source, target)
25-
)
21+
exists(RefType source, RefType target |
22+
source.getFile().getParentContainer*() = sourcePom.getFile().getParentContainer() and
23+
target.getFile().getParentContainer*() = targetPom.getFile().getParentContainer() and
24+
depends(source, target)
25+
)
2626
}

java/ql/src/Compatibility/JDK9/JdkInternals.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*
44
* http://hg.openjdk.java.net/jdk9/jdk9/langtools/file/6ba2130e87bd/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/resources/jdk8_internals.txt
55
*/
6-
76
predicate jdkInternalApi(string p) {
87
p = "apple.applescript" or
98
p = "apple.laf" or

java/ql/src/Compatibility/JDK9/JdkInternalsReplacement.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
*
44
* http://hg.openjdk.java.net/jdk9/jdk9/langtools/file/6ba2130e87bd/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/resources/jdkinternals.properties
55
*/
6-
76
predicate jdkInternalReplacement(string old, string new) {
87
exists(string r, int eqIdx | jdkInternalReplacement(r) and eqIdx = r.indexOf("=") |
98
old = r.prefix(eqIdx) and
10-
new = r.suffix(eqIdx+1)
9+
new = r.suffix(eqIdx + 1)
1110
)
1211
}
1312

14-
private
15-
predicate jdkInternalReplacement(string r) {
13+
private predicate jdkInternalReplacement(string r) {
1614
r = "com.sun.crypto.provider.SunJCE=Use java.security.Security.getProvider(provider-name) @since 1.3" or
1715
r = "com.sun.org.apache.xml.internal.security=Use java.xml.crypto @since 1.6" or
1816
r = "com.sun.org.apache.xml.internal.security.utils.Base64=Use java.util.Base64 @since 1.8" or

java/ql/src/Likely Bugs/Comparison/Equality.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class RefiningEquals extends EqualsMethod {
1515
// ... there is a `super` access that ...
1616
exists(MethodAccess sup, SuperAccess qual |
1717
// ... is of the form `super.something`, but not `A.super.something` ...
18-
qual = sup.getQualifier() and not exists(qual.getQualifier()) and
18+
qual = sup.getQualifier() and
19+
not exists(qual.getQualifier()) and
1920
// ... calls `super.equals` ...
2021
sup.getCallee() instanceof EqualsMethod and
2122
// ... on the (only) parameter of this method ...

java/ql/src/Likely Bugs/Comparison/UselessComparisonTest.qll

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,33 @@ library class BoundKind extends string {
1414
this = "<="
1515
}
1616

17-
predicate isEqual() {
18-
this = "="
19-
}
17+
predicate isEqual() { this = "=" }
2018

21-
predicate isNotEqual() {
22-
this = "!="
23-
}
19+
predicate isNotEqual() { this = "!=" }
2420

25-
predicate isLower() {
26-
this = ">="
27-
}
21+
predicate isLower() { this = ">=" }
2822

29-
predicate isUpper() {
30-
this = "<="
31-
}
23+
predicate isUpper() { this = "<=" }
3224

33-
predicate providesLowerBound() {
34-
isEqual() or isLower()
35-
}
25+
predicate providesLowerBound() { isEqual() or isLower() }
3626

37-
predicate providesUpperBound() {
38-
isEqual() or isUpper()
39-
}
27+
predicate providesUpperBound() { isEqual() or isUpper() }
4028
}
4129

4230
/**
4331
* The information from `s1` implies that `test` always has the value `testIsTrue`.
4432
*/
4533
predicate uselessTest(ConditionNode s1, BinaryExpr test, boolean testIsTrue) {
46-
exists(ConditionBlock cb, SsaVariable v, BinaryExpr cond, boolean condIsTrue, int k1, int k2, CompileTimeConstantExpr c1, CompileTimeConstantExpr c2 |
34+
exists(
35+
ConditionBlock cb, SsaVariable v, BinaryExpr cond, boolean condIsTrue, int k1, int k2,
36+
CompileTimeConstantExpr c1, CompileTimeConstantExpr c2
37+
|
4738
s1 = cond and
4839
cb.getCondition() = cond and
49-
cond.hasOperands(v.getAUse(), c1) and c1.getIntValue() = k1 and
50-
test.hasOperands(v.getAUse(), c2) and c2.getIntValue() = k2 and
40+
cond.hasOperands(v.getAUse(), c1) and
41+
c1.getIntValue() = k1 and
42+
test.hasOperands(v.getAUse(), c2) and
43+
c2.getIntValue() = k2 and
5144
v.getSourceVariable().getVariable() instanceof LocalScopeVariable and
5245
cb.controls(test.getBasicBlock(), condIsTrue) and
5346
v.getSourceVariable().getType() instanceof IntegralType and
@@ -62,22 +55,36 @@ predicate uselessTest(ConditionNode s1, BinaryExpr test, boolean testIsTrue) {
6255
or
6356
exists(ComparisonExpr comp | comp = cond |
6457
comp.getLesserOperand() = v.getAUse() and
65-
(condIsTrue = true and boundKind.isUpper() and (if comp.isStrict() then bound = k1-1 else bound = k1)
58+
(
59+
condIsTrue = true and
60+
boundKind.isUpper() and
61+
(if comp.isStrict() then bound = k1 - 1 else bound = k1)
6662
or
67-
condIsTrue = false and boundKind.isLower() and (if comp.isStrict() then bound = k1 else bound = k1+1))
63+
condIsTrue = false and
64+
boundKind.isLower() and
65+
(if comp.isStrict() then bound = k1 else bound = k1 + 1)
66+
)
6867
or
6968
comp.getGreaterOperand() = v.getAUse() and
70-
(condIsTrue = true and boundKind.isLower() and (if comp.isStrict() then bound = k1+1 else bound = k1)
69+
(
70+
condIsTrue = true and
71+
boundKind.isLower() and
72+
(if comp.isStrict() then bound = k1 + 1 else bound = k1)
7173
or
72-
condIsTrue = false and boundKind.isUpper() and (if comp.isStrict() then bound = k1 else bound = k1-1))
74+
condIsTrue = false and
75+
boundKind.isUpper() and
76+
(if comp.isStrict() then bound = k1 else bound = k1 - 1)
77+
)
7378
)
7479
|
7580
// Given the bound we check if the `test` is either
7681
// always true (`testIsTrue = true`) or always false (`testIsTrue = false`).
7782
exists(EqualityTest testeq, boolean pol | testeq = test and pol = testeq.polarity() |
7883
(
79-
boundKind.providesLowerBound() and k2 < bound or
80-
boundKind.providesUpperBound() and bound < k2 or
84+
boundKind.providesLowerBound() and k2 < bound
85+
or
86+
boundKind.providesUpperBound() and bound < k2
87+
or
8188
boundKind.isNotEqual() and k2 = bound
8289
) and
8390
testIsTrue = pol.booleanNot()
@@ -87,14 +94,42 @@ predicate uselessTest(ConditionNode s1, BinaryExpr test, boolean testIsTrue) {
8794
or
8895
exists(ComparisonExpr comp | comp = test |
8996
comp.getLesserOperand() = v.getAUse() and
90-
(boundKind.providesLowerBound() and testIsTrue = false and (k2 < bound or k2 = bound and comp.isStrict())
97+
(
98+
boundKind.providesLowerBound() and
99+
testIsTrue = false and
100+
(
101+
k2 < bound
102+
or
103+
k2 = bound and comp.isStrict()
104+
)
91105
or
92-
boundKind.providesUpperBound() and testIsTrue = true and (bound < k2 or bound = k2 and not comp.isStrict()))
106+
boundKind.providesUpperBound() and
107+
testIsTrue = true and
108+
(
109+
bound < k2
110+
or
111+
bound = k2 and not comp.isStrict()
112+
)
113+
)
93114
or
94115
comp.getGreaterOperand() = v.getAUse() and
95-
(boundKind.providesLowerBound() and testIsTrue = true and (k2 < bound or k2 = bound and not comp.isStrict())
116+
(
117+
boundKind.providesLowerBound() and
118+
testIsTrue = true and
119+
(
120+
k2 < bound
121+
or
122+
k2 = bound and not comp.isStrict()
123+
)
96124
or
97-
boundKind.providesUpperBound() and testIsTrue = false and (bound < k2 or bound = k2 and comp.isStrict()))
125+
boundKind.providesUpperBound() and
126+
testIsTrue = false and
127+
(
128+
bound < k2
129+
or
130+
bound = k2 and comp.isStrict()
131+
)
132+
)
98133
)
99134
)
100135
)

0 commit comments

Comments
 (0)