Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8 method references before keyword names not supported (breaks symbol matching) #140

Closed
FichteFoll opened this issue Jun 26, 2015 · 5 comments

Comments

@FichteFoll
Copy link
Contributor

import java.util.*;
import java.util.stream.*;

/*
Lines entered so screenshot
can show the list of methods
*/

public class SyntaxTest {
   public static void main(String... args) {
      printList(Arrays.stream(args)
         .collect(Collectors.toCollection(ArrayList::new)));
      anotherMethod();
   }

   private static void printList(List<String> args) {
      args.stream().forEach(System.out::println);
   }

   private static void anotherMethod() {

   }
}

System.out::println seems to not be an issue, but ArrayList::new is, seemingly because "new" is also a keyword.

Okay:
o

Broken:
b

Mirror from http://www.sublimetext.com/forum/viewtopic.php?f=3&t=18921

@StrangeNoises
Copy link

I have a fix, but I don't seem to be able to apply it in Sublime Text in a way that it'll take notice.

ST3 actually gets its Java language grammar and highlighting from the Textmate Java bundle. I was able to fix the issue there with a regex change in the Syntaxes/Java.plist file.

In the anonymous-classes-and-new section, edit the begin regex

from:

begin = '\bnew\b';

to

begin = '\b(?<!::)new\b';

Which makes it ignore the new keyword when it's prefixed by two colons. This appears to fix it for me in TextMate if I make the change in the Bundle Editor but I don't seem to have the knack of applying a fixed bundle myself. As TextMate isn't my main editor, I don't propose to work hard at finding out why. No, I think I just have found out why; it's an XML file, I needed to entityise the < in the regex!

The equivalent file in ST3 is: Packages/Java/Java.tmLanguage. However, making that same change (and entityising the < this time!) is being simply ignored. I deleted the cache files but I note the Java.tmLanguage.cache and .rcache files aren't being recreated. There's presumably something I've done to offend it but I can't see it, the change is just being silently ignored. There is a Java.sublime-syntax.cache and .rcache file pair, but I can't see any Java.sublime-syntax original anywhere. So if those are being generated out of the .tmLanguage file, I don't know why it's ignoring the change that works in Textmate.

I'm pretty sure this is the fix though, it's just how to apply fixes, both to this and the TextMate bundles system that seems to be unnecessarily difficult.

EDIT: TextMate Issue here: textmate/java.tmbundle#37

EDIT: Fixed for me by moving my changed Java.tmLanguage file into Packages/User where it probably always should have been! :-} And it works.

@FichteFoll
Copy link
Contributor Author

@StrangeNoises, you can also file a pull request now to the official repository of ST's shipped packages: https://github.com/sublimehq/Packages

Note the new format however.

@StrangeNoises
Copy link

Yes I did just note the new format, now there is a Java.sublime-syntax instead. But I was able to make the same change in the equivalent place there, and it's working for me. Expect a PR soon (just got to check that procedure that I do it right...)

@StrangeNoises
Copy link

... and done: sublimehq/Packages#89

@jrappen
Copy link

jrappen commented Jan 12, 2016

@FichteFoll I believe you can close this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants