Skip to content

Commit 84743ec

Browse files
committed
Java: Make support for array parameter and return values.
1 parent 5b65f5c commit 84743ec

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

java/ql/src/utils/model-generator/internal/CaptureTypeBasedSummaryModels.qll

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ private predicate genericContainerType(RefType t, TypeVariable tv) {
5252
et = t.(ContainerType).getElementType()
5353
or
5454
et = t.(IterableType).getElementType()
55+
or
56+
et = t.(Array).getElementType()
5557
|
5658
isEffectivelyUpperBound(et, tv)
5759
)
@@ -72,17 +74,25 @@ private predicate localTypeParameter(Callable callable, TypeVariable tv) {
7274
callable.(GenericCallable).getATypeParameter() = tv
7375
}
7476

77+
/**
78+
* Gets the access path postfix for `t`.
79+
*/
80+
private string getAccessPath(Type t) {
81+
if
82+
t instanceof Array and
83+
not Specific::isPrimitiveTypeUsedForBulkData(t.(Array).getElementType())
84+
then result = ".ArrayElement"
85+
else
86+
if t instanceof ContainerType or t instanceof IterableType
87+
then result = ".Element"
88+
else result = ""
89+
}
90+
91+
/**
92+
* Gets the access path for parameter `p`.
93+
*/
7594
private string parameterAccess(Parameter p) {
76-
exists(Type t | t = p.getType() |
77-
if
78-
t instanceof Array and
79-
not Specific::isPrimitiveTypeUsedForBulkData(p.getType().(Array).getElementType())
80-
then result = "Argument[" + p.getPosition() + "].ArrayElement"
81-
else
82-
if t instanceof ContainerType or t instanceof IterableType
83-
then result = "Argument[" + p.getPosition() + "].Element"
84-
else result = "Argument[" + p.getPosition() + "]"
85-
)
95+
result = "Argument[" + p.getPosition() + "]" + getAccessPath(p.getType())
8696
}
8797

8898
/**
@@ -117,9 +127,10 @@ private string getSyntheticField(TypeVariable tv) {
117127
private string implicit(Callable callable, TypeVariable tv) {
118128
classTypeParameter(callable, tv) and
119129
not callable.isStatic() and
120-
exists(string access |
121-
if genericContainerType(callable.getDeclaringType(), tv)
122-
then access = ".Element"
130+
exists(string access, Type decl |
131+
decl = callable.getDeclaringType() and
132+
if genericContainerType(decl, tv)
133+
then access = getAccessPath(decl)
123134
else access = getSyntheticField(tv)
124135
|
125136
result = Specific::qualifierString() + access
@@ -194,7 +205,7 @@ bindingset[callable]
194205
private string getAccess(Callable callable, Type return, TypeVariable tv) {
195206
return = tv and result = ""
196207
or
197-
genericContainerType(return, tv) and result = ".Element"
208+
genericContainerType(return, tv) and result = getAccessPath(return)
198209
or
199210
not genericContainerType(return, tv) and
200211
(

0 commit comments

Comments
 (0)