Bug 103377 - [refactoring] PromoteTempToField doesn't properly set the type and the modifiers of the resulting variable declaration statement
Summary: [refactoring] PromoteTempToField doesn't properly set the type and the modifi...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.1.1   Edit
Assignee: Markus Keller CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
: 101980 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-07-11 15:36 EDT by Olivier Thomann CLA Friend
Modified: 2005-09-02 12:13 EDT (History)
4 users (show)

See Also:


Attachments
Proposed fix (1.46 KB, patch)
2005-07-11 15:38 EDT, Olivier Thomann CLA Friend
no flags Details | Diff
Proposed fix (1.58 KB, patch)
2005-07-11 15:58 EDT, Olivier Thomann CLA Friend
no flags Details | Diff
Proposed fix (3.70 KB, patch)
2005-07-11 16:22 EDT, Olivier Thomann CLA Friend
no flags Details | Diff
Regression test (2.78 KB, patch)
2005-07-11 16:24 EDT, Olivier Thomann CLA Friend
no flags Details | Diff
Improved Fix (2.35 KB, patch)
2005-08-04 13:17 EDT, Markus Keller CLA Friend
no flags Details | Diff
Tests for improved fix (7.45 KB, patch)
2005-08-04 13:18 EDT, Markus Keller CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA Friend 2005-07-11 15:36:21 EDT
If you change the getType() of VariableDeclarationStatement class to return
double instead of int, three tests are failing in
org.eclipse.jdt.ui.tests.refactoring.PromoteTempToFieldTests.
They are test8, test13 and test15 (existing tests in 3.1).
Three new tests are also failing.
testMultiVariableDeclFragment01, testMultiVariableDeclFragment02,
testMultiVariableDeclFragment03.
These tests are new since 3.1 is out.

The problem comes from the fact that the type of the variable declaration
statement is not set. So a default type (int) is retrieved. I will attach a
patch for it.
This would be a candidate for 3.1.1.
Comment 1 Olivier Thomann CLA Friend 2005-07-11 15:38:33 EDT
Created attachment 24563 [details]
Proposed fix

This patch is based on 3.1 maintenance stream. Apply on jdt.ui project.
Comment 2 Olivier Thomann CLA Friend 2005-07-11 15:41:01 EDT
It is important to keep all tests clean at any time or create branch for each
test suite based on 3.1. Otherwise it is difficult to find out why tests are
failing after changes. I don't release code if I find a "potential" regression
and I thought this was a regression coming from my changes.
Comment 3 Olivier Thomann CLA Friend 2005-07-11 15:58:47 EDT
Created attachment 24568 [details]
Proposed fix

New patch that also preserves the existing modifiers of the multiple local
declaration. That declaration can potentially have modifiers (like final or an
annotation). They must be preserve after the promotion.
New tests would need to be added to the 3.1.1 stream.
I can provide a patch for an updated test that has been added post 3.1.
Comment 4 Olivier Thomann CLA Friend 2005-07-11 16:19:33 EDT
Current code doesn't support annotation among the modifiers.
I will provide a new patch for this.
Comment 5 Olivier Thomann CLA Friend 2005-07-11 16:22:13 EDT
Created attachment 24572 [details]
Proposed fix

With this patch the formatting of the modifiers is not preserved, but at least
existing annotations are preserved as well as existing modifiers.
This patch needs to be reviewed and all existing tests run.
Comment 6 Olivier Thomann CLA Friend 2005-07-11 16:24:37 EDT
Created attachment 24573 [details]
Regression test

Regression test based on HEAD contents because there is no branch for jdt/ui
refactoring tests.
Comment 7 Olivier Thomann CLA Friend 2005-07-11 16:25:54 EDT
Update title according to latest comments.
Comment 8 Dirk Baeumer CLA Friend 2005-07-11 16:44:16 EDT
Olivier, it would be really helpful to understand what JDT/Core changes in 3.1.1
so that JDT/UI has to fix this. I discussed this with Philippe and we agreed
that fixes that break JDT/UI tests even if there is a bug in JDT/UI should be
treated special

Very likely a dup of 101980.

We are shipping with this quite a while and we should be really careful about
what goes into 3.1.1 and what not.

Can you please comment on why this is critical from your point of view.
Comment 9 Olivier Thomann CLA Friend 2005-07-11 16:52:22 EDT
Yes, this seems to be a dup of bug 101980 for half of it.
We didn't change anything in core that broke this. This is broken for a while
and I think it should be fixed, because this refactoring is useless without a
good support for multiple local declarations.
As soon as you want to promote a local within a multiple local declaration to a
field, the type for remaining locals is set to int. Pretty annoying.
I would vote to get this fix for 3.1.1 since the fix is trivial as described in
bug 101980.
101980 covers only the type issue whereas this bug also refers to an issue with
the modifiers. The modifiers are simply removed.
Comment 10 Olivier Thomann CLA Friend 2005-07-11 16:59:45 EDT
Also I don't like the fact that existing tests are based on the fact that int is
returned as the type of a variable declaration statement when none is specified.
Comment 11 Philipe Mulet CLA Friend 2005-07-12 04:53:44 EDT
+1 for 3.1.1
Comment 12 Philipe Mulet CLA Friend 2005-07-12 05:51:22 EDT
Olivier - pls can you explain exactly why this is critical ? Your first comment
says that "If you change the getType() of VariableDeclarationStatement"; but are
we changing it in 3.1.1 ?
Comment 13 Dirk Baeumer CLA Friend 2005-07-12 06:00:32 EDT
Markus, can you please investigate and see how it relates to bug 101980. Can you
please check what the problem with the modifiers is that Olivier is referring to.

Why are the new tests failing in HEAD. Bug 101980 got fixed there and therefore
the HEAD test cases shouldn't fail anymore.

Olivier, when you run the HEAD test cases did you have HEAD from JDT/UI also ?
Comment 14 Olivier Thomann CLA Friend 2005-07-12 09:33:09 EDT
No, I don't have JDT/UI from HEAD. I have the contents of the 3.1 maintenance
branch. But I took the tests from HEAD since there is no 3.1 maintenance branch
for the tests.
Comment 15 Olivier Thomann CLA Friend 2005-07-12 09:35:22 EDT
(In reply to comment #12)
> Olivier - pls can you explain exactly why this is critical ? Your first comment
> says that "If you change the getType() of VariableDeclarationStatement"; but are
> we changing it in 3.1.1 ?
No, we don't plan to change it. I simply did that to expose the fact that
existing tests rely on this "default" type from being returned when no type has
been set.
I see it as critical because this refactoring without a fix doesn't support
multiple locals propertly. If the type of the local is not int, then the type of
the remaining locals after refactorting is always wrong.
The existing modifiers are also not preserved.

Comment 16 Markus Keller CLA Friend 2005-07-12 10:00:32 EDT
Bug 101980 was only about the return type. That one is already fixed in HEAD.
With HEAD, tests (including new tests for bug 101980) don't fail any more when
changing the default type in VariableDeclarationStatement.

Nothing has been released to R3_1_maintenance so far, but the branch is there
for jdt.ui, jdt.ui.tests, and jdt.ui.tests.refactoring.

The bug is not critical (no crash, loss of data, etc.), but I agree that it
should be fixed in 3.1.1. I'll fix it in HEAD and then attach patches for 3.1.1
here. Dirk, please approve for 3.1.1.
Comment 17 Markus Keller CLA Friend 2005-07-12 10:02:01 EDT
*** Bug 101980 has been marked as a duplicate of this bug. ***
Comment 18 Dirk Baeumer CLA Friend 2005-07-12 10:24:44 EDT
+1 for 3.1.1
Comment 19 Markus Keller CLA Friend 2005-08-04 13:17:27 EDT
Created attachment 25695 [details]
Improved Fix

This fix retains formatting/comments in the modifiers list.
Comment 20 Markus Keller CLA Friend 2005-08-04 13:18:14 EDT
Created attachment 25696 [details]
Tests for improved fix
Comment 21 Markus Keller CLA Friend 2005-08-04 13:28:57 EDT
Released fix to HEAD.
Comment 22 Dirk Baeumer CLA Friend 2005-08-08 06:27:40 EDT
Patch looks fine for me.

Martin, can you please do a review as well.
Comment 23 Martin Aeschlimann CLA Friend 2005-08-09 03:25:42 EDT
Patch looks fine for me.
Comment 24 Markus Keller CLA Friend 2005-08-10 14:34:55 EDT
Released Improved Fix to R3_1_Maintenance.
Comment 25 Dirk Baeumer CLA Friend 2005-09-02 12:02:18 EDT
start verifying...
Comment 26 Dirk Baeumer CLA Friend 2005-09-02 12:13:31 EDT
Verified the the type and modifiers are correctly preserved for single and multi
variable declarations.

Verified on M20050831-1200 and plug-in export.