The following is an adaptation of the approach suggested in Highlight text in code listing while also keeping syntax highlighting. The basic idea is to use listings moredelim option to mark the part to overbrace.
With the moredelim=** syntax you can define delimiters which styles apply on top of all other formattings. In the following I use backticks as delimiters, but you may choose any character:
\lstdefinestyle{...}{
moredelim=**[is][\btHL]{`}{`},
}
The only issue is the formatting commands to be applied (\btHL) do not get the text to highlight as a macro parameter. Instead, they have to work like the LaTeX font commands (e.g., \bfseries or \color) that take affect until the end of the current group. Hence, we have to catch the content in an lrbox.
Complete MWE (using Java instead of Scala to demonstrate the combination with syntax highlighting):
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings,xcolor,beramono,amsmath}
\makeatletter
\newenvironment{btHighlight}[1][]
{\begingroup\def\bt@Highlight@par{#1}\begin{lrbox}{\@tempboxa}}
{\end{lrbox}\bt@HL@box[\bt@Highlight@par]{\@tempboxa}\endgroup}
\newcommand\btHL[1][]{%
\begin{btHighlight}[#1]\bgroup\aftergroup\bt@HL@endenv%
}
\def\bt@HL@endenv{%
\end{btHighlight}%
\egroup
}
\newcommand{\bt@HL@box}[2][]{%
$\overset{\text{#1}}{\overbrace{\strut\usebox{#2}}}$%
}
\makeatother
\lstdefinestyle{Java}{
language={Java},basicstyle=\ttfamily,
moredelim=**[is][{\btHL[class name]}]{`}{`},
moredelim=**[is][{\btHL[important]}]{@}{@},
escapechar={§},
}
\begin{document}
A listing with {\btHL[overbrace text] highlighting of all \textbf{important} elements} looks as follows:
\begin{lstlisting}[style=Java]
public class `HelloWorld` {
public @static void@ main(String[] args) {
System.out.println("Hello, World");
}
}
\end{lstlisting}
\end{document}
