问题
在 Enterprise Architect 7.1.834 中的代码生成模板中,是否可以在文件模板的范围内打印一个类所属的所有父包?
需要这样做的原因是生成符合我公司编码标准的多包含警卫
什么不起作用
我都试过了:
%list="Namespace__Notes" @separator="-"%
和
%packageName%
两者的输出都只打印顶级父包(Package1),但我想看看:
Package1-Package2-Package3
有没有人找到办法做到这一点?
命名空间__Notes
Namepace__Notes 是一个 Namepace 类型的自定义模板,内容如下
%PI=""%
%packageName%
[编辑] 肮脏的解决方案
我当前的(肮脏的)解决方案是破坏文件路径。 我错过了什么吗?
编码:
$l_backslash = %REPLACE("\z","z","")%
$filepath = %filePath%
$upper_filepath = %TO_UPPER($filepath)%
$upper_package_as_path = $l_backslash + %TO_UPPER(packageName)% + $l_backslash
$upper_package_base_len = %LENGTH(packageName)%
$package_path_pos = %FIND($upper_filepath,$upper_package_as_path)%
%if $package_path_pos != "-1" and $package_path_pos != "0"%
$upper_filepath = %MID($upper_filepath,$package_path_pos)%
%endIf%
$file_define = "_" + $upper_filepath + "__"
$file_define = %REPLACE($file_define,".","_")%
$file_define = %REPLACE($file_define,$l_backslash,"_")%
$file_define = %REPLACE($file_define,"/","_")%
$body += "/**************************************************************************//**"
$body += "\n * \file " + %fileName%
$body += "\n *"
$body += "\n * \brief " + %elemType% + " " + %className% + " header file"
$body += "\n *"
$body += "\n * \author " + %classAuthor ? value : "<unknown>"%
$body += "\n *"
$body += "\n *****************************************************************************/"
$body += "\n"
$body += "\n#ifndef " + $file_define
$body += "\n#define " + $file_define
$body += "\n"