This is an automated email from the ASF dual-hosted git repository.

jlahoda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 30ea25a  Fixing TreeUtilities.pathFor in the presence of the synthetic 
'value=' in annotations.
30ea25a is described below

commit 30ea25a0860e3e1c06936e9ad0d1163a3fc13bf4
Author: Jan Lahoda <[email protected]>
AuthorDate: Thu Oct 7 07:38:20 2021 +0200

    Fixing TreeUtilities.pathFor in the presence of the synthetic 'value=' in 
annotations.
---
 .../netbeans/api/java/source/TreeUtilities.java    |  7 +++++-
 .../api/java/source/TreeUtilitiesTest.java         | 27 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git 
a/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java 
b/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
index 5a20ee5..3316ce9 100644
--- a/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
+++ b/java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
@@ -374,7 +374,12 @@ public final class TreeUtilities {
             
             public Void scan(Tree tree, Void p) {
                 if (tree != null) {
-                    if 
(sourcePositions.getStartPosition(getCurrentPath().getCompilationUnit(), tree) 
< pos && sourcePositions.getEndPosition(getCurrentPath().getCompilationUnit(), 
tree) >= pos) {
+                    long endPos = 
sourcePositions.getEndPosition(getCurrentPath().getCompilationUnit(), tree);
+                    if (endPos == (-1) && tree.getKind() == Kind.ASSIGNMENT && 
getCurrentPath().getLeaf().getKind() == Kind.ANNOTATION) {
+                        ExpressionTree value = ((AssignmentTree) 
tree).getExpression();
+                        endPos = 
sourcePositions.getEndPosition(getCurrentPath().getCompilationUnit(), value);
+                    }
+                    if 
(sourcePositions.getStartPosition(getCurrentPath().getCompilationUnit(), tree) 
< pos && endPos >= pos) {
                         if (tree.getKind() == Tree.Kind.ERRONEOUS) {
                             tree.accept(this, p);
                             throw new Result(getCurrentPath());
diff --git 
a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java
 
b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java
index c415776..83754eb 100644
--- 
a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java
+++ 
b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java
@@ -390,6 +390,33 @@ public class TreeUtilitiesTest extends NbTestCase {
         assertFalse(Kind.METHOD == tp.getParentPath().getLeaf().getKind());
     }
     
+    public void testAnnotationSyntheticValue1() throws Exception {
+        prepareTest("Test", "package test; @Meta(Test.VALUE) public class Test 
{ public static final String VALUE = \"\"; } @interface Meta { public String 
value(); }");
+        
+        TreePath tp = info.getTreeUtilities().pathFor(58 - 30);
+        
+        assertEquals(Kind.MEMBER_SELECT, tp.getLeaf().getKind());
+        assertEquals("Test.VALUE", tp.getLeaf().toString());
+    }
+    
+    public void testAnnotationSyntheticValue2() throws Exception {
+        prepareTest("Test", "package test; @Meta(Test.VALUE) public class Test 
{ public static final String VALUE = \"\"; } @interface Meta { public String[] 
value(); }");
+        
+        TreePath tp = info.getTreeUtilities().pathFor(58 - 30);
+        
+        assertEquals(Kind.MEMBER_SELECT, tp.getLeaf().getKind());
+        assertEquals("Test.VALUE", tp.getLeaf().toString());
+    }
+    
+    public void testAnnotationSyntheticValue3() throws Exception {
+        prepareTest("Test", "package test; @Meta({Test.VALUE}) public class 
Test { public static final String VALUE = \"\"; } @interface Meta { public 
String[] value(); }");
+        
+        TreePath tp = info.getTreeUtilities().pathFor(58 - 30);
+        
+        assertEquals(Kind.MEMBER_SELECT, tp.getLeaf().getKind());
+        assertEquals("Test.VALUE", tp.getLeaf().toString());
+    }
+    
     public void testAutoMapComments1() throws Exception {
         prepareTest("Test", "package test;\n" +
                             "import java.io.File;\n" +

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to