Repository: checkstyle/checkstyle

Problem statement:
Incorrect Indentation errors for expression switches with google_checks.xml
```bash
$ javac -fullversion
javac full version "20-ea+35-2342"
$ javac T.java

$ wget https://raw.githubusercontent.com/checkstyle/checkstyle/d02e867225c3eaa43dc681c2827ce89799dee88f/src/main/resources/google_checks.xml

$ cat T.java
class T {
  void doSomething(int i) {
    String s =
        switch (i) {
          case 1 -> "one";
          case 2 -> "two";
          default -> throw new AssertionError();
        };
  }
}
$ RUN_LOCALE="-Duser.language=en -Duser.country=US"
$ java -jar checkstyle-10.8.1-all.jar -c google_checks.xml T.java
Starting audit...
[WARN] /tmp/tmp.zK57404080/T.java:4:9: 'switch' has incorrect indentation level 8, expected level should be 4. [Indentation]
[WARN] /tmp/tmp.zK57404080/T.java:5:11: 'case' child has incorrect indentation level 10, expected level should be 6. [Indentation]
[WARN] /tmp/tmp.zK57404080/T.java:6:11: 'case' child has incorrect indentation level 10, expected level should be 6. [Indentation]
[WARN] /tmp/tmp.zK57404080/T.java:7:11: 'case' child has incorrect indentation level 10, expected level should be 6. [Indentation]
[WARN] /tmp/tmp.zK57404080/T.java:8:9: 'switch rcurly' has incorrect indentation level 8, expected level should be 4. [Indentation]
Audit done.
```

**Describe what you expect in detail.**

I expected no errors to be produced, because the input is formatted in a way that complies with the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)


Hints:
maybe you are having problem with the compiler i have executed the file and it got implemented corrected.May be you are using the early release version.The file runs correctly with Java(TM) SE Runtime Environment (build 19.0.2+7-44)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing).

`class T {
    void doSomething(int i) {
        String s =
            switch (i) {
                case 1 -> "one";
                case 2 -> "two";
                default -> throw new AssertionError();
            };
    }
    
    public static void main(String[] args) {
        T t = new T();
        t.doSomething(1); // calling the doSomething method with the argument 1
    }
}
`
Hi!
I have the same issue with switch. 

I reported in https://github.com/google/google-java-format/issues/915

Thanks!
I am also facing this issue, 
error - 'switch' has incorrect indentation level 8, expected level should be 4. [Indentation]
I tried with openjdk 17.0.6

```
static void testMethod(int month) {
    int result =
        switch (month) {
          case JANUARY, JUNE, JULY -> 3;
          case FEBRUARY, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER -> 1;
          case MARCH, MAY, APRIL, AUGUST -> {
            yield month * 4;
          }
          default -> 0;
        };
  }

Patch:
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/SwitchHandler.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/SwitchHandler.java
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/SwitchHandler.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/SwitchHandler.java
@@ -21,6 +21,7 @@
 
 import com.puppycrawl.tools.checkstyle.api.DetailAST;
 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
+import com.puppycrawl.tools.checkstyle.utils.TokenUtil;
 
 /**
  * Handler for switch statements.
@@ -76,6 +77,18 @@ private void checkSwitchExpr() {
             false);
     }
 
+    @Override
+    protected IndentLevel getIndentImpl() {
+        IndentLevel indentLevel = super.getIndentImpl();
+        // if switch is starting the line
+        if (isOnStartOfLine(getMainAst())
+                && TokenUtil.isOfType(getMainAst().getParent().getParent(), TokenTypes.ASSIGN)) {
+            indentLevel = new IndentLevel(indentLevel,
+                    getIndentCheck().getLineWrappingIndentation());
+        }
+        return indentLevel;
+    }
+
     @Override
     public void checkIndentation() {
         checkSwitchExpr();


Test patch:
diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4841indentation/IndentationTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4841indentation/IndentationTest.java
--- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4841indentation/IndentationTest.java
+++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4841indentation/IndentationTest.java
@@ -94,4 +94,9 @@ public void testCorrectAnnotationArrayInit() throws Exception {
     public void testFastMatcher() throws Exception {
         verifyWithWholeConfig(getPath("InputFastMatcher.java"));
     }
+
+    @Test
+    public void testSwitchOnTheStartOfTheLine() throws Exception {
+        verifyWithWholeConfig(getNonCompilablePath("InputSwitchOnStartOfTheLine.java"));
+    }
 }
diff --git a/src/it/resources-noncompilable/com/google/checkstyle/test/chapter4formatting/rule4841indentation/InputSwitchOnStartOfTheLine.java b/src/it/resources-noncompilable/com/google/checkstyle/test/chapter4formatting/rule4841indentation/InputSwitchOnStartOfTheLine.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources-noncompilable/com/google/checkstyle/test/chapter4formatting/rule4841indentation/InputSwitchOnStartOfTheLine.java
@@ -0,0 +1,47 @@
+// non-compiled with javac: Compilable with Java17
+
+package com.google.checkstyle.test.chapter4formatting.rule42blockindentation;
+
+/**some javadoc.*/
+public class InputSwitchOnStartOfTheLine {
+  String testMethod1(int i) {
+    String s =
+        switch (i) {
+          case 1 -> "one";
+          case 2 -> "two";
+          default -> "zero";
+        };
+    return s;
+  }
+
+  void testMethod2(int month) {
+    int result =
+        switch (month) {
+          case 1, 6, 7 -> 3;
+          case 2, 9, 10, 11, 12 -> 1;
+          case 3, 5, 4, 8 -> {
+            yield month * 4;
+          }
+          default -> 0;
+        };
+  }
+
+  void testMethod3Invalid(int num) {
+    int odd =
+      switch (num) {       // violation '.* incorrect indentation level 6, expected .* 8.'
+        case 1, 3, 7 -> 1; // violation '.* incorrect indentation level 8, expected .* 10.'
+        case 2, 4, 6 -> 2; // violation '.* incorrect indentation level 8, expected .* 10.'
+        default -> 0;      // violation '.* incorrect indentation level 8, expected .* 10.'
+      };                   // violation '.* incorrect indentation level 6, expected .* 8.'
+  }
+
+  String testMethod4Invalid(int i) {
+    String s =
+          switch (i) {         // violation '.* incorrect indentation level 10, expected .* 8.'
+            case 1 -> "one";   // violation '.* incorrect indentation level 12, expected .* 10.'
+            case 2 -> "two";   // violation '.* incorrect indentation level 12, expected .* 10.'
+            default -> "zero"; // violation '.* incorrect indentation level 12, expected .* 10.'
+        };
+    return s;
+  }
+}
diff --git a/src/it/resources-noncompilable/com/google/checkstyle/test/chapter4formatting/rule4841indentation/InputSwitchOnStartOfTheLineCorrect.java b/src/it/resources-noncompilable/com/google/checkstyle/test/chapter4formatting/rule4841indentation/InputSwitchOnStartOfTheLineCorrect.java
new file mode 100644
--- /dev/null
+++ b/src/it/resources-noncompilable/com/google/checkstyle/test/chapter4formatting/rule4841indentation/InputSwitchOnStartOfTheLineCorrect.java
@@ -0,0 +1,28 @@
+// non-compiled with javac: Compilable with Java17
+
+package com.google.checkstyle.test.chapter4formatting.rule42blockindentation;
+
+/**some javadoc.*/
+public class InputSwitchOnStartOfTheLineCorrect {
+  String testMethod1(int i) {
+    String s =
+        switch (i) {
+          case 1 -> "one";
+          case 2 -> "two";
+          default -> "zero";
+        };
+    return s;
+  }
+
+  void testMethod2(int month) {
+    int result =
+        switch (month) {
+          case 1, 6, 7 -> 3;
+          case 2, 9, 10, 11, 12 -> 1;
+          case 3, 5, 4, 8 -> {
+            yield month * 4;
+          }
+          default -> 0;
+        };
+  }
+}
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java
@@ -3057,6 +3057,32 @@ public void testIndentationLineBreakVariableDeclaration()
         verifyWarns(checkConfig, fileName, expected);
     }
 
+    @Test
+    public void testIndentationSwitchExpressionOnStartOfTheLine() throws Exception {
+        final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
+        checkConfig.addProperty("tabWidth", "4");
+        checkConfig.addProperty("basicOffset", "2");
+        checkConfig.addProperty("braceAdjustment", "2");
+        checkConfig.addProperty("caseIndent", "2");
+        checkConfig.addProperty("throwsIndent", "4");
+        checkConfig.addProperty("lineWrappingIndentation", "4");
+
+        final String[] expected = {
+            "40:7: " + getCheckMessage(MSG_ERROR, "switch", 6, 8),
+            "41:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
+            "42:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
+            "43:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 10),
+            "44:7: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
+            "49:11: " + getCheckMessage(MSG_ERROR, "switch", 10, 8),
+            "50:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
+            "51:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
+            "52:13: " + getCheckMessage(MSG_CHILD_ERROR, "case", 12, 10),
+        };
+
+        verifyWarns(checkConfig,
+                getNonCompilablePath("InputIndentationSwitchOnStartOfLine.java"), expected);
+    }
+
     @Test
     public void testIndentationPatternMatchingForSwitch()
             throws Exception {
diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationSwitchOnStartOfLine.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationSwitchOnStartOfLine.java
new file mode 100644
--- /dev/null
+++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationSwitchOnStartOfLine.java
@@ -0,0 +1,56 @@
+//non-compiled with javac: Compilable with Java17                           //indent:0 exp:0
+
+package com.puppycrawl.tools.checkstyle.checks.indentation.indentation;     //indent:0 exp:0
+
+/* Config:                                                                  //indent:0 exp:0
+ * This test-input is intended to be checked using following configuration: //indent:1 exp:1
+ * basicOffset = 2                                                          //indent:1 exp:1
+ * braceAdjustment = 2                                                      //indent:1 exp:1
+ * caseIndent = 2                                                           //indent:1 exp:1
+ * tabWidth = 4                                                             //indent:1 exp:1
+ * lineWrappingIndentation = 4                                              //indent:1 exp:1
+ * throwsIndent = 4                                                         //indent:1 exp:1
+ */                                                                         //indent:1 exp:1
+
+public class InputIndentationSwitchOnStartOfLine {                          //indent:0 exp:0
+  String testMethod1(int i) {                                               //indent:2 exp:2
+    String s =                                                              //indent:4 exp:4
+        switch (i) {                                                        //indent:8 exp:8
+          case 1 -> "one";                                                  //indent:10 exp:10
+          case 2 -> "two";                                                  //indent:10 exp:10
+          default -> "zero";                                                //indent:10 exp:10
+        };                                                                  //indent:8 exp:8
+    return s;                                                               //indent:4 exp:4
+  }                                                                         //indent:2 exp:2
+
+  void testMethod2(int month) {                                             //indent:2 exp:2
+    int result =                                                            //indent:4 exp:4
+        switch (month) {                                                    //indent:8 exp:8
+          case 1, 6, 7 -> 3;                                                //indent:10 exp:10
+          case 2, 9, 10, 11, 12 -> 1;                                       //indent:10 exp:10
+          case 3, 5, 4, 8 -> {                                              //indent:10 exp:10
+            yield month * 4;                                                //indent:12 exp:12
+          }                                                                 //indent:10 exp:10
+          default -> 0;                                                     //indent:10 exp:10
+        };                                                                  //indent:8 exp:8
+  }                                                                         //indent:2 exp:2
+
+  void testMethod3_invalid(int num) {                                       //indent:2 exp:2
+    int odd =                                                               //indent:4 exp:4
+      switch (num) {                                                        //indent:6 exp:8 warn
+        case 1, 3, 7 -> 1;                                                  //indent:8 exp:10 warn
+        case 2, 4, 6 -> 2;                                                  //indent:8 exp:10 warn
+        default -> 0;                                                       //indent:8 exp:10 warn
+      };                                                                    //indent:6 exp:8 warn
+  }                                                                         //indent:2 exp:2
+
+  String testMethod1_invalid(int i) {                                       //indent:2 exp:2
+    String s =                                                              //indent:4 exp:4
+          switch (i) {                                                      //indent:10 exp:8 warn
+            case 1 -> "one";                                                //indent:12 exp:10 warn
+            case 2 -> "two";                                                //indent:12 exp:10 warn
+            default -> "zero";                                              //indent:12 exp:10 warn
+        };                                                                  //indent:8 exp:8
+    return s;                                                               //indent:4 exp:4
+  }                                                                         //indent:2 exp:2
+}                                                                           //indent:0 exp:0