Bug 23052

Summary: DOM - CCE calling resolveBinding on an on-demand import from a type
Product: [Eclipse Project] JDT Reporter: mark_dixon
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0   
Target Milestone: 2.1 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description mark_dixon CLA 2002-08-30 16:24:00 EDT
Running I200208270833

This code
IWorkspace ws = testcasesPlugin.getWorkspace();
IWorkspaceRoot root = ws.getRoot();
IProject project = root.getProjects()[0];
IJavaProject jp = JavaCore.create(project);
		
CompilationUnit cu = AST.parseCompilationUnit(
   "import Class.*; public class Class {}".toCharArray(),
   "Class", jp);
cu.accept(new ASTVisitor() {
   public boolean visit(ImportDeclaration node) {
      try {
         IBinding binding = node.resolveBinding();
      }
      catch (Exception e) {
         System.out.println("Got a " + e.getClass() + ": " + e.getMessage());
      }
      return true;
   }
});

produces the output
Got a class java.lang.ClassCastException: 
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding

I think DefaultBindingResolver.resolveImport() needs to check whether the 
binding returned from getTypeOrPackage() is a type or package and respond 
appropriately.  On-demand imports from types are legal - JLS 7.5.2.

Thanks
Mark
Comment 1 Olivier Thomann CLA 2002-09-03 16:50:24 EDT
Fixed and released in 2.1 stream.
Comment 2 David Audel CLA 2002-09-19 04:47:28 EDT
Verified.
Comment 3 Olivier Thomann CLA 2002-09-19 11:07:17 EDT
Regression test added (test0375)