Skip to content

Commit 8554263

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: refactor CaptureModelsSpecific; resolve conflict for isInTestFile
1 parent 94f1102 commit 8554263

File tree

2 files changed

+7
-39
lines changed

2 files changed

+7
-39
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/ModelExclusions.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ class TestLibrary extends RefType {
2626

2727
/** Holds if the given file is a test file. */
2828
private predicate isInTestFile(File file) {
29-
file.getAbsolutePath().matches("%src/test/%") or
30-
file.getAbsolutePath().matches("%/guava-tests/%") or
31-
file.getAbsolutePath().matches("%/guava-testlib/%")
29+
file.getAbsolutePath().matches(["%/test/%", "%/guava-tests/%", "%/guava-testlib/%"]) and
30+
not file.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
3231
}
3332

3433
/** Holds if the given compilation unit's package is a JDK internal. */
@@ -54,8 +53,8 @@ private predicate isJdkInternal(CompilationUnit cu) {
5453
cu.getPackage().getName() = ""
5554
}
5655

57-
/** Holds if the given callable is not interesting to model. */
58-
private predicate isUninterestingForModels(Callable c) {
56+
/** Holds if the given callable is not worth modeling. */
57+
predicate isUninterestingForModels(Callable c) {
5958
isInTestFile(c.getCompilationUnit().getFile()) or
6059
isJdkInternal(c.getCompilationUnit()) or
6160
c instanceof MainMethod or

java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
private import java as J
66
private import semmle.code.java.dataflow.internal.DataFlowPrivate
77
private import semmle.code.java.dataflow.internal.ContainerFlow as ContainerFlow
8+
private import semmle.code.java.dataflow.internal.ModelExclusions
89
private import semmle.code.java.dataflow.DataFlow as Df
910
private import semmle.code.java.dataflow.SSA as Ssa
1011
private import semmle.code.java.dataflow.TaintTracking as Tt
@@ -26,33 +27,6 @@ private J::Method superImpl(J::Method m) {
2627
not m instanceof J::ToStringMethod
2728
}
2829

29-
private predicate isInTestFile(J::File file) {
30-
file.getAbsolutePath().matches(["%/test/%", "%/guava-tests/%", "%/guava-testlib/%"]) and
31-
not file.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
32-
}
33-
34-
private predicate isJdkInternal(J::CompilationUnit cu) {
35-
cu.getPackage().getName().matches("org.graalvm%") or
36-
cu.getPackage().getName().matches("com.sun%") or
37-
cu.getPackage().getName().matches("sun%") or
38-
cu.getPackage().getName().matches("jdk%") or
39-
cu.getPackage().getName().matches("java2d%") or
40-
cu.getPackage().getName().matches("build.tools%") or
41-
cu.getPackage().getName().matches("propertiesparser%") or
42-
cu.getPackage().getName().matches("org.jcp%") or
43-
cu.getPackage().getName().matches("org.w3c%") or
44-
cu.getPackage().getName().matches("org.ietf.jgss%") or
45-
cu.getPackage().getName().matches("org.xml.sax%") or
46-
cu.getPackage().getName().matches("com.oracle%") or
47-
cu.getPackage().getName().matches("org.omg%") or
48-
cu.getPackage().getName().matches("org.relaxng%") or
49-
cu.getPackage().getName() = "compileproperties" or
50-
cu.getPackage().getName() = "transparentruler" or
51-
cu.getPackage().getName() = "genstubs" or
52-
cu.getPackage().getName() = "netscape.javascript" or
53-
cu.getPackage().getName() = ""
54-
}
55-
5630
private predicate isInfrequentlyUsed(J::CompilationUnit cu) {
5731
cu.getPackage().getName().matches("javax.swing%") or
5832
cu.getPackage().getName().matches("java.awt%")
@@ -62,13 +36,8 @@ private predicate isInfrequentlyUsed(J::CompilationUnit cu) {
6236
* Holds if it is relevant to generate models for `api`.
6337
*/
6438
private predicate isRelevantForModels(J::Callable api) {
65-
not isInTestFile(api.getCompilationUnit().getFile()) and
66-
not isJdkInternal(api.getCompilationUnit()) and
67-
not isInfrequentlyUsed(api.getCompilationUnit()) and
68-
not api instanceof J::MainMethod and
69-
not api instanceof J::StaticInitializer and
70-
not exists(J::FunctionalExpr funcExpr | api = funcExpr.asMethod()) and
71-
not api.(J::Constructor).isParameterless()
39+
not isUninterestingForModels(api) and
40+
not isInfrequentlyUsed(api.getCompilationUnit())
7241
}
7342

7443
/**

0 commit comments

Comments
 (0)