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

Bug 475282

Summary: Luna QuickFix does not insert first import statement into correct location.
Product: [Eclipse Project] JDT Reporter: Alex Pogrebnyak <alex-pub.eclipse>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact: Manoj N Palat <manoj.palat>
Severity: normal    
Priority: P3 CC: jarthana, manoj.palat
Version: 4.5   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard: stalebug

Description Alex Pogrebnyak CLA 2015-08-18 13:44:52 EDT
Create this class foo/bar/Foo.java

===============
package foo.bar

/**
 * Copyright notice
 */

import java.util.List;

public class Foo
{
  List list;
}
===============

Save file.

Now add reference to java.util.Calendar

===============
package foo.bar

/**
 * Copyright notice
 */

import java.util.List;

public class Foo
{
  Calendar calendar;
  List list;
}
===============

Eclipse correctly highlights error on a new line.
Now QuickFix the calendar reference by accepting 'Import Calendar (java.util)'.

BUG -> new import statement appears before Copyright notice.

===============
package foo.bar

import java.util.Calendar;

/**
 * Copyright notice
 */

import java.util.List;

public class Foo
{
  Calendar calendar;
  List list;
}
=============

This behavior is new to Luna.  Previously used Eclipse version (Kepler), inserted new import line right before 'import java.util.List;' statement.

BTW, I do understand that it is not easy to find a correct place for the Only and First import statement, and for this, appending it after 'package' statement is as good default as any other.  However, when there are already existing imports in the file, QuickFix should pay attention to where they start.

This may be linked to issue with Cleanup eagerly removing first import statement -> https://bugs.eclipse.org/bugs/show_bug.cgi?id=475281
Comment 1 Jay Arthanareeswaran CLA 2015-08-20 02:02:39 EDT
I can see the bug in Mars M2 as well.
Comment 2 Eclipse Genie CLA 2019-11-01 02:46:36 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.