Add consistency checks

This commit is contained in:
Joe Farebrother
2021-06-30 12:27:18 +01:00
parent ecf130f7ae
commit 0577e12b97
3 changed files with 36 additions and 1 deletions

View File

@@ -18,6 +18,8 @@ class UsedInSource extends GeneratedDeclaration {
this = any(Expr e | e.getEnclosingCallable().fromSource()).getType()
or
this = any(RefType t | t.fromSource())
or
this = any(TypeAccess ta | ta.fromSource())
)
}
}
@@ -25,3 +27,21 @@ class UsedInSource extends GeneratedDeclaration {
from GeneratedTopLevel t
where not t.fromSource()
select t.getQualifiedName(), t.stubFile()
module Consistency {
query predicate noGeneratedStubs(string s) {
exists(GeneratedTopLevel t | s = t.getQualifiedName() |
not t.fromSource() and
not exists(t.stubFile())
)
}
query predicate multipleGeneratedStubs(string s) {
exists(GeneratedTopLevel t | s = t.getQualifiedName() |
not t.fromSource() and
strictcount(t.stubFile()) > 1
)
}
}
import Consistency

View File

@@ -128,6 +128,10 @@ private class IndirectType extends GeneratedType {
this = getAContainedType(t.getAGeneratedType()).(RefType).getSourceDeclaration()
)
or
this.getSourceDeclaration() instanceof GeneratedType
or
this = any(GeneratedType t).getSourceDeclaration()
or
exists(GeneratedType t | this = t.(BoundedType).getATypeBound().getType())
or
exists(GeneratedDeclaration decl |

View File

@@ -120,10 +120,21 @@ if run(['codeql', 'bqrs', 'decode', outputBqrsFile, '--format=json', '--output',
with open(outputJsonFile) as f:
results = json.load(f)
if not '#select' in results or not 'tuples' in results['#select']:
try:
results['#select']['tuples']
results['noGeneratedStubs']['tuples']
results['multipleGeneratedStubs']['tuples']
except ValueError:
print('Unexpected JSON output - no tuples found')
exit(1)
for (typ,) in results['noGeneratedStubs']['tuples']:
print(f"WARNING: No stubs generated for {typ}. This is probably a bug.")
for (typ,) in results['multipleGeneratedStubs']['tuples']:
print(
f"WARNING: Multiple stubs generated for {typ}. This is probably a bug. One will be chosen arbitrarily.")
for (typ, stub) in results['#select']['tuples']:
stubFile = os.path.join(stubDir, typ.replace(".", "/") + ".java")
os.makedirs(os.path.dirname(stubFile), exist_ok=True)