I found this question on SO but it is not adequately answered there. I thought that re-posting it here would bring it to the attention of people with more specialized knowledge who can answer it adequately. The SO answer doesn't even come close and basically just writes it off as impossible. I posted the best answer I could, but my solution isn't ideal either.
How do I edit the java.vim syntax file to highlight only the identifier of a Java function?
Here is the best regex I came up with, but as you'll see, it has a side effect: it incorrectly highlights the closing parenthesis as an error (presumably because my regex makes it part of the highlighted region).
syn region javaFuncDef start=+^\s\+\(\(public\|protected\|private\|static\|abstract\|final\|native\|synchronized\)\s\+\)*\(\(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\(<[^>]*>\)\=\(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*(+ end=+(+ contains=javaScopeDecl,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses
If I had a deeper knowledge of regex, or of Vim's syntax highlighting system, I might be able to fix it myself.
EDIT: I discovered a construct called a zero-width assertion with lookahead, which matches something but does not actually include it as part of the match. Trouble is, I still can't get it working.
In the example here it would be ?=(
right at the end of the regex, to match but not include the opening parameter list parenthesis. I've tried different uses of it (in the region start field, the region end field, and also as a standalone match rule rather than a region rule), all to no avail.
syn match '^\(public\|...\)\? \(static\)\? \w\+ \zs[^(]+\ze
It'soptional public/static... space followed by optional static then by one or more letters (return type) space match one or more characters that isn't open parenthesis
after/syntax
or what? So that I could test it.\zs
and\ze
regex atoms might be relevant here, as it seems user1685095 already used in his suggested. These are described well in the user docs.