mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Java: Deprecate Field.getSourceDeclaration() and Field.isSourceDeclaration()
Also follows the removal of the sourceid column of fields.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -40,7 +40,7 @@ class ImmutableField extends Field {
|
||||
this.getType() instanceof ImmutableType and
|
||||
// The field is only assigned to in a constructor or static initializer of the type it is declared in.
|
||||
forall(FieldAccess fw, AnyAssignment ae |
|
||||
fw.getField().getSourceDeclaration() = this and
|
||||
fw.getField() = this and
|
||||
fw = ae.getDest()
|
||||
|
|
||||
ae.getEnclosingCallable().getDeclaringType() = this.getDeclaringType() and
|
||||
|
||||
@@ -63,15 +63,10 @@ predicate isVMObserver(RefType rt) {
|
||||
from Field f, FieldRead fr
|
||||
where
|
||||
f.fromSource() and
|
||||
fr.getField().getSourceDeclaration() = f and
|
||||
fr.getField() = f and
|
||||
not f.getDeclaringType() instanceof EnumType and
|
||||
forall(Assignment ae, Field g | ae.getDest() = g.getAnAccess() and g.getSourceDeclaration() = f |
|
||||
ae.getSource() instanceof NullLiteral
|
||||
) and
|
||||
not exists(UnaryAssignExpr ua, Field g |
|
||||
ua.getExpr() = g.getAnAccess() and
|
||||
g.getSourceDeclaration() = f
|
||||
) and
|
||||
forall(Assignment ae | ae.getDest() = f.getAnAccess() | ae.getSource() instanceof NullLiteral) and
|
||||
not exists(UnaryAssignExpr ua | ua.getExpr() = f.getAnAccess()) and
|
||||
not f.isFinal() and
|
||||
// Exclude fields that may be accessed reflectively.
|
||||
not reflectivelyWritten(f) and
|
||||
|
||||
@@ -19,7 +19,7 @@ where
|
||||
not (f.isPublic() or f.isProtected()) and
|
||||
f.fromSource() and
|
||||
not f.getDeclaringType() instanceof EnumType and
|
||||
not exists(VarAccess va | va.getVariable().(Field).getSourceDeclaration() = f) and
|
||||
not exists(VarAccess va | va.getVariable() = f) and
|
||||
// Exclude results in generated classes.
|
||||
not f.getDeclaringType() instanceof GeneratedClass and
|
||||
// Exclude fields that may be reflectively read (this includes standard serialization).
|
||||
|
||||
@@ -33,7 +33,7 @@ private Field getField(Class c, string name, Type t) {
|
||||
|
||||
predicate thisAccess(LocalVariableDecl d, Field f) {
|
||||
shadows(d, _, f, _) and
|
||||
exists(VarAccess va | va.getVariable().(Field).getSourceDeclaration() = f |
|
||||
exists(VarAccess va | va.getVariable() = f |
|
||||
va.getQualifier() instanceof ThisAccess and
|
||||
va.getEnclosingCallable() = d.getCallable()
|
||||
)
|
||||
@@ -41,7 +41,7 @@ predicate thisAccess(LocalVariableDecl d, Field f) {
|
||||
|
||||
predicate confusingAccess(LocalVariableDecl d, Field f) {
|
||||
shadows(d, _, f, _) and
|
||||
exists(VarAccess va | va.getVariable().(Field).getSourceDeclaration() = f |
|
||||
exists(VarAccess va | va.getVariable() = f |
|
||||
not exists(va.getQualifier()) and
|
||||
va.getEnclosingCallable() = d.getCallable()
|
||||
)
|
||||
@@ -52,10 +52,7 @@ predicate assignmentToShadowingLocal(LocalVariableDecl d, Field f) {
|
||||
exists(Expr assignedValue, Expr use |
|
||||
d.getAnAssignedValue() = assignedValue and getARelevantChild(assignedValue) = use
|
||||
|
|
||||
exists(FieldAccess access, Field ff | access = assignedValue |
|
||||
ff = access.getField() and
|
||||
ff.getSourceDeclaration() = f
|
||||
)
|
||||
exists(FieldAccess access | access = assignedValue | f = access.getField())
|
||||
or
|
||||
exists(MethodCall get, Method getter | get = assignedValue and getter = get.getMethod() |
|
||||
getterFor(getter, f)
|
||||
@@ -73,10 +70,9 @@ predicate assignmentFromShadowingLocal(LocalVariableDecl d, Field f) {
|
||||
setterFor(setter, f)
|
||||
)
|
||||
or
|
||||
exists(Field instance, Expr assignedValue |
|
||||
exists(Expr assignedValue |
|
||||
access = getARelevantChild(assignedValue) and
|
||||
assignedValue = instance.getAnAssignedValue() and
|
||||
instance.getSourceDeclaration() = f
|
||||
assignedValue = f.getAnAssignedValue()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user