Fix test cases featuring primitive arrays

Previously we couldn't print the name of types like `byte[]` for example.
This commit is contained in:
Chris Smowton
2021-08-31 15:12:47 +01:00
parent f94d8c341d
commit b38a23daee
2 changed files with 4 additions and 4 deletions

View File

@@ -44,7 +44,7 @@ private class CallableToTest extends Callable {
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _) and summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _) and
this = interpretElement(namespace, type, subtypes, name, signature, ext) and this = interpretElement(namespace, type, subtypes, name, signature, ext) and
this.isPublic() and this.isPublic() and
getRootType(this.getDeclaringType()).isPublic() getRootType(this.getDeclaringType()).(RefType).isPublic()
) )
} }
} }

View File

@@ -12,7 +12,7 @@ private import FlowTestCase
*/ */
Type getRootSourceDeclaration(Type t) { Type getRootSourceDeclaration(Type t) {
if t instanceof RefType if t instanceof RefType
then result = getRootType(replaceTypeVariable(t)).getSourceDeclaration() then result = getRootType(replaceTypeVariable(t)).(RefType).getSourceDeclaration()
else result = t else result = t
} }
@@ -77,7 +77,7 @@ predicate mayBeAmbiguous(Callable c) {
/** /**
* Returns the outermost type enclosing type `t` (which may be `t` itself). * Returns the outermost type enclosing type `t` (which may be `t` itself).
*/ */
RefType getRootType(RefType t) { Type getRootType(Type t) {
if t instanceof NestedType if t instanceof NestedType
then result = getRootType(t.(NestedType).getEnclosingType()) then result = getRootType(t.(NestedType).getEnclosingType())
else else
@@ -95,9 +95,9 @@ string getShortNameIfPossible(Type t) {
if t instanceof Array if t instanceof Array
then result = getShortNameIfPossible(t.(Array).getComponentType()) + "[]" then result = getShortNameIfPossible(t.(Array).getComponentType()) + "[]"
else ( else (
getRootSourceDeclaration(t) = any(TestCase tc).getADesiredImport() and
if t instanceof RefType if t instanceof RefType
then then
getRootSourceDeclaration(t) = any(TestCase tc).getADesiredImport() and
exists(RefType replaced, string nestedName | exists(RefType replaced, string nestedName |
replaced = replaceTypeVariable(t).getSourceDeclaration() and replaced = replaceTypeVariable(t).getSourceDeclaration() and
nestedName = replaced.nestedName().replaceAll("$", ".") nestedName = replaced.nestedName().replaceAll("$", ".")