Skip to content

Commit 309f0e7

Browse files
Fix handling of arrays
1 parent 9ffcfbc commit 309f0e7

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

java/ql/src/utils/GenerateFlowTestCase.qll

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ string contentToken(Content c) {
158158
RefType getRootType(RefType t) {
159159
if t instanceof NestedType
160160
then result = getRootType(t.(NestedType).getEnclosingType())
161-
else result = t
161+
else
162+
if t instanceof Array
163+
then result = getRootType(t.(Array).getElementType())
164+
else result = t
162165
}
163166

164167
/**
@@ -495,18 +498,22 @@ predicate isImportable(Type t) {
495498
* if we cannot import it due to a name clash.
496499
*/
497500
string getShortNameIfPossible(Type t) {
498-
getRootSourceDeclaration(t) = any(TestCase tc).getADesiredImport() and
499-
if t instanceof RefType
500-
then
501-
exists(RefType replaced, string nestedName |
502-
replaced = replaceTypeVariable(t).getSourceDeclaration() and
503-
nestedName = replaced.nestedName().replaceAll("$", ".")
504-
|
505-
if isImportable(getRootSourceDeclaration(t))
506-
then result = nestedName
507-
else result = replaced.getPackage().getName() + "." + nestedName
508-
)
509-
else result = t.getName()
501+
if t instanceof Array
502+
then result = getShortNameIfPossible(t.(Array).getElementType()) + "[]"
503+
else (
504+
getRootSourceDeclaration(t) = any(TestCase tc).getADesiredImport() and
505+
if t instanceof RefType
506+
then
507+
exists(RefType replaced, string nestedName |
508+
replaced = replaceTypeVariable(t).getSourceDeclaration() and
509+
nestedName = replaced.nestedName().replaceAll("$", ".")
510+
|
511+
if isImportable(getRootSourceDeclaration(t))
512+
then result = nestedName
513+
else result = replaced.getPackage().getName() + "." + nestedName
514+
)
515+
else result = t.getName()
516+
)
510517
}
511518

512519
/**

0 commit comments

Comments
 (0)