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

Bug 102658

Summary: [refactoring] Moving classes to diff pkg breaks JSPs w/ * imports
Product: [WebTools] WTP Source Editing Reporter: Mark Sederqvist <ms>
Component: jst.jspAssignee: Ian Tewksbury <itewksbu>
Status: CLOSED DUPLICATE QA Contact: Nitin Dahyabhai <thatnitind>
Severity: normal    
Priority: P2 CC: itewksbu, nsand.dev
Version: 1.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Mark Sederqvist CLA 2005-07-04 11:03:59 EDT
When classes are moved between packages, the JSP page imports are not updated 
accordingly which breaks the JSPs.
Comment 1 David Williams CLA 2005-07-06 13:10:48 EDT
Phil, do we get "refactoring events" for these?
Comment 2 Phillip Avery CLA 2005-07-11 16:28:29 EDT
This should be working.  We definitely get refactoring events for this
(if invoked from the refactoring wizard or dnd from package explorer).

May be related to occurrences in file not working either.
Raising priority since it's important to have this working for 0.7.
Comment 3 Phillip Avery CLA 2005-07-11 17:08:11 EDT
This works for me when I test it so that brings up a couple questions:

 - what type of project are you in (java, web, simple...)?
 - how did you invoke the "move"? (dnd, refactoring dialog...)
 - how did you create the project (import, from scratch...)

It also might be possible that the JSP core plugin wasn't started when you
imported your files... which would cause the JSPs to not be indexed, so they
would be ignored by refactoring/search operations.
Comment 4 Mark Sederqvist CLA 2005-07-12 05:44:34 EDT
Sorry for the lack of specifics. I am running integration build I20050527-1300.

Also, the problem only occurs when the JSP import directive does not explicitly 
mention the class, but instead imports a whole package using '*' wildcard. 
Moving a class to a new package fails to update the import directive. It works 
when the import directive specifies the class name.

The error is recreated quite easily by creating a new J2EE web project, writing 
a class, writing a JSP that imports the class' package (using page import 
directive with wildcard, like <%@ page import="mypackage.*" %>) and then moving 
the class to another package using the 'refactor' menu.
Comment 5 Phillip Avery CLA 2005-07-12 10:35:37 EDT
Ah that makes sense then. Thanks for the details.

We're not handling this case.

The way refactoring currently works is we do a search for the Java element that
moved, then update the package if it's fully qualified (in an import or in the
file).

We currenly don't keep track of if the import "*" is linked to the refactored
Java element.

There would have to be some logic added...
 
Here are the scenarios that I can think of for handling "*" imports during
refactoring:

 - if there's 1 class from the imported package in the JSP, we would just update 
   that import

 - if there's 2 classes from the same package in the JSP, we would have to add 
   an aditional import, and leave the original
 
 - if the import came from an included file, that might make it more complicated

We would need to use not expensive way to find the import associated with the
moved Java element when it's not fully qualified in the file, and we would need
to know if the import "*" covers other classes in the JSP.

Maybe we should just start by adding another import statement (if it doesn't
exist already) which would usually be the case if someone uses import "*" (they
want to cover more than one class).

I don't think we'll be able to cover this for 0.7, but I at least wanted to
write some ideas down.
Comment 6 Phillip Avery CLA 2005-07-12 10:38:02 EDT
modifying abstract.
Comment 7 Mark Sederqvist CLA 2005-07-12 12:17:53 EDT
Just adding another import statement would be a good enough fix for us for the 
time being. The fact that refactoring breaks JSPs is a far worse issue than a 
few overlapping import statements.
Comment 8 Phillip Avery CLA 2005-07-14 14:48:00 EDT
Moving to M8 in light of other bugs.
Comment 9 David Williams CLA 2005-09-22 23:16:41 EDT
Part of a mass update. Based on 9/22/2005 development review meeting, it's 
determined this was an open bug/enhancement with tartget mistakenly set to M8. 
Since this will not be in M8, I am changing to "unspecified". 

If this is an error, please correct (for example the bug really has been fixed
in M8, change back to M8, and "fixed".)
Comment 10 David Mansfield CLA 2005-11-29 12:11:08 EST
this would be less important if the content-assist would do the imports for you.  since it doesn't, the JSP developer has to manually type the imports.  due to this huge flaw, the developer is more likely to use the * during import, and then get burned again during refactoring.
Comment 11 Phillip Avery CLA 2005-11-29 13:38:42 EST
Raising priortiy to see if we can address this or the content assist bug (auto import) by M10.
Comment 12 David Williams CLA 2006-03-28 02:03:24 EST
Nitin, will you evaluate and make a recommendation for 1.5 stream? 
Comment 13 Ian Tewksbury CLA 2009-12-21 14:52:22 EST
This scenario has been fixed by Bug 164263.
Comment 14 Ian Tewksbury CLA 2009-12-22 09:13:45 EST
This scenario has mostly been fixed by Bug 164263 but duping against Bug 298355 because the scenario there has to do with moving and until its fixed I can't claim that the moving scenarios all work.

*** This bug has been marked as a duplicate of bug 298355 ***