Skip to content

Commit

Permalink
fix: fix sniper bug delated to source position of super reference (IN…
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse authored and woutersmeenk committed Aug 29, 2021
1 parent e4a92cd commit bf6ccb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit bf6ccb6

Please sign in to comment.