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

Bug 7386

Summary: extract method: problems with bracketed expressions
Product: [Eclipse Project] JDT Reporter: Adam Kiezun <akiezun>
Component: UIAssignee: Dirk Baeumer <dirk_baeumer>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P4 CC: Olivier_Thomann
Version: 2.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Adam Kiezun CLA 2002-01-09 10:24:38 EST
it is not possible to extract:
int f= (/*[*/2/*]*/);

or 

int f= (/*[*/1 + 2/*]*/);

reasons given are different but equally incorrect
Comment 1 Adam Kiezun CLA 2002-01-09 11:41:34 EST
don't know if it is related but you can't extract the following neither:

int u= new A[/*[*/1+ 3/*[*/].length;

however, eveything is fine here:

Object y= new A[/*[*/1+ 3/*]*/];

very weird
Comment 2 Dirk Baeumer CLA 2002-01-25 05:38:35 EST
Regarding 
  int f= (2);

The problem is that the AST node representing the initializtion is an 
IntLiteral including the brackets (meaning spawns the text (2)). Therefore if 
you only select 2, the analyzer doesn't notice that this is actual the int 
literal.

Olivier, can you please comment on this and explain what the new AST will 
provide in this situation. 
Comment 3 Dirk Baeumer CLA 2002-01-25 09:28:07 EST
Fixed the array problem reported by implementing a workaround for bug 8452.
Comment 4 Olivier Thomann CLA 2002-01-29 13:10:11 EST
In fact it would be better to tell me what you want to be able to do and I can 
try to see if this is doable.
I would say that the number literal will include the parenthesis as well. Then 
selecting only the number should lead to the same problem.
What solution do you suggest?
Comment 5 Olivier Thomann CLA 2002-01-29 17:20:04 EST
I checked what the new AST nodes do in this case. The initializer is still (2). 
Then the number '2' doesn't mean anything. It is not a node.
Do you have a proposal to solve this problem?
Comment 6 Olivier Thomann CLA 2002-01-30 18:56:36 EST
This problem is gone with the new AST. (2) would be a parenthesized expression 
containing the int literal. Then you will be able to ask for the 
resolveTypeBinding() of either the parenthesized expression or the inner 
expression (in this case a number literal) and you will get the same binding.

So you will have the fined-grained in this case as long as you select a matching 
number of parenthesis. '(2' and '2)' will fail, but '(2)' or '2' should work.

See ASTConverterTests.test0202/test0203/test0204.
Using a lot of (((((((( can cause a StackOverFlowError in theory.

Is this fine for you?
Comment 7 Dirk Baeumer CLA 2002-01-31 04:50:46 EST
Yes this is absolutely fine with me.
Comment 8 Dirk Baeumer CLA 2002-03-11 11:40:19 EST
Case now work correctly if no comments are specified. Opened another PR for the 
comment case. See http://dev.eclipse.org/bugs/show_bug.cgi?id=11104.

Fixed in build > 20020307.