You can also use pgf's \foreach macro to iterate over the list and increase the horizontal indent at each iteration, and use tikz to add the lines.
To make it easier to control the formatting for each of the list members,
I have defined three different commands for the first, middle, and last list members:
\newcommand*{\FormatFirstListMember}[1]{\textcolor{magenta}{\texttt{#1}}}%
\newcommand*{\FormatMiddleListMember}[1]{\textcolor{blue}{\texttt{#1}}}%
\newcommand*{\FormatLastListMember}[1]{\texttt{#1}}%
With the above settings, here are the result of using:
\createindentedtext{java.lang.Object, java.awt.Component3, java.awt.Container, javax.swing.JComponent}
\createindentedtext[50pt]{java.lang.Object, java.awt.Component3, java.awt.Container, javax.swing.JComponent}

Notes:
- The optional first parameter to
\createindentedtext can be used to override the default setting of the indent amount. Default value is the value specified in \DefaultIndentSize.
- The
\FormatFirstListMember, \FormatMiddleListMember, \FormatLastListMember can be modified to tweak the desired formatting to be applied to the list members.
- You can adjust the settings in
\ConnectIndentedText to tweak the formatting of the lines.
- The current setting of the vertical bar joining the elements is set to half the indent size. This can be tweaked as desired by changing the
0.5 constant in the definition of \ConnectIndentedText. It can also be adjusted to always be under a specific letter (such as v in java) by replacing -0.5*#1 in this macro with an appropriate expression using \widthof{} from the the calc package (which is different than what \usetikzlibrary{calc} loads).
- The
showframe package was used to show the position of the text relative to the margins. The \noindent ensures that your text is shifted relative to the margin.
- This requires two runs. Once to determine the end point of the lines, and the second to draw them.
Code:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{tikz}
\usepackage{xstring}
\usepackage{showframe}
\usetikzlibrary{calc}
\newlength{\DefaultIndentSize}%
\setlength{\DefaultIndentSize}{25pt}% adjust to suit
% Specify the formatting of each of the list members
\newcommand{\FormatFirstListMember}[1]{\textcolor{magenta}{\texttt{#1}}}%
\newcommand{\FormatMiddleListMember}[1]{\textcolor{blue}{\texttt{#1}}}%
\newcommand*{\FormatLastListMember}[1]{\texttt{#1}}%
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\ConnectIndentedText}[2][\DefaultIndentSize]{%
\begin{tikzpicture}[overlay, remember picture]
\draw [thick, blue]
($(#2)+(0,0.5ex)$) --
($(#2)+(-0.5#1,0.5ex)$) --
($(#2)+(-0.5*#1,2.0ex)$)
;
\end{tikzpicture}
}%
\newcounter{TotalNumberOfListMembers}%
\newcommand{\SetTotalNumberOfListMembers}[1]{%
\setcounter{TotalNumberOfListMembers}{0}%
\foreach \member in {#1} {%
\stepcounter{TotalNumberOfListMembers}%
}%
}%
\newlength{\IndentLength}%
\newcounter{CurrentListMemberCount}%
\newtoggle{FirstIndentedText}%
\newcommand{\createindentedtext}[2][\DefaultIndentSize]{%
\setlength{\IndentLength}{0pt}%
\SetTotalNumberOfListMembers{#2}%
\setcounter{CurrentListMemberCount}{0}%
\global\toggletrue{FirstIndentedText}%
\foreach \member in {#2} {%
\stepcounter{CurrentListMemberCount}%
\par\noindent\hspace{\IndentLength}%
\tikzmark{start}%
\iftoggle{FirstIndentedText}{%
\FormatFirstListMember{\member}%
}{%
\IfEq{\the\value{CurrentListMemberCount}}{\the\value{TotalNumberOfListMembers}}{%
\FormatLastListMember{\member}%
}{%
\FormatMiddleListMember{\member}%
}%
\ConnectIndentedText[#1]{start}%
}%
\global\addtolength{\IndentLength}{#1}%
\global\togglefalse{FirstIndentedText}%
}%
}%
\begin{document}
\createindentedtext{java.lang.Object, java.awt.Component3, java.awt.Container, javax.swing.JComponent}
\bigskip
\createindentedtext[50pt]{java.lang.Object, java.awt.Component3, java.awt.Container, javax.swing.JComponent}
\end{document}