%% LaTeX2e file `tmp-gen-java-program.tex'
%% generated by the `filecontents' environment
%% from source `codeanatomy.lstlisting' on 2025/10/19.
%%
\lstset{escapeinside={!}{!}}
\begin{lrbox}{\mycodebox}
\begin{lstlisting}
public !\iPart{class}{class}! !\cPart{className}{HelloWorld}!
{
    !\mtPoint{mainLeft}!public static void main(String[] argv)
    {
        !\hmtPoint{left}\iPart{assign}{
            \bgcode{// Prints "Hello World" in the terminal window}}
        \extremPoint{fnR} \extremPoint{mR}!
        !\iPart{fnCall}{System.out.print("Hello World");}\dmbPoint{mostBottom}!
    }!\mbPoint{mainBottom}!
}
\end{lstlisting}
\end{lrbox}

\begin{tikzpicture}[remember picture]
\node(code) [anatomy] at (0,0){\usebox\mycodebox};

\fitExtrem{classBody}{(mainLeft) (mR) (mainBottom)}
\fitExtrem{functionBody}{(left) (fnR) (mostBottom)}

\codeAnnotation{fileNameText} (1.5,5) {text file named \texttt{HelloWorld.java}}
\codeAnnotation{classNameText} (3.5,4.25) {name}
\codeAnnotation{classBodyText} (6.5,3.6) {\texttt{main()} method}
\codeAnnotation{functionBodyText} (2.5,-0.5) {body}
\codeAnnotation{statement} (8,0) {statements}

{[on background layer]
  \draw[->,annotation] (fileNameText) -- (class);
  \draw[->,annotation] (classNameText) -- (className);
  \draw[->,annotation] (classBodyText.south west) -- (classBody);
  \draw[->,annotation] (functionBodyText) -- (functionBody);
  \draw[->,annotation] (statement) -- (assign.353);
  \draw[->,annotation] (statement) -- (fnCall.350);
}
\end{tikzpicture}
