Replace more eager asserts in project with lazy
This commit is contained in:
+22
-17
@@ -18,28 +18,33 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.utils.*
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.*
|
||||
import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
|
||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.kotlin.load.java.lazy.child
|
||||
import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.ifEmpty
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
import org.jetbrains.kotlin.utils.valuesToMap
|
||||
import java.util.ArrayList
|
||||
import java.util.Collections
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public class LazyJavaClassMemberScope(
|
||||
@@ -234,7 +239,7 @@ public class LazyJavaClassMemberScope(
|
||||
val (methodsNamedValue, otherMethods) = methods.
|
||||
partition { it.getName() == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME }
|
||||
|
||||
assert(methodsNamedValue.size() <= 1, "There can't be to methods named 'value' in annotation class: " + jClass)
|
||||
assert(methodsNamedValue.size() <= 1) { "There can't be more than one method named 'value' in annotation class: $jClass" }
|
||||
val methodNamedValue = methodsNamedValue.firstOrNull()
|
||||
if (methodNamedValue != null) {
|
||||
val parameterNamedValueJavaType = methodNamedValue.getAnnotationMethodReturnJavaType()
|
||||
@@ -258,8 +263,8 @@ public class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
private fun JavaMethod.getAnnotationMethodReturnJavaType(): JavaType {
|
||||
assert(getValueParameters().isEmpty(), "Annotation method can't have parameters: " + this)
|
||||
return getReturnType() ?: throw AssertionError("Annotation method has no return type: " + this)
|
||||
assert(getValueParameters().isEmpty()) { "Annotation method can't have parameters: $this" }
|
||||
return getReturnType() ?: throw AssertionError("Annotation method has no return type: $this")
|
||||
}
|
||||
|
||||
private fun MutableList<ValueParameterDescriptor>.addAnnotationValueParameter(
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ class LazyJavaTypeResolver(
|
||||
is JavaPrimitiveType -> {
|
||||
val canonicalText = javaType.getCanonicalText()
|
||||
val jetType = JavaToKotlinClassMap.INSTANCE.mapPrimitiveKotlinClass(canonicalText)
|
||||
assert(jetType != null, "Primitive type is not found: " + canonicalText)
|
||||
assert(jetType != null) { "Primitive type is not found: $canonicalText" }
|
||||
jetType!!
|
||||
}
|
||||
is JavaClassifierType ->
|
||||
|
||||
+17
-13
@@ -16,16 +16,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.impl
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import kotlin.properties.Delegates
|
||||
import java.util.ArrayList
|
||||
import java.util.LinkedHashSet
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
public class ModuleDescriptorImpl(
|
||||
moduleName: Name,
|
||||
@@ -46,7 +46,7 @@ public class ModuleDescriptorImpl(
|
||||
public fun seal() {
|
||||
if (isSealed) return
|
||||
|
||||
assert(this in dependencies, "Module $id is not contained in his own dependencies, this is probably a misconfiguration")
|
||||
assert(this in dependencies) { "Module $id is not contained in his own dependencies, this is probably a misconfiguration" }
|
||||
isSealed = true
|
||||
}
|
||||
|
||||
@@ -57,7 +57,9 @@ public class ModuleDescriptorImpl(
|
||||
seal()
|
||||
dependencies.forEach {
|
||||
dependency ->
|
||||
assert(dependency.isInitialized, "Dependency module ${dependency.id} was not initialized by the time contents of dependent module ${this.id} were queried")
|
||||
assert(dependency.isInitialized) {
|
||||
"Dependency module ${dependency.id} was not initialized by the time contents of dependent module ${this.id} were queried"
|
||||
}
|
||||
}
|
||||
CompositePackageFragmentProvider(dependencies.map {
|
||||
it.packageFragmentProviderForModuleContent!!
|
||||
@@ -68,8 +70,10 @@ public class ModuleDescriptorImpl(
|
||||
get() = packageFragmentProviderForModuleContent != null
|
||||
|
||||
public fun addDependencyOnModule(dependency: ModuleDescriptorImpl) {
|
||||
assert(!isSealed, "Can't modify dependencies of sealed module $id")
|
||||
assert(dependency !in dependencies, "Trying to add dependency on module ${dependency.id} a second time for module ${this.id}, this is probably a misconfiguration")
|
||||
assert(!isSealed) { "Can't modify dependencies of sealed module $id" }
|
||||
assert(dependency !in dependencies) {
|
||||
"Trying to add dependency on module ${dependency.id} a second time for module ${this.id}, this is probably a misconfiguration"
|
||||
}
|
||||
dependencies.add(dependency)
|
||||
}
|
||||
|
||||
@@ -81,7 +85,7 @@ public class ModuleDescriptorImpl(
|
||||
* Initialize() and seal() can be called in any order.
|
||||
*/
|
||||
public fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
||||
assert(!isInitialized, "Attempt to initialize module $id twice")
|
||||
assert(!isInitialized) { "Attempt to initialize module $id twice" }
|
||||
packageFragmentProviderForModuleContent = providerForModuleContent
|
||||
}
|
||||
|
||||
@@ -92,8 +96,8 @@ public class ModuleDescriptorImpl(
|
||||
override fun isFriend(other: ModuleDescriptor) = other == this || other in friendModules
|
||||
|
||||
public fun addFriend(friend: ModuleDescriptorImpl): Unit {
|
||||
assert(friend != this, "Attempt to make module $id a friend to itself")
|
||||
assert(!isSealed, "Attempt to add friend module ${friend.id} to sealed module $id")
|
||||
assert(friend != this) { "Attempt to make module $id a friend to itself" }
|
||||
assert(!isSealed) { "Attempt to add friend module ${friend.id} to sealed module $id" }
|
||||
friendModules.add(friend)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user