Fix the step-into target on multi line expression. Fix #519#520
Fix the step-into target on multi line expression. Fix #519#520testforstephen merged 4 commits intomicrosoft:mainfrom
Conversation
|
@testforstephen Let me know if you see a better condition to use in this scenario. |
I don't get how this fix works. When I tested the snippet you posted in the issue #519, the |
Let me check on this, I see the same, probably I missed to commit something |
8db3f21 to
9b60b13
Compare
Try now @testforstephen |
| @Override | ||
| public boolean visit(TypeDeclaration node) { | ||
| return shouldVisitNode(node); | ||
| return unit.getRoot() == node.getRoot() || shouldVisitNode(node); |
There was a problem hiding this comment.
The condition check unit.getRoot() == node.getRoot() is not needed. I tested #519 snippet without this check, it worked.
There was a problem hiding this comment.
For some reason for me it start to fail before in shouldVisitNode the end becomes -1 since the on JDT side the start + length of the node becomes equal to the end of the compilation unit's last position. I will try again without this check.
There was a problem hiding this comment.
OK now I found the reason, if you don't have a empty line at the end of the class, that after the last class definitions' brace, then the end getLineNumber becomes -1
There was a problem hiding this comment.
I can reproduce it, but i would prefer to modify the implementation shouldVisitNode() to fix the problem.
Since the offset range of the ast node is [node.getStartPosition, node.getStartPosition() + node.getLength() - 1], the ending line should be got from unit.getLineNumber(node.getStartPosition() + node.getLength() - 1).
The fix could be as follow:
private boolean shouldVisitNode(ASTNode node) {
int start = unit.getLineNumber(node.getStartPosition());
int end = unit.getLineNumber(node.getStartPosition() + node.getLength() - 1);
if (line >= start && line <= end) {
return true;
}
return false;
}| } | ||
|
|
||
| private boolean isSameLocation(Location original, Location current) { | ||
| private boolean isSameLocation(Location original, Location current, MethodInvocation targetStepIn) { |
There was a problem hiding this comment.
Look at the caller, actually we took the first parameter as current, the second one as original. So we should change the signature definition to private boolean isSameLocation(Location current, Location original, MethodInvocation targetStepIn).
| return originalMethod.equals(currentMethod) | ||
| && original.lineNumber() == current.lineNumber(); | ||
| && (original.lineNumber() == current.lineNumber() | ||
| || (targetStepIn != null && targetStepIn.lineStart > current.lineNumber())); |
There was a problem hiding this comment.
The last condition check should be (targetStepIn != null && targetStepIn.lineEnd >= current.lineNumber()), which supports multiline expression better.
|
I also found another corner case failure when steping target into List.of("1"). new ArrayList<>(List.of("1"))
.subList(0, 1)
.addAll(mergedData());It looks like the generic method signature (e.g. "(LE;)Ljava/util/List;") we parsed from JDT is slightly different with the one from the JDI (e.g. "(Ljava/lang/Object;)Ljava/util/List;"). We could fix it in another PR. |
9b60b13 to
8ec67a0
Compare
| @Override | ||
| public boolean visit(TypeDeclaration node) { | ||
| return shouldVisitNode(node); | ||
| return unit.getRoot() == node.getRoot() || shouldVisitNode(node); |
There was a problem hiding this comment.
I can reproduce it, but i would prefer to modify the implementation shouldVisitNode() to fix the problem.
Since the offset range of the ast node is [node.getStartPosition, node.getStartPosition() + node.getLength() - 1], the ending line should be got from unit.getLineNumber(node.getStartPosition() + node.getLength() - 1).
The fix could be as follow:
private boolean shouldVisitNode(ASTNode node) {
int start = unit.getLineNumber(node.getStartPosition());
int end = unit.getLineNumber(node.getStartPosition() + node.getLength() - 1);
if (line >= start && line <= end) {
return true;
}
return false;
}| return originalMethod.equals(currentMethod) | ||
| && original.lineNumber() == current.lineNumber(); | ||
| && (original.lineNumber() == current.lineNumber() | ||
| || (targetStepIn != null && targetStepIn.lineStart >= current.lineNumber())); |
There was a problem hiding this comment.
this doesn't work for multiline method invocation. We should use targetStepIn.lineEnd in the last check, e.g. targetStepIn.lineEnd >= current.lineNumber().
For the use case below, step-into target filterMe doesn't work, it stops at the line of "2", "3", .
new ArrayList<>(List.of("1"))
.subList(0, 1)
.addAll(filterMe("1",
"2", "3",
"4"));fix the comment
fix the comment
testforstephen
left a comment
There was a problem hiding this comment.
I have updated the PR to fix the comments. Now it's good to merge.
The fix try to compare the current line number against the target MethodInvocation start line if the debugger lines doesn't match because the current frame is at a wrapped line even though we are executing the same expression.