无论定义何种类,都跳转到方法定义 [英] Jump to method definition regardless of class it is defined in
问题描述
在MatlabⓇIDE中,有没有简单的方法可以跳转到特定方法的定义,而不知道它定义在哪个类中?
In the MatlabⓇ IDE, is there any easy way to jump to the definition of a particular method, without knowing in what class it is defined?
对于自我包含函数,我可以输入编辑funcname.m
。课程也一样。但是,特定类的超类层次结构可能很大。通过使用元类,我可以找到在哪个类中定义方法,然后打开该类,并浏览到适当的定义。这比自包含功能要多得多。
For self-contained functions, I can type edit funcname.m
. The same for classes. However, the hierarchy of superclasses for a particular class may be large. By using metaclasses, I can find out in what class a method was defined, then open the class, and browse to the appropiate definition. This is a lot more work than it is for self-contained functions.
从交互式提示中,是否有任何直接方式到 跳转到特定方法的定义,或在此方法中放置断点(以便执行它会导致编辑器跳转到定义)?
From the interactive prompt, is there any direct way to either jump to the definition of a particular method, or put a breakpoint in this method (so that executing it will cause the editor to jump to the definition)?
推荐答案
您可以使用哪个
在给定特定输入参数时找到函数。
You can use which
to locate a function when given specific input arguments.
比如我们在路径上有以下文件:
Say for example we have the following files on the path:
>> which -all fun
C:\Users\Amro\Desktop\fun.m
C:\Users\Amro\Desktop\Klass.m % Klass method
Klass.m
Klass.m
classdef Klass < handle
methods
function fun(obj)
disp('hello from Klass')
end
end
end
fun.m
fun.m
function fun()
disp('hello from fun')
end
现在我们可以区分两者给出的参数:
Now we can differentiate between the two given what arguments they take:
>> o = Klass();
>> which('fun(o)')
C:\Users\Amro\Desktop\Klass.m % Klass method
>> which('fun')
C:\Users\Amro\Desktop\fun.m
请注意,在类方法的情况下,我们必须使用以下语法: fun(obj,args,...)
而不是 obj.fun(args,...)
Note that in the class method case, we have to use the syntax: fun(obj, args, ...)
as opposed to obj.fun(args, ...)
您可以使用 matlab.desktop.editor
API:
matlab.desktop.editor.openAndGoToFunction(which('Klass'),'fun');
这篇关于无论定义何种类,都跳转到方法定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!