This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 104757 - Formatting option: treat @Override as a modifier
Summary: Formatting option: treat @Override as a modifier
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker with 1 vote (vote)
Assignee: Dusan Balek
URL:
Keywords:
: 117934 (view as bug list)
Depends on: 211037
Blocks:
  Show dependency tree
 
Reported: 2007-05-24 18:37 UTC by Jesse Glick
Modified: 2012-04-11 17:45 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Proposed fix (3.87 KB, patch)
2011-06-28 20:09 UTC, Jesse Glick
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2007-05-24 18:37:57 UTC
I like the idea of the "Add Override Annotation" hint, but I never use it (I
type in the annotation by hand) because I don't like the resulting formatting.
It is only a historical accident that @Override is an annotation rather than
part of the Java language syntax. (In C# it is a keyword.) I would prefer it to
be treated as a modifier, e.g.:

protected @Override void setUp() throws Exception {...}

However there is no such formatting option available.
Comment 1 Jesse Glick 2007-10-12 16:04:33 UTC
*** Issue 117934 has been marked as a duplicate of this issue. ***
Comment 2 Jesse Glick 2007-10-23 17:45:01 UTC
Worse, if you by hand write

    protected @Override void initialize() {
        super.initialize();
    }

and reformat, you get

    protected @Override
    void initialize() {
        super.initialize();
    }

which looks silly.
Comment 3 Jesse Glick 2011-06-28 18:56:37 UTC
    @Override protected void initialize() {
        super.initialize();
    }

works a bit better; at least Reformat will not touch this (unless Wrapping on Annotations is set to Always). However code generation will create

    @Override
    protected void initialize() {
        super.initialize();
    }

and Reformat will not fix it.
Comment 4 Jesse Glick 2011-06-28 19:44:36 UTC
(In reply to comment #3)
> code generation will create

ImplementOverrideMethodGenerator I guess. Not sure how to fix that.

> Reformat will not fix it.

This part I can fix.
Comment 5 Jesse Glick 2011-06-28 20:09:09 UTC
Created attachment 109154 [details]
Proposed fix

This patch implements inline @Override unconditionally; not sure if it should rather be an option?
Comment 6 Jesse Glick 2011-07-05 19:59:42 UTC
There are certain other annotations, such as @CheckForNull, which are used as type qualifiers on methods and fields and so ought to be formatted inline as well, since they logically belong right next to the type. Not sure how to distinguish these from annotations such as @SuppressWarnings or @Deprecated which semantically apply to the entire member; could hardcode a list of them, or check for @TypeQualifier or @TypeQualifierNickname.

(Certainly if the annotation follows an access modifier then we know inline formatting is appropriate, but this will not help in the case of package-private members.)
Comment 7 Quality Engineering 2011-10-26 14:24:29 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/4f3760d0cbb1
User: Jesse Glick <jglick@netbeans.org>
Log: @Override was getting reformatted badly (see #104757).