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 TreeUtilities.pathFor for synthetic 'value=' in annotations also for start position #7378

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
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,14 @@ private PathFinder(int pos, SourcePositions sourcePositions) {

public Void scan(Tree tree, Void p) {
if (tree != null) {
long startPos = sourcePositions.getStartPosition(getCurrentPath().getCompilationUnit(), tree);
long endPos = sourcePositions.getEndPosition(getCurrentPath().getCompilationUnit(), tree);
if (endPos == (-1)) {
switch (tree.getKind()) {
case ASSIGNMENT:
if (getCurrentPath().getLeaf().getKind() == Kind.ANNOTATION) {
ExpressionTree value = ((AssignmentTree) tree).getExpression();
startPos = sourcePositions.getStartPosition(getCurrentPath().getCompilationUnit(), value);
endPos = sourcePositions.getEndPosition(getCurrentPath().getCompilationUnit(), value);
}
break;
Expand All @@ -376,7 +378,7 @@ public Void scan(Tree tree, Void p) {
break;
}
}
if (sourcePositions.getStartPosition(getCurrentPath().getCompilationUnit(), tree) < pos && endPos >= pos) {
if (startPos < pos && endPos >= pos) {
if (tree.getKind() == Tree.Kind.ERRONEOUS) {
tree.accept(this, p);
throw new Result(getCurrentPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ public void testAnnotationSyntheticValue3() throws Exception {
assertEquals(Kind.MEMBER_SELECT, tp.getLeaf().getKind());
assertEquals("Test.VALUE", tp.getLeaf().toString());
}

public void testAnnotationSyntheticValue4() throws Exception {
prepareTest("Test", "package test; @Meta(String.class) public class Test { } @interface Meta { public Class value(); }");

TreePath tp = info.getTreeUtilities().pathFor(24);

assertEquals(Kind.IDENTIFIER, tp.getLeaf().getKind());
assertEquals("String", tp.getLeaf().toString());
}

public void testAutoMapComments1() throws Exception {
prepareTest("Test", "package test;\n" +
Expand Down
Loading