getDeclarationExpressions() {
private static final String INSIDE_PARENTHESES_LEVEL = "_INSIDE_PARENTHESES_LEVEL";
private static final String IS_INSIDE_INSTANCEOF_EXPR = "_IS_INSIDE_INSTANCEOF_EXPR";
private static final String IS_SWITCH_DEFAULT = "_IS_SWITCH_DEFAULT";
+ private static final String SWITCH_TYPE_PATTERN_BINDING = "_SWITCH_TYPE_PATTERN_BINDING";
+ // the next four keys are also read (as literals) by StaticTypeCheckingVisitor
+ private static final String SWITCH_PATTERN_SUBJECT = "_SWITCH_PATTERN_SUBJECT";
+ private static final String SWITCH_PATTERN_TYPE = "_SWITCH_PATTERN_TYPE";
+ private static final String SWITCH_PATTERN_GUARDED = "_SWITCH_PATTERN_GUARDED";
+ private static final String SWITCH_PATTERN_RECORD = "_SWITCH_PATTERN_RECORD";
+ private static final String SWITCH_PATTERN_LIST = "_SWITCH_PATTERN_LIST";
+ private static final String SWITCH_PATTERN_MAP = "_SWITCH_PATTERN_MAP";
+ private static final String SWITCH_PATTERN_ARM_ITEMS = "_SWITCH_PATTERN_ARM_ITEMS";
+ private static final String SWITCH_PATTERN_ARMS = "_SWITCH_PATTERN_ARMS";
+ private static final String SWITCH_PATTERN_DEFAULT = "_SWITCH_PATTERN_DEFAULT";
+ private static final ClassNode RECORD_PATTERN_SUPPORT_TYPE = ClassHelper.makeCached(RecordPatternSupport.class);
+ private static final ClassNode LIST_PATTERN_SUPPORT_TYPE = ClassHelper.makeCached(ListPatternSupport.class);
+ private static final ClassNode MAP_PATTERN_SUPPORT_TYPE = ClassHelper.makeCached(MapPatternSupport.class);
private static final String IS_NUMERIC = "_IS_NUMERIC";
private static final String IS_STRING = "_IS_STRING";
private static final String IS_INTERFACE_WITH_DEFAULT_METHODS = "_IS_INTERFACE_WITH_DEFAULT_METHODS";
diff --git a/src/main/java/org/apache/groovy/runtime/ListPatternSupport.java b/src/main/java/org/apache/groovy/runtime/ListPatternSupport.java
new file mode 100644
index 00000000000..e8971ca3979
--- /dev/null
+++ b/src/main/java/org/apache/groovy/runtime/ListPatternSupport.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.groovy.runtime;
+
+import org.apache.groovy.lang.annotation.Incubating;
+import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Runtime destructuring support for list patterns (GEP-19) — the emit
+ * target of the pattern switch lowering in the parser.
+ *
+ * List patterns destructure {@code List}, array and {@code Iterable} values
+ * structurally; other values (and {@code null}) do not match. An
+ * {@code Iterable} is materialised as a list for matching, so it must be
+ * traversable non-destructively.
+ *
+ * @since 6.0.0
+ */
+@Incubating
+public final class ListPatternSupport {
+
+ private ListPatternSupport() {
+ }
+
+ /**
+ * Returns the given value as a list of its elements, or {@code null} when the
+ * value is not destructurable by a list pattern: lists are returned as is,
+ * arrays (including primitive arrays) and other iterables as a copy.
+ */
+ @SuppressWarnings("unchecked")
+ public static List