Cleanup in core modules

This commit is contained in:
Ilya Gorbunov
2015-12-25 10:43:19 +03:00
parent b71b336a69
commit 911adfd04d
42 changed files with 134 additions and 134 deletions
@@ -138,7 +138,7 @@ class LazyJavaClassDescriptor(
private val supertypes = c.storageManager.createLazyValue<Collection<KotlinType>> {
val javaTypes = jClass.getSupertypes()
val result = ArrayList<KotlinType>(javaTypes.size())
val result = ArrayList<KotlinType>(javaTypes.size)
val incomplete = ArrayList<JavaType>(0)
val purelyImplementedSupertype: KotlinType? = getPurelyImplementedSupertype()
@@ -179,7 +179,7 @@ class LazyJavaClassDescriptor(
val classDescriptor = c.module.builtIns.getBuiltInClassByNameNullable(purelyImplementedFqName.shortName()) ?: return null
if (classDescriptor.getTypeConstructor().getParameters().size() != getParameters().size()) return null
if (classDescriptor.getTypeConstructor().getParameters().size != getParameters().size) return null
val parametersAsTypeProjections = getParameters().map {
parameter -> TypeProjectionImpl(Variance.INVARIANT, parameter.getDefaultType())
@@ -196,7 +196,7 @@ class LazyJavaClassDescriptor(
getAnnotations().
findAnnotation(JvmAnnotationNames.PURELY_IMPLEMENTS_ANNOTATION) ?: return null
val fqNameString = (annotation.getAllValueArguments().values().singleOrNull() as? StringValue)?.value ?: return null
val fqNameString = (annotation.getAllValueArguments().values.singleOrNull() as? StringValue)?.value ?: return null
if (!isValidJavaFqName(fqNameString)) return null
return FqName(fqNameString)
@@ -76,7 +76,7 @@ public class LazyJavaClassMemberScope(
internal val constructors = c.storageManager.createLazyValue {
val constructors = jClass.getConstructors()
val result = ArrayList<JavaConstructorDescriptor>(constructors.size())
val result = ArrayList<JavaConstructorDescriptor>(constructors.size)
for (constructor in constructors) {
val descriptor = resolveConstructor(constructor)
result.add(descriptor)
@@ -482,7 +482,7 @@ public class LazyJavaClassMemberScope(
private fun SimpleFunctionDescriptor.doesOverrideBuiltinFunctionWithErasedValueParameters(
builtinWithErasedParameters: FunctionDescriptor
): Boolean {
if (this.valueParameters.size() != builtinWithErasedParameters.valueParameters.size()) return false
if (this.valueParameters.size != builtinWithErasedParameters.valueParameters.size) return false
if (!this.typeParameters.isEmpty() || !builtinWithErasedParameters.typeParameters.isEmpty()) return false
if (this.extensionReceiverParameter != null || builtinWithErasedParameters.extensionReceiverParameter != null) return false
@@ -549,14 +549,14 @@ public class LazyJavaClassMemberScope(
private fun createAnnotationConstructorParameters(constructor: ConstructorDescriptorImpl): List<ValueParameterDescriptor> {
val methods = jClass.getMethods()
val result = ArrayList<ValueParameterDescriptor>(methods.size())
val result = ArrayList<ValueParameterDescriptor>(methods.size)
val attr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes(allowFlexible = false, isForAnnotationParameter = true)
val (methodsNamedValue, otherMethods) = methods.
partition { it.getName() == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME }
assert(methodsNamedValue.size() <= 1) { "There can't be more than one method 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.getReturnType()
@@ -641,7 +641,7 @@ public class LazyJavaClassMemberScope(
}
override fun getClassNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
= nestedClassIndex().keySet() + enumEntryIndex().keySet()
= nestedClassIndex().keys + enumEntryIndex().keys
override fun getPropertyNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name> {
if (jClass.isAnnotationType()) return memberIndex().getMethodNames(nameFilter)
@@ -182,7 +182,7 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
}
val name = if (function.getName().asString() == "equals" &&
jValueParameters.size() == 1 &&
jValueParameters.size == 1 &&
c.module.builtIns.getNullableAnyType() == outType) {
// This is a hack to prevent numerous warnings on Kotlin classes that inherit Java classes: if you override "equals" in such
// class without this hack, you'll be warned that in the superclass the name is "p0" (regardless of the fact that it's
@@ -213,7 +213,7 @@ class LazyJavaTypeResolver(
return getConstructorTypeParameterSubstitute().getArguments()
}
if (typeParameters.size() != javaType.getTypeArguments().size()) {
if (typeParameters.size != javaType.getTypeArguments().size) {
// Most of the time this means there is an error in the Java code
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.getName().asString())) }
}
@@ -221,7 +221,7 @@ class LazyJavaTypeResolver(
return javaType.getTypeArguments().withIndex().map {
javaTypeParameter ->
val (i, t) = javaTypeParameter
val parameter = if (i >= typeParameters.size())
val parameter = if (i >= typeParameters.size)
ErrorUtils.createErrorTypeParameter(i, "#$i for ${typeConstructor}")
else typeParameters[i]
transformToTypeProjection(t, howTheProjectionIsUsed.toAttributes(), parameter)
@@ -287,7 +287,7 @@ class LazyJavaTypeResolver(
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>, jetType: KotlinType, flexibility: Flexibility): T? {
@Suppress("UNCHECKED_CAST")
return when (capabilityClass) {
javaClass<CustomTypeVariable>(), javaClass<Specificity>() -> Impl(flexibility) as T
CustomTypeVariable::class.java, Specificity::class.java -> Impl(flexibility) as T
else -> null
}
}
@@ -45,11 +45,11 @@ public object RawTypeCapabilities : TypeCapabilities {
override fun renderInflexible(type: KotlinType, renderer: DescriptorRenderer): String? {
if (type.arguments.isNotEmpty()) return null
return StringBuilder {
return buildString {
append(renderer.renderTypeConstructor(type.constructor))
append("(raw)")
if (type.isMarkedNullable) append('?')
}.toString()
}
}
override fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair<String, String>? {
@@ -75,9 +75,9 @@ public object RawTypeCapabilities : TypeCapabilities {
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
@Suppress("UNCHECKED_CAST")
return when(capabilityClass) {
javaClass<CustomSubstitutionCapability>() -> RawSubstitutionCapability as T
javaClass<CustomFlexibleRendering>() -> RawFlexibleRendering as T
javaClass<RawTypeTag>() -> RawTypeTag as T
CustomSubstitutionCapability::class.java -> RawSubstitutionCapability as T
CustomFlexibleRendering::class.java -> RawFlexibleRendering as T
RawTypeTag::class.java -> RawTypeTag as T
else -> null
}
}
@@ -35,8 +35,8 @@ private fun propertyNameFromAccessorMethodName(methodName: Name, prefix: String,
if (methodName.isSpecial()) return null
val identifier = methodName.getIdentifier()
if (!identifier.startsWith(prefix)) return null
if (identifier.length() == prefix.length()) return null
if (identifier[prefix.length()] in 'a'..'z') return null
if (identifier.length == prefix.length) return null
if (identifier[prefix.length] in 'a'..'z') return null
if (addPrefix != null) {
assert(removePrefix)
@@ -45,7 +45,7 @@ object BuiltinSpecialProperties {
private val GETTER_JVM_NAME_TO_PROPERTIES_SHORT_NAME_MAP: Map<Name, List<Name>> =
PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP.getInversedShortNamesMap()
private val FQ_NAMES = PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP.keySet()
private val FQ_NAMES = PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP.keys
internal val SHORT_NAMES = FQ_NAMES.map { it.shortName() }.toSet()
fun hasBuiltinSpecialPropertyFqName(callableMemberDescriptor: CallableMemberDescriptor): Boolean {
@@ -166,7 +166,7 @@ object BuiltinMethodsWithDifferentJvmName {
FqName("kotlin.CharSequence.get") to Name.identifier("charAt")
)
val ORIGINAL_SHORT_NAMES: List<Name> = FQ_NAMES_TO_JVM_MAP.keySet().map { it.shortName() }
val ORIGINAL_SHORT_NAMES: List<Name> = FQ_NAMES_TO_JVM_MAP.keys.map { it.shortName() }
val JVM_SHORT_NAME_TO_BUILTIN_SHORT_NAMES_MAP: Map<Name, List<Name>> = FQ_NAMES_TO_JVM_MAP.getInversedShortNamesMap()
@@ -298,4 +298,4 @@ public fun CallableMemberDescriptor.isFromBuiltins(): Boolean {
public fun CallableMemberDescriptor.isFromJavaOrBuiltins() = isFromJava || isFromBuiltins()
private fun Map<FqName, Name>.getInversedShortNamesMap(): Map<Name, List<Name>> =
entrySet().groupBy { it.value }.mapValues { entry -> entry.value.map { it.key.shortName() } }
entries.groupBy { it.value }.mapValues { entry -> entry.value.map { it.key.shortName() } }
@@ -118,7 +118,7 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
return Result(enhancedType, globalArgIndex - index)
}
private fun List<Annotations>.compositeAnnotationsOrSingle() = when (size()) {
private fun List<Annotations>.compositeAnnotationsOrSingle() = when (size) {
0 -> error("At least one Annotations object expected")
1 -> single()
else -> CompositeAnnotations(this.toReadOnlyList())
@@ -118,7 +118,7 @@ fun KotlinType.computeIndexedQualifiersForOverride(fromSupertypes: Collection<Ko
// Note that `this` is flexible here, so it's equal to it's bounds
val onlyHeadTypeConstructor = isCovariant && fromSupertypes.any { !KotlinTypeChecker.DEFAULT.equalTypes(it, this) }
val treeSize = if (onlyHeadTypeConstructor) 1 else indexedThisType.size()
val treeSize = if (onlyHeadTypeConstructor) 1 else indexedThisType.size
val computedResult = Array(treeSize) {
index ->
val isHeadTypeConstructor = index == 0
@@ -36,7 +36,7 @@ class JvmNameResolver(
// Here we expand the 'range' field of the Record message for simplicity to a list of records
private val records: List<Record> = ArrayList<Record>().apply {
val records = types.recordList
this.ensureCapacity(records.size())
this.ensureCapacity(records.size)
for (record in records) {
repeat(record.range) {
this.add(record)
@@ -57,7 +57,7 @@ class JvmNameResolver(
if (record.substringIndexCount >= 2) {
val (begin, end) = record.substringIndexList
if (0 <= begin && begin <= end && end <= string.length()) {
if (0 <= begin && begin <= end && end <= string.length) {
string = string.substring(begin, end)
}
}
@@ -75,8 +75,8 @@ class JvmNameResolver(
string = string.replace('$', '.')
}
DESC_TO_CLASS_ID -> {
if (string.length() >= 2) {
string = string.substring(1, string.length() - 1)
if (string.length >= 2) {
string = string.substring(1, string.length - 1)
}
string = string.replace('$', '.')
}
@@ -131,7 +131,7 @@ class JvmNameResolver(
"kotlin/ListIterator", "kotlin/MutableListIterator"
)
private val PREDEFINED_STRINGS_MAP = PREDEFINED_STRINGS.withIndex().toMap({ it.value }, { it.index })
private val PREDEFINED_STRINGS_MAP = PREDEFINED_STRINGS.withIndex().toMapBy({ it.value }, { it.index })
fun getPredefinedStringIndex(string: String): Int? = PREDEFINED_STRINGS_MAP[string]
}