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]
}
@@ -23,20 +23,20 @@ import java.lang.reflect.Method
public class ReflectJavaAnnotation(private val annotation: Annotation) : ReflectJavaElement(), JavaAnnotation {
override fun findArgument(name: Name): JavaAnnotationArgument? {
return getArgumentValue(annotation.annotationType().getDeclaredMethod(name.asString()))
return getArgumentValue(annotation.annotationClass.java.getDeclaredMethod(name.asString()))
}
override fun getArguments(): Collection<JavaAnnotationArgument> {
return annotation.annotationType().getDeclaredMethods().map { getArgumentValue(it) }
return annotation.annotationClass.java.getDeclaredMethods().map { getArgumentValue(it) }
}
private fun getArgumentValue(argument: Method): ReflectJavaAnnotationArgument {
return argument.invoke(annotation).let { ReflectJavaAnnotationArgument.create(it, Name.identifier(argument.getName())) }
}
override fun resolve() = ReflectJavaClass(annotation.annotationType())
override fun resolve() = ReflectJavaClass(annotation.annotationClass.java)
override fun getClassId() = annotation.annotationType().classId
override fun getClassId() = annotation.annotationClass.java.classId
override fun equals(other: Any?) = other is ReflectJavaAnnotation && annotation == other.annotation
@@ -54,7 +54,7 @@ class ReflectJavaEnumValueAnnotationArgument(
override fun resolve(): ReflectJavaField {
val clazz = value.javaClass
val enumClass = if (clazz.isEnum()) clazz else clazz.getEnclosingClass()
return ReflectJavaField(enumClass.getDeclaredField(value.name()))
return ReflectJavaField(enumClass.getDeclaredField(value.name))
}
}
@@ -35,5 +35,5 @@ fun getAnnotations(annotations: Array<Annotation>): List<ReflectJavaAnnotation>
}
fun findAnnotation(annotations: Array<Annotation>, fqName: FqName): ReflectJavaAnnotation? {
return annotations.firstOrNull { it.annotationType().classId.asSingleFqName() == fqName }?.let { ReflectJavaAnnotation(it) }
return annotations.firstOrNull { it.annotationClass.java.classId.asSingleFqName() == fqName }?.let { ReflectJavaAnnotation(it) }
}
@@ -47,8 +47,8 @@ public class ReflectJavaClass(
override fun getOuterClass() = klass.getDeclaringClass()?.let(::ReflectJavaClass)
override fun getSupertypes(): Collection<JavaClassifierType> {
if (klass == javaClass<Any>()) return emptyList()
return listOf(klass.genericSuperclass ?: javaClass<Any>(), *klass.genericInterfaces).map(::ReflectJavaClassifierType)
if (klass == Any::class.java) return emptyList()
return listOf(klass.genericSuperclass ?: Any::class.java, *klass.genericInterfaces).map(::ReflectJavaClassifierType)
}
override fun getMethods() = klass.getDeclaredMethods()
@@ -66,7 +66,7 @@ public class ReflectJavaClass(
private fun isEnumValuesOrValueOf(method: Method): Boolean {
return when (method.getName()) {
"values" -> method.getParameterTypes().isEmpty()
"valueOf" -> Arrays.equals(method.getParameterTypes(), arrayOf(javaClass<String>()))
"valueOf" -> Arrays.equals(method.getParameterTypes(), arrayOf(String::class.java))
else -> false
}
}
@@ -31,14 +31,14 @@ public class ReflectJavaConstructor(override val member: Constructor<*>) : Refle
val klass = member.getDeclaringClass()
val realTypes = when {
klass.getDeclaringClass() != null && !Modifier.isStatic(klass.getModifiers()) -> types.copyOfRange(1, types.size())
klass.getDeclaringClass() != null && !Modifier.isStatic(klass.getModifiers()) -> types.copyOfRange(1, types.size)
else -> types
}
val annotations = member.getParameterAnnotations()
val realAnnotations = when {
annotations.size() < realTypes.size() -> throw IllegalStateException("Illegal generic signature: $member")
annotations.size() > realTypes.size() -> annotations.copyOfRange(annotations.size() - realTypes.size(), annotations.size())
annotations.size < realTypes.size -> throw IllegalStateException("Illegal generic signature: $member")
annotations.size > realTypes.size -> annotations.copyOfRange(annotations.size - realTypes.size, annotations.size)
else -> annotations
}
@@ -42,7 +42,7 @@ public abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnot
parameterAnnotations: Array<Array<Annotation>>,
isVararg: Boolean
): List<JavaValueParameter> {
val result = ArrayList<JavaValueParameter>(parameterTypes.size())
val result = ArrayList<JavaValueParameter>(parameterTypes.size)
val names = Java8ParameterNamesLoader.loadParameterNames(member)
for (i in parameterTypes.indices) {
val type = ReflectJavaType.create(parameterTypes[i])
@@ -30,7 +30,7 @@ public class ReflectJavaTypeParameter(
) : ReflectJavaElement(), JavaTypeParameter {
override fun getUpperBounds(): List<ReflectJavaClassifierType> {
val bounds = typeVariable.getBounds().map { bound -> ReflectJavaClassifierType(bound) }
if (bounds.singleOrNull()?.type == javaClass<Any>()) return emptyList()
if (bounds.singleOrNull()?.type == Any::class.java) return emptyList()
return bounds
}
@@ -24,17 +24,17 @@ public class ReflectJavaWildcardType(override val type: WildcardType): ReflectJa
override fun getBound(): ReflectJavaType? {
val upperBounds = type.getUpperBounds()
val lowerBounds = type.getLowerBounds()
if (upperBounds.size() > 1 || lowerBounds.size() > 1) {
if (upperBounds.size > 1 || lowerBounds.size > 1) {
throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $type")
}
return when {
lowerBounds.size() == 1 -> ReflectJavaType.create(lowerBounds.single())
upperBounds.size() == 1 -> upperBounds.single().let { ub -> if (ub != javaClass<Any>()) ReflectJavaType.create(ub) else null }
lowerBounds.size == 1 -> ReflectJavaType.create(lowerBounds.single())
upperBounds.size == 1 -> upperBounds.single().let { ub -> if (ub != Any::class.java) ReflectJavaType.create(ub) else null }
else -> null
}
}
override fun isExtends() = type.getUpperBounds().firstOrNull() != javaClass<Any>()
override fun isExtends() = type.getUpperBounds().firstOrNull() != Any::class.java
override fun getTypeProvider(): JavaTypeProvider = throw UnsupportedOperationException()
}
@@ -25,7 +25,7 @@ public val Class<*>.safeClassLoader: ClassLoader
get() = classLoader ?: ClassLoader.getSystemClassLoader()
public fun Class<*>.isEnumClassOrSpecializedEnumEntryClass(): Boolean =
javaClass<Enum<*>>().isAssignableFrom(this)
Enum::class.java.isAssignableFrom(this)
/**
* NOTE: does not perform a Java -> Kotlin mapping. If this is not expected, consider using KClassImpl#classId instead
@@ -98,7 +98,7 @@ private object ReflectClassStructure {
for ((parameterIndex, annotations) in method.getParameterAnnotations().withIndex()) {
for (annotation in annotations) {
val annotationType = annotation.annotationType()
val annotationType = annotation.annotationClass.java
visitor.visitParameterAnnotation(parameterIndex, annotationType.classId, ReflectAnnotationSource(annotation))?.let {
processAnnotationArguments(it, annotation, annotationType)
}
@@ -125,11 +125,11 @@ private object ReflectClassStructure {
// - local/anonymous classes may have many parameters for captured values
// At the moment this seems like a working heuristic for computing number of synthetic parameters for Kotlin classes,
// although this is wrong and likely to change, see KT-6886
val shift = constructor.getParameterTypes().size() - parameterAnnotations.size()
val shift = constructor.getParameterTypes().size - parameterAnnotations.size
for ((parameterIndex, annotations) in parameterAnnotations.withIndex()) {
for (annotation in annotations) {
val annotationType = annotation.annotationType()
val annotationType = annotation.annotationClass.java
visitor.visitParameterAnnotation(
parameterIndex + shift, annotationType.classId, ReflectAnnotationSource(annotation)
)?.let {
@@ -156,7 +156,7 @@ private object ReflectClassStructure {
}
private fun processAnnotation(visitor: KotlinJvmBinaryClass.AnnotationVisitor, annotation: Annotation) {
val annotationType = annotation.annotationType()
val annotationType = annotation.annotationClass.java
visitor.visitAnnotation(annotationType.classId, ReflectAnnotationSource(annotation))?.let {
processAnnotationArguments(it, annotation, annotationType)
}
@@ -182,9 +182,9 @@ private object ReflectClassStructure {
clazz.isEnumClassOrSpecializedEnumEntryClass() -> {
// isEnum returns false for specialized enum constants (enum entries which are anonymous enum subclasses)
val classId = (if (clazz.isEnum()) clazz else clazz.getEnclosingClass()).classId
visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name()))
visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name))
}
javaClass<Annotation>().isAssignableFrom(clazz) -> {
Annotation::class.java.isAssignableFrom(clazz) -> {
val annotationClass = clazz.getInterfaces().single()
val v = visitor.visitAnnotation(name, annotationClass.classId) ?: return
processAnnotationArguments(v, value as Annotation, annotationClass)
@@ -195,7 +195,7 @@ private object ReflectClassStructure {
if (componentType.isEnum()) {
val enumClassId = componentType.classId
for (element in value as Array<*>) {
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name()))
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
}
}
else {
@@ -40,6 +40,6 @@ class RuntimePackagePartProvider(val classLoader : ClassLoader) : PackagePartPro
override fun findPackageParts(packageFqName: String): List<String> {
return module2Mapping.values().map { it.value.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }.distinct()
return module2Mapping.values.map { it.value.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }.distinct()
}
}
@@ -42,7 +42,7 @@ public class BuiltInFictitiousFunctionClassFactory(
val prefix = kind.classNamePrefix
if (!className.startsWith(prefix)) return null
val arity = toInt(className.substring(prefix.length())) ?: return null
val arity = toInt(className.substring(prefix.length)) ?: return null
// TODO: validate arity, should be <= 255
return KindWithArity(kind, arity)
@@ -73,7 +73,7 @@ public class FunctionClassDescriptor(
fun typeParameter(variance: Variance, name: String) {
result.add(TypeParameterDescriptorImpl.createWithDefaultBound(
this@FunctionClassDescriptor, Annotations.EMPTY, false, variance, Name.identifier(name), result.size()
this@FunctionClassDescriptor, Annotations.EMPTY, false, variance, Name.identifier(name), result.size
))
}
@@ -120,7 +120,7 @@ public class FunctionClassDescriptor(
val typeConstructor = descriptor.getTypeConstructor()
// Substitute all type parameters of the super class with our last type parameters
val arguments = getParameters().takeLast(typeConstructor.getParameters().size()).map {
val arguments = getParameters().takeLast(typeConstructor.getParameters().size).map {
TypeProjectionImpl(it.getDefaultType())
}
@@ -28,7 +28,7 @@ public enum class AnnotationUseSiteTarget(renderName: String? = null) {
CONSTRUCTOR_PARAMETER("param"),
SETTER_PARAMETER("setparam");
public val renderName: String = renderName ?: name().toLowerCase()
public val renderName: String = renderName ?: name.toLowerCase()
public companion object {
public fun getAssociatedUseSiteTarget(descriptor: DeclarationDescriptor): AnnotationUseSiteTarget? = when (descriptor) {
@@ -77,7 +77,7 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
init {
for (target in KotlinTarget.values()) {
map[target.name()] = target
map[target.name] = target
}
}
@@ -47,7 +47,7 @@ public open class SubpackagesScope(private val moduleDescriptor: ModuleDescripto
if (fqName.isRoot() && kindFilter.excludes.contains(DescriptorKindExclude.TopLevelPackages)) return listOf()
val subFqNames = moduleDescriptor.getSubPackagesOf(fqName, nameFilter)
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
val result = ArrayList<DeclarationDescriptor>(subFqNames.size)
for (subFqName in subFqNames) {
val shortName = subFqName.shortName()
if (nameFilter(shortName)) {
@@ -25,7 +25,7 @@ public fun FqName.isSubpackageOf(packageName: FqName): Boolean {
}
private fun isSubpackageOf(subpackageNameStr: String, packageNameStr: String): Boolean {
return subpackageNameStr.startsWith(packageNameStr) && subpackageNameStr[packageNameStr.length()] == '.'
return subpackageNameStr.startsWith(packageNameStr) && subpackageNameStr[packageNameStr.length] == '.'
}
public fun FqName.isOneSegmentFQN(): Boolean = !isRoot() && parent().isRoot()
@@ -43,7 +43,7 @@ public fun FqName.tail(prefix: FqName): FqName {
return when {
!isSubpackageOf(prefix) || prefix.isRoot() -> this
this == prefix -> FqName.ROOT
else -> FqName(asString().substring(prefix.asString().length() + 1))
else -> FqName(asString().substring(prefix.asString().length + 1))
}
}
@@ -239,11 +239,11 @@ internal class DescriptorRendererImpl(
override fun renderTypeArguments(typeArguments: List<TypeProjection>): String {
if (typeArguments.isEmpty()) return ""
return StringBuilder {
return buildString {
append(lt())
appendTypeProjections(typeArguments, this)
append(gt())
}.toString()
}
}
private fun renderDefaultType(type: KotlinType): String {
@@ -279,7 +279,7 @@ internal class DescriptorRendererImpl(
}
append(renderPossiblyInnerType(possiblyInnerType))
}.toString()
}
private fun renderPossiblyInnerType(possiblyInnerType: PossiblyInnerType): String =
buildString {
@@ -304,9 +304,9 @@ internal class DescriptorRendererImpl(
}
}
override fun renderTypeProjection(typeProjection: TypeProjection) = StringBuilder {
override fun renderTypeProjection(typeProjection: TypeProjection) = buildString {
appendTypeProjections(listOf(typeProjection), this)
}.toString()
}
private fun appendTypeProjections(typeProjections: List<TypeProjection>, builder: StringBuilder) {
typeProjections.map {
@@ -321,7 +321,7 @@ internal class DescriptorRendererImpl(
}
private fun renderFunctionType(type: KotlinType): String {
return StringBuilder {
return buildString {
val isNullable = type.isMarkedNullable()
if (isNullable) append("(")
@@ -344,7 +344,7 @@ internal class DescriptorRendererImpl(
append(renderNormalizedType(KotlinBuiltIns.getReturnTypeFromFunctionType(type)))
if (isNullable) append(")?")
}.toString()
}
}
@@ -370,7 +370,7 @@ internal class DescriptorRendererImpl(
val excluded = if (annotated is KotlinType) excludedTypeAnnotationClasses else excludedAnnotationClasses
val annotationsBuilder = StringBuilder {
val annotationsBuilder = StringBuilder().apply {
// Sort is needed just to fix some order when annotations resolved from modifiers
// See AnnotationResolver.resolveAndAppendAnnotationsFromModifiers for clarification
// This hack can be removed when modifiers will be resolved without annotations
@@ -389,7 +389,7 @@ internal class DescriptorRendererImpl(
}
override fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget?): String {
return StringBuilder {
return buildString {
append('@')
if (target != null) {
append(target.renderName + ":")
@@ -398,7 +398,7 @@ internal class DescriptorRendererImpl(
if (verbose) {
renderAndSortAnnotationArguments(annotation).joinTo(this, ", ", "(", ")")
}
}.toString()
}
}
private fun renderAndSortAnnotationArguments(descriptor: AnnotationDescriptor): List<String> {
@@ -410,7 +410,7 @@ internal class DescriptorRendererImpl(
val defaultList = parameterDescriptorsWithDefaultValue.filter { !allValueArguments.containsKey(it) }.map {
"${it.getName().asString()} = ..."
}
val argumentList = allValueArguments.entrySet()
val argumentList = allValueArguments.entries
.map { entry ->
val name = entry.key.getName().asString()
val value = if (!parameterDescriptorsWithDefaultValue.contains(entry.key)) renderConstant(entry.value) else "..."
@@ -440,7 +440,7 @@ internal class DescriptorRendererImpl(
private fun renderModality(modality: Modality, builder: StringBuilder) {
if (DescriptorRendererModifier.MODALITY !in modifiers) return
val keyword = modality.name().toLowerCase()
val keyword = modality.name.toLowerCase()
builder.append(renderKeyword(keyword)).append(" ")
}
@@ -471,7 +471,7 @@ internal class DescriptorRendererImpl(
if (overrideRenderingPolicy != OverrideRenderingPolicy.RENDER_OPEN) {
builder.append("override ")
if (verbose) {
builder.append("/*").append(callableMember.getOverriddenDescriptors().size()).append("*/ ")
builder.append("/*").append(callableMember.getOverriddenDescriptors().size).append("*/ ")
}
}
}
@@ -480,7 +480,7 @@ internal class DescriptorRendererImpl(
private fun renderMemberKind(callableMember: CallableMemberDescriptor, builder: StringBuilder) {
if (DescriptorRendererModifier.MEMBER_KIND !in modifiers) return
if (verbose && callableMember.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
builder.append("/*").append(callableMember.getKind().name().toLowerCase()).append("*/ ")
builder.append("/*").append(callableMember.getKind().name.toLowerCase()).append("*/ ")
}
}
@@ -509,13 +509,13 @@ internal class DescriptorRendererImpl(
}
override fun render(declarationDescriptor: DeclarationDescriptor): String {
return StringBuilder {
return buildString {
declarationDescriptor.accept(RenderDeclarationDescriptorVisitor(), this)
if (withDefinedIn) {
appendDefinedIn(declarationDescriptor, this)
}
}.toString()
}
}
@@ -537,7 +537,7 @@ internal class DescriptorRendererImpl(
builder.append(renderKeyword(variance)).append(" ")
}
renderName(typeParameter, builder)
val upperBoundsCount = typeParameter.getUpperBounds().size()
val upperBoundsCount = typeParameter.getUpperBounds().size
if ((upperBoundsCount > 1 && !topLevel) || upperBoundsCount == 1) {
val upperBound = typeParameter.getUpperBounds().iterator().next()
if (!KotlinBuiltIns.isDefaultBound(upperBound)) {
@@ -685,12 +685,12 @@ internal class DescriptorRendererImpl(
}
override fun renderValueParameters(parameters: Collection<ValueParameterDescriptor>, synthesizedParameterNames: Boolean): String {
return StringBuilder { renderValueParameters(parameters, synthesizedParameterNames, this) }.toString()
return buildString { renderValueParameters(parameters, synthesizedParameterNames, this) }
}
private fun renderValueParameters(parameters: Collection<ValueParameterDescriptor>, synthesizedParameterNames: Boolean, builder: StringBuilder) {
val includeNames = shouldRenderParameterNames(synthesizedParameterNames)
val parameterCount = parameters.size()
val parameterCount = parameters.size
valueParametersHandler.appendBeforeValueParameters(parameterCount, builder)
for ((index, parameter) in parameters.withIndex()) {
valueParametersHandler.appendBeforeValueParameter(parameter, index, parameterCount, builder)
@@ -862,7 +862,7 @@ internal class DescriptorRendererImpl(
if (KotlinBuiltIns.isNothing(klass.defaultType)) return
val supertypes = klass.getTypeConstructor().getSupertypes()
if (supertypes.isEmpty() || supertypes.size() == 1 && KotlinBuiltIns.isAnyOrNullableAny(supertypes.iterator().next())) return
if (supertypes.isEmpty() || supertypes.size == 1 && KotlinBuiltIns.isAnyOrNullableAny(supertypes.iterator().next())) return
renderSpaceIfNeeded(builder)
builder.append(": ")
@@ -975,16 +975,16 @@ internal class DescriptorRendererImpl(
}
private fun renderSpaceIfNeeded(builder: StringBuilder) {
val length = builder.length()
if (length == 0 || builder.charAt(length - 1) != ' ') {
val length = builder.length
if (length == 0 || builder[length - 1] != ' ') {
builder.append(' ')
}
}
private fun replacePrefixes(lowerRendered: String, lowerPrefix: String, upperRendered: String, upperPrefix: String, foldedPrefix: String): String? {
if (lowerRendered.startsWith(lowerPrefix) && upperRendered.startsWith(upperPrefix)) {
val lowerWithoutPrefix = lowerRendered.substring(lowerPrefix.length())
val upperWithoutPrefix = upperRendered.substring(upperPrefix.length())
val lowerWithoutPrefix = lowerRendered.substring(lowerPrefix.length)
val upperWithoutPrefix = upperRendered.substring(upperPrefix.length)
val flexibleCollectionName = foldedPrefix + lowerWithoutPrefix
if (lowerWithoutPrefix == upperWithoutPrefix) return flexibleCollectionName
@@ -100,7 +100,7 @@ public val DeclarationDescriptorWithVisibility.isEffectivelyPublicApi: Boolean
while (parent != null) {
if (!parent.getVisibility().isPublicAPI) return false
parent = DescriptorUtils.getParentOfType(parent, javaClass<DeclarationDescriptorWithVisibility>())
parent = DescriptorUtils.getParentOfType(parent, DeclarationDescriptorWithVisibility::class.java)
}
return true
@@ -185,9 +185,9 @@ public fun Annotated.isDocumentedAnnotation(): Boolean =
public fun Annotated.getAnnotationRetention(): KotlinRetention? {
val annotationEntryDescriptor = annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.retention) ?: return null
val retentionArgumentValue = annotationEntryDescriptor.allValueArguments.entrySet().firstOrNull {
val retentionArgumentValue = annotationEntryDescriptor.allValueArguments.entries.firstOrNull {
it.key.name.asString() == "value"
}?.getValue() as? EnumValue ?: return null
}?.value as? EnumValue ?: return null
return KotlinRetention.valueOf(retentionArgumentValue.value.name.asString())
}
@@ -155,7 +155,7 @@ public class DescriptorKindFilter(
.filterNotNull()
.toReadOnlyList()
private inline fun <reified T : Any> staticFields() = javaClass<T>().getFields().filter { Modifier.isStatic(it.getModifiers()) }
private inline fun <reified T : Any> staticFields() = T::class.java.getFields().filter { Modifier.isStatic(it.getModifiers()) }
}
}
@@ -41,7 +41,7 @@ class SingletonTypeCapabilities(private val clazz: Class<*>, private val typeCap
}
}
public inline fun <reified T : TypeCapability> KotlinType.getCapability(): T? = getCapability(javaClass<T>())
public inline fun <reified T : TypeCapability> KotlinType.getCapability(): T? = getCapability(T::class.java)
public interface Specificity : TypeCapability {
@@ -55,7 +55,7 @@ public interface Specificity : TypeCapability {
}
fun KotlinType.getSpecificityRelationTo(otherType: KotlinType) =
this.getCapability(javaClass<Specificity>())?.getSpecificityRelationTo(otherType) ?: Specificity.Relation.DONT_KNOW
this.getCapability(Specificity::class.java)?.getSpecificityRelationTo(otherType) ?: Specificity.Relation.DONT_KNOW
fun oneMoreSpecificThanAnother(a: KotlinType, b: KotlinType) =
a.getSpecificityRelationTo(b) != Specificity.Relation.DONT_KNOW || b.getSpecificityRelationTo(a) != Specificity.Relation.DONT_KNOW
@@ -73,9 +73,9 @@ public interface CustomTypeVariable : TypeCapability {
public fun substitutionResult(replacement: KotlinType): KotlinType
}
public fun KotlinType.isCustomTypeVariable(): Boolean = this.getCapability(javaClass<CustomTypeVariable>())?.isTypeVariable ?: false
public fun KotlinType.isCustomTypeVariable(): Boolean = this.getCapability(CustomTypeVariable::class.java)?.isTypeVariable ?: false
public fun KotlinType.getCustomTypeVariable(): CustomTypeVariable? =
this.getCapability(javaClass<CustomTypeVariable>())?.let {
this.getCapability(CustomTypeVariable::class.java)?.let {
if (it.isTypeVariable) it else null
}
@@ -87,13 +87,13 @@ public interface SubtypingRepresentatives : TypeCapability {
}
public fun KotlinType.getSubtypeRepresentative(): KotlinType =
this.getCapability(javaClass<SubtypingRepresentatives>())?.subTypeRepresentative ?: this
this.getCapability(SubtypingRepresentatives::class.java)?.subTypeRepresentative ?: this
public fun KotlinType.getSupertypeRepresentative(): KotlinType =
this.getCapability(javaClass<SubtypingRepresentatives>())?.superTypeRepresentative ?: this
this.getCapability(SubtypingRepresentatives::class.java)?.superTypeRepresentative ?: this
public fun sameTypeConstructors(first: KotlinType, second: KotlinType): Boolean {
val typeRangeCapability = javaClass<SubtypingRepresentatives>()
val typeRangeCapability = SubtypingRepresentatives::class.java
return first.getCapability(typeRangeCapability)?.sameTypeConstructor(second) ?: false
|| second.getCapability(typeRangeCapability)?.sameTypeConstructor(first) ?: false
}
@@ -84,8 +84,8 @@ public class IndexedParametersSubstitution(
private val approximateCapturedTypes: Boolean = false
) : TypeSubstitution() {
init {
assert(parameters.size() <= arguments.size()) {
"Number of arguments should not be less then number of parameters, but: parameters=${parameters.size()}, args=${arguments.size()}"
assert(parameters.size <= arguments.size) {
"Number of arguments should not be less then number of parameters, but: parameters=${parameters.size}, args=${arguments.size}"
}
}
@@ -101,7 +101,7 @@ public class IndexedParametersSubstitution(
val parameter = key.constructor.declarationDescriptor as? TypeParameterDescriptor ?: return null
val index = parameter.index
if (index < parameters.size() && parameters[index].typeConstructor == parameter.typeConstructor) {
if (index < parameters.size && parameters[index].typeConstructor == parameter.typeConstructor) {
return arguments[index]
}
@@ -31,7 +31,7 @@ class DynamicTypesAllowed: DynamicTypesSettings() {
interface Dynamicity : TypeCapability
fun KotlinType.isDynamic(): Boolean = this.getCapability(javaClass<Dynamicity>()) != null
fun KotlinType.isDynamic(): Boolean = this.getCapability(Dynamicity::class.java) != null
fun createDynamicType(builtIns: KotlinBuiltIns) = object : DelegatingFlexibleType(
builtIns.nothingType,
@@ -50,10 +50,10 @@ public object DynamicTypeCapabilities : FlexibleTypeCapabilities {
private class Impl(flexibility: Flexibility) : Dynamicity, Specificity, NullAwareness, FlexibleTypeDelegation {
companion object {
internal val capabilityClasses = hashSetOf(
javaClass<Dynamicity>(),
javaClass<Specificity>(),
javaClass<NullAwareness>(),
javaClass<FlexibleTypeDelegation>()
Dynamicity::class.java,
Specificity::class.java,
NullAwareness::class.java,
FlexibleTypeDelegation::class.java
)
}
@@ -55,11 +55,11 @@ public interface Flexibility : TypeCapability, SubtypingRepresentatives {
override fun sameTypeConstructor(type: KotlinType) = false
}
public fun KotlinType.isFlexible(): Boolean = this.getCapability(javaClass<Flexibility>()) != null
public fun KotlinType.flexibility(): Flexibility = this.getCapability(javaClass<Flexibility>())!!
public fun KotlinType.isFlexible(): Boolean = this.getCapability(Flexibility::class.java) != null
public fun KotlinType.flexibility(): Flexibility = this.getCapability(Flexibility::class.java)!!
public fun KotlinType.isNullabilityFlexible(): Boolean {
val flexibility = this.getCapability(javaClass<Flexibility>()) ?: return false
val flexibility = this.getCapability(Flexibility::class.java) ?: return false
return TypeUtils.isNullableType(flexibility.lowerBound) != TypeUtils.isNullableType(flexibility.upperBound)
}
@@ -72,7 +72,7 @@ public fun KotlinType.isNullabilityFlexible(): Boolean {
// So, we are looking for a type among this set such that it is equal to all others semantically
// (by KotlinTypeChecker.DEFAULT.equalsTypes()), and fits at least as well as they do.
fun Collection<KotlinType>.singleBestRepresentative(): KotlinType? {
if (this.size() == 1) return this.first()
if (this.size == 1) return this.first()
return this.firstOrNull {
candidate ->
@@ -86,10 +86,10 @@ fun Collection<KotlinType>.singleBestRepresentative(): KotlinType? {
}
fun Collection<TypeProjection>.singleBestRepresentative(): TypeProjection? {
if (this.size() == 1) return this.first()
if (this.size == 1) return this.first()
val projectionKinds = this.map { it.getProjectionKind() }.toSet()
if (projectionKinds.size() != 1) return null
if (projectionKinds.size != 1) return null
val bestType = this.map { it.getType() }.singleBestRepresentative()
if (bestType == null) return null
@@ -116,10 +116,10 @@ public open class DelegatingFlexibleType protected constructor(
) : DelegatingType(), NullAwareness, Flexibility, FlexibleTypeDelegation {
companion object {
internal val capabilityClasses = hashSetOf(
javaClass<NullAwareness>(),
javaClass<Flexibility>(),
javaClass<SubtypingRepresentatives>(),
javaClass<FlexibleTypeDelegation>()
NullAwareness::class.java,
Flexibility::class.java,
SubtypingRepresentatives::class.java,
FlexibleTypeDelegation::class.java
)
@JvmStatic
@@ -168,7 +168,7 @@ public open class DelegatingFlexibleType protected constructor(
override fun computeIsNullable() = delegateType.isMarkedNullable()
override fun isMarkedNullable(): Boolean = getCapability(javaClass<NullAwareness>())!!.computeIsNullable()
override fun isMarkedNullable(): Boolean = getCapability(NullAwareness::class.java)!!.computeIsNullable()
override val delegateType: KotlinType
get() {
@@ -176,7 +176,7 @@ public open class DelegatingFlexibleType protected constructor(
return lowerBound
}
override fun getDelegate() = getCapability(javaClass<FlexibleTypeDelegation>())!!.delegateType
override fun getDelegate() = getCapability(FlexibleTypeDelegation::class.java)!!.delegateType
override fun toString() = "('$lowerBound'..'$upperBound')"
}
@@ -50,7 +50,7 @@ data class BinaryVersion private constructor(
major = version.getOrNull(0) ?: UNKNOWN,
minor = version.getOrNull(1) ?: UNKNOWN,
patch = version.getOrNull(2) ?: UNKNOWN,
rest = if (version.size() > 3) version.asList().subList(3, version.size()).toList() else listOf()
rest = if (version.size > 3) version.asList().subList(3, version.size).toList() else listOf()
)
}
@@ -48,7 +48,7 @@ public class ClassDeserializer(private val components: DeserializationComponents
}
else {
val fragments = components.packageFragmentProvider.getPackageFragments(classId.packageFqName)
assert(fragments.size() == 1) { "There should be exactly one package: $fragments, class id is $classId" }
assert(fragments.size == 1) { "There should be exactly one package: $fragments, class id is $classId" }
val fragment = fragments.single()
if (fragment is DeserializedPackageFragment) {
@@ -50,7 +50,7 @@ public class TypeDeserializer(
}
val ownTypeParameters: List<TypeParameterDescriptor>
get() = typeParameterDescriptors().values().toReadOnlyList()
get() = typeParameterDescriptors().values.toReadOnlyList()
// TODO: don't load identical types from TypeTable more than once
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
@@ -280,7 +280,7 @@ public class DeserializedClassDescriptor(
}
fun all(): Collection<ClassDescriptor> {
val result = ArrayList<ClassDescriptor>(nestedClassNames.size())
val result = ArrayList<ClassDescriptor>(nestedClassNames.size)
nestedClassNames.forEach { name -> result.addIfNotNull(findNestedClass(name)) }
return result
}
@@ -143,12 +143,12 @@ public abstract class DeserializedMemberScope protected constructor(
location: LookupLocation
) {
if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) {
val keys = propertyProtos().keySet().filter { nameFilter(it.name) }
val keys = propertyProtos().keys.filter { nameFilter(it.name) }
addMembers(result, keys) { getContributedVariables(it, location) }
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) {
val keys = functionProtos().keySet().filter { nameFilter(it.name) }
val keys = functionProtos().keys.filter { nameFilter(it.name) }
addMembers(result, keys) { getContributedFunctions(it, location) }
}
}
@@ -26,7 +26,7 @@ public fun ModuleDescriptor.findClassAcrossModuleDependencies(classId: ClassId):
val segments = classId.relativeClassName.pathSegments()
val topLevelClass = packageViewDescriptor.memberScope.getContributedClassifier(segments.first(), NoLookupLocation.FROM_DESERIALIZATION) as? ClassDescriptor ?: return null
var result = topLevelClass
for (name in segments.subList(1, segments.size())) {
for (name in segments.subList(1, segments.size)) {
result = result.unsubstitutedInnerClassesScope.getContributedClassifier(name, NoLookupLocation.FROM_DESERIALIZATION) as? ClassDescriptor ?: return null
}
return result
@@ -61,7 +61,7 @@ class SmartSet<T> private constructor() : AbstractSet<T>() {
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) }
else Arrays.copyOf(arr, size + 1).apply { set(size - 1, e) }
}
else -> {
val set = data as MutableSet<T>
@@ -23,13 +23,13 @@ package org.jetbrains.kotlin.util.capitalizeDecapitalize
*/
public fun String.decapitalizeSmart(asciiOnly: Boolean = false): String {
fun isUpperCaseCharAt(index: Int): Boolean {
val c = charAt(index)
val c = this[index]
return if (asciiOnly) c in 'A'..'Z' else c.isUpperCase()
}
if (isEmpty() || !isUpperCaseCharAt(0)) return this
if (length() == 1 || !isUpperCaseCharAt(1)) {
if (length == 1 || !isUpperCaseCharAt(1)) {
return if (asciiOnly) decapitalizeAsciiOnly() else decapitalize()
}
@@ -49,7 +49,7 @@ public fun String.capitalizeFirstWord(asciiOnly: Boolean = false): String {
fun toUpperCase(string: String) = if (asciiOnly) string.toUpperCaseAsciiOnly() else string.toUpperCase()
fun isLowerCaseCharAt(index: Int): Boolean {
val c = charAt(index)
val c = this[index]
return if (asciiOnly) c in 'a'..'z' else c.isLowerCase()
}
@@ -60,7 +60,7 @@ public fun String.capitalizeFirstWord(asciiOnly: Boolean = false): String {
public fun String.capitalizeAsciiOnly(): String {
if (isEmpty()) return this
val c = charAt(0)
val c = this[0]
return if (c in 'a'..'z')
c.toUpperCase() + substring(1)
else
@@ -69,7 +69,7 @@ public fun String.capitalizeAsciiOnly(): String {
public fun String.decapitalizeAsciiOnly(): String {
if (isEmpty()) return this
val c = charAt(0)
val c = this[0]
return if (c in 'A'..'Z')
c.toLowerCase() + substring(1)
else
@@ -77,7 +77,7 @@ public fun String.decapitalizeAsciiOnly(): String {
}
public fun String.toLowerCaseAsciiOnly(): String {
val builder = StringBuilder(length())
val builder = StringBuilder(length)
for (c in this) {
builder.append(if (c in 'A'..'Z') c.toLowerCase() else c)
}
@@ -85,7 +85,7 @@ public fun String.toLowerCaseAsciiOnly(): String {
}
public fun String.toUpperCaseAsciiOnly(): String {
val builder = StringBuilder(length())
val builder = StringBuilder(length)
for (c in this) {
builder.append(if (c in 'a'..'z') c.toUpperCase() else c)
}