Java: Deprecate Field.getSourceDeclaration() and Field.isSourceDeclaration()

Also follows the removal of the sourceid column of fields.
This commit is contained in:
Ian Lynagh
2024-09-18 11:27:20 +01:00
parent 0be52f9660
commit bda779a58d
11 changed files with 24 additions and 41 deletions

View File

@@ -159,7 +159,7 @@ private Element definition(Element e, string kind) {
e.(TypeAccess).getType().(RefType).getSourceDeclaration() = result and kind = "T"
or
exists(Variable v | v = e.(VarAccess).getVariable() |
result = v.(Field).getSourceDeclaration() or
result = v.(Field) or
result = v.(Parameter).getSourceDeclaration() or
result = v.(LocalVariableDecl)
) and

View File

@@ -18,7 +18,7 @@ predicate hasName(Element e, string name) {
or
methods(e, name, _, _, _, _)
or
fields(e, name, _, _, _)
fields(e, name, _, _)
or
packages(e, name)
or

View File

@@ -52,7 +52,7 @@ predicate depends(RefType t, RefType dep) {
or
// the declaring type of a field accessed in `t`,
exists(Field f | f.getAnAccess().getEnclosingCallable().getDeclaringType() = t |
usesType(f.getSourceDeclaration().getDeclaringType(), dep)
usesType(f.getDeclaringType(), dep)
)
or
// the type of a local variable declared in `t`,

View File

@@ -64,7 +64,7 @@ predicate numDepends(RefType t, RefType dep, int value) {
elem = fa and
fa.getEnclosingCallable().getDeclaringType() = t
|
usesType(fa.getField().getSourceDeclaration().getDeclaringType(), dep)
usesType(fa.getField().getDeclaringType(), dep)
)
or
// the type of a local variable declared in `t`,

View File

@@ -115,7 +115,7 @@ private predicate hasChildElement(Element parent, Element e) {
or
params(e, _, _, parent, _)
or
fields(e, _, _, parent, _)
fields(e, _, _, parent)
or
typeVars(e, _, _, parent)
}

View File

@@ -756,13 +756,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. */
override KotlinType getKotlinType() { fieldsKotlinType(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.
@@ -794,18 +794,12 @@ class Field extends Member, ExprParent, @field, Variable {
}
/**
* Gets the source declaration of this field.
*
* For fields that are members of a parameterized
* instance of a generic type, the source declaration is the
* corresponding field in the generic type.
*
* For all other fields, the source declaration is the field itself.
* DEPRECATED: The result is always `this`.
*/
Field getSourceDeclaration() { fields(this, _, _, _, result) }
deprecated Field getSourceDeclaration() { result = this }
/** Holds if this field is the same as its source declaration. */
predicate isSourceDeclaration() { this.getSourceDeclaration() = this }
/** DEPRECATED: This always holds. */
deprecated predicate isSourceDeclaration() { any() }
override predicate isPublic() {
Member.super.isPublic()

View File

@@ -324,7 +324,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,
@@ -1195,12 +1195,10 @@ class EnumType extends Class {
EnumType() { isEnumType(this) }
/** Gets the enum constant with the specified name. */
EnumConstant getEnumConstant(string name) {
fields(result, _, _, this, _) and result.hasName(name)
}
EnumConstant getEnumConstant(string 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