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

Does not handle Class::new method reference in Java 8 #37

Open
StrangeNoises opened this issue Aug 12, 2015 · 1 comment
Open

Does not handle Class::new method reference in Java 8 #37

StrangeNoises opened this issue Aug 12, 2015 · 1 comment

Comments

@StrangeNoises
Copy link

If you're using Streams in Java 8 sooner or later you'll want to use method references. There's a problem when you use the ::new method reference, as in:

    .collect(Collectors.toCollection(ArrayList::new));

It recognises the 'new' keyword and expects stuff to come after it that it's not getting. This then breaks the syntax's ability to recognise any methods in the Java source that follow the usage of the above syntax.

I have a fix. :-)

As a user I can go to Bundles -> Edit Bundles... and select Java -> Language Grammars -> Java and go to anonymous-classes-and-new and change the begin regexp as follows:

original:

begin = '\bnew\b';

fix:

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

And save. This stops it recognising new when it's prefixed by those colons, and so it just appears in the same way as other method references; and more importantly for me, it goes on to recognise the rest of the methods in that source file.

NB: I forked the repository and made that change to my own working copy preparatory to doing a PR for it, but I'm afraid I don't sufficiently get Textmate bundle development to be able to get it to load! (The bundle loads but it's missing the Java language grammer. I'm guessing some build process needs to happen but I can't see it.) So even though the above is the only change in it, and it works if I just apply the change directly in Bundle Editor, I'm not at current going to attempt to commit it. :-) (EDIT: It's probably because I didn't entityise the < as it appears in the Java.plist XML file. Duh!)

This problem was originally observed in Sublime Text 3 jskinner/DefaultPackages#140 which is actually my preferred editor, I just also noticed that Textmate has the same issue and then found that Sublime actually "borrows" files from this Java.tmbundle to supply its syntax highlighting, so thought I'd try to fix it in Textmate first. After I submit this I'm going to go and add a note there to the same effect.

@pchaigno
Copy link
Contributor

I forked the repository and made that change to my own working copy preparatory to doing a PR for it, but I'm afraid I don't sufficiently get Textmate bundle development to be able to get it to load!

If you just want to test your changes you can use Lightshow ;)

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

No branches or pull requests

2 participants