Skip to content

Commit b34448a

Browse files
committed
{Generic,Parameterized,Raw}Type: implement getAPrimaryQlClass
An aid to debugging
1 parent 9b8f558 commit b34448a

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

java/ql/src/semmle/code/java/Generics.qll

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,25 @@ class GenericType extends RefType {
7575
* Gets the number of type parameters of this generic type.
7676
*/
7777
int getNumberOfTypeParameters() { result = strictcount(getATypeParameter()) }
78+
79+
override string getAPrimaryQlClass() { result = "GenericType" }
7880
}
7981

8082
/** A generic type that is a class. */
81-
class GenericClass extends GenericType, Class { }
83+
class GenericClass extends GenericType, Class {
84+
override string getAPrimaryQlClass() {
85+
result = Class.super.getAPrimaryQlClass() or
86+
result = GenericType.super.getAPrimaryQlClass()
87+
}
88+
}
8289

8390
/** A generic type that is an interface. */
84-
class GenericInterface extends GenericType, Interface { }
91+
class GenericInterface extends GenericType, Interface {
92+
override string getAPrimaryQlClass() {
93+
result = Interface.super.getAPrimaryQlClass() or
94+
result = GenericType.super.getAPrimaryQlClass()
95+
}
96+
}
8597

8698
/**
8799
* A common super-class for Java types that may have a type bound.
@@ -115,6 +127,8 @@ abstract class BoundedType extends RefType, @boundedtype {
115127
or
116128
result = getUpperBoundType().(BoundedType).getAnUltimateUpperBoundType()
117129
}
130+
131+
override string getAPrimaryQlClass() { result = "BoundedType" }
118132
}
119133

120134
/**
@@ -354,13 +368,25 @@ class ParameterizedType extends RefType {
354368

355369
/** Holds if this type originates from source code. */
356370
override predicate fromSource() { typeVars(_, _, _, _, this) and RefType.super.fromSource() }
371+
372+
override string getAPrimaryQlClass() { result = "ParameterizedType" }
357373
}
358374

359375
/** A parameterized type that is a class. */
360-
class ParameterizedClass extends Class, ParameterizedType { }
376+
class ParameterizedClass extends Class, ParameterizedType {
377+
override string getAPrimaryQlClass() {
378+
result = Class.super.getAPrimaryQlClass() or
379+
result = ParameterizedType.super.getAPrimaryQlClass()
380+
}
381+
}
361382

362383
/** A parameterized type that is an interface. */
363-
class ParameterizedInterface extends Interface, ParameterizedType { }
384+
class ParameterizedInterface extends Interface, ParameterizedType {
385+
override string getAPrimaryQlClass() {
386+
result = Interface.super.getAPrimaryQlClass() or
387+
result = ParameterizedType.super.getAPrimaryQlClass()
388+
}
389+
}
364390

365391
/**
366392
* The raw version of a generic type is the type that is formed by
@@ -384,13 +410,25 @@ class RawType extends RefType {
384410

385411
/** Holds if this type originates from source code. */
386412
override predicate fromSource() { not any() }
413+
414+
override string getAPrimaryQlClass() { result = "RawType" }
387415
}
388416

389417
/** A raw type that is a class. */
390-
class RawClass extends Class, RawType { }
418+
class RawClass extends Class, RawType {
419+
override string getAPrimaryQlClass() {
420+
result = Class.super.getAPrimaryQlClass() or
421+
result = RawType.super.getAPrimaryQlClass()
422+
}
423+
}
391424

392425
/** A raw type that is an interface. */
393-
class RawInterface extends Interface, RawType { }
426+
class RawInterface extends Interface, RawType {
427+
override string getAPrimaryQlClass() {
428+
result = Interface.super.getAPrimaryQlClass() or
429+
result = RawType.super.getAPrimaryQlClass()
430+
}
431+
}
394432

395433
// -------- Generic callables --------
396434
/**

java/ql/test/library-tests/dependency-counts/PrintAst.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Example.java:
33
#-----| -1: (Imports)
44
# 1| 1: [ImportType] import Set
55
# 2| 2: [ImportType] import List
6-
# 4| 1: [Interface] Example
6+
# 4| 1: [GenericType,Interface,ParameterizedType] Example
77
#-----| -2: (Generic Parameters)
88
# 4| 0: [TypeVariable] A
99
#-----| -1: (Base Types)

java/ql/test/library-tests/dependency/PrintAst.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependency/A.java:
22
# 0| [CompilationUnit] A
3-
# 3| 1: [Class] A
3+
# 3| 1: [Class,GenericType,ParameterizedType] A
44
#-----| -2: (Generic Parameters)
55
# 3| 0: [TypeVariable] T
66
# 6| 2: [Class] B

java/ql/test/library-tests/generics/PrintAst.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ generics/A.java:
33
#-----| -1: (Imports)
44
# 3| 1: [ImportType] import HashMap
55
# 4| 2: [ImportType] import Map
6-
# 6| 1: [Class] A
6+
# 6| 1: [Class,GenericType,ParameterizedType] A
77
#-----| -2: (Generic Parameters)
88
# 6| 0: [TypeVariable] T
99
# 7| 2: [Class] B
@@ -23,7 +23,7 @@ generics/A.java:
2323
# 13| -3: [TypeAccess] HashMap<String,Object>
2424
# 13| 0: [TypeAccess] String
2525
# 13| 1: [TypeAccess] Object
26-
# 16| 3: [Class] D
26+
# 16| 3: [Class,GenericType,ParameterizedType] D
2727
#-----| -2: (Generic Parameters)
2828
# 16| 0: [TypeVariable] V
2929
# 16| 0: [TypeAccess] Number

java/ql/test/library-tests/typeaccesses/PrintAst.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ typeaccesses/TA.java:
8484
# 13| 0: [ExprStmt] <Expr>;
8585
# 13| 0: [MethodAccess] method3(...)
8686
# 13| -1: [TypeAccess] TA
87-
# 14| 10: [Class] Inner
87+
# 14| 10: [Class,GenericType,ParameterizedType] Inner
8888
#-----| -2: (Generic Parameters)
8989
# 14| 0: [TypeVariable] T
9090
# 14| 0: [TypeAccess] ArrayList<TA>

0 commit comments

Comments
 (0)