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

Bug 326065

Summary: [quick assist] refactoring String concatenation to MessageFormat/StringBuilder gives up on unparenthesised number arithmetic
Product: [Eclipse Project] JDT Reporter: Oisín Mac Fhearaí <denpashogai>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: enhancement    
Priority: P3 CC: deepakazad
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

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 :)