mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
Kotlin: Give fields a Kotlin type
This meant refactoring the EnumEntry extraction a bit. The IR doesn't give us a type for fields, so we have to make it up based on the parent.
This commit is contained in:
@@ -353,6 +353,7 @@ fields(
|
||||
unique int id: @field,
|
||||
string nodeName: string ref,
|
||||
int typeid: @type ref,
|
||||
int kttypeid: @kt_type ref,
|
||||
int parentid: @reftype ref,
|
||||
int sourceid: @field ref
|
||||
);
|
||||
|
||||
@@ -20,7 +20,7 @@ predicate hasName(Element e, string name) {
|
||||
or
|
||||
methods(e, name, _, _, _, _)
|
||||
or
|
||||
fields(e, name, _, _, _)
|
||||
fields(e, name, _, _, _, _)
|
||||
or
|
||||
packages(e, name)
|
||||
or
|
||||
|
||||
@@ -63,7 +63,7 @@ private predicate hasChildElement(Element parent, Element e) {
|
||||
or
|
||||
params(e, _, _, parent, _)
|
||||
or
|
||||
fields(e, _, _, parent, _)
|
||||
fields(e, _, _, _, parent, _)
|
||||
or
|
||||
typeVars(e, _, _, _, parent)
|
||||
}
|
||||
|
||||
@@ -598,10 +598,13 @@ class FieldDeclaration extends ExprParent, @fielddecl, Annotatable {
|
||||
/** A class or instance field. */
|
||||
class Field extends Member, ExprParent, @field, Variable {
|
||||
/** Gets the declared type of this field. */
|
||||
override Type getType() { fields(this, _, result, _, _) }
|
||||
override Type getType() { fields(this, _, result, _, _, _) }
|
||||
|
||||
/** Gets the Kotlin type of this field. */
|
||||
KotlinType getKotlinType() { fields(this, _, _, result, _, _) }
|
||||
|
||||
/** Gets the type in which this field is declared. */
|
||||
override RefType getDeclaringType() { fields(this, _, _, result, _) }
|
||||
override RefType getDeclaringType() { fields(this, _, _, _, result, _) }
|
||||
|
||||
/**
|
||||
* Gets the field declaration in which this field is declared.
|
||||
@@ -631,7 +634,7 @@ class Field extends Member, ExprParent, @field, Variable {
|
||||
*
|
||||
* For all other fields, the source declaration is the field itself.
|
||||
*/
|
||||
Field getSourceDeclaration() { fields(this, _, _, _, result) }
|
||||
Field getSourceDeclaration() { fields(this, _, _, _, _, result) }
|
||||
|
||||
/** Holds if this field is the same as its source declaration. */
|
||||
predicate isSourceDeclaration() { this.getSourceDeclaration() = this }
|
||||
|
||||
@@ -319,7 +319,7 @@ predicate declaresMember(Type t, @member m) {
|
||||
or
|
||||
constrs(m, _, _, _, t, _)
|
||||
or
|
||||
fields(m, _, _, t, _)
|
||||
fields(m, _, _, _, t, _)
|
||||
or
|
||||
enclInReftype(m, t) and
|
||||
// Since the type `@member` in the dbscheme includes all `@reftype`s,
|
||||
@@ -1109,11 +1109,11 @@ class EnumType extends Class {
|
||||
|
||||
/** Gets the enum constant with the specified name. */
|
||||
EnumConstant getEnumConstant(string name) {
|
||||
fields(result, _, _, this, _) and result.hasName(name)
|
||||
fields(result, _, _, _, this, _) and result.hasName(name)
|
||||
}
|
||||
|
||||
/** Gets an enum constant declared in this enum type. */
|
||||
EnumConstant getAnEnumConstant() { fields(result, _, _, this, _) }
|
||||
EnumConstant getAnEnumConstant() { fields(result, _, _, _, this, _) }
|
||||
|
||||
override predicate isFinal() {
|
||||
// JLS 8.9: An enum declaration is implicitly `final` unless it contains
|
||||
|
||||
Reference in New Issue
Block a user