`
yangzb
  • 浏览: 3503157 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Enterprise Architect's Code Template Syntax

 
阅读更多

Code Templates are written as plain text, using Enterprise Architect's code template editor (see The Code Template Editor ). The template syntax centers on three basic constructs:

Templates can contain any or all of these constructs.

Literal Text

All text within a given template that is not part of a macro or a variable definition/reference, is considered literal text. With the exception of blank lines, which are ignored, literal text is directly substituted from the template into the generated code.

Consider the following excerpt from the java Class Declaration template:

%PI=" "%

%CONVERT_SCOPE(classScope)%

%classStereotype=="static" ? "static": ""%

%classStereotype=="final" ? "final": ""%

%classStereotype=="static final" ? "static final": ""%

%classAbstract=="T" ? "abstract": ""%

%PI=""%

class %className%$bases

On the final line, the word class , including the subsequent space, would be treated as literal text and thus reproduced in the output. The blank line following the CONVERT_SCOPE macro, however, would have no effect on the output.

The %, $ and " characters have special meaning in the template syntax and cannot always be used as literal text. If these characters must be generated from within the templates, they can be safely reproduced using the following direct substitution macros:

Macro

Use to

%dl%

Produce a literal $ character.

%pc%

Produce a literal % character.

%qt%

Produce a literal " character.

Macros

Macros provide access to element fields within the UML model and are also used to structure the generated output. All macros are enclosed within percent ( % ) signs. The CTF contains six basic types of macros:

In general, macros (including the % delimiters) are substituted with literal text in the output. For example consider the following item from the Class Declaration template:

... class %className% ...

The field substitution macro, %className% , would result in the current Class name being substituted in the output. So if the Class being generated was named Foo , the output would be:

... class Foo ...

 

Variables

Template variables provide a convenient way of storing and retrieving data within a template. This section explains how variables are defined and referenced .

Variable Definitions

Variable definitions take the basic form:

$<name> = <value>

where <name> can be any alpha-numeric sequence and <value> is derived from a macro or another variable.

A simple example definition would be:

$foo = %className%

Variables can be defined, using values from:

  • Substitution, function or list macros
  • String literals, enclosed within double quotation marks
  • Variable references.

Definition Rules

The following rules apply to variable definitions:

  • Variables have global scope within the template in which they are defined and are not accessible to other templates
  • Each variable must be defined at the start of a line, without any intervening whitespace
  • Variables are denoted by prefixing the name with $, as in $foo
  • Variables do not have to be declared, prior to being defined
  • Variables must be defined using either the assignment operator (=), or the addition-assignment operator (+=)
  • Multiple terms can be combined in a single definition using the addition operator (+).

Examples

Using a substitution macro:

$foo = %opTag:"bar"%

Using a literal string:

$foo = "bar"

Using another variable:

$foo = $bar

Using a list macro:

$ops = %list="Operation" @separator="\n\n" @indent="\t"%

Using the addition-assignment operator ( += ):

$body += %list="Operation" @separator="\n\n" @indent="\t"%

The above definition is equivalent to the following:

$body = $body + %list="Operation" @separator="\n\n" @indent="\t"%

Using multiple terms:

$templateArgs = %list="ClassParameter" @separator=", "%

$template ="template<" + $templateArgs + ">"

Variable References

Variable values can be retrieved by using a reference of the form:

$<name>

where <name> can be a previously defined variable.

Variable references can be used in one of the following ways:

  • As part of a macro, such as the argument to a function macro
  • As a term in a variable definition
  • As a direct substitution of the variable value into the output.

Note:

It is legal to reference a variable before it is defined. In this case, the variable is assumed to contain an empty string value: ""

Example 1

Using variables as part of a macro. The following is an excerpt from the default C++ ClassNotes template.

$wrapLen = %genOptWrapComment%

$style = %genOptCPPCommentStyle%

%if $style == "XML.NET"%

%XML_COMMENT($wrapLen)%

%else%

%CSTYLE_COMMENT($wrapLen)%

%endIf%

Define variables to store the style and wrap length options.

Reference to $style as part of a condition.

Reference to $wrapLen as an argument to function macro.

Example 2

Using variable references as part of a variable definitions:

$foo = "foo"

$bar = "bar"

$foobar = $foo + $bar

Define our variables.

$foobar now contains the value foobar.

Example 3

Substituting variable values into the output

$bases=%classInherits%

Class %className%$bases

Store the result of the ClassInherits template in $bases.

Now output the value of $bases after the Class name.

分享到:
评论

相关推荐

    Enterprise Architect 破解版

    Enterprise Architect 破解版 Enterprise Architect 破解版 Enterprise Architect 破解版 Enterprise Architect 破解版

    Enterprise Architect 8.0.858 汉化补丁包

    Enterprise Architect是一款强大的统一建模语言(UML)工具,由Sparx Systems公司开发,用于软件工程、系统工程、业务过程建模等多个领域。这款工具提供了全面的模型构建、管理和协作功能,支持从需求捕获到系统设计...

    Enterprise Architect 8.0汉化版附注册码

    Enterprise Architect是一款强大的统一建模语言(UML)工具,由Sparx Systems公司开发,用于软件工程、系统工程、业务过程建模等多个领域。在这个"Enterprise Architect 8.0汉化版附注册码"的资源中,用户可以获取到...

    Enterprise Architect 破解补丁

    Enterprise Architect 破解补丁 亲测可破解 EA10

    在EnterpriseArchitect中的需求建模实例

    虽然才EnterpriseArchitect还没多长时间,但它杰出的管理能力,强大的功能,小巧的体积,柔和的界面设计,都让我非常惊叹!与之前的rose相比,EnterpriseArchitect是我现在画用例图与做需求的首选工具。对Enterprise...

    enterprise architect 12(含注册码和中文包)

    企业架构师(Enterprise Architect,简称EA)是一款由Sparx Systems公司开发的强大的统一建模语言(UML)工具,广泛应用于软件开发、系统分析和企业架构规划等领域。本文将深入探讨"Enterprise Architect 12"的主要...

    EnterpriseArchitect汉化版(绝对可用)

    《企业架构师Enterprise Architect的汉化实践》 在IT领域,建模工具是软件开发过程中不可或缺的一部分,尤其在系统分析和设计阶段。Enterprise Architect(EA)是一款强大的UML建模工具,深受全球开发者喜爱。然而...

    Enterprise Architect 7.5 汉化工具

    Enterprise Architect V7.5 汉化工具 安装玩Enterprise Architect 7.5后直接安装该工具,即可实现汉化! 该文件是exe文件

    EnterpriseArchitect 7.5汉化+序列号

    Enterprise Architect是一款强大的软件建模工具,由Sparx Systems公司开发,主要用于企业级的系统分析、设计和开发。"Enterprise Architect 7.5汉化+序列号"的资源显然是为那些希望在中文环境下使用该软件的用户提供...

    EnterpriseArchitect中文经典教程.pdf

    根据提供的文件信息,下面对“Enterprise Architect中文经典教程.pdf”文件中所提及的技术知识点进行详细解读。 首先,从标题“Enterprise Architect中文经典教程.pdf”我们可以推断出,本文档很可能是一本关于...

    Enterprise Architect13.5破解版

    该工具为Enterprise Architect13.5破解版,用于企业及的项目需求分析,架构设计,UML类图的设计工具,非常好用欢迎大家下载使用,有问题私聊我!

    Enterprise Architect 中文用户手册

    Sparx Systems 的Enterprise Architect 是一个完整生命周期的UML 工具: · 设计和建造一个广泛的软件系统 · 业务分析,业务流程建模,管理要求 · 系统建模,系统架构建模,组件设计,仿真 · 广义域特定...

    Enterprise Architect 建模实例视频

    Enterprise Architect是一款强大的建模工具,尤其在企业级应用架构领域有着广泛的应用。在这个"Enterprise Architect 建模实例视频"中,我们将会深入探讨如何利用该工具进行ATM(自动取款机)系统的建模,以及如何在...

    Enterprise Architect 汉化版

    ea 汉化版,Enterprise Architect是构建和共享基于业务模型的理想平台,可完全集成到整个企业或系统级架构中。 开发支持从复杂的战略模型到简单的思维导图,过程建模,需求管理,BPMN模型等。

    EnterpriseArchitect 2016

    Enterprise Architect 2016,作为Sparx Systems公司的旗舰产品,是一款强大的UML设计工具,专为软件开发者、系统架构师以及业务分析师提供全面的建模解决方案。该工具以其高效、灵活和全面的特性在业界享有盛誉。...

    ea Enterprise Architect 8.0汉化破解

    ea Enterprise Architect 8.0汉化破解

    enterprise architect 15中文版 v15.0.1509.rar

    Enterprise Architect是一个对于软件系统开发有着极好支持的CASE软件(Computer Aided Software Engineering)。EA不同于普通的UML画图工具(如VISIO),它将支撑系统开发的全过程。在需求分析阶段,系统分析与设计...

    Enterprise Architect 13.5

    Enterprise Architect是由Sparx Systems开发的一款强大的统一建模语言(UML)建模工具,它在版本13.5中提供了 Ultimate Edition,旨在为专业软件开发者、系统架构师以及业务分析师提供全面的模型构建和协作环境。...

    Enterprise Architect永久试用中文版

    Enterprise Architect(EA)13.0永久试用中文版 无限期30天试用 Enterprise Architect 是Sparx Systems 公司的旗舰产品。它覆盖了系统开发的整个周期,除了开发类模型之外,还包括事务进程分析,使用案例需求,动态...

Global site tag (gtag.js) - Google Analytics