Bug 39468

Summary: IJavaElement#getJavaProject() returns wrong project (external JARs are shared in multiple classpaths)
Product: [Eclipse Project] JDT Reporter: Lars Ködderitzsch <rookie_no2>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, dirk_baeumer, klaus.heywinkel, M8R-sgiphk, markus.kell.r
Version: 2.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 319294, 100488, 347128    
Attachments:
Description Flags
Proposed patch none

Description Lars Ködderitzsch CLA 2003-06-30 05:17:02 EDT
Hi,

I am writing a plugin that allows the user to select a certain java element 
(IType, IClassFile, ICompilationUnit) and and invoke an action to create a 
patchfile for the selected element.
The patchfile should be written to the (or one of the) source folder of the 
project "the selected element comes from".
To find out this project I need to call IJavaElement.getJavaProject().

When this java element comes from an external archive AND the same archive is 
used in more than one open project in the workspace IJavaElement.
getJavaProject() can return the wrong project - depending on the order these 
projects were opened.

I believe this behaviour may be "by design", to optimize the underlying java 
model to hold the contents of the archive only once.
But there should be a way to safely determine, from which project the selected 
java element exactly came from.
Comment 1 Philipe Mulet CLA 2003-06-30 05:57:09 EDT
Your assumption is the right one. This is a performance issue.
The user selection should tell you the proper project context.
Comment 2 Lars Ködderitzsch CLA 2003-06-30 06:27:47 EDT
Given an IStructuredSelection in my action object, how does this selection 
reveal me the proper project context?
The only thing in this selection object is the selected element itself...


Regards,
Lars
Comment 3 Philipe Mulet CLA 2003-07-03 07:22:11 EDT
Moving to JDT/UI, they probably know the answer.
Comment 4 Dirk Baeumer CLA 2003-07-13 10:49:46 EDT
No, JDT/UI has the same problem. We don't have "proper project context" either 
since selections are managed by JFace.

Moving back to JDT/Core.
Comment 5 Lars Ködderitzsch CLA 2003-07-14 02:29:57 EDT
Hi all,

seems like there is more interest in this request than just mine.
I would propose that selections in trees lead to a specialized 
IStructuredSelection, which would allow to navigate the selection path
(maybe similar to javax.swing.tree.TreePath).
That would perfectly fit my needs and probably the needs of JDT/UI as well.

Will some of you support a feature request?

Regards,
Lars
Comment 6 Jerome Lanneluc CLA 2003-12-18 10:29:01 EST
Created attachment 7225 [details]
Proposed patch

Changing equals(...) on PackageFragmentRoot and JarPackageFragmentRoot to also
consider the parent. However the element info is still shared, the key being
the package fragment root's path.
Comment 7 Philipe Mulet CLA 2005-04-07 07:34:57 EDT
Deferring post 3.1
Comment 8 Eclipse Webmaster CLA 2009-08-30 02:38:03 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.
Comment 9 Markus Keller CLA 2010-07-19 12:09:49 EDT
*** Bug 162037 has been marked as a duplicate of this bug. ***