You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/01/29 21:36:17 UTC

[GitHub] [netbeans] mbien opened a new pull request #3540: [jackpot] DefaultRuleUtilities::referencedIn fix for single variable matching

mbien opened a new pull request #3540:
URL: https://github.com/apache/netbeans/pull/3540


   `referencedIn(v, in)` did not match if `in` was a single variable.
   
   example:
   ```java
   for(int $i = $from; $i < $to; $i++) {
       $array[$i] = $n;
   } 
   :: !referencedIn($i, $n) && !matchesAny($n, "$i") /*&& more()*/ =>
   java.util.Arrays.fill($array, $n);
   ;;
   ```
   needed an extra `!matchesAny($n, "$i")` to make sure `$n` is not actually equal to `$i`. (i+1 would be matched by `referencedIn` but not i). After this PR `matchesAny` is no longer needed.
   
   * added a small optimization which adds a fast path to the recursion if a result has been already determined.
   * couldn't find tests for referencedIn so I added some.
   
   btw the in-editor test integration for rule files is super cool


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] neilcsmith-net commented on pull request #3540: [jackpot] DefaultRuleUtilities::referencedIn fix for single variable matching

Posted by GitBox <gi...@apache.org>.
neilcsmith-net commented on pull request #3540:
URL: https://github.com/apache/netbeans/pull/3540#issuecomment-1026062067


   > This looks fairly low risk to me (I don't think the utility functions are even used in netbeans itself).
   
   Not sure how to assess the latter point against bug criteria then, so will take your word on the first point and sneak it in rc3! :smile: Will merge tomorrow, give @jlahoda time to comment if needed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] mbien commented on pull request #3540: [jackpot] DefaultRuleUtilities::referencedIn fix for single variable matching

Posted by GitBox <gi...@apache.org>.
mbien commented on pull request #3540:
URL: https://github.com/apache/netbeans/pull/3540#issuecomment-1025558000


   @JaroslavTulach I do what i can but a lot of this is still black magic to me :)
   
   I am going to rebase this PR for delivery just in case it can be still integrated. This looks fairly low risk to me (I don't think the utility functions are even used in netbeans itself).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] mbien commented on a change in pull request #3540: [jackpot] DefaultRuleUtilities::referencedIn fix for single variable matching

Posted by GitBox <gi...@apache.org>.
mbien commented on a change in pull request #3540:
URL: https://github.com/apache/netbeans/pull/3540#discussion_r796465847



##########
File path: java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/conditionapi/Matcher.java
##########
@@ -90,25 +91,38 @@ public Void scan(Tree tree, Void p) {
         return result[0];
     }
 
+    @SuppressWarnings("BoxedValueEquality")
     public boolean referencedIn(@NonNull Variable variable, @NonNull Variable in) {
-        final Element e = ctx.ctx.getInfo().getTrees().getElement(ctx.getSingleVariable(variable));
+        final Trees trees = ctx.ctx.getInfo().getTrees();
+        final Element e = trees.getElement(ctx.getSingleVariable(variable));
 
         if (e == null) { //TODO: check also error
             return false;
         }
 
+        TreePath v = ctx.getSingleVariable(in);
+        if (v != null && e.equals(trees.getElement(v))) {

Review comment:
       haven't considered that. Fixed + added another test for the mentioned case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] jlahoda commented on pull request #3540: [jackpot] DefaultRuleUtilities::referencedIn fix for single variable matching

Posted by GitBox <gi...@apache.org>.
jlahoda commented on pull request #3540:
URL: https://github.com/apache/netbeans/pull/3540#issuecomment-1027601326


   Looks great, BTW!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] neilcsmith-net merged pull request #3540: [jackpot] DefaultRuleUtilities::referencedIn fix for single variable matching

Posted by GitBox <gi...@apache.org>.
neilcsmith-net merged pull request #3540:
URL: https://github.com/apache/netbeans/pull/3540


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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


[GitHub] [netbeans] jlahoda commented on a change in pull request #3540: [jackpot] DefaultRuleUtilities::referencedIn fix for single variable matching

Posted by GitBox <gi...@apache.org>.
jlahoda commented on a change in pull request #3540:
URL: https://github.com/apache/netbeans/pull/3540#discussion_r796290460



##########
File path: java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/conditionapi/Matcher.java
##########
@@ -90,25 +91,38 @@ public Void scan(Tree tree, Void p) {
         return result[0];
     }
 
+    @SuppressWarnings("BoxedValueEquality")
     public boolean referencedIn(@NonNull Variable variable, @NonNull Variable in) {
-        final Element e = ctx.ctx.getInfo().getTrees().getElement(ctx.getSingleVariable(variable));
+        final Trees trees = ctx.ctx.getInfo().getTrees();
+        final Element e = trees.getElement(ctx.getSingleVariable(variable));
 
         if (e == null) { //TODO: check also error
             return false;
         }
 
+        TreePath v = ctx.getSingleVariable(in);
+        if (v != null && e.equals(trees.getElement(v))) {

Review comment:
       Good catch, but it would be better, I think, to move this test into the for loop (and operate over `tp`). We could have something like: `Arrays.asList(0, 1, b, 3)` with a pattern list `Arrays.asList($arrgs$)`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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