Minor, fix warnings in core/ modules

This commit is contained in:
Alexander Udalov
2016-04-17 13:35:17 +03:00
parent f773966458
commit 027cc898e7
9 changed files with 30 additions and 30 deletions
+3 -2
View File
@@ -21,5 +21,6 @@ import kotlin.internal.PureReifiable
/**
* Returns an empty array of the specified type [T].
*/
public inline fun <reified @PureReifiable T> emptyArray(): Array<T> = arrayOfNulls<T>(0) as Array<T>
public inline fun <reified @PureReifiable T> emptyArray(): Array<T> =
@Suppress("CAST_NEVER_SUCCEEDS")
arrayOfNulls<T>(0) as Array<T>
@@ -103,7 +103,7 @@ class LazyJavaStaticClassScope(
private fun getStaticFunctionsFromJavaSuperClasses(name: Name, descriptor: ClassDescriptor): Set<SimpleFunctionDescriptor> {
val staticScope = descriptor.getParentJavaStaticClassScope() ?: return emptySet()
return staticScope.getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { it as SimpleFunctionDescriptor }.toSet()
return staticScope.getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).toSet()
}
private fun getStaticPropertiesFromJavaSupertypes(name: Name, descriptor: ClassDescriptor): Set<PropertyDescriptor> {
@@ -218,7 +218,7 @@ class LazyJavaTypeResolver(
// Most of the time this means there is an error in the Java code
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }.toReadOnlyList()
}
var howTheProjectionIsUsed = if (attr.howThisTypeIsUsed == SUPERTYPE) SUPERTYPE_ARGUMENT else TYPE_ARGUMENT
val howTheProjectionIsUsed = if (attr.howThisTypeIsUsed == SUPERTYPE) SUPERTYPE_ARGUMENT else TYPE_ARGUMENT
return javaType.typeArguments.withIndex().map {
indexedArgument ->
val (i, javaTypeArgument) = indexedArgument
@@ -263,10 +263,9 @@ class LazyJavaTypeResolver(
override fun getCapabilities(): TypeCapabilities = if (isRaw()) RawTypeCapabilities else TypeCapabilities.NONE
private val nullable = c.storageManager.createLazyValue l@ {
when (attr.flexibility) {
FLEXIBLE_LOWER_BOUND -> return@l false
FLEXIBLE_UPPER_BOUND -> return@l true
}
if (attr.flexibility == FLEXIBLE_LOWER_BOUND) return@l false
if (attr.flexibility == FLEXIBLE_UPPER_BOUND) return@l true
!attr.isMarkedNotNull &&
// 'L extends List<T>' in Java is a List<T> in Kotlin, not a List<T?>
// nullability will be taken care of in individual member signatures
@@ -406,6 +406,7 @@ internal class DescriptorRendererImpl(
}
private fun renderVisibility(visibility: Visibility, builder: StringBuilder) {
@Suppress("NAME_SHADOWING")
var visibility = visibility
if (DescriptorRendererModifier.VISIBILITY !in modifiers) return
if (normalizedVisibilities) {
@@ -168,6 +168,7 @@ public class DescriptorUtils {
}
@Nullable
@SuppressWarnings("unchecked")
public static <D extends DeclarationDescriptor> D getParentOfType(
@Nullable DeclarationDescriptor descriptor,
@NotNull Class<D> aClass,
@@ -179,7 +180,6 @@ public class DescriptorUtils {
}
while (descriptor != null) {
if (aClass.isInstance(descriptor)) {
//noinspection unchecked
return (D) descriptor;
}
descriptor = descriptor.getContainingDeclaration();
@@ -420,21 +420,22 @@ public class DescriptorUtils {
* TODO: probably all call-sites of this method are wrong, they should handle all super-declarations
*/
@NotNull
@SuppressWarnings("unchecked")
public static <D extends CallableMemberDescriptor> D unwrapFakeOverride(@NotNull D descriptor) {
while (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
Collection<? extends CallableMemberDescriptor> overridden = descriptor.getOverriddenDescriptors();
if (overridden.isEmpty()) {
throw new IllegalStateException("Fake override should have at least one overridden descriptor: " + descriptor);
}
//noinspection unchecked
descriptor = (D) overridden.iterator().next();
}
return descriptor;
}
@NotNull
@SuppressWarnings("unchecked")
public static <D extends DeclarationDescriptorWithVisibility> D unwrapFakeOverrideToAnyDeclaration(@NotNull D descriptor) {
if (descriptor instanceof CallableMemberDescriptor) {
//noinspection unchecked
return (D) unwrapFakeOverride((CallableMemberDescriptor) descriptor);
}
@@ -482,12 +483,12 @@ public class DescriptorUtils {
}
@NotNull
@SuppressWarnings("unchecked")
public static <D extends CallableMemberDescriptor> Set<D> getAllOverriddenDeclarations(@NotNull D memberDescriptor) {
Set<D> result = new HashSet<D>();
for (CallableMemberDescriptor overriddenDeclaration : memberDescriptor.getOverriddenDescriptors()) {
CallableMemberDescriptor.Kind kind = overriddenDeclaration.getKind();
if (kind == DECLARATION) {
//noinspection unchecked
result.add((D) overriddenDeclaration);
}
else if (kind == DELEGATION || kind == FAKE_OVERRIDE || kind == SYNTHESIZED) {
@@ -496,7 +497,6 @@ public class DescriptorUtils {
else {
throw new AssertionError("Unexpected callable kind " + kind);
}
//noinspection unchecked
result.addAll(getAllOverriddenDeclarations((D) overriddenDeclaration));
}
return result;
@@ -48,24 +48,24 @@ class SmartSet<T> private constructor() : AbstractSet<T>() {
else -> (data as MutableSet<T>).iterator()
}
override fun add(e: T): Boolean {
override fun add(element: T): Boolean {
when {
size == 0 -> {
data = e
data = element
}
size == 1 -> {
if (data == e) return false
data = arrayOf(data, e)
if (data == element) return false
data = arrayOf(data, element)
}
size < ARRAY_THRESHOLD -> {
val arr = data as Array<T>
if (e in arr) return false
data = if (size == ARRAY_THRESHOLD - 1) linkedSetOf(*arr).apply { add(e) }
else Arrays.copyOf(arr, size + 1).apply { set(size - 1, e) }
if (element in arr) return false
data = if (size == ARRAY_THRESHOLD - 1) linkedSetOf(*arr).apply { add(element) }
else Arrays.copyOf(arr, size + 1).apply { set(size - 1, element) }
}
else -> {
val set = data as MutableSet<T>
if (!set.add(e)) return false
if (!set.add(element)) return false
}
}
@@ -78,14 +78,14 @@ class SmartSet<T> private constructor() : AbstractSet<T>() {
size = 0
}
override fun contains(o: T): Boolean = when {
override fun contains(element: T): Boolean = when {
size == 0 -> false
size == 1 -> data == o
size < ARRAY_THRESHOLD -> o in data as Array<T>
else -> o in data as Set<T>
size == 1 -> data == element
size < ARRAY_THRESHOLD -> element in data as Array<T>
else -> element in data as Set<T>
}
private class SingletonIterator<T>(private val element: T) : MutableIterator<T> {
private class SingletonIterator<out T>(private val element: T) : MutableIterator<T> {
private var hasNext = true
override fun next(): T =
@@ -100,7 +100,7 @@ class SmartSet<T> private constructor() : AbstractSet<T>() {
override fun remove() = throw UnsupportedOperationException()
}
private class ArrayIterator<T>(array: Array<T>) : MutableIterator<T> {
private class ArrayIterator<out T>(array: Array<T>) : MutableIterator<T> {
private val arrayIterator = array.iterator()
override fun hasNext(): Boolean = arrayIterator.hasNext()
@@ -73,6 +73,7 @@ public class WrappedValues {
}
@Nullable
@SuppressWarnings("unchecked")
public static <V> V unescapeThrowable(@Nullable Object value) {
if (value instanceof ThrowableWrapper) {
Throwable originThrowable = ((ThrowableWrapper) value).getThrowable();
@@ -85,7 +86,6 @@ public class WrappedValues {
throw ExceptionUtilsKt.rethrow(originThrowable);
}
//noinspection unchecked
return (V) value;
}
@@ -80,6 +80,7 @@ fun <T: Any> T.check(predicate: (T) -> Boolean): T? = if (predicate(this)) this
fun <T : Any> constant(calculator: () -> T): T {
val cached = constantMap[calculator]
@Suppress("UNCHECKED_CAST")
if (cached != null) return cached as T
// safety check
@@ -132,8 +132,6 @@ private fun <T> Iterable<T>.elementAt(position: Int): T {
idx++
} while (true)
throw IllegalStateException()
}
private fun <T> Iterator<T>.remaining(): List<T> {