Bug 39468 - IJavaElement#getJavaProject() returns wrong project (external JARs are shared in multiple classpaths)
Summary: IJavaElement#getJavaProject() returns wrong project (external JARs are shared...
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 162037 (view as bug list)
Depends on:
Blocks: 319294 100488 347128
  Show dependency tree
 
Reported: 2003-06-30 05:17 EDT by Lars Ködderitzsch CLA
Modified: 2011-05-25 11:48 EDT (History)
5 users (show)

See Also:


Attachments
Proposed patch (4.34 KB, patch)
2003-12-18 10:29 EST, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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. ***