I'd like to find a list of the message IDs of the built-in code analyzer warning messages used for suppressing those messages either on a single line or in a file (see here). I know you can search by message ID, but the list in the preferences (see here) doesn't actually show the ID itself. Any help would be appreciated, thanks!
After a while of digging within the MATLAB API, I've come up with the solution you wanted:
%// Obtain all definitions
msgDefinitions = com.mathworks.widgets.text.mcode.MLint.getMessageDefinitions();
%// Count definitions
numDefinitions = msgDefinitions.size();
definitionDictionary{numDefinitions,2}=[]; %//Preallocation
for ind1=1:numDefinitions
definitionDictionary{ind1,1} = char(msgDefinitions.get(ind1-1).toString());
definitionDictionary{ind1,2} = char(msgDefinitions.get(ind1-1).getTag().toString);
end
%//Optional for convenience:
definitionDictionary = sortrows(definitionDictionary,2);
An alternative solution (resulting in a longer, but messier list) is
allMsgs = mlint('-allmsg', filename);
where filename
can be any valid filename. Category tags may be recognized by a bunch of =======
in the message.
allMsgs = mlint('-allmsg', 'Untitled.m');
msgCodes = regexpi(strtrim({allMsgs.message}'),' ','split'); ...'
msgCodes = cellfun(@(v) v(1), msgCodes(:,1));
alternativeDictionary = sortrows([{allMsgs.message}' msgCodes],2);
In MATLAB 2014a the 2nd solution results in a dictionary of size 571
. The 1st solution is of length 477
. Generally speaking, the 2nd solution provides more information.
More information is available in the Undocumented MATLAB article. You can also look at this question on SO.
Below are some details on how I uncovered the 1st solution:
The internal workflow inside the code checker is as follows:
MKit.class
adds 3 options to suppress warnings that execute the following methods of CodeAnalyzerUtils.class
:
suppressMessage
.suppressAllMessages
.disableMessage
.doInsertSuppression
method is called, adding the string: " %#ok<" + paramString + '>'
.paramString
is a private property named fTag
that is present within subclasses of MLint.class
and accessible using a getTag()
method. Where the tags come from is still unclear.Sources (in order of appearance):
$matlabroot/java/jar/widgets.jar -> com.mathworks.widgets.text.mcode.MKit
$matlabroot/java/jar/widgets.jar -> com.mathworks.widgets.text.mcode.analyzer.CodeAnalyzerUtils
$matlabroot/java/jar/widgets.jar -> com.mathworks.widgets.text.mcode.analyzer.CodeAnalyzerActions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With