Minor, simplify code in TypeIntrinsics

This commit is contained in:
Alexander Udalov
2015-10-19 14:28:22 +03:00
parent 121807654a
commit 8f6f6f7807
@@ -33,160 +33,144 @@ public class TypeIntrinsics {
throw sanitizeStackTrace(new ClassCastException(argumentClassName + " cannot be cast to " + requestedClassName)); throw sanitizeStackTrace(new ClassCastException(argumentClassName + " cannot be cast to " + requestedClassName));
} }
public static void throwCce(ClassCastException e) { public static ClassCastException throwCce(ClassCastException e) {
throw Intrinsics.sanitizeStackTrace(e, TypeIntrinsics.class.getName()); throw sanitizeStackTrace(e);
} }
public static boolean isMutableIterator(Object obj) { public static boolean isMutableIterator(Object obj) {
return (obj instanceof Iterator) && return obj instanceof Iterator &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableIterator)); (!(obj instanceof KMappedMarker) || obj instanceof KMutableIterator);
} }
public static Iterator asMutableIterator(Object obj) { public static Iterator asMutableIterator(Object obj) {
Iterator result = null; if (obj instanceof KMappedMarker && !(obj instanceof KMutableIterator)) {
try {
result = (Iterator) obj;
}
catch (ClassCastException e) {
throwCce(e);
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterator)) {
throwCce(obj, "kotlin.MutableIterator"); throwCce(obj, "kotlin.MutableIterator");
} }
return result; try {
return (Iterator) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
} }
public static boolean isMutableListIterator(Object obj) { public static boolean isMutableListIterator(Object obj) {
return (obj instanceof ListIterator) && return obj instanceof ListIterator &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableListIterator)); (!(obj instanceof KMappedMarker) || obj instanceof KMutableListIterator);
} }
public static ListIterator asMutableListIterator(Object obj) { public static ListIterator asMutableListIterator(Object obj) {
ListIterator result = null; if (obj instanceof KMappedMarker && !(obj instanceof KMutableListIterator)) {
try {
result = (ListIterator) obj;
}
catch (ClassCastException e) {
throwCce(e);
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableListIterator)) {
throwCce(obj, "kotlin.MutableListIterator"); throwCce(obj, "kotlin.MutableListIterator");
} }
return result; try {
return (ListIterator) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
} }
public static boolean isMutableIterable(Object obj) { public static boolean isMutableIterable(Object obj) {
return (obj instanceof Iterable) && return obj instanceof Iterable &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableIterable)); (!(obj instanceof KMappedMarker) || obj instanceof KMutableIterable);
} }
public static Iterable asMutableIterable(Object obj) { public static Iterable asMutableIterable(Object obj) {
Iterable result = null; if (obj instanceof KMappedMarker && !(obj instanceof KMutableIterable)) {
try {
result = (Iterable) obj;
}
catch (ClassCastException e) {
throwCce(e);
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterable)) {
throwCce(obj, "kotlin.MutableIterable"); throwCce(obj, "kotlin.MutableIterable");
} }
return result; try {
return (Iterable) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
} }
public static boolean isMutableCollection(Object obj) { public static boolean isMutableCollection(Object obj) {
return (obj instanceof Collection) && return obj instanceof Collection &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableCollection)); (!(obj instanceof KMappedMarker) || obj instanceof KMutableCollection);
} }
public static Collection asMutableCollection(Object obj) { public static Collection asMutableCollection(Object obj) {
Collection result = null; if (obj instanceof KMappedMarker && !(obj instanceof KMutableCollection)) {
try {
result = (Collection) obj;
}
catch (ClassCastException e) {
throwCce(e);
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableCollection)) {
throwCce(obj, "kotlin.MutableCollection"); throwCce(obj, "kotlin.MutableCollection");
} }
return result; try {
return (Collection) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
} }
public static boolean isMutableList(Object obj) { public static boolean isMutableList(Object obj) {
return (obj instanceof List) && return obj instanceof List &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableList)); (!(obj instanceof KMappedMarker) || obj instanceof KMutableList);
} }
public static List asMutableList(Object obj) { public static List asMutableList(Object obj) {
List result = null; if (obj instanceof KMappedMarker && !(obj instanceof KMutableList)) {
try {
result = (List) obj;
}
catch (ClassCastException e) {
throwCce(e);
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableList)) {
throwCce(obj, "kotlin.MutableList"); throwCce(obj, "kotlin.MutableList");
} }
return result; try {
return (List) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
} }
public static boolean isMutableSet(Object obj) { public static boolean isMutableSet(Object obj) {
return (obj instanceof Set) && return obj instanceof Set &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableSet)); (!(obj instanceof KMappedMarker) || obj instanceof KMutableSet);
} }
public static Set asMutableSet(Object obj) { public static Set asMutableSet(Object obj) {
Set result = null; if (obj instanceof KMappedMarker && !(obj instanceof KMutableSet)) {
try {
result = (Set) obj;
}
catch (ClassCastException e) {
throwCce(e);
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableSet)) {
throwCce(obj, "kotlin.MutableSet"); throwCce(obj, "kotlin.MutableSet");
} }
return result; try {
return (Set) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
} }
public static boolean isMutableMap(Object obj) { public static boolean isMutableMap(Object obj) {
return (obj instanceof Map) && return obj instanceof Map &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableMap)); (!(obj instanceof KMappedMarker) || obj instanceof KMutableMap);
} }
public static Map asMutableMap(Object obj) { public static Map asMutableMap(Object obj) {
Map result = null; if (obj instanceof KMappedMarker && !(obj instanceof KMutableMap)) {
try {
result = (Map) obj;
}
catch (ClassCastException e) {
throwCce(e);
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap)) {
throwCce(obj, "kotlin.MutableMap"); throwCce(obj, "kotlin.MutableMap");
} }
return result; try {
return (Map) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
} }
public static boolean isMutableMapEntry(Object obj) { public static boolean isMutableMapEntry(Object obj) {
return (obj instanceof Map.Entry) && return obj instanceof Map.Entry &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableMap.Entry)); (!(obj instanceof KMappedMarker) || obj instanceof KMutableMap.Entry);
} }
public static Map.Entry asMutableMapEntry(Object obj) { public static Map.Entry asMutableMapEntry(Object obj) {
Map.Entry result = null; if (obj instanceof KMappedMarker && !(obj instanceof KMutableMap.Entry)) {
try {
result = (Map.Entry) obj;
}
catch (ClassCastException e) {
throwCce(e);
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap.Entry)) {
throwCce(obj, "kotlin.MutableMap.MutableEntry"); throwCce(obj, "kotlin.MutableMap.MutableEntry");
} }
return result; try {
return (Map.Entry) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
} }
public static int getFunctionArity(Object obj) { public static int getFunctionArity(Object obj) {