Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions code/+nansen/+config/SessionMethodsCatalog.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

function S = getDefaultItem()
%getDefaultItem Get default item for catalog
S = eval( sprintf('%s.getBlankItem()', mfilename('class')) );

S = feval([mfilename('class'), '.getBlankItem']);
% Note: No default exists for this item type, so returning the
% blank item
end
Expand Down
2 changes: 1 addition & 1 deletion code/+nansen/+dataio/+fileadapter/+imagestack/ImageStack.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function uifind(obj, varargin)

for i = 1:numel(virtualDataClasses)
thisClassName = virtualDataClasses{i};
fileNameExpression = eval([thisClassName, '.FilenameExpression']);
fileNameExpression = nansen.internal.introspection.getConstantPropertyValue(thisClassName, 'FilenameExpression');

if ~isempty( regexp(filename, fileNameExpression, 'once') )
className = thisClassName;
Expand Down
40 changes: 40 additions & 0 deletions code/+nansen/+internal/+introspection/getConstantPropertyValue.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function value = getConstantPropertyValue(className, propertyName)
% getConstantPropertyValue - Get the value of a Constant property by class name string.
%
% value = nansen.internal.introspection.getConstantPropertyValue(className, propertyName)
% returns the value of the Constant property named propertyName on the class
% identified by the string className. This is the safe replacement for
% eval(sprintf('%s.%s', className, propertyName)).
%
% Input Arguments:
% className - Fully qualified class name (string or char)
% propertyName - Name of a Constant property on that class (string or char)
%
% Output Arguments:
% value - Value of the Constant property

arguments
className (1,1) string
propertyName (1,1) string
end

mc = meta.class.fromName(className);
if isempty(mc)
error('nansen:introspection:ClassNotFound', ...
'Class "%s" was not found. Ensure the class is on the MATLAB path.', className)
end

matchIdx = strcmp({mc.PropertyList.Name}, propertyName);
if ~any(matchIdx)
error('nansen:introspection:PropertyNotFound', ...
'Class "%s" has no property named "%s".', className, propertyName)
end

prop = mc.PropertyList(matchIdx);
if ~prop.Constant
error('nansen:introspection:NotConstant', ...
'Property "%s.%s" is not Constant.', className, propertyName)
end

value = prop.DefaultValue;
end
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function runPostConstructionUpdateActions(obj)
if ~nargin || isempty(userName)
warning('No username given, returning prefdir for default user')
className = mfilename('class');
userName = eval(sprintf('%s.DEFAULT_USER_NAME', className));
userName = nansen.internal.introspection.getConstantPropertyValue(className, 'DEFAULT_USER_NAME');
end
preferenceDirectory = fullfile(prefdir, 'Nansen', userName);
end
Expand Down
2 changes: 1 addition & 1 deletion code/+nansen/+internal/+user/Preferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
function filename = createFilename()
%Create filename for a preference file.
classname = mfilename('class');
prefGroupName = eval(sprintf('%s.PreferenceGroupName', classname));
prefGroupName = nansen.internal.introspection.getConstantPropertyValue(classname, 'PreferenceGroupName');
prefGroupName = matlab.lang.makeValidName(prefGroupName);
filename = fullfile(sprintf('%s_Preferences.mat', prefGroupName));
end
Expand Down
91 changes: 0 additions & 91 deletions code/+nansen/+manage/OptionsAdapter.m

This file was deleted.

6 changes: 2 additions & 4 deletions code/+nansen/+manage/OptionsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -956,14 +956,12 @@ function updateOptionsFromDefault(obj)
fcnName = strcat(obj.FunctionName, '.getDefaultOptions');
fcnHandle = str2func(fcnName);

methodNameFcnName = strcat(obj.FunctionName, '.MethodName');

% Return as options entry (struct)
opts = fcnHandle();
name = 'Preset Options';

try
methodName = eval(methodNameFcnName);
methodName = nansen.internal.introspection.getConstantPropertyValue(obj.FunctionName, 'MethodName');
catch
methodName = obj.FunctionName;
end
Expand Down Expand Up @@ -1010,7 +1008,7 @@ function updateOptionsFromDefault(obj)
function optionsEntry = getPresetsFromSuperclass(obj)
%getPresetsFromSuperclass

optManager = eval(sprintf('%s.OptionsManager', obj.FunctionName));
optManager = nansen.internal.introspection.getConstantPropertyValue(obj.FunctionName, 'OptionsManager');
presetOptionsNames = optManager.PresetOptionNames;

for i = 1:numel(presetOptionsNames)
Expand Down
2 changes: 1 addition & 1 deletion code/+nansen/+metadata/+utility/formatTableForDisplay.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
% Step 3: does the data type have it's own formatter?
dataHasTableFormatter = cellfun(@(c) isa(c, 'nansen.metadata.tablevar.mixin.HasTableColumnFormatter'), firstRowData);
formattingFcn(dataHasTableFormatter) = cellfun(@(c) ...
str2func(class(eval( strjoin({class(c), 'TableColumnFormatter'}, '.')))), ...
str2func(class(nansen.internal.introspection.getConstantPropertyValue(class(c), 'TableColumnFormatter'))), ...
firstRowData(dataHasTableFormatter), 'uni', 0);

% Step 4: Format all the table columns that needs formatting
Expand Down
2 changes: 1 addition & 1 deletion code/+nansen/+metadata/@MetaTable/MetaTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function markClean(obj)
schemaIdName = obj.MetaTableIdVarname;
else
try
schemaIdName = eval(strjoin({obj.MetaTableClass, 'IDNAME'}, '.'));
schemaIdName = nansen.internal.introspection.getConstantPropertyValue(obj.MetaTableClass, 'IDNAME');
catch
schemaIdName = 'id';
end
Expand Down
2 changes: 1 addition & 1 deletion code/+nansen/+ui/MetaTableColumnLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ function checkAndUpdateColumnEntries(obj)

if isa(dataValue, 'nansen.metadata.abstract.TableVariable') %|| isa(dataValue, 'nansen.metadata.tablevar.mixin.HasTableColumnFormatter')
if isempty(dataValue)
isEditable = eval(sprintf('%s.IS_EDITABLE', class(dataValue)));
isEditable = nansen.internal.introspection.getConstantPropertyValue(class(dataValue), 'IS_EDITABLE');
else
isEditable = dataValue.IS_EDITABLE;
end
Expand Down
2 changes: 1 addition & 1 deletion code/apps/+nansen/@App/App.m
Original file line number Diff line number Diff line change
Expand Up @@ -3641,7 +3641,7 @@ function onSessionTaskSelected(app, ~, evt)
return
elseif strcmp(evt.Mode, 'Help')
try
titleStr = eval(sprintf('%s.MethodName', evt.TaskAttributes.FunctionName));
titleStr = nansen.internal.introspection.getConstantPropertyValue(evt.TaskAttributes.FunctionName, 'MethodName');
catch
if ~isempty(evt.TaskAttributes.MethodName)
titleStr = evt.TaskAttributes.MethodName;
Expand Down
2 changes: 1 addition & 1 deletion code/apps/+structeditor/App.m
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ function addComponents(obj, panelNum)
y = y + obj.RowHeight;

otherwise
val = eval(strcat('S', '.', currentProperty));
val = S.(currentProperty);
[yCorrTmp, wasAborted] = obj.newInputField(contentPanel, y, currentProperty, val, config, tip);
if wasAborted; continue; end

Expand Down
4 changes: 2 additions & 2 deletions code/general/+tools/editStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ function createComponents(guiFig, S, fieldNames)
for i = 1:numel(propertyFields)
currentField = propertyFields{i};
name = strcat(currentProperty, '.', currentField);
val = eval(strcat('S', '.', name));
val = S.(currentProperty).(currentField);
addInputField(guiPanel, y, name, val)
y = y + rowHeight + rowSep;
end
end

otherwise
val = eval(strcat('S', '.', currentProperty));
val = S.(currentProperty);
addInputField(guiPanel, y, currentProperty, val)
y = y + rowHeight + rowSep;
end
Expand Down
5 changes: 3 additions & 2 deletions code/wrappers/+nansen/+wrapper/+abstract/OptionsAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@

nvPairs = cell(1, numel(C)*2);
for i = 1:numel(C)
name = eval(strjoin({'nameMap', C{i}}, '.'));
value = eval(strjoin({'S', C{i}}, '.'));
s = struct('type', {'.'}, 'subs', strsplit(C{i}, '.'));
name = subsref(nameMap, s);
value = subsref(S, s);
ind = (i-1)*2 + (1:2);
nvPairs(ind) = {name, value};
end
Expand Down
Loading