Skip to content

Commit a82c76d

Browse files
committed
Java: Set literals.
1 parent 3983587 commit a82c76d

File tree

8 files changed

+530
-1285
lines changed

8 files changed

+530
-1285
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ class TearDownMethod extends Method {
3838

3939
private class TestRelatedAnnotation extends Annotation {
4040
TestRelatedAnnotation() {
41-
this.getType().getPackage().hasName("org.testng.annotations") or
42-
this.getType().getPackage().hasName("org.junit") or
43-
this.getType().getPackage().hasName("org.junit.runner") or
44-
this.getType().getPackage().hasName("org.junit.jupiter.api") or
45-
this.getType().getPackage().hasName("org.junit.jupiter.params")
41+
this.getType()
42+
.getPackage()
43+
.hasName([
44+
"org.testng.annotations", "org.junit", "org.junit.runner", "org.junit.jupiter.api",
45+
"org.junit.jupiter.params"
46+
])
4647
}
4748
}
4849

java/ql/lib/semmle/code/java/controlflow/unreachableblocks/ExcludeDebuggingProfilingLogging.qll

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@ import semmle.code.java.controlflow.UnreachableBlocks
1717
class ExcludeDebuggingProfilingLogging extends ExcludedConstantField {
1818
ExcludeDebuggingProfilingLogging() {
1919
exists(string validFieldName |
20-
validFieldName = "debug" or
21-
validFieldName = "profiling" or
22-
validFieldName = "profile" or
23-
validFieldName = "time" or
24-
validFieldName = "verbose" or
25-
validFieldName = "report" or
26-
validFieldName = "dbg" or
27-
validFieldName = "timing" or
28-
validFieldName = "assert" or
29-
validFieldName = "log"
20+
validFieldName =
21+
[
22+
"debug", "profiling", "profile", "time", "verbose", "report", "dbg", "timing", "assert",
23+
"log"
24+
]
3025
|
3126
getName().regexpMatch(".*(?i)" + validFieldName + ".*")
3227
) and

java/ql/lib/semmle/code/java/frameworks/JaxWS.qll

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ string getAJaxRsPackage(string subpackage) { result = getAJaxRsPackage() + "." +
2525
class JaxWsEndpoint extends Class {
2626
JaxWsEndpoint() {
2727
exists(AnnotationType a | a = this.getAnAnnotation().getType() |
28-
a.hasName("WebService") or
29-
a.hasName("WebServiceProvider") or
30-
a.hasName("WebServiceClient")
28+
a.hasName(["WebService", "WebServiceProvider", "WebServiceClient"])
3129
)
3230
}
3331

3432
/** Gets a method annotated with `@WebMethod` or `@WebEndpoint`. */
3533
Callable getARemoteMethod() {
3634
result = this.getACallable() and
3735
exists(AnnotationType a | a = result.getAnAnnotation().getType() |
38-
a.hasName("WebMethod") or
39-
a.hasName("WebEndpoint")
36+
a.hasName(["WebMethod", "WebEndpoint"])
4037
)
4138
}
4239
}
@@ -62,12 +59,7 @@ class JaxRsResourceMethod extends Method {
6259
a = this.getAnAnnotation().getType() and
6360
a.getPackage().getName() = getAJaxRsPackage()
6461
|
65-
a.hasName("GET") or
66-
a.hasName("POST") or
67-
a.hasName("DELETE") or
68-
a.hasName("PUT") or
69-
a.hasName("OPTIONS") or
70-
a.hasName("HEAD")
62+
a.hasName(["GET", "POST", "DELETE", "PUT", "OPTIONS", "HEAD"])
7163
)
7264
or
7365
// A JaxRS resource method can also inherit these annotations from a supertype, but only if
@@ -201,13 +193,10 @@ class JaxRsInjectionAnnotation extends JaxRSAnnotation {
201193
a = this.getType() and
202194
a.getPackage().getName() = getAJaxRsPackage()
203195
|
204-
a.hasName("BeanParam") or
205-
a.hasName("CookieParam") or
206-
a.hasName("FormParam") or
207-
a.hasName("HeaderParam") or
208-
a.hasName("MatrixParam") or
209-
a.hasName("PathParam") or
210-
a.hasName("QueryParam")
196+
a.hasName([
197+
"BeanParam", "CookieParam", "FormParam", "HeaderParam", "MatrixParam", "PathParam",
198+
"QueryParam"
199+
])
211200
)
212201
or
213202
this.getType().hasQualifiedName(getAJaxRsPackage("core"), "Context")

java/ql/lib/semmle/code/java/frameworks/Protobuf.qll

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ class ProtobufMessageLite extends Interface {
4040
*/
4141
Method getAGetterMethod() {
4242
exists(RefType decl | decl = result.getDeclaringType() and decl = this.getASubtype+() |
43-
exists(string name, string suffix |
44-
suffix = "" or
45-
suffix = "list" or
46-
suffix = "map" or
47-
suffix = "ordefault" or
48-
suffix = "orthrow"
49-
|
43+
exists(string name, string suffix | suffix = ["", "list", "map", "ordefault", "orthrow"] |
5044
exists(Field f | f.getDeclaringType() = decl |
5145
f.getName().toLowerCase().replaceAll("_", "") = name
5246
) and

java/ql/lib/semmle/code/java/metrics/MetricRefType.qll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,7 @@ class MetricRefType extends RefType, MetricElement {
264264
* for use with the specialization index metric.
265265
*/
266266
predicate ignoreOverride(Method c) {
267-
c.hasStringSignature("equals(Object)") or
268-
c.hasStringSignature("hashCode()") or
269-
c.hasStringSignature("toString()") or
270-
c.hasStringSignature("finalize()") or
271-
c.hasStringSignature("clone()")
267+
c.hasStringSignature(["equals(Object)", "hashCode()", "toString()", "finalize()", "clone()"])
272268
}
273269

274270
/** Gets a method that overrides a non-abstract method in a super type. */

java/ql/lib/semmle/code/java/security/RelativePaths.qll

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import java
77
predicate relativePath(Element tree, string command) {
88
exists(StringLiteral lit, string text | tree = lit and text = lit.getRepresentedString() |
99
text != "" and
10-
(
11-
text.regexpMatch("[^/\\\\ \t]*") or
12-
text.regexpMatch("[^/\\\\ \t]*[ \t].*")
13-
) and
10+
text.regexpMatch(["[^/\\\\ \t]*", "[^/\\\\ \t]*[ \t].*"]) and
1411
command = text.replaceAll("\t", " ").splitAt(" ", 0).replaceAll("\"", "")
1512
)
1613
or
@@ -35,39 +32,11 @@ predicate arrayStartingWithRelative(Element tree, string command) {
3532
* because they do not correspond to files in the filesystem.
3633
*/
3734
predicate shellBuiltin(string command) {
38-
command = "." or
39-
command = "[" or
40-
command = "[[" or
41-
command = "alias" or
42-
command = "builtin" or
43-
command = "case" or
44-
command = "command" or
45-
command = "compgen" or
46-
command = "complete" or
47-
command = "compopt" or
48-
command = "echo" or
49-
command = "eval" or
50-
command = "exec" or
51-
command = "false" or
52-
command = "fc" or
53-
command = "for" or
54-
command = "getopts" or
55-
command = "help" or
56-
command = "history" or
57-
command = "if" or
58-
command = "kill" or
59-
command = "printf" or
60-
command = "pwd" or
61-
command = "select" or
62-
command = "source" or
63-
command = "test" or
64-
command = "time" or
65-
command = "times" or
66-
command = "trap" or
67-
command = "true" or
68-
command = "type" or
69-
command = "typeset" or
70-
command = "ulimit" or
71-
command = "until" or
72-
command = "while"
35+
command =
36+
[
37+
".", "[", "[[", "alias", "builtin", "case", "command", "compgen", "complete", "compopt",
38+
"echo", "eval", "exec", "false", "fc", "for", "getopts", "help", "history", "if", "kill",
39+
"printf", "pwd", "select", "source", "test", "time", "times", "trap", "true", "type",
40+
"typeset", "ulimit", "until", "while"
41+
]
7342
}

0 commit comments

Comments
 (0)