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

Bug 375263

Summary: [Java formatter enhancement] - Different new line behavior if an annotation is places after modifiers
Product: [Eclipse Project] JDT Reporter: sinuhe pop <sinuhepop>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: VERIFIED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: manoj.palat, mateusz.matela
Version: 3.8   
Target Milestone: 4.18 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description sinuhe pop CLA 2012-03-24 21:04:05 EDT
Build Identifier: 


I usually prefer simple annotations on fields being inlined:

    @Autowired private Repository<Student> studentRepository;


But some annotations look better with new line after each:

    @Size(min = 1, max = 3)
    @ManyToMany
    @JoinTable(name = "CUST_PHONE",
        joinColumns = @JoinColumn(name = "CUST_ID", referencedColumnName = "ID"),
        inverseJoinColumns = @JoinColumn(name = "PHONE_ID", referencedColumnName = "ID")
    )
    public Set<PhoneNumber> getPhones() { return phones; }


So, I thought that an easy way of having both configurations at the same time is a different behavior (no new line) if annotation is after modifiers, for example:

    private @Autowired Repository<Student> teacherRepository;


This could be configurable, but IMHO this would be the default behaviour, because a new line in this case is specially ugly:

    private @Autowired 
    Repository<Student> teacherRepository;


Same behavior could be applied on methods and types too.

Reproducible: Always
Comment 1 Michal Politowski CLA 2014-03-18 08:15:10 EDT
Too bad this idea would not work well with the terribly underused default (no modifier) visibility.

But some way to have the formatter allow both inlined and newline-separated field annotations in the same codebase would be great.
Comment 2 Mateusz Matela CLA 2020-10-12 15:59:54 EDT
An annotation after other modifiers is considered a type annotation, there's a separate setting for that.

*** This bug has been marked as a duplicate of bug 425040 ***
Comment 3 Manoj N Palat CLA 2020-11-18 02:23:22 EST
Verified for Eclipse 4.18 M3 Version: 2020-12 (4.18) with Build id: I20201117-0600