Kotlin: Handle properties better

This commit is contained in:
Ian Lynagh
2021-11-12 14:41:33 +00:00
parent 44bf35e623
commit e6e56238c5
8 changed files with 232 additions and 17 deletions

View File

@@ -948,7 +948,8 @@ javadocText(
/** A program element that has a name. */
@element = @file | @package | @primitive | @class | @interface | @method | @constructor | @modifier | @param | @exception | @field |
@annotation | @boundedtype | @array | @localvar | @expr | @stmt | @import | @fielddecl | @kt_type | @kt_type_alias;
@annotation | @boundedtype | @array | @localvar | @expr | @stmt | @import | @fielddecl | @kt_type | @kt_type_alias |
@kt_property;
@modifiable = @member_modifiable| @param | @localvar ;
@@ -960,7 +961,7 @@ javadocText(
@locatable = @file | @class | @interface | @fielddecl | @field | @constructor | @method | @param | @exception
| @boundedtype | @typebound | @array | @primitive
| @import | @stmt | @expr | @whenbranch | @localvar | @javadoc | @javadocTag | @javadocText
| @xmllocatable | @ktcomment | @kt_type_alias;
| @xmllocatable | @ktcomment | @kt_type_alias | @kt_property;
@top = @element | @locatable | @folder;
@@ -1108,3 +1109,23 @@ ktExtensionFunctions(
int typeid: @type ref,
int kttypeid: @kt_type ref
)
ktProperties(
unique int id: @kt_property,
string nodeName: string ref
)
ktPropertyGetters(
unique int id: @kt_property ref,
int getter: @method ref
)
ktPropertySetters(
unique int id: @kt_property ref,
int setter: @method ref
)
ktPropertyBackingFields(
unique int id: @kt_property ref,
int backingField: @field ref
)

View File

@@ -45,6 +45,8 @@ predicate hasName(Element e, string name) {
modifiers(e, name)
or
kt_type_alias(e, name, _)
or
ktProperties(e, name)
}
/**

View File

@@ -686,6 +686,20 @@ class InstanceField extends Field {
InstanceField() { not this.isStatic() }
}
/** A Kotlin property. */
class Property extends Element, @kt_property {
/** Gets the getter method for this property, if any. */
Method getGetter() { ktPropertyGetters(this, result) }
/** Gets the setter method for this property, if any. */
Method getSetter() { ktPropertySetters(this, result) }
/** Gets the backing field for this property, if any. */
Field getBackingField() { ktPropertyBackingFields(this, result) }
override string getAPrimaryQlClass() { result = "Property" }
}
/** A Kotlin extension function. */
class ExtensionMethod extends Method {
Type extendedType;