From 027cc898e74de5f24a487cfb358315dcb8b5f462 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Sun, 17 Apr 2016 13:35:17 +0300 Subject: [PATCH] Minor, fix warnings in core/ modules --- core/builtins/src/kotlin/ArrayIntrinsics.kt | 5 ++-- .../descriptors/LazyJavaStaticClassScope.kt | 2 +- .../java/lazy/types/LazyJavaTypeResolver.kt | 9 +++--- .../kotlin/renderer/DescriptorRendererImpl.kt | 1 + .../kotlin/resolve/DescriptorUtils.java | 10 +++---- .../org/jetbrains/kotlin/utils/SmartSet.kt | 28 +++++++++---------- .../jetbrains/kotlin/utils/WrappedValues.java | 2 +- .../org/jetbrains/kotlin/utils/addToStdlib.kt | 1 + .../kotlin/test/CollectionAssertions.kt | 2 -- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/core/builtins/src/kotlin/ArrayIntrinsics.kt b/core/builtins/src/kotlin/ArrayIntrinsics.kt index 4da52a63162..0be76d8a78f 100644 --- a/core/builtins/src/kotlin/ArrayIntrinsics.kt +++ b/core/builtins/src/kotlin/ArrayIntrinsics.kt @@ -21,5 +21,6 @@ import kotlin.internal.PureReifiable /** * Returns an empty array of the specified type [T]. */ -public inline fun emptyArray(): Array = arrayOfNulls(0) as Array - +public inline fun emptyArray(): Array = + @Suppress("CAST_NEVER_SUCCEEDS") + arrayOfNulls(0) as Array diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticClassScope.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticClassScope.kt index ef48cfe0d7e..4f261283161 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticClassScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticClassScope.kt @@ -103,7 +103,7 @@ class LazyJavaStaticClassScope( private fun getStaticFunctionsFromJavaSuperClasses(name: Name, descriptor: ClassDescriptor): Set { 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 { diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt index b2fad355ae8..6eb904373d0 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt @@ -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' in Java is a List in Kotlin, not a List // nullability will be taken care of in individual member signatures diff --git a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt index 3a7229d5897..6c531738397 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/renderer/DescriptorRendererImpl.kt @@ -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) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java index 39f309e8f56..b66af0ff790 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java @@ -168,6 +168,7 @@ public class DescriptorUtils { } @Nullable + @SuppressWarnings("unchecked") public static D getParentOfType( @Nullable DeclarationDescriptor descriptor, @NotNull Class 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 unwrapFakeOverride(@NotNull D descriptor) { while (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { Collection 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 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 Set getAllOverriddenDeclarations(@NotNull D memberDescriptor) { Set result = new HashSet(); 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; diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt index 0c446cbaf20..8a9d12034c0 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt @@ -48,24 +48,24 @@ class SmartSet private constructor() : AbstractSet() { else -> (data as MutableSet).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 - 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 - if (!set.add(e)) return false + if (!set.add(element)) return false } } @@ -78,14 +78,14 @@ class SmartSet private constructor() : AbstractSet() { 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 - else -> o in data as Set + size == 1 -> data == element + size < ARRAY_THRESHOLD -> element in data as Array + else -> element in data as Set } - private class SingletonIterator(private val element: T) : MutableIterator { + private class SingletonIterator(private val element: T) : MutableIterator { private var hasNext = true override fun next(): T = @@ -100,7 +100,7 @@ class SmartSet private constructor() : AbstractSet() { override fun remove() = throw UnsupportedOperationException() } - private class ArrayIterator(array: Array) : MutableIterator { + private class ArrayIterator(array: Array) : MutableIterator { private val arrayIterator = array.iterator() override fun hasNext(): Boolean = arrayIterator.hasNext() diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/WrappedValues.java b/core/util.runtime/src/org/jetbrains/kotlin/utils/WrappedValues.java index 62a0f25feae..d12671a781c 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/WrappedValues.java +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/WrappedValues.java @@ -73,6 +73,7 @@ public class WrappedValues { } @Nullable + @SuppressWarnings("unchecked") public static 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; } diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt index 94635284695..4cc9c439663 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt @@ -80,6 +80,7 @@ fun T.check(predicate: (T) -> Boolean): T? = if (predicate(this)) this fun constant(calculator: () -> T): T { val cached = constantMap[calculator] + @Suppress("UNCHECKED_CAST") if (cached != null) return cached as T // safety check diff --git a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/CollectionAssertions.kt b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/CollectionAssertions.kt index a04e3d0b64c..c43d75aec4d 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/CollectionAssertions.kt +++ b/libraries/kotlin.test/shared/src/main/kotlin/kotlin/test/CollectionAssertions.kt @@ -132,8 +132,6 @@ private fun Iterable.elementAt(position: Int): T { idx++ } while (true) - - throw IllegalStateException() } private fun Iterator.remaining(): List {