KT-9377 Support is-checks for read-only collections
Reorganize marker interfaces and is/as/as? intrinsics.
This commit is contained in:
@@ -300,23 +300,23 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
private static Map<String, String> KOTLIN_MARKER_INTERFACES = new HashMap<String, String>();
|
||||
static {
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Iterator", "kotlin/jvm/internal/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Iterable", "kotlin/jvm/internal/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Collection", "kotlin/jvm/internal/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.List", "kotlin/jvm/internal/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.ListIterator", "kotlin/jvm/internal/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Set", "kotlin/jvm/internal/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Map", "kotlin/jvm/internal/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Map.Entry", "kotlin/jvm/internal/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Iterator", "kotlin/jvm/internal/markers/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Iterable", "kotlin/jvm/internal/markers/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Collection", "kotlin/jvm/internal/markers/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.List", "kotlin/jvm/internal/markers/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.ListIterator", "kotlin/jvm/internal/markers/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Set", "kotlin/jvm/internal/markers/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Map", "kotlin/jvm/internal/markers/KMappedMarker");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.Map.Entry", "kotlin/jvm/internal/markers/KMappedMarker");
|
||||
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableIterator", "kotlin/jvm/internal/KMutableIterator");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableIterable", "kotlin/jvm/internal/KMutableIterable");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableCollection", "kotlin/jvm/internal/KMutableCollection");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableList", "kotlin/jvm/internal/KMutableList");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableListIterator", "kotlin/jvm/internal/KMutableListIterator");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableSet", "kotlin/jvm/internal/KMutableSet");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableMap", "kotlin/jvm/internal/KMutableMap");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableMap.MutableEntry", "kotlin/jvm/internal/KMutableMap$Entry");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableIterator", "kotlin/jvm/internal/markers/KMutableIterator");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableIterable", "kotlin/jvm/internal/markers/KMutableIterable");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableCollection", "kotlin/jvm/internal/markers/KMutableCollection");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableList", "kotlin/jvm/internal/markers/KMutableList");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableListIterator", "kotlin/jvm/internal/markers/KMutableListIterator");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableSet", "kotlin/jvm/internal/markers/KMutableSet");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableMap", "kotlin/jvm/internal/markers/KMutableMap");
|
||||
KOTLIN_MARKER_INTERFACES.put("kotlin.MutableMap.MutableEntry", "kotlin/jvm/internal/markers/KMutableMap$Entry");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.TypeInsnNode
|
||||
|
||||
object CheckCast {
|
||||
private val INTRINSICS_CLASS = "kotlin/jvm/internal/Intrinsics"
|
||||
private val INTRINSICS_CLASS = "kotlin/jvm/internal/TypeIntrinsics"
|
||||
|
||||
private val CHECKCAST_METHOD_NAME = hashMapOf(
|
||||
"kotlin.MutableIterator" to "asMutableIterator",
|
||||
@@ -82,6 +82,6 @@ object CheckCast {
|
||||
}
|
||||
|
||||
private fun getCheckcastIntrinsicMethodSignature(asmType: Type): String =
|
||||
"(Ljava/lang/Object;)${asmType.descriptor}"
|
||||
Type.getMethodDescriptor(asmType, Type.getObjectType("java/lang/Object"));
|
||||
|
||||
}
|
||||
@@ -27,9 +27,10 @@ import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.TypeInsnNode
|
||||
|
||||
object InstanceOf {
|
||||
private val INTRINSICS_CLASS = "kotlin/jvm/internal/Intrinsics"
|
||||
private val INTRINSICS_CLASS = "kotlin/jvm/internal/TypeIntrinsics"
|
||||
|
||||
private val INSTANCEOF_METHOD_SIGNATURE = "(Ljava/lang/Object;)Z"
|
||||
private val INSTANCEOF_METHOD_SIGNATURE =
|
||||
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getObjectType("java/lang/Object"))
|
||||
|
||||
private val INSTANCEOF_METHOD_NAME = hashMapOf(
|
||||
"kotlin.MutableIterator" to "isMutableIterator",
|
||||
|
||||
+18
-18
@@ -31,27 +31,27 @@ fun expectInterfaces(jClass: Class<*>, expectedInterfaceNames: Set<String>) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
expectInterfaces(Itr::class.java, setOf("java.util.Iterator", "kotlin.jvm.internal.KMappedMarker"))
|
||||
expectInterfaces(MItr::class.java, setOf("java.util.Iterator", "kotlin.jvm.internal.KMutableIterator"))
|
||||
expectInterfaces(LItr::class.java, setOf("java.util.ListIterator", "kotlin.jvm.internal.KMappedMarker"))
|
||||
expectInterfaces(MLItr::class.java, setOf("java.util.ListIterator", "kotlin.jvm.internal.KMutableListIterator"))
|
||||
expectInterfaces(It::class.java, setOf("java.lang.Iterable", "kotlin.jvm.internal.KMappedMarker"))
|
||||
expectInterfaces(MIt::class.java, setOf("java.lang.Iterable", "kotlin.jvm.internal.KMutableIterable"))
|
||||
expectInterfaces(C::class.java, setOf("java.util.Collection", "kotlin.jvm.internal.KMappedMarker"))
|
||||
expectInterfaces(MC::class.java, setOf("java.util.Collection", "kotlin.jvm.internal.KMutableCollection"))
|
||||
expectInterfaces(L::class.java, setOf("java.util.List", "kotlin.jvm.internal.KMappedMarker"))
|
||||
expectInterfaces(ML::class.java, setOf("java.util.List", "kotlin.jvm.internal.KMutableList"))
|
||||
expectInterfaces(S::class.java, setOf("java.util.Set", "kotlin.jvm.internal.KMappedMarker"))
|
||||
expectInterfaces(MS::class.java, setOf("java.util.Set", "kotlin.jvm.internal.KMutableSet"))
|
||||
expectInterfaces(M::class.java, setOf("java.util.Map", "kotlin.jvm.internal.KMappedMarker"))
|
||||
expectInterfaces(MM::class.java, setOf("java.util.Map", "kotlin.jvm.internal.KMutableMap"))
|
||||
expectInterfaces(ME::class.java, setOf("java.util.Map\$Entry", "kotlin.jvm.internal.KMappedMarker"))
|
||||
expectInterfaces(MME::class.java, setOf("java.util.Map\$Entry", "kotlin.jvm.internal.KMutableMap\$Entry"))
|
||||
expectInterfaces(Itr::class.java, setOf("java.util.Iterator", "kotlin.jvm.internal.markers.KMappedMarker"))
|
||||
expectInterfaces(MItr::class.java, setOf("java.util.Iterator", "kotlin.jvm.internal.markers.KMutableIterator"))
|
||||
expectInterfaces(LItr::class.java, setOf("java.util.ListIterator", "kotlin.jvm.internal.markers.KMappedMarker"))
|
||||
expectInterfaces(MLItr::class.java, setOf("java.util.ListIterator", "kotlin.jvm.internal.markers.KMutableListIterator"))
|
||||
expectInterfaces(It::class.java, setOf("java.lang.Iterable", "kotlin.jvm.internal.markers.KMappedMarker"))
|
||||
expectInterfaces(MIt::class.java, setOf("java.lang.Iterable", "kotlin.jvm.internal.markers.KMutableIterable"))
|
||||
expectInterfaces(C::class.java, setOf("java.util.Collection", "kotlin.jvm.internal.markers.KMappedMarker"))
|
||||
expectInterfaces(MC::class.java, setOf("java.util.Collection", "kotlin.jvm.internal.markers.KMutableCollection"))
|
||||
expectInterfaces(L::class.java, setOf("java.util.List", "kotlin.jvm.internal.markers.KMappedMarker"))
|
||||
expectInterfaces(ML::class.java, setOf("java.util.List", "kotlin.jvm.internal.markers.KMutableList"))
|
||||
expectInterfaces(S::class.java, setOf("java.util.Set", "kotlin.jvm.internal.markers.KMappedMarker"))
|
||||
expectInterfaces(MS::class.java, setOf("java.util.Set", "kotlin.jvm.internal.markers.KMutableSet"))
|
||||
expectInterfaces(M::class.java, setOf("java.util.Map", "kotlin.jvm.internal.markers.KMappedMarker"))
|
||||
expectInterfaces(MM::class.java, setOf("java.util.Map", "kotlin.jvm.internal.markers.KMutableMap"))
|
||||
expectInterfaces(ME::class.java, setOf("java.util.Map\$Entry", "kotlin.jvm.internal.markers.KMappedMarker"))
|
||||
expectInterfaces(MME::class.java, setOf("java.util.Map\$Entry", "kotlin.jvm.internal.markers.KMutableMap\$Entry"))
|
||||
expectInterfaces(L2::class.java, setOf<String>())
|
||||
expectInterfaces(ML2::class.java, setOf<String>())
|
||||
expectInterfaces(Weird::class.java,
|
||||
setOf("java.util.Iterator", "kotlin.jvm.internal.KMappedMarker",
|
||||
"java.util.List", "kotlin.jvm.internal.KMutableList"))
|
||||
setOf("java.util.Iterator", "kotlin.jvm.internal.markers.KMappedMarker",
|
||||
"java.util.List", "kotlin.jvm.internal.markers.KMutableList"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package kotlin.jvm.internal;
|
||||
|
||||
import kotlin.KotlinNullPointerException;
|
||||
import kotlin.UninitializedPropertyAccessException;
|
||||
import kotlin.jvm.internal.markers.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -34,10 +35,6 @@ public class Intrinsics {
|
||||
throw sanitizeStackTrace(new KotlinNullPointerException());
|
||||
}
|
||||
|
||||
public static void throwCce(String message) {
|
||||
throw sanitizeStackTrace(new ClassCastException(message));
|
||||
}
|
||||
|
||||
public static void throwUninitializedPropertyAccessException(String propertyName) {
|
||||
throw sanitizeStackTrace(new UninitializedPropertyAccessException(propertyName));
|
||||
}
|
||||
@@ -126,12 +123,16 @@ public class Intrinsics {
|
||||
}
|
||||
|
||||
private static <T extends Throwable> T sanitizeStackTrace(T throwable) {
|
||||
return sanitizeStackTrace(throwable, Intrinsics.class.getName());
|
||||
}
|
||||
|
||||
static <T extends Throwable> T sanitizeStackTrace(T throwable, String classNameToDrop) {
|
||||
StackTraceElement[] stackTrace = throwable.getStackTrace();
|
||||
int size = stackTrace.length;
|
||||
|
||||
int lastIntrinsic = -1;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (Intrinsics.class.getName().equals(stackTrace[i].getClassName())) {
|
||||
if (classNameToDrop.equals(stackTrace[i].getClassName())) {
|
||||
lastIntrinsic = i;
|
||||
}
|
||||
}
|
||||
@@ -140,268 +141,4 @@ public class Intrinsics {
|
||||
throwable.setStackTrace(list.toArray(new StackTraceElement[list.size()]));
|
||||
return throwable;
|
||||
}
|
||||
|
||||
public static boolean isMutableIterator(Object obj) {
|
||||
return (obj instanceof Iterator) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableIterator));
|
||||
}
|
||||
|
||||
public static Iterator asMutableIterator(Object obj) {
|
||||
Iterator result = null;
|
||||
try {
|
||||
result = (Iterator) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce("argument is not an Iterator");
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterator)) {
|
||||
throwCce("argument is not a MutableIterator");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Iterator safeAsMutableIterator(Object obj) {
|
||||
Iterator result;
|
||||
try {
|
||||
result = (Iterator) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterator)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableListIterator(Object obj) {
|
||||
return (obj instanceof ListIterator) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableListIterator));
|
||||
}
|
||||
|
||||
public static ListIterator asMutableListIterator(Object obj) {
|
||||
ListIterator result = null;
|
||||
try {
|
||||
result = (ListIterator) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce("argument is not a ListIterator");
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableListIterator)) {
|
||||
throwCce("argument is not a MutableListIterator");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ListIterator safeAsMutableListIterator(Object obj) {
|
||||
ListIterator result;
|
||||
try {
|
||||
result = (ListIterator) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableListIterator)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableIterable(Object obj) {
|
||||
return (obj instanceof Iterable) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableIterable));
|
||||
}
|
||||
|
||||
public static Iterable asMutableIterable(Object obj) {
|
||||
Iterable result = null;
|
||||
try {
|
||||
result = (Iterable) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce("argument is not an Iterable");
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterable)) {
|
||||
throwCce("argument is not a MutableIterable");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Iterable safeAsMutableIterable(Object obj) {
|
||||
Iterable result;
|
||||
try {
|
||||
result = (Iterable) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterable)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableCollection(Object obj) {
|
||||
return (obj instanceof Collection) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableCollection));
|
||||
}
|
||||
|
||||
public static Collection asMutableCollection(Object obj) {
|
||||
Collection result = null;
|
||||
try {
|
||||
result = (Collection) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce("argument is not a Collection");
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableCollection)) {
|
||||
throwCce("argument is not a MutableCollection");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Collection safeAsMutableCollection(Object obj) {
|
||||
Collection result;
|
||||
try {
|
||||
result = (Collection) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableCollection)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableList(Object obj) {
|
||||
return (obj instanceof List) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableList));
|
||||
}
|
||||
|
||||
public static List asMutableList(Object obj) {
|
||||
List result = null;
|
||||
try {
|
||||
result = (List) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce("argument is not a List");
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableList)) {
|
||||
throwCce("argument is not a MutableList");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List safeAsMutableList(Object obj) {
|
||||
List result;
|
||||
try {
|
||||
result = (List) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableList)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableSet(Object obj) {
|
||||
return (obj instanceof Set) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableSet));
|
||||
}
|
||||
|
||||
public static Set asMutableSet(Object obj) {
|
||||
Set result = null;
|
||||
try {
|
||||
result = (Set) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce("argument is not a Set");
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableSet)) {
|
||||
throwCce("argument is not a MutableSet");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Set safeAsMutableSet(Object obj) {
|
||||
Set result;
|
||||
try {
|
||||
result = (Set) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableSet)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableMap(Object obj) {
|
||||
return (obj instanceof Map) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableMap));
|
||||
}
|
||||
|
||||
public static Map asMutableMap(Object obj) {
|
||||
Map result = null;
|
||||
try {
|
||||
result = (Map) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce("argument is not a Map");
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap)) {
|
||||
throwCce("argument is not a MutableMap");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map safeAsMutableMap(Object obj) {
|
||||
Map result = null;
|
||||
try {
|
||||
result = (Map) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableMapEntry(Object obj) {
|
||||
return (obj instanceof Map.Entry) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableMap.Entry));
|
||||
}
|
||||
|
||||
public static Map.Entry asMutableMapEntry(Object obj) {
|
||||
Map.Entry result = null;
|
||||
try {
|
||||
result = (Map.Entry) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce("argument is not a Map.Entry");
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap.Entry)) {
|
||||
throwCce("argument is not a MutableMap.MutableEntry");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map.Entry safeAsMutableMapEntry(Object obj) {
|
||||
Map.Entry result = null;
|
||||
try {
|
||||
result = (Map.Entry) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap.Entry)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed 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 kotlin.jvm.internal;
|
||||
|
||||
import kotlin.jvm.internal.markers.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TypeIntrinsics {
|
||||
public static void throwCce(Object argument, String requestedClassName) {
|
||||
String argumentClassName = argument == null ? "null" : argument.getClass().getName();
|
||||
ClassCastException classCastException = new ClassCastException(argumentClassName + " cannot be cast to " + requestedClassName);
|
||||
throw Intrinsics.sanitizeStackTrace(classCastException, TypeIntrinsics.class.getName());
|
||||
}
|
||||
|
||||
public static void throwCce(ClassCastException e) {
|
||||
throw Intrinsics.sanitizeStackTrace(e, TypeIntrinsics.class.getName());
|
||||
}
|
||||
|
||||
public static boolean isMutableIterator(Object obj) {
|
||||
return (obj instanceof Iterator) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableIterator));
|
||||
}
|
||||
|
||||
public static Iterator asMutableIterator(Object obj) {
|
||||
Iterator result = null;
|
||||
try {
|
||||
result = (Iterator) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce(e);
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterator)) {
|
||||
throwCce(obj, "kotlin.MutableIterator");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Iterator safeAsMutableIterator(Object obj) {
|
||||
Iterator result;
|
||||
try {
|
||||
result = (Iterator) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterator)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableListIterator(Object obj) {
|
||||
return (obj instanceof ListIterator) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableListIterator));
|
||||
}
|
||||
|
||||
public static ListIterator asMutableListIterator(Object obj) {
|
||||
ListIterator result = null;
|
||||
try {
|
||||
result = (ListIterator) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce(e);
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableListIterator)) {
|
||||
throwCce(obj, "kotlin.MutableListIterator");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ListIterator safeAsMutableListIterator(Object obj) {
|
||||
ListIterator result;
|
||||
try {
|
||||
result = (ListIterator) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableListIterator)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableIterable(Object obj) {
|
||||
return (obj instanceof Iterable) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableIterable));
|
||||
}
|
||||
|
||||
public static Iterable asMutableIterable(Object obj) {
|
||||
Iterable result = null;
|
||||
try {
|
||||
result = (Iterable) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce(e);
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterable)) {
|
||||
throwCce(obj, "kotlin.MutableIterable");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Iterable safeAsMutableIterable(Object obj) {
|
||||
Iterable result;
|
||||
try {
|
||||
result = (Iterable) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterable)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableCollection(Object obj) {
|
||||
return (obj instanceof Collection) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableCollection));
|
||||
}
|
||||
|
||||
public static Collection asMutableCollection(Object obj) {
|
||||
Collection result = null;
|
||||
try {
|
||||
result = (Collection) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce(e);
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableCollection)) {
|
||||
throwCce(obj, "kotlin.MutableCollection");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Collection safeAsMutableCollection(Object obj) {
|
||||
Collection result;
|
||||
try {
|
||||
result = (Collection) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableCollection)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableList(Object obj) {
|
||||
return (obj instanceof List) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableList));
|
||||
}
|
||||
|
||||
public static List asMutableList(Object obj) {
|
||||
List result = null;
|
||||
try {
|
||||
result = (List) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce(e);
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableList)) {
|
||||
throwCce(obj, "kotlin.MutableList");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List safeAsMutableList(Object obj) {
|
||||
List result;
|
||||
try {
|
||||
result = (List) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableList)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableSet(Object obj) {
|
||||
return (obj instanceof Set) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableSet));
|
||||
}
|
||||
|
||||
public static Set asMutableSet(Object obj) {
|
||||
Set result = null;
|
||||
try {
|
||||
result = (Set) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce(e);
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableSet)) {
|
||||
throwCce(obj, "kotlin.MutableSet");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Set safeAsMutableSet(Object obj) {
|
||||
Set result;
|
||||
try {
|
||||
result = (Set) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableSet)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableMap(Object obj) {
|
||||
return (obj instanceof Map) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableMap));
|
||||
}
|
||||
|
||||
public static Map asMutableMap(Object obj) {
|
||||
Map result = null;
|
||||
try {
|
||||
result = (Map) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce(e);
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap)) {
|
||||
throwCce(obj, "kotlin.MutableMap");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map safeAsMutableMap(Object obj) {
|
||||
Map result;
|
||||
try {
|
||||
result = (Map) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isMutableMapEntry(Object obj) {
|
||||
return (obj instanceof Map.Entry) &&
|
||||
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableMap.Entry));
|
||||
}
|
||||
|
||||
public static Map.Entry asMutableMapEntry(Object obj) {
|
||||
Map.Entry result = null;
|
||||
try {
|
||||
result = (Map.Entry) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throwCce(e);
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap.Entry)) {
|
||||
throwCce(obj, "kotlin.MutableMap.MutableEntry");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map.Entry safeAsMutableMapEntry(Object obj) {
|
||||
Map.Entry result;
|
||||
try {
|
||||
result = (Map.Entry) obj;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap.Entry)) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal.markers;
|
||||
|
||||
public interface KMappedMarker {
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal.markers;
|
||||
|
||||
public interface KMutableCollection extends KMutableIterable {
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal.markers;
|
||||
|
||||
public interface KMutableIterable extends KMappedMarker {
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal.markers;
|
||||
|
||||
public interface KMutableIterator extends KMappedMarker {
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal.markers;
|
||||
|
||||
public interface KMutableList extends KMutableCollection {
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal.markers;
|
||||
|
||||
public interface KMutableListIterator extends KMutableIterator {
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal.markers;
|
||||
|
||||
public interface KMutableMap extends KMappedMarker {
|
||||
interface Entry extends KMappedMarker {
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal;
|
||||
package kotlin.jvm.internal.markers;
|
||||
|
||||
public interface KMutableSet extends KMutableCollection {
|
||||
}
|
||||
Reference in New Issue
Block a user