Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 66 lines (63 sloc) 1.921 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
if [ ! -e ${1} ]; then
echo "Usage: ./devel/dot-fsm.sh path/to/java/file"
exit 1
fi
FILE=${1}
# NOTE: change clusterrank to "local" to enable clustering
HEADER='digraph bootstrap {
size="160,80";
ranksep=.1;
nodesep=.4;
color="gray";
overlap="prism";
clusterrank="global";
center="true";
rankdir="BT";'
FOOTER="}"
TRANS="$(cat ${FILE} | sed 's/)\./)\n/g;
s/^ *//g;
s/State\.//g;
s/Transition\.//g;
s/\.class//g;
s/\(\w\)( *\(.*\));$/\1( \2/g' | \
awk '
/new StateMachineBuilder/{start="true"}
/newAtomicStateMachine/{start="false"}
/from\(/{from=$2}
/to\(/{to=$2}
/error\(/{err=$2}
/on\(/{on=$2}
/run\(/ && start == "true" {
states[from]=from;
labelProps="fontsize=\"8.0\"";
action=gensub("(.*run.|.*condition\\()","","g",$0);
if(from) printf("\t%s -> %s [style=\"bold\",wieght=\"2\",label=<<FONT POINT-SIZE=\"12\">%s</FONT><BR/><FONT POINT-SIZE=\"12\">%s</FONT>>,%s];\n",from,to,on,action,labelProps);
if(err) printf("\t%s -> %s [style=\"dashed\",wieght=\"0.5\",color=\"red\",label=\"%s\",%s];\n", to, err, on, labelProps)
}
END{
print "\tsubgraph cluster_all{\n\t\trank=max;"
for( i in states ) if(index(i,"_")==0) print "\t\t"i" [shape=\"doublecircle\",weight=\"2.0\",label=<<FONT POINT-SIZE=\"18\">"i"</FONT>>];"
print "\t}"
}
' | sed 's/\./=/g;/^\t* \[shape.*/d')"

SUBGRAPHS=$(echo "${TRANS}" | \
awk '
/\w*_.*->/{
superstate=gensub(";","","g",gensub("_.*","","g",$1));
trans[superstate]=$1"#"trans[superstate];
}
END{
subgraphFormat="\tsubgraph cluster_%1$s{\n" \
"\t\tstyle=rounded;\n" \
"\t\trankdir=\"BT\";\n" \
"\t\t%1$s [shape=\"doublecircle\",weight=\"2.0\",label=<<FONT POINT-SIZE=\"18\">%1$s</FONT>>]\n" \
"\t\t%2$s\n" \
"\t}\n"
for(i in trans) printf(subgraphFormat, i, trans[i]);
}' | \
sed 's/\([^_]*\)_\([^#]*\)#/\1_\2 [label=<<FONT POINT-SIZE="10">\1_\2<\/FONT>>];\n\t\t/g;s/#}/\n\t}/g'
)

echo "${HEADER}"
echo "${SUBGRAPHS}"
echo "${TRANS}"
echo "${FOOTER}"
Something went wrong with that request. Please try again.