Community
Participate
Working Groups
public static void main(String[] args) { (A) int calculate = calculate(new IntSupplier() { @Override public int getAsInt() { return 10 * 20; } }); (B) int calc = calculate(new IntSup()); } public static int calculate(IntSupplier supplier) { return supplier.getAsInt() * 2; } private static class IntSup implements IntSupplier { @Override public int getAsInt() { return 10 * 20; } } In the above code if i try to evaluate line (A) i get a evaluation error, but if i try to evaluate line (B) it evaluates without any issues. We need to add support for evaluating expressions with anonymous classes. May be the fix for this code can be used to solve the https://bugs.eclipse.org/bugs/show_bug.cgi?id=448473 issue as well with a workaround solution.
If someone can work on this, we can guide and review. We have lot of inputs in Bug 448473 to start with. I am occupied with Java 13 work and will not be able to work on this right now.
@Sarika Seems like the evaluation engine receiving a wrong snippet because of this method implementation. org.eclipse.jdt.internal.debug.eval.ast.engine.EvaluationSourceGenerator.getCompleteSnippet(String) But trying to hack it and get it to return the correct snippet cause two new errors that the evaluation cannot have anonymous classes and evaluations cannot have constructor calls of local types. Anonymous classes are written to disc as class files, right? Why the ASTEngine cannot load those class byte code?
I looked a bit more and found that in org.eclipse.jdt.internal.debug.eval.ast.engine.ASTInstructionCompiler.visit(ClassInstanceCreation) we skip the anonymous class creations. I think the reason is this anonymous class is not yet loaded into the debugging VM. For this do we need to take the same approach that the RemoteEvaluator has taken? Or can we just load the anonymous class bytes with a random class name and rewrite the expression with that class name. If so how to do this rewrite operation? any hints?
(In reply to Gayan Perera from comment #3) > I looked a bit more and found that in > org.eclipse.jdt.internal.debug.eval.ast.engine.ASTInstructionCompiler. > visit(ClassInstanceCreation) we skip the anonymous class creations. I think > the reason is this anonymous class is not yet loaded into the debugging VM. > > For this do we need to take the same approach that the RemoteEvaluator has > taken? Or can we just load the anonymous class bytes with a random class > name and rewrite the expression with that class name. If so how to do this > rewrite operation? any hints? RemoteEvaluator approach might be better in this case.
I tried, but seems like i need to catch up lot on the internal working of debugger and how the remote evaluator supposed to work. Seems like it lot to take with the limited help i can get from the JDT members :(.
I tried again, i think i found out how the remote evaluator works like in the movie "A Beautiful Mind" :). I got it working for anonymous classes the evaluation and instructions are correctly getting executed with the remote evaluator. But i'm missing the return statement of the complete snippet which is generated from org.eclipse.jdt.internal.debug.eval.ast.engine.EvaluationSourceGenerator.getCompleteSnippet(String). seems like it is hard to change this method with the way it has been written. because a inner class is a complex structure. Is there a way i can create a AST tree for the selected source text and traverse that and complete the statement to a compilable one ?
(In reply to Gayan Perera from comment #6) > I tried again, i think i found out how the remote evaluator works like in > the movie "A Beautiful Mind" :). I got it working for anonymous classes the > evaluation and instructions are correctly getting executed with the remote > evaluator. But i'm missing the return statement of the complete snippet > which is generated from > org.eclipse.jdt.internal.debug.eval.ast.engine.EvaluationSourceGenerator. > getCompleteSnippet(String). > > seems like it is hard to change this method with the way it has been > written. because a inner class is a complex structure. Is there a way i can > create a AST tree for the selected source text and traverse that and > complete the statement to a compilable one ? You mean, you want to enhance "getCompleteSnippet" for inner class ?
@Sarika yes, today the getCompleteSnippet doesn’t support anonymous classes declarations at all. It tries to insert the return statement prematurely. I tried to fix it but with the current algorithm its hard to get the context of the code block. If we can create a small syntax tree it will be very much easy and simpler. But I’m not sure if it is possible to create a syntax tree for adhoc statement. At least that was the initial thought i have. Please let me know how we should handle this ?
We should and an entry to N&N also, Thanks Gayan!
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/165846
Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/165762 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=4a8e32b644a5768610a9f6b9c8fcfadabfa07232
Gayan can you add the entry in N&N?
Already added
(In reply to Gayan Perera from comment #13) > Already added Where is it? Can't see the gerrit and the content? https://www.eclipse.org/eclipse/news/4.17/jdt.php#Debug
@Sarika the Gerrit is not approved on eclipse news repo. The gerrit is there in this issue.
Gerrit change https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/165846 was merged to [master]. Commit: http://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=e8aeef472d36e3ed486dc25045634389a16ef27e