Open liufuyang opened 9 months ago
@mpalat could you please assign this ticket to me ?
@mpalat could you please assign this ticket to me ?
Manoj is on leave - there you have it assigned to you
Preliminary analysis
package test;
import java.util.function.*;
public class C {
public void execute(){
int j=1;
a();
Function<String,String> f1=s1 -> "good";
int i1=0;
sam();
}
}
The above code, line No 6, I have added an ExpressionStatement(expression as a MethodInvocation) and which is an undeclared method a()
. Also added another undeclared method sam()
in line No 9. The CU will generate the same what I have added in the test code. Please see the screenshot(same code in Eclipse)
The IDE is showing errors on lines 6 and 9, as both a()
and sam()
are undeclared, which is expected.
package test;
import java.util.function.*;
public class C {
public void execute(){
int j=1;
a;
Function<String,String> f1=s1 -> "good";
int i1=0;
sam();
}
}
Here, line No 6 is an ExpressionStatement with expression as an Assessment). The CU will generate the below code
package test;
import java.util.function.*;
public class C {
public void execute(){
int j=1;
a=$missing$;
Function<String,String> f1=s1 -> "good";
}
}
In line No6, the Assessment of the ExpressionStatement is incomplete( that is the main reason a;
is replaced with a=$missing$;
(Please refer he below screenshot). I assume this is because the SimpleName of the Assessment's RIGHT_HAND_SIDE does not have a valid value.
Additionally, as reported by @liufuyang , the nodes after the lambda have been omitted by the parser.
The error message in the line No 9 has gone. I don't know which is related to the same issue or not. @mpalat could you please share your thoughts ?
@subyssurendran666 the issue is due to a recovered parse tree from the compilation.
@liufuyang Your input is a code that has compiler errors - which essentially means that your parse tree will be based on error recovery of the compiler. That implies that the structure of the parse-tree may have some constructs missed. You should check whether the code is malformed or not by using code similar to as shown below:
""" MethodDeclaration method = (MethodDeclaration) node; if ((method.getFlags() & ASTNode.MALFORMED) != 0) {.... """
The issue is best to explained with an running code sample here:
The output is:
Note that the expected element of
i1
in the compilationUnit print or visit print is missing.Expected output should be like:
Note that this expected output can be seem by simply switching the line of
to
I would assume that it should not make any differences for the
ASTParser
when the lambda expression is written ass1 -> "good"
ors1 -> {return "good";}
?Thank you.