atom / language-java

Java package for Atom
Other
62 stars 59 forks source link

Variable highlighting in for-each loop #163

Closed sadikovi closed 6 years ago

sadikovi commented 6 years ago

Requirements

Description of the Change

I found when working on other issue that variables in for-each loops are not scoped correctly, for example:

class Test {
  void func() {
    // correctly highlighted in for loop
    for (int i = 0; i < 10; i++) {
      // do something
    }

    // incorrectly highlighted and scoped in for-each loop
    for (int i : elements) {
      // do something
    }

    // incorrectly highlighted and scoped in for-each loop
    for (HashMap<String, String> map : elementsFunc()) {
      // do something
    }
  }
}

Before patch:

before

After patch:

after

I simply extended the list of characters that terminate variable patterns and added : as such. Added test to cover this scenario.

Alternate Designs

None were considered.

Benefits

Fixes variable highlighting in for-each loops.

Possible Drawbacks

Should not be any.

Applicable Issues

None

sadikovi commented 6 years ago

@50Wliu could you review this PR? Thanks!

I found this inconsistency when working on Java 10 var support, so I thought I might as well fix it (more or less).

sadikovi commented 6 years ago

ping @50Wliu