Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 123529 - Trying to get the corresponding IMethodBinding for an IMethod seems to be broken
Summary: Trying to get the corresponding IMethodBinding for an IMethod seems to be broken
Status: RESOLVED DUPLICATE of bug 99137
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-11 19:32 EST by Thomas Cook CLA
Modified: 2006-01-27 14:04 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Cook CLA 2006-01-11 19:32:24 EST
To reproduce this problem, write some code that:
1.  Finds a particular IMethod that has both non-primitive parameters and a non-void, non-primitive return type.
2.  Using the binding key from the IMethod, try to get the corresponding IMethodBinding, using something like this:

        IMethod method = findSomeMethod();

        try {
            keys = new String[] { method.getKey() };
        }
        catch (JavaModelException jme) {}
       
        final BindingRequestor requestor = new BindingRequestor();
        final ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setResolveBindings(true);
        parser.setProject(method.getJavaProject());

        // this doesn’t really do a parse; it’s a type lookup
        parser.createASTs(new ICompilationUnit[] {}, keys, requestor, null);
        return requestor._result;

where BindingRequestor looks like this:

        class BindingRequestor extends ASTRequestor {
            private IMethodBinding _result = null;

            public void acceptBinding(String bindingKey, IBinding binding) {
                if (_result == null && binding != null && binding.getKind() == IBinding.METHOD)
                _result = (IMethodBinding) binding;
            }
        }


Expected: requestor._result contains the IMethodBinding that corresponds to the IMethod

Actual: you get the ITypeBinding for the class containing the method.  On closer inspection this seems to happen because the key from the IMethod does not match the key in the IMethodBinding.  If you tweak the key in a debugger to match, the code works.  Seems like the key for the IMethod is not correctly generated.

This looks like it might be similar to https://bugs.eclipse.org/bugs/show_bug.cgi?id=99137 but I'm not sure it's the same issue.
Comment 1 Olivier Thomann CLA 2006-01-27 14:04:41 EST

*** This bug has been marked as a duplicate of 99137 ***