Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-6241

SwitchToRuleSwitch Hint not working with Pattern Matching Switch

    XMLWordPrintableJSON

Details

    Description

      With the given code :

      static void testSwitchStatements(Integer i) {
              switch (i) {
                  case 1, 2 : System.out.println("1"); break;
                  case 3 : System.out.println("3"); break;
                  case Integer i : System.out.println(i);
                           break;
              } 
          }
      

      We get the hint to covert to rule switch. The output of the hint does not convert the binding pattern to rule switch case.

      static void testSwitchStatements(Integer i) {
              switch (i) {
                  case 1, 2 -> System.out.println("1");
                  case 3 -> System.out.println("3");
                  case Integer i : System.out.println(i);
                           break;
              } 
          }
      
      

       

      When running the hint on a switch expression :

      switch (p) {
          case (Integer i  && (i > 10)):
               return (String) o1;
          default :
               return (String) o2;
      }

      The output is multiple default statements.

      return (String) (switch (p) {
                  default -> o1;
                  default -> o2;
      }); 

      Attachments

        Issue Links

          Activity

            People

              mishra.sandeep Sandeep Mishra
              mishra.sandeep Sandeep Mishra
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m