Skip to content

Commit 49c9c36

Browse files
committed
Type-variable-in-scope consistency query: account for all enclosing elements that declare type parameters.
1 parent 4e15f5f commit 49c9c36

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

java/ql/consistency-queries/typeParametersInScope.ql

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,22 @@ Type getATypeUsedInClass(RefType type) {
3030
result = getAMentionedType(getATypeUsedInClass(type))
3131
}
3232

33-
TypeVariable getATypeVariableInScope(RefType type) {
34-
result = type.getACallable().(GenericCallable).getATypeParameter()
35-
or
36-
result = type.(GenericType).getATypeParameter()
37-
or
38-
result = getAMentionedType(type.(InstantiatedType).getATypeArgument())
33+
Element getEnclosingElementStar(RefType e) {
34+
result = e
3935
or
40-
result = getATypeVariableInScope(type.getEnclosingType())
36+
result.contains(e)
37+
}
38+
39+
TypeVariable getATypeVariableInScope(RefType type) {
40+
exists(Element e | e = getEnclosingElementStar(type) |
41+
result = e.(RefType).getACallable().(GenericCallable).getATypeParameter()
42+
or
43+
result = e.(GenericType).getATypeParameter()
44+
or
45+
result = e.(GenericCallable).getATypeParameter()
46+
or
47+
result = getAMentionedType(e.(InstantiatedType).getATypeArgument())
48+
)
4149
}
4250

4351
from ClassOrInterface typeUser, TypeVariable outOfScope

0 commit comments

Comments
 (0)