Bug 132576

Summary: Default package has no subpackages
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: 3.3 RC4   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 125486    

Description Markus Keller CLA 2006-03-20 13:38:01 EST
I20060315-1200

The IPackageFragment of a default package should always answer false to #hasSubpackages(). See JLS3 7.4.2: "Note that an unnamed package cannot have subpackages, since the syntax of a package declaration always includes a reference to a named top level package."

Currently, it returns true if the package fragment root has packages other than the default.
Comment 1 Jerome Lanneluc CLA 2007-06-21 11:44:55 EDT
Unfortunately, the spec for IPackageFragment#hasSubpackages() is slightly different. It says that it "returns whether this package fragment's name is a prefix of other package fragments in this package fragment's root".
Since the name of the default package fragment is "", it is always a prefix of any other package fragment's name (if any).
This cannot be changed without breaking the IPackageFragment's spec.
Comment 2 Victor Toni CLA 2007-06-21 12:03:35 EDT
(In reply to comment #1)
> Since the name of the default package fragment is "", it is always a prefix of
> any other package fragment's name (if any).

I disagree since packages have a separator which is ".". If other packages should be treated as subpackages of "" their names should be something like ".my.own.subpackage" which is not a valid package name.
Comment 3 Jerome Lanneluc CLA 2007-06-21 12:12:34 EDT
(In reply to comment #2)
> I disagree since packages have a separator which is ".". If other packages
> should be treated as subpackages of "" their names should be something like
> ".my.own.subpackage" which is not a valid package name.
Yes, this is what JLS3 7.4.2 says. However IPackageFragment#hasSubpackages() is not compatible with JLS3 7.4.2 (since it is using the word 'prefix' and an empty string is always a prefix of any string).
So if you wish, you can enter a feature request to ask for a new API that corresponds to JLS3 7.4.2.