Open PavelTurk opened 4 months ago
Try Editor / Formatting / Language: Java / Category: Wrapping
and change the value of Annotations
from Always
to Never
. Does this work for you? Annotations is one area I find the automatic formatting settings to be a problem by default, partly because they're not contextual.
@neilcsmith-net I tried you suggestion. This is source code:
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NewClass {
private @Nullable List<String> foos;
public @NotNull String doItNow() {
return null;
}
}
And this is the result code:
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NewClass {
private @Nullable List<String> foos;
public @NotNull
String doItNow() {
return null;
}
}
As you see it worked for field, but not for method
Yes, can reproduce. Seems to be OK for method and method parameter annotations, but not on the return type. That definitely seems to be a bug. Then there's an open question about what the default should be.
Apache NetBeans version
Apache NetBeans 22
What happened
NB formats code in a wrong way when annotation is used for function return type.
Language / Project Type / NetBeans Component
Java Maven Project using Java Modules (JPMS)
How to reproduce
Create NewClass:
And press ALT + SHIFT + F to format the code. You will get this result:
The same happens for class fields:
Did this work correctly in an earlier version?
No / Don't know
Operating System
Ubuntu 20.04.3 LTS
JDK
Java: 21.0.2; OpenJDK 64-Bit Server VM 21.0.2+13-58
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
No response
Are you willing to submit a pull request?
No