Debian Codegraph @

texmf-dist/doc/latex/codeanatomy/demo-anatomy-of-a-static-method.tex

raw
1 \begin{lrbox}{\mycodebox}
2 \lstset{escapeinside={!}{!}}
3 \begin{lstlisting}
4 !\cPart{s}{public static \cPart{rt}{double} \cPart{fn}{harmonic}(\cPart{al}{\iPart{at}{int} \iPart{pv}{n}})}!
5 {
6 !\hmtPoint{left}\cPart{lv}{double sum}! = 0.0;
7 for (int i = 0; i <= n; ++i)!\extremPoint{right}!
8 {
9 sum += 1.0/i;
10 }
11 !\cPart{rs}{return sum;}\dmbPoint{bottom}!
12 }
13 \end{lstlisting}
14 \end{lrbox}
15
16 \begin{tikzpicture}[remember picture]
17 %{[on background layer]\draw[code grid debug] (-2.5,-0.5) grid (8.5,3.5);}
18 \node(code) [anatomy] at (0,0) {\usebox\mycodebox};
19
20 \fitExtrem{b}{(left) (right) (bottom)}
21
22 % Annotation
23 \codeAnnotation{sText} (-0.7,5.25) {signature}
24 \codeAnnotation{rtText} (2,5.25) {return\\type}
25 \codeAnnotation{fnText} ( 4,5.25) {method\\name}
26 \codeAnnotation{alText} ( 6,5.25) {argument\\list}
27 \codeAnnotation{atText} (6.75,1.75) {argument\\type}
28 \codeAnnotation{pvText} (7.5,2.70) {parameter\\variable}
29 \codeAnnotation{lvText} (-0.7,3) {local\\variable}
30 \codeAnnotation{bText} (-0.7,1.5) {method\\body}
31 \codeAnnotation{rsText} (3,-0.4) {return statement}
32 % Arrows
33 \draw[->,annotation] (sText) -- (s.north west);
34 \draw[->,annotation] (rtText) -- (rt);
35 \draw[->,annotation] (fnText) -- (fn);
36 \draw[->,annotation] (alText) -- (al);
37 \draw[->,annotation] (atText) -- (at);
38 \draw[->,annotation] (pvText) -- (pv);
39 \draw[->,annotation] (lvText) -- (lv.west);
40 \draw[->,annotation] (bText) -- (b);
41 \draw[->,annotation] (rsText) -- (rs);
42 \end{tikzpicture}