jlahoda commented on a change in pull request #2791:
URL: https://github.com/apache/netbeans/pull/2791#discussion_r594900900



##########
File path: 
java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertSwitchToRuleSwitchTest.java
##########
@@ -875,6 +875,73 @@ public void 
testSwitch2SwitchExpressionNestedInnerSwitchStatement() throws Excep
                               "     }\n" +
                               "}\n");
     }
+    
+    public void testSwitchToRuleSwitchFormattingMultiple() throws Exception {
+        if(!ConvertSwitchToRuleSwitchTest.isJDK14())
+            return;
+        String output = HintTest.create()
+                .input("package test;" +
+                        "public class Test {\n" +
+                        "     private void test(int p) {\n" +
+                        "         String result;\n" +
+                        "         switch (p) {\n" +
+                        "            case 0:\n" +
+                        "            case 1:\n" +
+                        "            case 2:\n" +
+                        "            case 3: result=\"a\"; break;\n" +
+                        "            default: System.err.println(\"No.\"); 
break;" +
+                        "         }\n" +
+                        "     }\n" +
+                        "}\n")
+                .sourceLevel(SourceVersion.latest().name())
+                .run(ConvertSwitchToRuleSwitch.class)
+                .findWarning("3:9-3:15:verifier:" + 
Bundle.ERR_ConvertSwitchToRuleSwitch())
+                .applyFix()
+                .assertCompilable().getOutput();
+        String expected="package test;" +
+                        "public class Test {\n" +
+                        "     private void test(int p) {\n" +
+                        "         String result;\n" +
+                        "         switch (p) {\n" +
+                        "            case 0, 1, 2, 3 -> result=\"a\";\n" +
+                        "            default -> 
System.err.println(\"No.\");\n" +
+                        "         }\n" +
+                        "     }\n" +
+                        "}\n";
+        assertEquals(expected, output);

Review comment:
       A partly stylistic comment there: it is usually better to have testcases 
for the code generation under 
`java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen`, so that 
regressions are found without running `java.hints` tests. The `java.hints` 
tests then can usually use `assertOutput`, which ignores formatting changes, 
but if formatting check is desired, `assertVerbatimOutput` can be used instead 
of calling `getOutput()` and `assertEquals`.

##########
File path: 
java/java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java
##########
@@ -1954,6 +1961,14 @@ protected int diffCase(JCCase oldT, JCCase newT, int[] 
bounds) {
             endpos = endPos(oldPatterns.get(oldPatterns.size() - 1));
 
             if (newPatterns.isEmpty()) {
+                if(copyTo > localPointer){

Review comment:
       Should this be something like `copyTo(localPointer, copyTo);`?




----------------------------------------------------------------
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:
us...@infra.apache.org



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

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

Reply via email to