Bug 123522 - @SuppressWarnings("unused") does not suppress "unused import" warning
Summary: @SuppressWarnings("unused") does not suppress "unused import" warning
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 124697 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-01-11 18:42 EST by Gary Horen CLA
Modified: 2006-02-21 01:13 EST (History)
5 users (show)

See Also:


Attachments
Patch for Annotation (1.29 KB, patch)
2006-01-19 07:55 EST, Philipe Mulet CLA
no flags Details | Diff
Patch for comment 10 scenario (1.07 KB, patch)
2006-01-19 17:11 EST, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Horen CLA 2006-01-11 18:42:55 EST
when placed on the class declaration, and it can't be moved above the import statement. For generated code, this can be a big distraction. (You can't move the annotation above the import statement.) Repro case:


import java.io.InputStream;

@SuppressWarnings("unused")
public class Quack {

}
Comment 1 Gary Horen CLA 2006-01-11 19:01:52 EST
Can't place the annotation in package-info.java either. 
Comment 2 Olivier Thomann CLA 2006-01-11 19:04:52 EST
If this bothers you so much, why don't you run "Organize imports"? <g>
Comment 3 Gary Horen CLA 2006-01-11 19:10:00 EST
Well, yes if there was a user writing the file, who would hit Ctl Shift O that would be an option. But this is happening in generated code. And correcting their modeling in the generation logic to only import used types (at this point) is non-trivial. The end-user's organize-import gesture, if used in this case, would be overlaid in short order by the next dispatch of APT ...:)
Comment 4 Philipe Mulet CLA 2006-01-12 06:42:46 EST
@SuppressWarnings will never be able to address this, as it only acts on nested code. The only alternative would be to introduce another tag // $NO_WARN$ when generating the code, but I suspect it is as doable as having the generator not produce the offending import statement.

I don't see us taking any action here. Pls reopen if you disagree.
Comment 5 Philipe Mulet CLA 2006-01-19 07:33:32 EST
I wonder if we couldn't treat import warnings as being part of the first type... it would change things a little bit, but likely for the best in the end.

Note that using a single-type import, and targeting a deprecated type, the same symptoms can be reproduced with javac.

------------ X.java
import p.A;
@SuppressWarnings("all")
public class X {
	void foo(A a) {
	}
}
------------ p/A.java
package p;
/** @deprecated */
public class A {	
}	
------------
javac says:

X.java:1: warning: [deprecation] p.A in p has been deprecated
import p.A;
         ^
X.java:5: warning: [deprecation] p.A in p has been deprecated
        void foo(A a) {

The second warning feels a bug, as it should have been suppressed.

Comment 6 Philipe Mulet CLA 2006-01-19 07:52:19 EST
Added disabled test: AnnotationTest#test185.
Comment 7 Philipe Mulet CLA 2006-01-19 07:55:41 EST
Created attachment 33266 [details]
Patch for Annotation

Patch spanning the scope of @SuppressWarnings for first type declaration from beginning of unit to end of type (as opposed to from type start only).

Note: it works for any sort of warnings: i.e. deprecation, raw type ref, unused imports
Comment 8 Philipe Mulet CLA 2006-01-19 07:57:14 EST
Should we consider this for inclusion for 3.2 ?
Comment 9 Martin Aeschlimann CLA 2006-01-19 09:32:43 EST
I think that makes sense.
Comment 10 Marcelo Paternostro CLA 2006-01-19 12:34:37 EST
Just addding another scenario that may be considerig when working on this issue:

1. Using M4, create a Java file, and use a deprecated class (IDOMNode for example)
=> Both the import and the line that uses the class should have the deprecation warning

2. Deprecate the class you've just created
=> The import has the deprecation warning

IMHO, I think the warning at the import should go away so that the Java file itself is not "yellow" marked.
Comment 11 Philipe Mulet CLA 2006-01-19 16:25:24 EST
Good point, it should also be handled in a similar fashion for consistency purpose.
Comment 12 Gary Horen CLA 2006-01-19 16:42:45 EST
+1 for 3.2. This makes it a lot easier for people who generate java code (things like annotation processors and wsdl compilers for example), who otherwise will either spend a lot of energy generating warning-free code, or pollute the user experience with unnecessary warnings.
Comment 13 Philipe Mulet CLA 2006-01-19 16:44:56 EST
Ok, if we have consensus, I will reopen it and apply the patch.
I will try to also solve the case in comment 10.
Comment 14 Philipe Mulet CLA 2006-01-19 17:11:22 EST
Created attachment 33308 [details]
Patch for comment 10 scenario
Comment 15 Philipe Mulet CLA 2006-01-19 17:19:57 EST
Enabled AnnotationTest#test185.
Added DeprecatedTest#test010 + variant with @Deprecated as AnnotationTest#test187 (but this one doesn't yet work with patch yet due to a separate issue in @Deprecated early resolution, see bug 124346).
Comment 16 Philipe Mulet CLA 2006-01-20 03:32:41 EST
Fixed
Comment 17 Olivier Thomann CLA 2006-01-20 15:22:52 EST
*** Bug 124697 has been marked as a duplicate of this bug. ***
Comment 18 Jerome Lanneluc CLA 2006-02-15 06:53:58 EST
Verified for 3.2 M5 using build I20060215-0010
Comment 19 Frederic Fusier CLA 2006-02-16 10:43:42 EST
*** Bug 124697 has been marked as a duplicate of this bug. ***
Comment 20 Marcelo Paternostro CLA 2006-02-21 01:13:41 EST
Verified in M5. Thx for the fix.