mplushnikov / lombok-intellij-plugin

Lombok Plugin for IntelliJ IDEA
Apache License 2.0
3.11k stars 635 forks source link

IntelliJ 2018.1 highlights that 'val' variables should have 'final' modifier #469

Open TechPriest-alpha opened 6 years ago

TechPriest-alpha commented 6 years ago

Short description

After upgrade to IntelliJ 2018.1 and latest Lombok Plugin available from plugin repository I'm getting IDE highlights on variables marked with 'val', that they don't have 'final' modifier (IDEA inspection 'Local variable or parameter can be final').

Expected behavior

No variable highlighting and IDE correctly reads 'val' as having 'final' modifier.

Version information

Steps to reproduce

  1. Enable inspection 'Local variable or parameter can be final' in IDE
  2. Create Java class with any method containing something like val x = new Object();
  3. IDE highlights variable 'x' as not having 'final' modifier. (See also attached screenshot) valissue example

Sample project

Please provide a sample project that exhibits the problem. You should also include .idea folder so we can inspect the settings.

cazacugmihai commented 6 years ago

Check this.

TechPriest-alpha commented 6 years ago

Thanks for the suggestion, but unfortunately it didn't help. Original problem remains: IDEA still displays same highlights for plugin installed from disk. 'Invalidate caches & Restart' after plugin re-install didn't help either.

Just to clarify: there are neither compilation problems, nor any errors when working with vals in code. Just false-positive warnings from IDE about missing finals.

MaximilianWiedemann commented 6 years ago

I experience the same problem. Unfortunately, this also leads to other problems when using lombok's val in combination with other plugins like "SaveActions" that seem to rely on the suggestions offered by IntelliJ. Since the 2018.1 update, SaveActions automatically applies the final keyword before val which was definitely not the case before.

kossmoboleat commented 6 years ago

Surprisingly this seems to be a problem in Intellij's inspection which ignores how this plugin "fakes" the final keyword:

https://youtrack.jetbrains.com/issue/IDEA-182740

TechPriest-alpha commented 6 years ago

That's indeed surprising! Thank you @kossmoboleat :) As suggested in referenced IDEA issue: disabling "Report variables which are implicit final" under "Local variable or parameter can be final" seems to solve problem.

I'd leave this ticket open for awhile just in case there is possible workaround on lombok plugin side (comment from plugin maintainers will be really appreciated). If there is no way to update plugin's behavior to work with new IDEA API, then it would OK to close this issue I think.

kossmoboleat commented 6 years ago

Yes, the workaround seems to work for the inspection, but it doesn't for usage in combination with the "save actions" plugin, because that one doesn't seem to respect the checkmark.

Also by using this workaround, we're then not getting the correct the correct inspection result for that try-with-resources case mentioned in the youtrack issue. I wrote there again, but I'm also not that knowledgeable if the check I proposed there is the way to go.

kossmoboleat commented 6 years ago

@mplushnikov What do you think is the best course of action here? Should we ask the Jetbrains developer to add a new API for this?

It seems to me that one would a new access to the final modifier because the implicit modifier is either ignored in the default setting or it isn't and the linked resource case isn't properly handled.

kossmoboleat commented 6 years ago

@mplushnikov Any new thoughts on this?

mplushnikov commented 6 years ago

@kossmoboleat Nothing special at the moment, just only asked @akozlova about new extension point...

kossmoboleat commented 6 years ago

@mplushnikov Ok, the Intellij developer requires some feedback before she continues: https://youtrack.jetbrains.com/issue/IDEA-182740

kossmoboleat commented 5 years ago

@mplushnikov, can you please answer @akozlova on youtrack?

mplushnikov commented 5 years ago

@kossmoboleat I'm very sorry, answered the question only now. There is a lot of work family man:(