-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathTypeVariableHidesType.ql
More file actions
39 lines (35 loc) · 1.06 KB
/
TypeVariableHidesType.ql
File metadata and controls
39 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @name Type variable hides another type
* @description A type variable with the same name as another type that is in scope can cause
* the two types to be confused.
* @kind problem
* @problem.severity warning
* @precision medium
* @id java/type-variable-hides-type
* @tags quality
* maintainability
* readability
* types
*/
import java
RefType anOuterType(TypeVariable var) {
var.getGenericCallable().getDeclaringType() = result or
var.getGenericType() = result or
result = anOuterType(var).(NestedType).getEnclosingType()
}
pragma[inline]
RefType aTypeVisibleFrom(TypeVariable var) {
result = anOuterType(var)
or
exists(ImportType i |
var.getLocation().getFile() = i.getCompilationUnit() and
result = i.getImportedType()
)
or
var.getPackage() = result.getPackage() and result instanceof TopLevelType
}
from RefType hidden, TypeVariable var
where
hidden = aTypeVisibleFrom(var) and
var.getName() = hidden.getName()
select var, "Type $@ is hidden by this type variable.", hidden, hidden.getQualifiedName()