Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 326065 - [quick assist] refactoring String concatenation to MessageFormat/StringBuilder gives up on unparenthesised number arithmetic
Summary: [quick assist] refactoring String concatenation to MessageFormat/StringBuilde...
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows Vista
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-23 10:38 EDT by Oisín Mac Fhearaí CLA
Modified: 2010-09-25 13:45 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oisín Mac Fhearaí CLA 2010-09-23 10:38:04 EDT
Build Identifier: 20100218-1602

The "Use 'MessageFormat' for string concatenation" option given by Quick Fix in the context of a string concatenation with the + operator will give up if it encounters unparenthesised numeric arithmetic.
It's a good idea to parenthesise such expressions anyway, but it would be nice if the case was handled transparently.

Reproducible: Always

Steps to Reproduce:
1. Write: String test = "hello " + 4*2 + "a " + 3 + " c" + 4;
2. Put the cursor at the start of the string (or somewhere where the Quick Fix expects it) and open the quick fix menu (ctrl+1)
3. Select "Use 'MessageFormat' for string concatenation" (or StringBuilder)

Expected result:

MessageFormat.format("hello {0}a {1} c{2}", 4*2, 3, 4)

Actual result:

MessageFormat.format("{0}{1}", "hello " + 4*2 + "a " + 3 + " c", 4)

Workaround: Parenthesise the problem expression.

String test2 = "hello " + (4*2) + "a " + 3 + " c" + 4;
Comment 1 Deepak Azad CLA 2010-09-23 10:58:14 EDT
(In reply to comment #0)
> Build Identifier: 20100218-1602

This works with the latest release Eclipse 3.6 - http://download.eclipse.org/eclipse/downloads/drops/R-3.6-201006080911/index.php . Can you please try with the this.

Closing as WORKSFORME.
Comment 2 Oisín Mac Fhearaí CLA 2010-09-25 13:45:32 EDT
(In reply to comment #1)
> (In reply to comment #0)
> > Build Identifier: 20100218-1602
> 
> This works with the latest release Eclipse 3.6 -
> http://download.eclipse.org/eclipse/downloads/drops/R-3.6-201006080911/index.php
> . Can you please try with the this.
> 
> Closing as WORKSFORME.

Hi,

You're right, it's fixed indeed. Thanks :)