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 2019/06/10 04:32:25 UTC

[GitHub] [netbeans] vikasprabhakar commented on a change in pull request #1237: [NETBEANS-2349] Convert switch typecast case to switch expression

vikasprabhakar commented on a change in pull request #1237: [NETBEANS-2349] Convert switch typecast case to switch expression
URL: https://github.com/apache/netbeans/pull/1237#discussion_r291877063
 
 

 ##########
 File path: java/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java
 ##########
 @@ -3244,15 +3245,23 @@ public Void visitIdentifier(IdentifierTree node, Void p) {
                     body = statements.get(0);
                 }
             }
-            if (isExpression) {
+            if (isSwitchExpression) {
                 if (statements.get(0).getKind() == Tree.Kind.RETURN) {
                     body = ((JCTree.JCReturn) statements.get(0)).getExpression();
-                    isReturnExpression = true;
+                    switchType = SWITCH_TYPE.SWITCH_EXPRESSION_RETURN_CASE;
                 } else {
+                    switchType = SWITCH_TYPE.SWITCH_EXPRESSION_ASSIGN_CASE;
                     JCTree.JCExpressionStatement jceTree = (JCTree.JCExpressionStatement) statements.get(0);
                     body = ((JCTree.JCAssign) jceTree.expr).rhs;
-                    variable = ((JCTree.JCAssign) jceTree.expr).lhs;
+                    if (body instanceof JCTree.JCTypeCast) {
+                        switchType = SWITCH_TYPE.SWITCH_EXPRESSION_CAST_CASE;
+                    }
+                    leftVariable = ((JCTree.JCAssign) jceTree.expr).lhs;
                 }
+                if (body instanceof JCTree.JCTypeCast) {
 
 Review comment:
   Could you please provide the use case code for your above feedback?
   I checked with following nested scenario and suggestion hints working properly.
   public String test(int p) {
           String str;
           int i = 10;
           int j = 10;
           switch (i) {
               case 1:
                   return (switch (j) {
                       case 1->
                           "One";
                       default->
                           "Default";
                   });
   
               default:
                   return "default outer";
   
           }
       }
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
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