-
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
MessageSend incorrectly uses "ThisReference" as receiver for static imports and methods from enclosing classes #515
Comments
As you found the correct location inside the parser, you halfway answered this yourself: this is the parser, which has no idea, whether the target method is static or not. Later, when the method is resolved, it is not a good idea to invent synthetic AST to represent the static receiver. Couldn't you infer all the information you need from the resolved As for BTW: You are referring to the internal compiler AST (which is not API), but I thought spoon uses the public DOM AST? |
Is there any specific reason? I was planning (and do) just that in my PR. I currently insert a fake type referene / this reference where appropriate. It felt nicer than having a wrong
I suppose so. I currently check whether I had just hoped I could circumvent doing all of this myself, as this is yet another hack on the pile of JDT-workarounds. I understand why your parser isn't happy to disambiguate that and it seems like later stages don't really care about the AST layout and clean things up themselves when needed (once, for codegen).
I wish. I have never looked at the official API, so I can't say much about it. Last I heard the public API did not provide all the necessary information to construct a usable Spoon-AST. Spoon is very often used without large chunks of the classpath and tries to build a usable AST with quite a lot of information. Maybe that has changed by now, but this decision was made over a decade before I became affiliated with the project (or started Programming) :) |
@I-Al-Istannen it's been a while since. Is this issue still relevant for you, or is accessing such information from bindings rather than AST a viable option for you? I.e., can we close this issue? :) |
I don't remember what we did for this to be honest, it truly has been a while. Looking at the linked issue past-me said he hacked around this on the spoon side. I sadly don't particularly trust that guy, but let's take his word. I think we can close this :) |
Hey,
I am trying to accurately model static imports and ran into a problem. Consider the following code:
The
entrypoint
method contains four method calls without an explicit receiver.Currently JDT sets it to
ThisReferene
in every call:IMHO the receiver should differ:
entrypoint()
the correct receiver isThisReference
outerMethod()
the correct receiver is the implicit instance bound by the non-static inner class. This should probably be modeled as an implicit qualified this reference?staticOuterMethod()
the correct receiver isTest
lineSeparator()
the correct receiver isjava.lang.System
Additionally,
receiver.isImplicitThis()
returns true in all of these cases.As far as I can see this is intentional but I don't understand why this decision was made. It looks wrong to me?
eclipse.jdt.core/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
Line 5585 in 3515713
The text was updated successfully, but these errors were encountered: