-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve MethodBinding$LambdaMethod to LambdaMethod java element #2124
Resolve MethodBinding$LambdaMethod to LambdaMethod java element #2124
Conversation
Note that while it improves things, the case of eg test0027 is not resolved by that case. |
I have looked at the case of test0027, and it looks to me that for this case, the issue is not really the Binding -> JavaElement resolution (which may be fixed with this patch), but more that the DefaultBindingResolver only inserts 1 of the LambdaMethod/LambdaExpression couple in the bindingToASTNodes map instead of the 3 ones existing in the code; line 941 |
93e674e
to
616ecab
Compare
I could fix my patch to also address the concern of former comment. |
616ecab
to
4454920
Compare
4454920
to
628e6e5
Compare
@srikanth-sankaran Can you help with reviewing this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if the test should be in ASTConverter18Tests or perhaps an additional test. There you can call JavaElement.toStringWithAncestors(false) to verify the hierarchy.
// resolving all parent lambdas is necessary for proper resolution | ||
// as it populates newAstToOldAst. | ||
ASTNode current = domNode; | ||
while (current != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be done every time or can it be done once and then marked as completed or can the LambdaFactory LambdaMethod be cached to avoid this in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage of this method is relatively sporadic (happens only when user Ctrl+clicks it at the moment) and execution remains relatively fast. On the other hand, the DOM may be retained for a long time, so adding some cache here increase memory consumption.
Overall, I think it's best to not cache and keep more memory free for that case. We can easily revisit later if my impressions are proven wrong though.
This looks very close/similar to https://bugs.eclipse.org/bugs/show_bug.cgi?id=573834 - Need to check why that solution is not covering this case. There also code selection is involved |
The previous patch doesn't involve the DOM nor its bindings. It fixes the SelectionEngine and the SelectionParser , which are not involved when building a DOM. |
Correct, I realized that as started reviewing. |
"Unexpected elements", | ||
"abc [in doit(I) [in <lambda #1> [in doit(I) [in <lambda #1> [in doit(I) [in <lambda #1> [in main(String[]) [in X [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]]]]]]]", | ||
new IJavaElement[] { javaElement } | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At every level lambda ordinal is 1 - is that right ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a similar assertion that's implemented in test0027, with 1
being the ordinal on every level (unlike anonymous which have an ordinal based on the including type because it's used to generate the .class, lambdas do not generate a .class and thus ordinal seems only relative to the direct parent)
There appears to be a serious pre-existing defect in What I am wondering is: org.eclipse.jdt.core.dom.DefaultBindingResolver.getBindingsToNodesMap().new BindingsToNodesMap() {...}.get(Binding) takes a compiler binding as argument and does this with it:
Now
(call stack while debugging your new test) I am wondering if the fix should really belong in the WDYT ? |
OK, I am closing shop for the week, I'll continue to look at this early next week. Just fixing the above bug doesn't change much, but I would still like to discuss what is the impact of such glaringly defective code: If I change it to:
it starts returning the mapping properly although in the context of this bug, it doesn't change much. Still I wonder if the fix should perhaps belong in the Will study more early next week |
Amazingly that code dates back 15 years. Someone please tell me I misunderstood it! 😆 |
I will try to investigate further later today or early next week. But 1 particular issue I've found is that the "parent" lambda bindings are not included in the maps unless we do explicitly call Note that the bug about the requested type in the map was made visible with #1617 (comment) some time ago. |
@stephan-herrmann Take a bow! 😊 This is the third whopper of a bug I find in the past 6 weeks. For the last week's entry see the most recent change to org.eclipse.jdt.internal.compiler.codegen.CodeStream.invoke(byte, MethodBinding, TypeBinding, TypeReference[]) But usually these nasty bugs will manifest in corner case situations. This one seems very broken. How do things work ?? 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the pre-existing issue point out already, this looks ok. I haven't worked in these parts in almost 10 years - I must state that too :)
As the patch is approved and covered with test - merging. |
Fixes #2047
What it does
Fixes the resolution of Binding->JavaElement for lambda methods: now returns a LambdaMethod Java Element as expected by eg
codeSelect
in test0024 instead of returning the binding of the overridden method.How to test
Run new test with or without fix.
Author checklist