基本语法
每个普通节点:冒号开头,分号结尾
活动图的起始和结尾:start、end或stop
start
:case1;
:case2;
end
条件语句
start
if(predicate?) then (yes)
:case yes;
else (no)
:case no;
endif
end
多重条件语句
plaintUML里没有switch语法,只能使用elseif代替
start
note right:多分支条件语句,实现switch
if (condition A) then (yes)
:Text 1;
elseif (condition B) then (yes)
:Text 2;
stop
elseif (condition C) then (yes)
:Text 3;
elseif (condition D) then (yes)
:Text 4;
else (nothing)
:Text else;
endif
stop
do while循环
start
note right:do while循环
repeat
:read data;
:generate diagrams;
repeat while (more data?) is (yes)
stop
while后面可以跟is表达式来标识箭头
while do循环
start
note right:while do循环
while (check filesize ?) is (not empty)
:read file;
endwhile (empty)
:close file;
end
while后面可以跟is表达式来标识箭头
endwhile后跟括号表达式来标识箭头
并行处理
start
note right:并行处理fork
if (multiprocessor?) then (yes)
fork
:Treatment 1;
fork again
:Treatment 2;
end fork
else (monoproc)
:Treatment 1;
:Treatment 2;
endif
end
fork换成split,可以更改样式
注释
start
note right:添加注释
:foo1;
floating note left: This is a note
:foo2;
note right
This note is on several
//lines// and can
contain HTML
====
* Calling the method ""foo()"" is prohibited
end note
stop
一行注释可在note声明后跟冒号
多行注释需要换行,并用end note语句标识结束
浮动注释可使用floating关键字
note声明后可标识方位:仅支持left和right
文本格式支持creole wiki语法
节点颜色
start
note right:配置节点颜色
:starting progress;
#HotPink:reading configuration files
These files should edited at this point!;
#AAAAAA:ending of the process;
end
#开头,可使用色值或文字描述,需要放在语句前方
箭头颜色样式
start
note right:修改箭头颜色样式
:foo1;
-> You can put text on arrows;
if (test) then
-[#blue]->
:foo2;
-[#green,dashed]-> The text can
also be on several lines
and **very** long...;
:foo3;
else
-[#black,dotted]->
:foo4;
endif
-[#gray,bold]->
:foo5;
end
连接器
start
note right:连接器
:Some activity;
(A)
detach
(A)
:Other activity;
end
组合
start
note right:组合:定义分区
partition Initialization {
:read config file;
:init internal variable;
}
partition Running {
:wait for user interaction;
:print information;
}
stop
分离
start
note right:分离
fork
:foo1;
:foo2;
fork again
:foo3;
detach
endfork
if (foo4) then
:foo5;
detach
endif
:foo6;
detach
:foo7;
stop
特殊领域语言
用其他符号代替分号结尾,可修改节点样式
|
<
>
/
]
}
start
note right:特殊领域语言(SDL)
:Ready;
:next(o)|
:Receiving;
split
:nak(i)<
:ack(o)>
split again
:ack(i)<
:next(o)
on several line|
:i := i + 1]
:ack(o)>
split again
:err(i)<
:nak(o)>
split again
:foo/
split again
:i > 5}
stop
end split
:finish;
end
泳道
泳道比较特殊,整个代码必须以泳道标识开头
类似于节点颜色,在语句前方可以设置颜色;后设置的颜色会覆盖之前设置的
|Swimlane1|
start
:foo1;
|#AntiqueWhite|Swimlane2|
:foo2;
:foo3;
|Swimlane1|
:foo4;
|Swimlane2|
:foo5;
stop