Bug 106814 - [code manipulation] 'Add import' leaves '.' before type name
Summary: [code manipulation] 'Add import' leaves '.' before type name
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Martin Aeschlimann CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-12 01:56 EDT by Mike Grigorov CLA Friend
Modified: 2005-09-02 09:44 EDT (History)
3 users (show)

See Also:


Attachments
patch on AddImportsOperation.java (633 bytes, patch)
2005-08-17 09:16 EDT, Martin Aeschlimann CLA Friend
no flags Details | Diff
patch on AddImportTest.java (1.97 KB, patch)
2005-08-17 09:16 EDT, Martin Aeschlimann CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Grigorov CLA Friend 2005-08-12 01:56:21 EDT
Build id: I20050627-1435
Does not happen always, seps are like this:
1. Type a class name within method body and hit Ctrl + Space to resolve class -
this adds fully qualified class since auto imports are disabled. 
2. Type '.' and access a field. Code looks like this:
  com.some.util.TypeDocs.SALES_MEMO
3. Hit Ctrl+Shif+M to add import. Import is added, but the dot before class name
remains and must be removed  manually. Code is like this: 
  .TypeDocs.SALES_MEMO
Comment 1 Dani Megert CLA Friend 2005-08-12 05:53:11 EDT
Simple test case:
type: java.util.Data<CTRL+SHIFT+M>

It works if there's no compile error, e.g. java.util Date d;

Tom, please investigate. If the fix is simple I'd like to backport this to 3.1.1.
Comment 2 Tom Hofmann CLA Friend 2005-08-15 11:01:01 EDT
OrganizeImports is jdt-ui.

I see two different scenarios (| denotes the caret, press Ctrl+Shift+M):

A) type import does not work with compile error:

public class Test {
    Object m() {
        return java.util.Collections|
    }
}

-> adds type import, leaves the leading dot (works with trailing semicolon)

B) static import on field does not work with compile error:

public class Test {
    Object m() {
        return java.util.Collections.EMPTY_LIST|
    }
}

-> does not add static import for field (works with trailing semicolon)

C) bogus import behavior for class literal:

public class Test {
    Object m() {
        return java.util.Collections.class|;
    }
}

-> type gets removed, leading dot remains, no import added
Comment 3 Dirk Baeumer CLA Friend 2005-08-17 05:38:40 EDT
Martin, can you please comment.
Comment 4 Martin Aeschlimann CLA Friend 2005-08-17 09:16:13 EDT
Created attachment 26193 [details]
patch on AddImportsOperation.java
Comment 5 Martin Aeschlimann CLA Friend 2005-08-17 09:16:50 EDT
Created attachment 26194 [details]
patch on AddImportTest.java
Comment 6 Martin Aeschlimann CLA Friend 2005-08-17 09:19:09 EDT
patches are for the orginal problem (comment 2, problem A).
B is as intended, we need the AST here for static imports.
C should be looked at. Suggest to file a different bug.

patch would be a 3.1.1 candidate.
Comment 7 Martin Aeschlimann CLA Friend 2005-08-17 09:21:27 EDT
fixes released in 3.2 HEAD
Comment 8 Tom Hofmann CLA Friend 2005-08-17 09:33:32 EDT
(In reply to comment #6)
> C should be looked at. Suggest to file a different bug.

bug 107206
Comment 9 Dirk Baeumer CLA Friend 2005-08-17 14:05:35 EDT
Patch looks OK to me. Approved for 3.1.1 (used to work in 3.0.2).
Comment 10 Martin Aeschlimann CLA Friend 2005-08-18 04:03:36 EDT
Tom, can you do the second review?
Comment 11 Tom Hofmann CLA Friend 2005-08-18 06:08:36 EDT
Patch looks good - ok.
Comment 12 Martin Aeschlimann CLA Friend 2005-08-18 06:27:15 EDT
fix released in 3.1.1  > 20050818
Comment 13 Dani Megert CLA Friend 2005-09-02 08:56:19 EDT
Start verification...
Comment 14 Dani Megert CLA Friend 2005-09-02 09:44:12 EDT
Verified using M20050831-1200.