Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of MATLAB code analyzer message IDs

Tags:

matlab

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!

like image 361
orenyk Avatar asked Sep 30 '22 05:09

orenyk


1 Answers

Solution 1: (provides only some message tags)

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);

Solution 2: (provides Category tags, Syntax Errors, Aesthetics and Readability ...)

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.

Solution comparison:

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:

  1. When you right-click on a suppressible warning the Code Checker (AKA CodeAnalyzer, lint, mlint) it, MKit.class adds 3 options to suppress warnings that execute the following methods of CodeAnalyzerUtils.class:
    • On this line - executes the method suppressMessage.
    • In this file - executes the method suppressAllMessages.
    • In all files - executes the method disableMessage.
  2. Having clicked on one of the first two options, the doInsertSuppression method is called, adding the string: " %#ok<" + paramString + '>'.
  3. The mysterious 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):

  1. $matlabroot/java/jar/widgets.jar -> com.mathworks.widgets.text.mcode.MKit
  2. $matlabroot/java/jar/widgets.jar -> com.mathworks.widgets.text.mcode.analyzer.CodeAnalyzerUtils
  3. $matlabroot/java/jar/widgets.jar -> com.mathworks.widgets.text.mcode.analyzer.CodeAnalyzerActions
like image 131
Dev-iL Avatar answered Nov 15 '22 12:11

Dev-iL