-
Notifications
You must be signed in to change notification settings - Fork 159
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
Fix the step-into target on multi line expression. Fix #519 #520
Fix the step-into target on multi line expression. Fix #519 #520
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 |
@@ -71,7 +71,7 @@ public boolean visit(MethodDeclaration node) { | |||
|
|||
@Override | |||
public boolean visit(TypeDeclaration node) { | |||
return shouldVisitNode(node); | |||
return unit.getRoot() == node.getRoot() || shouldVisitNode(node); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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;
}
@@ -438,15 +439,19 @@ private boolean shouldDoExtraStepInto(int originalStackDepth, Location originalL | |||
return true; | |||
} | |||
|
|||
private boolean isSameLocation(Location original, Location current) { | |||
private boolean isSameLocation(Location original, Location current, MethodInvocation targetStepIn) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. Lines 330 to 345 in 9bdd997
|
9b60b13
to
8ec67a0
Compare
@@ -71,7 +71,7 @@ public boolean visit(MethodDeclaration node) { | |||
|
|||
@Override | |||
public boolean visit(TypeDeclaration node) { | |||
return shouldVisitNode(node); | |||
return unit.getRoot() == node.getRoot() || shouldVisitNode(node); |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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 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.