Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-core-dev] Possible bug in Binding2JavaModel.findCompilationUnit()

I may have found a bug in

  Binding2JavaModel.findCompilationUnit(ITypeBinding, IJavaProject)

For the code sequence

ICompilationUnit  cu     = <refers to "Test.java">;
MethodDeclaration decl   = <refers to X.foo()>;
ASTNode           parent = decl.getParent();
TypeDeclaration   type   = (TypeDeclaration) parent;
ICompilationUnit  declUnit =
  Binding2JavaModel.findCompilationUnit(type.resolveBinding(),
                                        fCu.getJavaProject());

when run in the context of the following *single* compilation unit,
findCompilationUnit() returns null. Note the non-public top-level class,
which the Eclipse Java compiler handles properly, but which I suspect
is the cause of the problem. I verified in the debugger the claims given
in <>'s regarding the nature of the entities to which cu and decl refer.

public class Test {
  public static void main(String[] args) {
    String s = (String) new X().foo();
  }
}

class X {
  public Object foo() { return new String(); }
}

I don't think findCompilationUnit() should be returning null in this case.
Am I wrong in thinking that?  If I am wrong, how can I find the compilation
unit containing such a class?

===================================================
Dr. Robert M. Fuhrer, rfuhrer@xxxxxxxxxxxxxx
IBM T.J. Watson Research Center


Back to the top