Recognizing properties, methods and function names in Matlab code.

I'm writing a global naming convention change utility for Matlab code. To this end, I would like to know the answers to the following:
In correctly written Matlab and excluding dynamic access:
1. Given a property name outside of its declaration in class, will it always be preceded by a dot?
2. Given a method name outside of its declaration in class, will it always be preceded by a dot?
3. Given a method name outside of its declaration in class, will it always be followed by zero or more whitespaces and an open parenthesis OR followed by an @ symbol?
4. Given a standalone function name will it always, in correctly (non-deprecated) written code, be followed by zero or more whitespaces and an open parenthesis OR be preceded by an @ symbol?
Thank you for any help.

Answers (1)

None of that is true. Some counter examples:
  1. set(obj, 'property', value)
  2. mymeth(obj, ...)
  3. obj.mymeth % no argument
  4. feval('myfun', arg1)

8 Comments

1 and 4 are not serious as they can be considered "dynamic" access.
3 is bad form in my opinion - so I 'm going to overlook that. I'm not aiming to be watertight.
I forgot about (2) which can be addressed by adding "<name>(" to the patterns for methods.
Anything else?
"3 is bad form in my opinion"
it's your opinion. who use
alpha = pi();
insteade of
alpha = pi;
If you want your utility to work and robust, you cannot assume it only works on what you consider as good practice.
Well, then pi should be a constant property :-)
But nevertheless, it is not possible for me to determine the context for each and every name - unless I take on the task of parsing the language - which I have no intention of doing. The utility relies more on getting confirmation from the user when required. I could at most recognize a class declaration or a function/method declaration as an aid to recognizing a name.
Also would you have to know foo is property or method for this case?
bar = obj.foo(1);
Then all the structure fields use also dot syntax that can create confusion.
"bar = obj.foo(1);" Ive not seen this before for a property, but I'll check it out.
Thanks for pointing out the structure fields issue.
Well as you migh guess this is accessing to the first element of a property.
Of course, how stupid of me. Yes that certainly would be an issue.
I will also assume that the root folder tree is closed (that is all references to names inside the folder tree are defined within the tree and there are no references to names from outside the tree). This would make it simpler.

Sign in to comment.

Products

Asked:

SK
on 16 Apr 2022

Commented:

SK
on 16 Apr 2022

Community Treasure Hunt

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

Start Hunting!