|
| 1 | +/** Provides classes and predicates for exclusions related to MaD models. */ |
| 2 | + |
| 3 | +import java |
| 4 | + |
| 5 | +/** Holds if the given package `p` is a test package. */ |
| 6 | +pragma[nomagic] |
| 7 | +private predicate isTestPackage(Package p) { |
| 8 | + p.getName() |
| 9 | + .matches([ |
| 10 | + "org.junit%", "junit.%", "org.mockito%", "org.assertj%", |
| 11 | + "com.github.tomakehurst.wiremock%", "org.hamcrest%", "org.springframework.test.%", |
| 12 | + "org.springframework.mock.%", "org.springframework.boot.test.%", "reactor.test%", |
| 13 | + "org.xmlunit%", "org.testcontainers.%", "org.opentest4j%", "org.mockserver%", |
| 14 | + "org.powermock%", "org.skyscreamer.jsonassert%", "org.rnorth.visibleassertions", |
| 15 | + "org.openqa.selenium%", "com.gargoylesoftware.htmlunit%", "org.jboss.arquillian.testng%", |
| 16 | + "org.testng%" |
| 17 | + ]) |
| 18 | +} |
| 19 | + |
| 20 | +/** |
| 21 | + * A test library. |
| 22 | + */ |
| 23 | +class TestLibrary extends RefType { |
| 24 | + TestLibrary() { isTestPackage(this.getPackage()) } |
| 25 | +} |
| 26 | + |
| 27 | +/** Holds if the given file is a test file. */ |
| 28 | +private predicate isInTestFile(File file) { |
| 29 | + file.getAbsolutePath().matches(["%/test/%", "%/guava-tests/%", "%/guava-testlib/%"]) and |
| 30 | + not file.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work |
| 31 | +} |
| 32 | + |
| 33 | +/** Holds if the given compilation unit's package is a JDK internal. */ |
| 34 | +private predicate isJdkInternal(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 | + |
| 56 | +/** Holds if the given callable is not worth modeling. */ |
| 57 | +predicate isUninterestingForModels(Callable c) { |
| 58 | + isInTestFile(c.getCompilationUnit().getFile()) or |
| 59 | + isJdkInternal(c.getCompilationUnit()) or |
| 60 | + c instanceof MainMethod or |
| 61 | + c instanceof StaticInitializer or |
| 62 | + exists(FunctionalExpr funcExpr | c = funcExpr.asMethod()) or |
| 63 | + c.getDeclaringType() instanceof TestLibrary or |
| 64 | + c.(Constructor).isParameterless() |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * A class that represents all callables for which we might be |
| 69 | + * interested in having a MaD model. |
| 70 | + */ |
| 71 | +class ModelApi extends SrcCallable { |
| 72 | + ModelApi() { |
| 73 | + this.fromSource() and |
| 74 | + this.isEffectivelyPublic() and |
| 75 | + not isUninterestingForModels(this) |
| 76 | + } |
| 77 | +} |
0 commit comments