EclipseCodeFormatter
EclipseCodeFormatter copied to clipboard
Methods starting with “when(…)” in test files are left unformatted
Hi.
With 23.4.223.000.0-Eclipse_2023-03
, I run into a strange issue: some methods are just skipped rather than formatted, while the rest of the file is processed just fine, and the conditions for this to happen seem to be:
- Be in a test class rather than a business class. (Edit: This might be a misconception from before I noticed that methods other than
when(…)
worked fine. We don’t use Mockito in business code, so…)
AND
- The first statement of the method, ignoring comments, is an unqualified Mockito
when(…)
call (rather thanMockito.when(…)
).
Adding another statement before the when(…)
, even if it’s just a lone ;
, fixes the issue.
Other methods do not seem to cause this issue; even other Mockito methods like mock()
seem to be OK.
What steps will reproduce the issue?
Somewhere under a Test Sources Root directory, create a file like:
import static org.mockito.Mockito.when;
public class FormatterBug {
void foo() {
when(null);
// Random indentation
// Random indentation
// Random indentation
}
}
What is the expected result?
Something consistent, along the lines of (depending on the config):
import static org.mockito.Mockito.when;
public class FormatterBug {
void foo() {
when(null);
// Random indentation
// Random indentation
// Random indentation
}
}
What happens instead?
The whole method is not formatted, only what surrounds it is. There is no crash though: the formatter looks happy.
Сonsider attaching a screenshot, screencast, or a code sample when it's hard to articulate the problem.
eclipse-adapter-formatter-bug-static.webm
Paste information about IDE and OS (it can be copied from Help | About dialog).
IntelliJ IDEA 2024.1 (Ultimate Edition)
Build #IU-241.14494.240, built on March 28, 2024
Licensed to XXX
Subscription is active until XXX.
Runtime version: 17.0.10+8-b1207.12 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.15.0-107-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 3982M
Cores: 8
Non-Bundled Plugins:
Pythonid (241.14494.314)
EclipseCodeFormatter (23.4.223.000.0-Eclipse_2023-03)
org.asciidoctor.intellij.asciidoc (0.41.14)
com.haulmont.jpab (241.14494.158)
Kotlin: 241.14494.240-IJ
Current Desktop: XFCE