Bug 83656 - [1.5] Organize Imports is broken for annotations
Summary: [1.5] Organize Imports is broken for annotations
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 84519 (view as bug list)
Depends on: 85115
Blocks:
  Show dependency tree
 
Reported: 2005-01-25 15:54 EST by Jon Nall CLA
Modified: 2005-02-18 04:25 EST (History)
1 user (show)

See Also:


Attachments
Testcase (687 bytes, application/x-gzip)
2005-02-09 14:17 EST, Jon Nall CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Nall CLA 2005-01-25 15:54:40 EST
if i have the following code:
===========================================
@Retention(RetentionPolicy.RUNTIME)
@interface Foo { }
===========================================



and "Organize Imports", the import for java.lang.annotation.RetentionPolicy is
pulled in, but java.lang.annotation.Retention is not and i get a compile error.
the code now looks like:
===========================================
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
@interface Foo { }
===========================================



if i highlight Retention and select "Add Import", the import for
java.lang.annotation.Retention is added correctly and the code compiles:
===========================================
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
@interface Foo { }
===========================================



however if i then select "Organize Imports" option again, the import for
java.lang.annotation.Retention is removed resulting in code with compile errors:
===========================================
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
@interface Foo { }
===========================================

Seems to be a bug in Organize Imports.
Comment 1 Jon Nall CLA 2005-01-28 14:19:11 EST
Changed subject to reflect that the bug is related to new 1.5 features.
Comment 2 Dirk Baeumer CLA 2005-02-03 05:54:06 EST
Jon, which build are you using. 
Comment 3 Martin Aeschlimann CLA 2005-02-03 06:15:20 EST
works in latest (I20050202)
Comment 4 Jon Nall CLA 2005-02-03 08:00:48 EST
I am using 3.1M4.
Comment 5 Jon Nall CLA 2005-02-09 14:17:02 EST
Created attachment 17800 [details]
Testcase
Comment 6 Jon Nall CLA 2005-02-09 14:18:03 EST
This bug is still lingering as of version I20050202-0800. If i annotate an
element in package A with an annotation from package B, and then use "organize
imports" to import the annotation from package B, all is well. however, if
immediately do another "organize imports", the import statement for the
annotation is removed. a third "organize imports" will once again import the
annotation. you can toggle this repeatedly. i'm attaching a testcase. to observe
the bug do the following:

1. import the annotation-test project into eclipse
2. open annotation-test/src/pkg2/Foo.java
3. Note that Foo is annotated with FooAnnotation, but FooAnnotation is not
imported and this causes a compile error
4. Organize imports -- this imports pkg1.FooAnnotation (correct)
5. Organize imports again -- this removes the pkg1.FooAnnotation (incorrect)
6. Organize imports again -- this imports pkg1.FooAnnotation
...

I believe that the behavior observed at step 5 is incorrect and at that point
subsequent "organize import" operations should have no effect.
Comment 7 Martin Aeschlimann CLA 2005-02-13 17:37:13 EST
can you attach the archive (or the single files) again? I can't open it, it
seems to be corrupted.
Comment 8 Martin Aeschlimann CLA 2005-02-13 17:49:47 EST
I found a reproducible case. The bug is in jdt.core. Filed bug 85115 for this.
Comment 9 Olivier Thomann CLA 2005-02-14 22:55:02 EST
*** Bug 84519 has been marked as a duplicate of this bug. ***
Comment 10 Martin Aeschlimann CLA 2005-02-15 04:59:44 EST
fixed in M5
Comment 11 Tobias Widmer CLA 2005-02-18 04:25:11 EST
Verified I20050217-2000