Use predicate for isConstructor

This commit is contained in:
Koen Vlaswinkel
2024-01-31 14:19:14 +01:00
parent c1aaf5a574
commit d5f0a5ce72

View File

@@ -69,10 +69,10 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
DataFlow::MethodNode getNode() { result = this }
override string getName() {
result = super.getMethodName() and this.isConstructor() = false
result = super.getMethodName() and not this.isConstructor()
or
// Constructors are modeled as Type!#new rather than Type#initialize
result = "new" and this.isConstructor() = true
result = "new" and this.isConstructor()
}
/**
@@ -81,13 +81,13 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
override string getType() {
result =
any(DataFlow::ModuleNode m | m.getOwnInstanceMethod(this.getName()) = this).getQualifiedName() and
this.isConstructor() = false
not this.isConstructor()
or
// Constructors are modeled on `Type!`, not on `Type`
result =
any(DataFlow::ModuleNode m | m.getOwnInstanceMethod(super.getMethodName()) = this)
.getQualifiedName() + "!" and
this.isConstructor() = true
this.isConstructor()
or
result =
any(DataFlow::ModuleNode m | m.getOwnSingletonMethod(this.getName()) = this)
@@ -158,12 +158,9 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
/**
* Holds if this method is a constructor for a module.
*/
private boolean isConstructor() {
if
super.getMethodName() = "initialize" and
exists(DataFlow::ModuleNode m | m.getOwnInstanceMethod(super.getMethodName()) = this)
then result = true
else result = false
private predicate isConstructor() {
super.getMethodName() = "initialize" and
exists(DataFlow::ModuleNode m | m.getOwnInstanceMethod(super.getMethodName()) = this)
}
}