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/05/22 08:42:42 UTC

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

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

 ##########
 File path: java/java.hints/src/org/netbeans/modules/java/hints/errors/Utilities.java
 ##########
 @@ -3265,16 +3274,36 @@ public Void visitIdentifier(IdentifierTree node, Void p) {
                 }
             }
         }
-        if (isReturnExpression) {
-            ExpressionTree et = (ExpressionTree) make.SwitchExpression(TreeShims.getExpressions(st).get(0), newCases);
-            wc.rewrite(st, make.Return(et));
-        } else if (isExpression) {
-            ExpressionTree et = (ExpressionTree) make.SwitchExpression(TreeShims.getExpressions(st).get(0), newCases);
-            wc.rewrite(st, make.ExpressionStatement((ExpressionTree) make.Assignment((ExpressionTree) variable, et)));
-        } else if (switchExpressionFlag) {
-            wc.rewrite(st, make.SwitchExpression(TreeShims.getExpressions(st).get(0), newCases));
-        } else {
-            wc.rewrite((SwitchTree) st, make.Switch(((SwitchTree) st).getExpression(), newCases));
+        ExpressionTree et = null;
+        switch(switchType){
+            case SWITCH_EXPRESSION_RETURN_CASE:
+                et = (ExpressionTree) make.SwitchExpression(TreeShims.getExpressions(st).get(0), newCases);
+                if(typeCastTree != null){
+                    et = make.Parenthesized(et);
+                    et = make.TypeCast(typeCastTree, et);
+                }
+                wc.rewrite(st, make.Return(et));
+                break;
+            case SWITCH_EXPRESSION_CAST_CASE:
+                et = (ExpressionTree) make.SwitchExpression(TreeShims.getExpressions(st).get(0), newCases);
+                if(typeCastTree != null){
+                    et = make.Parenthesized(et);
+                    et = make.TypeCast(typeCastTree, et);
+                }
+                wc.rewrite(st, make.ExpressionStatement((ExpressionTree) make.Assignment((ExpressionTree) leftVariable, et)));
+                break;
+            case SWITCH_EXPRESSION_ASSIGN_CASE:
+                et = (ExpressionTree) make.SwitchExpression(TreeShims.getExpressions(st).get(0), newCases);
+                wc.rewrite(st, make.ExpressionStatement((ExpressionTree) make.Assignment((ExpressionTree) leftVariable, et)));
+                break;
+            case SWITCH_EXPRESSION:
 
 Review comment:
   IMHO cases for `SWITCH_EXPRESSION_RETURN_CASE`, `SWITCH_EXPRESSION_CAST_CASE`, `SWITCH_EXPRESSION_ASSIGN_CASE` can be mostly merged, except the last rewrite step, which is unique for each of them.
   - all are switch expressions;
   - if `typeCastTree` is available, wrap in type cast
   - (the case-specific statement replacement)

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