Bug 192497 - Cannot always find method definition, depending on cursor position
Summary: Cannot always find method definition, depending on cursor position
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3.1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-13 13:29 EDT by Koen van Dijken CLA
Modified: 2008-09-16 06:00 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix (2.26 KB, patch)
2007-06-14 09:17 EDT, David Audel CLA
no flags Details | Diff
Proposed patch for 3.3.1 (2.18 KB, patch)
2007-07-03 09:30 EDT, David Audel CLA
no flags Details | Diff
Proposed patch for 3.3.1 (2.18 KB, patch)
2007-07-03 09:31 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Koen van Dijken CLA 2007-06-13 13:29:51 EDT
Build ID: 3.3RC4 I20070608-1718

In the following piece of code:

public class Test {

	void doLoad() {
		
	}
	
	void call() {
		doLoad();
	}
}


1. place the cursor on the call to doLoad() between the 'd' and the 'o'
2. press F3
3. The definition of doLoad is not found, an error message appears 'Current text selection does not resolve to a Java element'
4. any other position of the cursor and pressing F3 succeeds in locating the definition of doLoad()
Comment 1 Martin Aeschlimann CLA 2007-06-14 03:33:24 EDT
reproduced in 3.3 RC4.
ICompilationUnit.codeResolve is called with the offset 'o' in doLoad();. No result returned.
Comment 2 David Audel CLA 2007-06-14 09:12:48 EDT
This is a regression added by the fix for bug 161400.
The problem is caused by SelectionEngine#checkSelection().

To reproduce the problem the cursor must be inside an identifier. A part of the identifier must correspond to a keyword and the cursor must be just before the last character of the keyword.

eg.
d|oLoad
fo|rmat

This is not a common case but this is a regression. We should fix this bug for 3.3.1.
Comment 3 David Audel CLA 2007-06-14 09:17:05 EDT
Created attachment 71305 [details]
Proposed fix

checkSelection() must scan from the beginning of the line to the end of the source instead of from the beginning of the line to the cursor location.
Comment 4 David Audel CLA 2007-06-27 09:44:15 EDT
Released for 3.4M1.

Test added:
  ResolveTests#testSelectOnCursor1()

I will prepare a patch for 3.3.1.
Comment 5 David Audel CLA 2007-07-03 09:30:23 EDT
Created attachment 72945 [details]
Proposed patch for 3.3.1

The bug is a regression and the fix isn't risky.
With this patch checkSelection() the end position of the scanner is set to the end of the source file instead of to the cursor position to be able to fully scan the selected token.
Only the first token is scanned so move the end position won't have impact on performance.
Comment 6 David Audel CLA 2007-07-03 09:31:19 EDT
Created attachment 72946 [details]
Proposed patch for 3.3.1

The bug is a regression and the fix isn't risky.
With this patch checkSelection() the end position of the scanner is set to the end of the source file instead of to the cursor position to be able to fully scan the selected token.
Only the first token is scanned so move the end position won't have impact on performance.
Comment 7 Jerome Lanneluc CLA 2007-07-03 09:43:08 EDT
+1 for 3.3.1
Comment 8 David Audel CLA 2007-07-03 09:48:31 EDT
Released for 3.3.1

Test added:
  ResolveTests#testSelectOnCursor1()
Comment 9 Frederic Fusier CLA 2007-08-03 08:41:34 EDT
Verified for 3.4M1 using build I20070802-0800.
Comment 10 Jerome Lanneluc CLA 2007-09-03 07:41:37 EDT
Verified for 3.3.1 using M20070831-2000