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

Bug 331111

Summary: [change method signature] leaves unwanted white space between empty parenthesis
Product: [Eclipse Project] JDT Reporter: Rüdiger Herrmann <ruediger.herrmann>
Component: CoreAssignee: Manoj N Palat <manoj.palat>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, markus.kell.r, Olivier_Thomann
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
example project none

Description Rüdiger Herrmann CLA 2010-11-25 06:31:31 EST
Steps to reproduce:
* create a method with one or more arguments like so:
  void foo( Object arg )
* use the Change Method Signature refactoring to remove the argument
- the resulting method is:  
  void foo( )
-> the refactoring leaves a white space character between the opening and closing parenthesis. Expected outcome would be: foo()
The formatter settings are set to have no white space between empty parenthesis.
Comment 1 Markus Keller CLA 2010-11-25 06:42:58 EST
This is a problem in the ASTRewrite. We just call ListRewrite#remove(..) to remove the method parameter.
Comment 2 Markus Keller CLA 2010-11-25 06:48:39 EST
Created attachment 183844 [details]
example project

Project to reproduce.

Code formatter is default Eclipse profile with White Space > Declarations > Methods > 'after opening parenthesis' and 'before closing parenthesis' checked.
Note: If these options are not checked, then it's acceptable for the ASTRewrite to not remove all spaces (since the original code already was formatted correctly).
Comment 3 Olivier Thomann CLA 2010-11-26 09:39:09 EST
Released regression test:
org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingMethodDeclTest#_testListRemoves3

Right now the formatting preferences are not used on remove.
Comment 4 Olivier Thomann CLA 2010-11-26 10:54:55 EST
Ayushman, if you get some time, please take a look.
Comment 5 Ayushman Jain CLA 2010-11-30 06:40:08 EST
Another case that formatter has to cover (from bug 331412)-

* create a method with no arguments like so:
  void foo()
* use the Change Method Signature refactoring to add an argument
* the resulting method is:
  void foo(Object arg)
-> the refactoring does not insert white space characters after opening and
before  closing parenthesis. Expected outcome would be: void foo( Object arg )
The formatter settings are set to have white space after opening parenthesis
and before closing parenthesis.
Comment 6 Ayushman Jain CLA 2010-11-30 06:40:55 EST
*** Bug 331412 has been marked as a duplicate of this bug. ***
Comment 7 Rüdiger Herrmann CLA 2014-10-15 17:12:13 EDT
This bug is really annoying. Maybe someone with JDT insight could help me fix this?
I managed to write a failing test case but now I'm not sure how to proceed.

In ASTRewriteAnalyzer$ListRewriter#rewriteList line 692 the 'end' variable is assigned, but by one too short in this case. Would 'getStartOfNextNode()' be the right place to handle the special-case 'empty list'?

Or should I leave the ASTRewrite as it is and re-format the affected text region when the rewrite was applied? In which case I would welcone hints where and how this should happen?
Comment 8 Markus Keller CLA 2014-10-16 13:32:20 EDT
(In reply to Rüdiger Herrmann from comment #7)
> I managed to write a failing test case but now I'm not sure how to proceed.
We already have a test, see comment 3.

> In ASTRewriteAnalyzer$ListRewriter#rewriteList line 692 the 'end' variable
> is assigned, but by one too short in this case. Would 'getStartOfNextNode()'
> be the right place to handle the special-case 'empty list'?

The fix needs to be somewhere in ASTRewriteAnalyzer#visit(MethodDeclaration) or a method called from there. We wouldn't accept a solution that uses the formatter after the rewrite is done.

I can't give you a definitive answer without investigating and fixing the whole problem, but I think rewriteNodeList and rewriteList don't have enough context to know if the whitespace needs to be removed. The fix will probably go into visit(MethodDeclaration) itself. Since this is a very specific formatter option, you can maybe just read the DefaultCodeFormatterConstants option and then do what's necessary.
Comment 9 Jay Arthanareeswaran CLA 2014-10-17 05:09:43 EDT
Rüdiger, Manoj will help you with review and releasing. But I am not sure how much time he will have, though.
Comment 10 Rüdiger Herrmann CLA 2014-10-21 09:17:59 EDT
(In reply to Jayaprakash Arthanareeswaran from comment #9)
> Rüdiger, Manoj will help you with review and releasing. But I am not sure
> how much time he will have, though.

Thanks for your support. I report here as soon as I have a patch ready. However, it may take a while since I am working on this in my spare time.
Comment 11 Eclipse Genie CLA 2020-02-23 13:07:10 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.