Skip to content

Commit 5709365

Browse files
authored
Merge pull request #6921 from igfoo/igfoo/types
Java: Replace @type with more specific types
2 parents afc7867 + 830f81b commit 5709365

File tree

7 files changed

+1985
-14
lines changed

7 files changed

+1985
-14
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Some uses of `RefType` in the support for 'generics' and 'imports' now use the more specific `ClassOrInterface` instead

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ typeVars(
393393
string nodeName: string ref,
394394
int pos: int ref,
395395
int kind: int ref, // deprecated
396-
int parentid: @typeorcallable ref
396+
int parentid: @classorinterfaceorcallable ref
397397
);
398398

399399
wildcards(
@@ -414,7 +414,7 @@ typeBounds(
414414
typeArgs(
415415
int argumentid: @reftype ref,
416416
int pos: int ref,
417-
int parentid: @typeorcallable ref
417+
int parentid: @classorinterfaceorcallable ref
418418
);
419419

420420
isParameterized(
@@ -487,7 +487,7 @@ hasModifier(
487487

488488
imports(
489489
unique int id: @import,
490-
int holder: @typeorpackage ref,
490+
int holder: @classorinterfaceorpackage ref,
491491
string name: string ref,
492492
int kind: int ref
493493
);
@@ -857,10 +857,9 @@ javadocText(
857857
@javadocParent = @javadoc | @javadocTag;
858858
@javadocElement = @javadocTag | @javadocText;
859859

860-
@typeorpackage = @type | @package;
861-
862-
@typeorcallable = @type | @callable;
863860
@classorinterface = @interface | @class;
861+
@classorinterfaceorpackage = @classorinterface | @package;
862+
@classorinterfaceorcallable = @classorinterface | @callable;
864863
@boundedtype = @typevariable | @wildcard;
865864
@reftype = @classorinterface | @array | @boundedtype;
866865
@classorarray = @class | @array;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Type
3838
*
3939
* For example, `X` in `class X<T> { }`.
4040
*/
41-
class GenericType extends RefType {
41+
class GenericType extends ClassOrInterface {
4242
GenericType() { typeVars(_, _, _, _, this) }
4343

4444
/**
@@ -139,7 +139,7 @@ abstract class BoundedType extends RefType, @boundedtype {
139139
*/
140140
class TypeVariable extends BoundedType, @typevariable {
141141
/** Gets the generic type that is parameterized by this type parameter, if any. */
142-
RefType getGenericType() { typeVars(this, _, _, _, result) }
142+
GenericType getGenericType() { typeVars(this, _, _, _, result) }
143143

144144
/** Gets the generic callable that is parameterized by this type parameter, if any. */
145145
GenericCallable getGenericCallable() { typeVars(this, _, _, _, result) }
@@ -321,7 +321,7 @@ class TypeBound extends @typebound {
321321
* For example, `List<Number>` is a parameterization of
322322
* the generic type `List<E>`, where `E` is a type parameter.
323323
*/
324-
class ParameterizedType extends RefType {
324+
class ParameterizedType extends ClassOrInterface {
325325
ParameterizedType() {
326326
typeArgs(_, _, this) or
327327
typeVars(_, _, _, _, this)
@@ -367,7 +367,9 @@ class ParameterizedType extends RefType {
367367
}
368368

369369
/** Holds if this type originates from source code. */
370-
override predicate fromSource() { typeVars(_, _, _, _, this) and RefType.super.fromSource() }
370+
override predicate fromSource() {
371+
typeVars(_, _, _, _, this) and ClassOrInterface.super.fromSource()
372+
}
371373

372374
override string getAPrimaryQlClass() { result = "ParameterizedType" }
373375
}

java/ql/lib/semmle/code/java/Import.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ImportType extends Import {
2525
ImportType() { imports(this, _, _, 1) }
2626

2727
/** Gets the imported type. */
28-
RefType getImportedType() { imports(this, result, _, _) }
28+
ClassOrInterface getImportedType() { imports(this, result, _, _) }
2929

3030
override string toString() { result = "import " + this.getImportedType().toString() }
3131

@@ -44,7 +44,7 @@ class ImportOnDemandFromType extends Import {
4444
ImportOnDemandFromType() { imports(this, _, _, 2) }
4545

4646
/** Gets the type from which accessible nested types are imported. */
47-
RefType getTypeHoldingImport() { imports(this, result, _, _) }
47+
ClassOrInterface getTypeHoldingImport() { imports(this, result, _, _) }
4848

4949
/** Gets an imported type. */
5050
NestedType getAnImport() { result.getEnclosingType() = this.getTypeHoldingImport() }
@@ -87,7 +87,7 @@ class ImportStaticOnDemand extends Import {
8787
ImportStaticOnDemand() { imports(this, _, _, 4) }
8888

8989
/** Gets the type from which accessible static members are imported. */
90-
RefType getTypeHoldingImport() { imports(this, result, _, _) }
90+
ClassOrInterface getTypeHoldingImport() { imports(this, result, _, _) }
9191

9292
/** Gets an imported type. */
9393
NestedType getATypeImport() { result.getEnclosingType() = this.getTypeHoldingImport() }
@@ -118,7 +118,7 @@ class ImportStaticTypeMember extends Import {
118118
ImportStaticTypeMember() { imports(this, _, _, 5) }
119119

120120
/** Gets the type from which static members with a given name are imported. */
121-
RefType getTypeHoldingImport() { imports(this, result, _, _) }
121+
ClassOrInterface getTypeHoldingImport() { imports(this, result, _, _) }
122122

123123
/** Gets the name of the imported member(s). */
124124
override string getName() { imports(this, _, result, _) }

0 commit comments

Comments
 (0)