Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 387696

Summary: Quick Fix for Null Type Safety and Code Formatter
Product: [Eclipse Project] JDT Reporter: Robert Kish <robert.kish>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad, mateusz.matela, stephan.herrmann
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Robert Kish CLA 2012-08-21 10:24:58 EDT
1. Should quick fix place the @NonNull annotation before a method's scope declaration so that code formatting places it one per line (by default) with other annotations on the method?

    @NonNull
    @Deprecated
    public String getX() {
        return x;
    }

This is summarized as "Is Quick Fix wrong?"

2. Or should there be an option to (not) Insert new line after annotation on return values of methods.


Current Eclipse formatting:

    @Deprecated
    public @NonNull
    String getX() {
        return x;
    }

vs:

Desired Eclipse formatting:

    @Deprecated
    public @NonNull String getX() {
        return x;
    }

This is summarized as "Do we want more formatting options?"


From all of the examples I've seen, I'm more included to believe we just want more formatting options.
Comment 1 Deepak Azad CLA 2012-08-21 22:34:28 EDT
(In reply to comment #0)
>     @Deprecated
>     public @NonNull String getX() {
>         return x;
>     }

Yeah, even I prefer this style (since the annotation really modifies the return type), but don't think Eclipse formatter does that... at least not by default.
Comment 2 Eclipse Genie CLA 2020-01-09 15:38:44 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Stephan Herrmann CLA 2020-01-09 16:08:57 EST
When using TYPE_USE annotations, the quick fix "Change return type of getX() to '@NonNull String'" already uses the correct position for insertion.

If the annotation is placed after the visibility modifier, also the formatter get's it right.

Just an annotation with no preceding modifier still causes an undesired line break.

@Mateusz, is it possible for the formatter to detect TYPE_USE annotations, and always avoid a line break between annotation and type?
Comment 4 Mateusz Matela CLA 2020-01-11 16:59:05 EST
(In reply to Stephan Herrmann from comment #3)

So for a code like this?
	@Deprecated
	@NonNull
	String getX() {
		return x;
	}
It's not possible to know if the annotations are associated with the whole method or just the return type.

There's a simple workaround - add explicit "default" modifier.

The original report was about a more obvious case, which is no longer a problem, so I would close as worksforme :)