1. Georg Brandl
  2. pygments-main
Issue #524 on hold

java highlight doesn't understand generics

Alexander Kjäll
created an issue

This piece of code doesn't get highlighted properly:

public interface myDAO { List<String> getValue(String kind);

String getCategory(String id); }

The first function doesn't get hilighted as a function.

Comments (3)

  1. Tim Hatch

    Agreed. We've historically had problems keeping function detection regexes to be fast, so this may require some thought. IIRC Java syntax allows the same sort of nesting as C++, so you might have a

    Foo<Map<Integer, String>, Double> func(String x);

    Needs some more thought.

  2. Alexander Kjäll reporter

    I agree, I wouldn't try to parse recursive things with regular expressions.

    If i would do it in python i would most likely do it with the library pyparsing.

  3. bethard

    While you can't solve all of the cases, lots of instances of Java generics are not recursive; they look like the List<String> example above. What about a special-case for this very common, non-recursive pattern, something like r"(<[^>]*>)?"?

    FWIW, I ran into a similar issue with new Something<X, Y>() not being recognized as a constructor call (via Jekyll, which is using pygments.rb 0.6.1 == Pygments 2.0 AFAICT).

  4. Log in to comment