Ok, I’m not too good at regex, but I came up with a reReplaceNoCase that seems to work pretty well. Can a few of you with funky model mappings try pasting yours between the cfsavecontent tags in my code sample below and running it to see if it successfully converts your mappings while leaving any other surrounding code/comments intact?
The only place where this doesn’t work is in some cases where there are nested function calls inside of the addModelMapping call. The only way to solve that would be with some simple code parsing to count opening and closing parenthesis, but it’s probably not worth it if that is an edge case.
Thanks!
~Brad
// regular
addModelMapping(‘ConstantService’,‘com.ruceci.Utility.ConstantService’);
// Named arguments
addModelMapping(alias=“myAlias”,path=‘com.ruceci.Utility.ConstantService’);
// Lots of spaces!
addModelMapping ( alias = “myAlias” , path = ‘com.ruceci.Utility.ConstantService’ ) ;
// Funky!
addModelMapping(
alias=“myAlias”,
path=‘com.ruceci.Utility.ConstantService’
);
// random variable set
mappingPrefix = “com.ruceci”;
// with stuff
addModelMapping(‘ConstantService’,’#mappingPrefix#.Utility.ConstantService’);
// other stuff
addModelMapping(“ConstantService”,mappingPrefix & ‘.Utility.ConstantService’);
// conditional
if(foo == ‘bar’)
{
addModelMapping(‘ConstantService’,‘com.ruceci.Utility.ConstantService’);
}
else
{
addModelMapping(‘123’,‘com.ruceci.Utility.ConstantService’);
}
addModelMapping(variableName,‘com.ruceci.Utility.ConstantService’);
// This works
addModelMapping(“foobar”,right(“Hello”,3));
// Sadly, these do not
addModelMapping(left(“foobar”,2),“Hello”);
addModelMapping(left(“foobar”,2),right(“Hello”,3));
#reReplaceNoCase(modelMappings,regex,"map(\2).to(\4);","ALL")#