Bug 73961 - IPackageBinding#getName() should return "" for default package
Summary: IPackageBinding#getName() should return "" for default package
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.1 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-15 03:28 EDT by Markus Keller CLA
Modified: 2004-09-23 13:01 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2004-09-15 03:28:52 EDT
The Javadoc of IPackageBinding#getName() says: 
"[..] For unnamed packages, this is a distinctive string
that can be used to refer to this unnamed package (since there
may in fact be multiple unnamed packages). [..]"

How can IPackageBindings refer to different default packages? As I understand
it, an IPackageBinding is a compiler-world notion that only knows one default
package whose contents are based on a java project's buildpath.

Since getName() cannot return different strings, I opt to change the string for
the default package from "UNNAMED" to "". This would match
IPackageFragment#getElementName() and eliminate the need for special code when
comparing an IPackageBinding to an IPackageFragment.
Comment 1 Olivier Thomann CLA 2004-09-16 11:33:02 EDT
This is trivial to change.
Jim, would this be still in line with the specs?
Comment 2 Jim des Rivieres CLA 2004-09-16 12:45:40 EDT
Kent confirms that there are multiple default/unnamed packages at the compiler 
level (each project has its own). This distinction should be visible at the 
DOM binding level as distinct package bindings with distinctive names. That 
way clients can know whether the packages they encounter are from the same or 
different unnamed package. 

So the spec is right, and the implementation has a bug.
Comment 3 Markus Keller CLA 2004-09-16 13:03:22 EDT
Jim: Your argument would also apply to named packages. You can have two package
fragments with the same name in two projects, and there's no API to
differentiate them in the bindings world.

AFAIK, bindings are only defined in the context of one project - and there,
they're unique. The distinction among package fragments from different projects
is only represented in the java model (IJavaElement) world.
Comment 4 Jim des Rivieres CLA 2004-09-16 13:44:51 EDT
Markus, I believe default/unnamed packages are different from named packages.

Here's a case that I thought would show off the difference:
(1) Set up projects P1 and P2 with P2 depending on P1
(2) Foo.java in default/unnamed package of project P1
(3) Bar.java in default/unnamed package of project P2
Code for Bar references Foo (no import).
Bar should not be able to reference Foo. Even though Foo and Bar are both in 
default/unnamed packages, there are considered to be in different ones.

However, when I tried this, it compiled without errors.
Kent, What have I got wrong?
Comment 5 Jim des Rivieres CLA 2004-09-16 14:47:41 EDT
It appears I misunderstood. Markus is correct. The compiler's treatment of 
default/unnamed packages is no different from named packages.

I've changed the spec and implementation for IPackageBinding.getName() to 
always return "" for the unnamed/default package. This API change should not 
break existing clients because the previous spec did not specify what string 
would be returned.

Olivier, I've fixed tests as well and updated build notes.
Comment 6 David Audel CLA 2004-09-23 13:01:11 EDT
Verified in I200409230100.