atom/language-java

Catch parameter not correctly highlighted when declared in new line or with a comment in between

Closed this issue · 4 comments

Description

Catch parameter name is highlighted as type when declared in new line or with a comment in between.

Steps to Reproduce

Paste the following code to editor:

public static void main(String[] args) {
    try {
        // something
    } catch // this is a comment
    (NoSuchMethodException |
        SecurityException
      | InstantiationException | llegalAccessException |
      IllegalArgumentException | invocationTargetException 
      e
    ) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    try {
        // something
    } catch // this is a comment
    (NoSuchMethodException |
        SecurityException
      | InstantiationException | llegalAccessException |
      IllegalArgumentException | invocationTargetException /* comment */ e
    ) {
        e.printStackTrace();
    }
}

Expected behavior: e is highlighted as variable.parameter.java

Actual behavior:

e is highlighted as storage.type.java:
image

Reproduces how often: Always

Hello @Vigilans, thanks for the report, I have simplified the examples, let me know if you have any comments.

Closing bracket in on a new line.

try {} catch (ex e
){}

Comment between the type and variable name.

try {} catch (ex /**/ e){}

It is basically two scenarios:

  • there is a comment between Exception and e -> have to update regex
  • e is on a new line -> oniguruma engine limitation (can't match new lines, see #186)

@lkashef

try {} catch (ex e
){}

should be

try {} catch (ex
e){}

Thanks @sadikovi! 🙇