Bug 357471 - ASTParser cannot resolve binding of PackageDeclaration if class name is equal to the first segment of the package name
Summary: ASTParser cannot resolve binding of PackageDeclaration if class name is equal...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.8 M3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-13 07:39 EDT by Missing name Mising name CLA
Modified: 2011-10-24 20:15 EDT (History)
2 users (show)

See Also:


Attachments
Patch v1 (6.38 KB, patch)
2011-09-13 14:13 EDT, Olivier Thomann CLA
no flags Details | Diff

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