Skip to content
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: fix sniper bug delated to source position of super reference #4092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/spoon/support/compiler/jdt/PositionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.jdt.internal.compiler.ast.Initializer;
import org.eclipse.jdt.internal.compiler.ast.Javadoc;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.SuperReference;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
Expand Down Expand Up @@ -445,6 +446,11 @@ SourcePosition buildPositionCtElement(CtElement e, ASTNode node) {
} else if ((node instanceof AssertStatement)) {
AssertStatement assert_ = (AssertStatement) node;
sourceEnd = findNextChar(contents, contents.length, sourceEnd, ';');
} else if (node instanceof SuperReference) {
// when a super reference is followed by a unary operator (e.g. `super.method(-x)`),
// JDT for some reason sets the end source position to the unary operator, so we
// must adjust for this.
sourceEnd = sourceStart + "super".length() - 1;
}

if (e instanceof CtModifiable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ void testSniperRespectsDeletionInForUpdate() {
}

@Test
@Disabled("UnresolvedBug")
@GitHubIssue(issueNumber = 4021)
void testSniperRespectsSuperWithUnaryOperator() {
// Combining CtSuperAccess and CtUnaryOperator leads to SpoonException with Sniper
Expand Down