Ruby: replace asMethod with asCallableAstNode

This commit is contained in:
Asger F
2022-11-07 09:38:48 +01:00
parent af5a378572
commit 25f0382fce
2 changed files with 15 additions and 11 deletions

View File

@@ -822,7 +822,9 @@ class ModuleNode instanceof Module {
*
* Does not take inheritance into account.
*/
MethodNode getAnOwnSingletonMethod() { result.asMethod() = super.getAnOwnSingletonMethod() }
MethodNode getAnOwnSingletonMethod() {
result.asCallableAstNode() = super.getAnOwnSingletonMethod()
}
/**
* Gets the singleton method named `name` declared in this module (or in a singleton class
@@ -841,7 +843,7 @@ class ModuleNode instanceof Module {
* Does not take inheritance into account.
*/
MethodNode getAnOwnInstanceMethod() {
result.asMethod() = this.getADeclaration().getAMethod().(Method)
result.asCallableAstNode() = this.getADeclaration().getAMethod().(Method)
}
/**
@@ -860,7 +862,7 @@ class ModuleNode instanceof Module {
* Does not take inheritance into account.
*/
ParameterNode getAnOwnInstanceSelf() {
result = TSelfParameterNode(this.getAnOwnInstanceMethod().asMethod())
result = TSelfParameterNode(this.getAnOwnInstanceMethod().asCallableAstNode())
}
/**
@@ -1015,10 +1017,10 @@ class MethodNode extends CallableNode {
MethodNode() { super.asCallableAstNode() instanceof MethodBase }
/** Gets the underlying AST node for this method. */
MethodBase asMethod() { result = this.asCallableAstNode() }
override MethodBase asCallableAstNode() { result = super.asCallableAstNode() }
/** Gets the name of this method. */
string getMethodName() { result = this.asMethod().getName() }
string getMethodName() { result = this.asCallableAstNode().getName() }
}
/**
@@ -1028,7 +1030,7 @@ class BlockNode extends CallableNode {
BlockNode() { super.asCallableAstNode() instanceof Block }
/** Gets the underlying AST node for this block. */
Block asBlock() { result = this.asCallableAstNode() }
override Block asCallableAstNode() { result = super.asCallableAstNode() }
}
/**

View File

@@ -55,7 +55,9 @@ class ActionControllerClass extends DataFlow::ClassNode {
/**
* Gets an `ActionControllerActionMethod` defined in this class.
*/
ActionControllerActionMethod getAnAction() { result = this.getAnInstanceMethod().asMethod() }
ActionControllerActionMethod getAnAction() {
result = this.getAnInstanceMethod().asCallableAstNode()
}
/**
* Gets a `self` that possibly refers to an instance of this class.
@@ -99,7 +101,7 @@ class ActionControllerActionMethod extends Method, Http::Server::RequestHandler:
private ActionControllerClass controllerClass;
ActionControllerActionMethod() {
this = controllerClass.getAnInstanceMethod().asMethod() and not this.isPrivate()
this = controllerClass.getAnInstanceMethod().asCallableAstNode() and not this.isPrivate()
}
/**
@@ -140,7 +142,7 @@ class ActionControllerActionMethod extends Method, Http::Server::RequestHandler:
exists(string name, DataFlow::MethodNode m |
isRoute(result, name, controllerClass) and
m = controllerClass.getInstanceMethod(name) and
this = m.asMethod()
this = m.asCallableAstNode()
)
}
}
@@ -379,7 +381,7 @@ class RedirectToCall extends MethodCall {
ActionControllerActionMethod getRedirectActionMethod() {
exists(string name |
this.getKeywordArgument("action").getConstantValue().isStringlikeValue(name) and
result = controller.getInstanceMethod(name).asMethod()
result = controller.getInstanceMethod(name).asCallableAstNode()
)
}
@@ -441,7 +443,7 @@ class ActionControllerHelperMethod extends Method {
exists(DataFlow::MethodNode m, string name |
m = controllerClass.getInstanceMethod(name) and
actionControllerHasHelperMethodCall(controllerClass, name) and
this = m.asMethod()
this = m.asCallableAstNode()
)
}