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

Bug 311283

Summary: [navigation] Open Declaration should work like hyperlink in .java file not on classpath
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: TextAssignee: Raksha Vasisht <raksha.vasisht>
Status: VERIFIED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: daniel_megert, deepakazad
Version: 3.4   
Target Milestone: 3.7 M1   
Hardware: All   
OS: All   
Whiteboard:

Description Markus Keller CLA 2010-05-01 10:17:58 EDT
I20100429-1549

Open Declaration (F3) should work like hyperlink (Ctrl+click) in a .java file that is not on the classpath.

Use case: I have SWT from CVS, and I'm in Control.java from another platform. Ctrl+click works perfectly for members that are declared in the same file, and it works reasonably well when I Ctrl+click other references (only opens types that are on the classpath, but that's OK and expected).

F3 always shows a 'Cannot Perform Operation' dialog, which is unnecessary, since the implementation in the hyperlink could and should be used.
Comment 1 Dani Megert CLA 2010-05-02 02:40:51 EDT
Like that since 3.4.

We have bug 78522 for a command that does the same as hyperlinking. Regarding F3, we should leave it as is i.e. show the dialog and not the lightweight chooser. But of course I agree that functionality wise it should do the same.
Comment 2 Dani Megert CLA 2010-06-08 06:29:49 EDT
Test Case:
1. create a Java project with 'src' as source folder (default out of the box)
2. create file 'Test.java' in the project (not in 'src' folder) with this: 
import java.util.HashMap;

public class Test {

	void foo() {
		bar();
	}

	private void bar() {
		HashMap m= new HashMap();
		m.isEmpty();
	}
}
==> Ctrl+click works on "bar" inside 'foo', on "HashMap" and on "isEmpty" but F3 does not.


NOTE: It does work for Ctrl+click and F3 in the following example:
1. create a Java project with the project itself as the source folder
2. create file 'Test.java' in the project's '.settings' folder with this:
import java.util.HashMap;

public class Test {

	void foo() {
		bar();
	}

	private void bar() {
		HashMap m= new HashMap();
		m.isEmpty();
	}
}
Comment 3 Raksha Vasisht CLA 2010-06-08 06:39:36 EDT
Example :

//File aaaa.java
package p;
public class aaaa {
	public   aaaa(){            
		aaaa a = new aaaa();     
		a.toString();
		zoo z= new zoo();
		z.foo();
	}		
	@Override
	public String toString(){  
		return "hi"; 		   
	}
}

// File zoo.java
package p;
public class zoo {
	public void foo() {
		
	}
}

1) Create a new Java Project Test, paste the 2 files into the src folder .
2) Now remove src from build path. (Right click on Src Build Path -> Remove from Build Path
3) Ctrl+click on a.toString() -> works as normal
F3 -> gives an error : Cannot Perform Operation : The resource is not on the build path of a Java project.

4) Ctrl+click on zoo -> no hyperlink 
F3 -> gives the same error as (3)

I looked into the code to fix step (3)(declaration in same class) , that should adopt the same logic as hyperlink and jump to the appropriate declaration but do we continue to show the error dialog for f3 in step(4) or is there anything else we want to do?
Comment 4 Dani Megert CLA 2010-06-08 06:52:43 EDT
>F3 -> gives the same error as (3)
Yes of course and this is acceptable as Markus already wrote in comment 0:
>Ctrl+click works perfectly for members that are declared in the same file, and
>it works reasonably well when I Ctrl+click other references (only opens types
>that are on the classpath, but that's OK and expected).
Comment 5 Dani Megert CLA 2010-06-08 06:54:05 EDT
We only want to fix the test case from comment 2.
Comment 6 Raksha Vasisht CLA 2010-06-17 14:44:27 EDT
Fixed in HEAD.

 (In reply to comment #4)
> >F3 -> gives the same error as (3)
> Yes of course and this is acceptable as Markus already wrote in comment 0:
> >Ctrl+click works perfectly for members that are declared in the same file, and
> >it works reasonably well when I Ctrl+click other references (only opens types
> >that are on the classpath, but that's OK and expected).

We continue to show the error dialog in case of step 4 (outside references).
Comment 7 Raksha Vasisht CLA 2010-06-18 06:18:26 EDT
(In reply to comment #6)
> Fixed in HEAD.
Fixed in org.eclipse.jdt.ui.actions.OpenAction.
Comment 8 Deepak Azad CLA 2010-08-03 03:00:13 EDT
Verified with I20100802-1800 on Ubuntu.