Bug 357471

Summary: ASTParser cannot resolve binding of PackageDeclaration if class name is equal to the first segment of the package name
Product: [Eclipse Project] JDT Reporter: Missing name Mising name <hjs.becker>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, srikanth_sankaran
Version: 3.8   
Target Milestone: 3.8 M3   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Patch v1 none

Description Missing name Mising name CLA 2011-09-13 07:39:46 EDT
Build Identifier: I20110613-1736

We have the following example:

package one.two;
public class one {
}

We use the ASTParser to get the AST of the code.
The binding of the PackageDeclaration 'package one.two;' is null, but the binding of the QualifiedName 'one.two' is the correct package binding.
Furthermore, if we have this case, then in any other compilation unit contained in the same package, the binding of the PackageDeclaration is null. 

Reproducible: Always

Steps to Reproduce:
1. Create a Java class 'one' in the package 'one.two'.
2. Use the ASTView to get the AST of this class.
3. Look at the binding of the PackageDeclaration. It is null.
4. Look at the binding of the QualifiedName 'one.two'. It is the expected package binding.
Comment 1 Olivier Thomann CLA 2011-09-13 09:53:02 EDT
I'll take a look.
Comment 2 Olivier Thomann CLA 2011-09-13 14:13:34 EDT
Created attachment 203277 [details]
Patch v1
Comment 3 Olivier Thomann CLA 2011-09-13 14:15:54 EDT
Could you please give it a try ?
Comment 4 Missing name Mising name CLA 2011-09-13 16:01:27 EDT
The patch works perfectly. The bindings of the PackageDeclarations can now be resolved.
Comment 5 Olivier Thomann CLA 2011-09-14 13:57:07 EDT
Since the call to org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(char[][]) with "one.two" as the name doesn't work when resolved in the context of the package "one.two" (it considers that one is the type inside the package instead of the package 'one' itself), I suggest to add a method that retrieves packages only.

Srikanth, please let me know what you think. I found quite weird that getPackage(..) doesn't do the job, but trying to change it is causing more trouble.
Comment 6 Olivier Thomann CLA 2011-09-20 09:40:49 EDT
Released for 3.8M3.
Comment 7 Srikanth Sankaran CLA 2011-10-24 20:15:10 EDT
Fix verified by reporter via comment#4. (In reply to comment #5)

> Srikanth, please let me know what you think. I found quite weird that
> getPackage(..) doesn't do the job, but trying to change it is causing more
> trouble.

Agree with the approach.

VERIFIED for 3.8 M3.