lombok-intellij-plugin icon indicating copy to clipboard operation
lombok-intellij-plugin copied to clipboard

Using val, IDEA breaks and ‘declares final’ any variables

Open brawaru opened this issue 4 years ago • 3 comments

Short description

When using val, IDEA breaks and starts to declare any new variable introduced via postfix-es as ‘final’, no matter whether it comes from lombok or are standard Java variable declarations. Neither val should have choice to ‘Declare [it] final’, because it already does it.

Screenshot of IDEA automatically checking ‘Declare final’ for when value variable (val) created via postfix

Expected behavior

Either IDEA or plugin must respect the project / IDE settings regarding code generation, as well as user's choice to disable final (when user ticks/unticks the ‘Declare final’ in popup). Neither usage of val should break standard IDEA postfix for variables (which respects settings above).

Screenshot of ‘Code generation’ in ‘Code Style’ settings, ‘Make generated local variables final’ is unchecked

Version information

  • IDEA Version: IDEA 2020.3.2
  • JDK Version: AdoptOpenJDK 1.8.0_282
  • OS Type & Version: Windows 10 20H2
  • Lombok Plugin Version: 203.7148.57
  • Lombok Dependency Version: 1.18.18

Steps to reproduce

  1. Have any non-void contents
  2. Introduce a new variable using .var postfix, notice that IDEA respects settings
  3. Undo and introduce a new variable using .val postfix, IDEA declares it final by default.
  4. Undo and introduce a new variable using .varl postfix, result is same as in step 2.
  5. Undo and introduce a new variable using .var postfix again, result is same as in step 2.
  6. Restart IDEA and try step 1 again, IDEA respects settings until you use lombok-related postfix.

Sample project

TestProject.zip

  • [x] Sample project provided
  • [x] I am able to reproduce this error on the sample project by following the steps described above

Additional information

Additional extensions installed: Rider UI Theme Pack, com.intellij.plugins.vscodekeymap, com.wakatime.intellij.plugin, google-java-format, indent-rainbow.indent-rainbow, com.codota.csp.intellij, com.dubreuia, org.sonarlint.idea, com.demonwav.minecraft-dev

Stacktrace

Not applicable.

brawaru avatar Feb 12 '21 17:02 brawaru

+1

ly-chn avatar Sep 09 '21 07:09 ly-chn

Same problem. "someExpression.val (tab)" -> "final val [cursor] = someExpression" The "final" should not be there.

spyro2000 avatar Aug 08 '23 17:08 spyro2000

Until version 2024.1.1, the same problem still exists.... :(

sunxiang0918 avatar May 17 '24 06:05 sunxiang0918