Skip to content

Commit 9828ad0

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add draft of class to represent callables we are interested in modeling
1 parent 2e76e12 commit 9828ad0

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/** Provides classes and predicates for exclusions related to MaD models. */
2+
3+
import java
4+
5+
pragma[nomagic]
6+
private predicate isTestPackage(Package p) {
7+
p.getName()
8+
.matches([
9+
"org.junit%", "junit.%", "org.mockito%", "org.assertj%",
10+
"com.github.tomakehurst.wiremock%", "org.hamcrest%", "org.springframework.test.%",
11+
"org.springframework.mock.%", "org.springframework.boot.test.%", "reactor.test%",
12+
"org.xmlunit%", "org.testcontainers.%", "org.opentest4j%", "org.mockserver%",
13+
"org.powermock%", "org.skyscreamer.jsonassert%", "org.rnorth.visibleassertions",
14+
"org.openqa.selenium%", "com.gargoylesoftware.htmlunit%", "org.jboss.arquillian.testng%",
15+
"org.testng%", "%.test%"
16+
])
17+
}
18+
19+
/**
20+
* A test library.
21+
*/
22+
private class TestLibrary extends RefType {
23+
TestLibrary() { isTestPackage(this.getPackage()) }
24+
}
25+
26+
private predicate isInTestFile(File file) {
27+
file.getAbsolutePath().matches("%src/test/%") or
28+
file.getAbsolutePath().matches("%/guava-tests/%") or
29+
file.getAbsolutePath().matches("%/guava-testlib/%")
30+
}
31+
32+
private predicate isJdkInternal(CompilationUnit cu) {
33+
cu.getPackage().getName().matches("org.graalvm%") or
34+
cu.getPackage().getName().matches("com.sun%") or // ! maybe don't exclude `sun` ones? see SensitiveApi models again.
35+
cu.getPackage().getName().matches("sun%") or
36+
cu.getPackage().getName().matches("jdk%") or
37+
cu.getPackage().getName().matches("java2d%") or
38+
cu.getPackage().getName().matches("build.tools%") or
39+
cu.getPackage().getName().matches("propertiesparser%") or
40+
cu.getPackage().getName().matches("org.jcp%") or
41+
cu.getPackage().getName().matches("org.w3c%") or // ! maybe don't exclude these?
42+
cu.getPackage().getName().matches("org.ietf.jgss%") or
43+
cu.getPackage().getName().matches("org.xml.sax%") or
44+
cu.getPackage().getName().matches("com.oracle%") or
45+
cu.getPackage().getName().matches("org.omg%") or
46+
cu.getPackage().getName().matches("org.relaxng%") or
47+
cu.getPackage().getName() = "compileproperties" or
48+
cu.getPackage().getName() = "transparentruler" or
49+
cu.getPackage().getName() = "genstubs" or
50+
cu.getPackage().getName() = "netscape.javascript" or
51+
cu.getPackage().getName() = "" or
52+
cu.getPackage().getName().matches("%internal%")
53+
}
54+
55+
/** Holds if the given callable is not worth modeling. */
56+
private predicate isUninterestingForModels(Callable c) {
57+
c.getDeclaringType() instanceof TestLibrary or
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.(Constructor).isParameterless()
64+
}
65+
66+
/**
67+
* A class that represents all callables for which we might be
68+
* interested in having a MaD model.
69+
*/
70+
class ModelApi extends SrcCallable {
71+
ModelApi() {
72+
this.fromSource() and
73+
this.isEffectivelyPublic() and
74+
not isUninterestingForModels(this)
75+
}
76+
}

0 commit comments

Comments
 (0)