Skip to content

Commit 0577e12

Browse files
Add consistency checks
1 parent ecf130f commit 0577e12

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

java/ql/src/utils/MinimalStubsFromSource.ql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,30 @@ class UsedInSource extends GeneratedDeclaration {
1818
this = any(Expr e | e.getEnclosingCallable().fromSource()).getType()
1919
or
2020
this = any(RefType t | t.fromSource())
21+
or
22+
this = any(TypeAccess ta | ta.fromSource())
2123
)
2224
}
2325
}
2426

2527
from GeneratedTopLevel t
2628
where not t.fromSource()
2729
select t.getQualifiedName(), t.stubFile()
30+
31+
module Consistency {
32+
query predicate noGeneratedStubs(string s) {
33+
exists(GeneratedTopLevel t | s = t.getQualifiedName() |
34+
not t.fromSource() and
35+
not exists(t.stubFile())
36+
)
37+
}
38+
39+
query predicate multipleGeneratedStubs(string s) {
40+
exists(GeneratedTopLevel t | s = t.getQualifiedName() |
41+
not t.fromSource() and
42+
strictcount(t.stubFile()) > 1
43+
)
44+
}
45+
}
46+
47+
import Consistency

java/ql/src/utils/Stubs.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ private class IndirectType extends GeneratedType {
128128
this = getAContainedType(t.getAGeneratedType()).(RefType).getSourceDeclaration()
129129
)
130130
or
131+
this.getSourceDeclaration() instanceof GeneratedType
132+
or
133+
this = any(GeneratedType t).getSourceDeclaration()
134+
or
131135
exists(GeneratedType t | this = t.(BoundedType).getATypeBound().getType())
132136
or
133137
exists(GeneratedDeclaration decl |

java/ql/src/utils/makeStubs.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,21 @@ def run(cmd):
120120
with open(outputJsonFile) as f:
121121
results = json.load(f)
122122

123-
if not '#select' in results or not 'tuples' in results['#select']:
123+
try:
124+
results['#select']['tuples']
125+
results['noGeneratedStubs']['tuples']
126+
results['multipleGeneratedStubs']['tuples']
127+
except ValueError:
124128
print('Unexpected JSON output - no tuples found')
125129
exit(1)
126130

131+
for (typ,) in results['noGeneratedStubs']['tuples']:
132+
print(f"WARNING: No stubs generated for {typ}. This is probably a bug.")
133+
134+
for (typ,) in results['multipleGeneratedStubs']['tuples']:
135+
print(
136+
f"WARNING: Multiple stubs generated for {typ}. This is probably a bug. One will be chosen arbitrarily.")
137+
127138
for (typ, stub) in results['#select']['tuples']:
128139
stubFile = os.path.join(stubDir, typ.replace(".", "/") + ".java")
129140
os.makedirs(os.path.dirname(stubFile), exist_ok=True)

0 commit comments

Comments
 (0)