How do I create custom signatures for non-static class methods?

11 次查看(过去 30 天)
Hi all,
I'm having trouble getting MATLAB to display the custom signatures for some of my non-static class methods.
For example, if I have a class:
classdef SomeClass
methods(Access = public)
function obj = SomeClass(a,b,c)
% ...
end
function this = foo(this,x,y,z)
% ...
end
end
end
a functionSignatures.json file:
{
"_schemaVersion": "1.0.0",
"SomeClass.SomeClass":
{
"inputs":
[
{
"mutuallyExclusiveGroup":
[
[
{"name":"A", "kind":"required", "type":"logical"}
],
[
{"name":"X", "kind":"required", "type":"numeric"},
{"name":"Y", "kind":"required", "type":"numeric"},
{"name":"Z", "kind":"required", "type":"numeric"}
]
]
}
]
},
"SomeClass.foo":
{
"inputs":
[
{
"mutuallyExclusiveGroup":
[
[
{"name":"A", "kind":"required", "type":"logical"}
],
[
{"name":"X", "kind":"required", "type":"numeric"},
{"name":"Y", "kind":"required", "type":"numeric"},
{"name":"Z", "kind":"required", "type":"numeric"}
]
]
}
]
}
}
and a script file:
clar,clc,validateFunctionSignaturesJSON("./functionSignatures.json");
obj = SomeClass(...);
obj.foo(...);
Line 1 completes with no messages. Line 2 gives me an autocomplete popup with 2 signatures. Line 3 shows no autocomplete popup. Any idea what I'm doing wrong?
  1 个评论
Matt J
Matt J 2024-2-8
编辑:Matt J 2024-2-8
Your post does not appear to be a copy-paste of the code you actually ran, which means it would be hazardous for us to assess it. In particular, there is no Matlab function called validateFunctionSignatures (although there is a function called validateFunctionSignaturesJSON). So, Line 1 should not have completed at all.

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2024-2-8
The foo method of your SomeClass class is an ordinary method (as opposed to a static method) so at least one of the inputs must be an instance of the SomeClass class.
From the Signature Objects section on this documentation page, "If you specify an instance method such as myClass.myMethod in the JSON file, one of the elements in inputs must be an object of myClass. Typically, this object is the first element. MATLAB supports code suggestions and completions for a specified method when you call it using either dot notation (b = myObj.myMethod(a)) or function notation (b = myMethod(myObj,a)) syntax."
The JSON file segment you posted does not satisfy this requirement.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Toolbox Distribution 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by