Community
Participate
Working Groups
Steps to reproduce: 1. Invoke "Inline" on "m" in code below 2. The resulting file cannot be compiled ("The left-hand side of an assignment must be a variable") class InlineLocalVariableBug1 { void f() { // Invoke "Inline..." on "m" result in "new int[10][0] = 0;" int[] m = new int[10]; m[0] = 0; } }
The issue is reproducible. The refactoring results in compiler error.
Created attachment 236120 [details] bug fix + unit test This contribution complies with http://www.eclipse.org/legal/CoO.php
(In reply to Nikolay Metchev from comment #2) > Created attachment 236120 [details] [diff] > bug fix + unit test > > This contribution complies with http://www.eclipse.org/legal/CoO.php The fix should go in org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker.needsParentheses(Expression expression, ASTNode parent, StructuralPropertyDescriptor locationInParent, ITypeBinding leftOperandType) which is already invoked in InlineTempRefactoring, and so that the issue is handled everywhere (example: (new int[10])[0] = 0; should not suggest the quick assist to remove parentheses i.e. "Remove extra parentheses"). Also, make sure that extra parentheses are not added when the array creation expr has initializer. Add test case for the same. Verify that it is fixed for InlineConstantRefactoring also.
Created attachment 249595 [details] bug fix + unit test This contribution complies with http://www.eclipse.org/legal/CoO.php Thanks Noopur, I have incorporated your suggestions. Just to let you know that test_29 and test_30 cover the case where the array creation has an initializer, so I didn't add a duplicate test.
(In reply to Nikolay Metchev from comment #4) > Created attachment 249595 [details] [diff] > bug fix + unit test > > This contribution complies with http://www.eclipse.org/legal/CoO.php Fixed copyright and contributors list, inlined the new method and released with: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=0501a95fb1ec44c661d81f4d2740f27ae93fe234