diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaElementCollectionFromPsiArrayUtil.kt b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaElementCollectionFromPsiArrayUtil.kt index db8719a1a4c..56955b23d39 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaElementCollectionFromPsiArrayUtil.kt +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/JavaElementCollectionFromPsiArrayUtil.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @file:JvmName("JavaElementCollectionFromPsiArrayUtil") @@ -25,12 +14,11 @@ import org.jetbrains.kotlin.load.java.structure.* import org.jetbrains.kotlin.load.java.structure.impl.source.JavaElementSourceFactory import org.jetbrains.kotlin.name.Name -inline fun Array.convert(factory: (Psi) -> Java): List = - when (size) { - 0 -> emptyList() - 1 -> listOf(factory(first())) - else -> map(factory) - } +inline fun Array.convert(factory: (Psi) -> Java): List = when (size) { + 0 -> emptyList() + 1 -> listOf(factory(first())) + else -> map(factory) +} inline fun Array.convertIndexed(factory: (Int, Psi) -> Java): List = when (size) { 0 -> emptyList() @@ -38,54 +26,61 @@ inline fun Array.convertIndexed(factory: (Int, Psi) -> Java): L else -> mapIndexed(factory) } -fun Collection.convert(factory: (Psi) -> Java): List = - when (size) { - 0 -> emptyList() - 1 -> listOf(factory(first())) - else -> map(factory) - } +fun Collection.convert(factory: (Psi) -> Java): List = when (size) { + 0 -> emptyList() + 1 -> listOf(factory(first())) + else -> map(factory) +} -internal fun classes(classes: Array, sourceFactory: JavaElementSourceFactory): Collection = - classes.convert { JavaClassImpl(sourceFactory.createPsiSource(it)) } +internal fun classes(classes: Array, sourceFactory: JavaElementSourceFactory): Collection = classes.convert { + JavaClassImpl(sourceFactory.createPsiSource(it)) +} -internal fun classes(classes: Collection, sourceFactory: JavaElementSourceFactory): Collection = - classes.convert { JavaClassImpl(sourceFactory.createPsiSource(it)) } +internal fun classes(classes: Collection, sourceFactory: JavaElementSourceFactory): Collection = classes.convert { + JavaClassImpl(sourceFactory.createPsiSource(it)) +} -internal fun packages(packages: Array, scope: GlobalSearchScope, sourceFactory: JavaElementSourceFactory): Collection = - packages.convert { psi -> JavaPackageImpl(sourceFactory.createPsiSource(psi), scope) } +internal fun packages( + packages: Array, + scope: GlobalSearchScope, + sourceFactory: JavaElementSourceFactory, +): Collection = packages.convert { psi -> JavaPackageImpl(sourceFactory.createPsiSource(psi), scope) } internal fun methods(methods: Collection, sourceFactory: JavaElementSourceFactory): Collection = - methods.convert { JavaMethodImpl(sourceFactory.createPsiSource(it)) } + methods.convert { JavaMethodImpl(sourceFactory.createPsiSource(it)) } internal fun constructors(methods: Collection, sourceFactory: JavaElementSourceFactory): Collection = - methods.convert { JavaConstructorImpl(sourceFactory.createPsiSource(it)) } + methods.convert { JavaConstructorImpl(sourceFactory.createPsiSource(it)) } internal fun fields(fields: Collection, sourceFactory: JavaElementSourceFactory): Collection = - fields.convert { JavaFieldImpl(sourceFactory.createPsiSource(it)) } + fields.convert { JavaFieldImpl(sourceFactory.createPsiSource(it)) } internal fun valueParameters(parameters: Array, sourceFactory: JavaElementSourceFactory): List = - parameters.convert { JavaValueParameterImpl(sourceFactory.createPsiSource(it)) } + parameters.convert { JavaValueParameterImpl(sourceFactory.createPsiSource(it)) } internal fun typeParameters(typeParameters: Array, sourceFactory: JavaElementSourceFactory): List = - typeParameters.convert { JavaTypeParameterImpl(sourceFactory.createPsiSource(it)) } + typeParameters.convert { JavaTypeParameterImpl(sourceFactory.createPsiSource(it)) } internal fun classifierTypes(classTypes: Array, sourceFactory: JavaElementSourceFactory): Collection = - classTypes.convert { JavaClassifierTypeImpl(sourceFactory.createTypeSource(it)) } + classTypes.convert { JavaClassifierTypeImpl(sourceFactory.createTypeSource(it)) } internal fun annotations(annotations: Array, sourceFactory: JavaElementSourceFactory): Collection = - annotations.convert { JavaAnnotationImpl(sourceFactory.createPsiSource(it)) } + annotations.convert { JavaAnnotationImpl(sourceFactory.createPsiSource(it)) } -internal fun nullabilityAnnotations(annotations: Array, sourceFactory: JavaElementSourceFactory): Collection = - annotations.convert { JavaAnnotationImpl(sourceFactory.createPsiSource(it)) } - .filter { annotation -> - val fqName = annotation.classId?.asSingleFqName() ?: return@filter false - fqName in NULLABILITY_ANNOTATIONS - } +internal fun nullabilityAnnotations( + annotations: Array, + sourceFactory: JavaElementSourceFactory, +): Collection = annotations.convert { JavaAnnotationImpl(sourceFactory.createPsiSource(it)) }.filter { annotation -> + val fqName = annotation.classId?.asSingleFqName() ?: return@filter false + fqName in NULLABILITY_ANNOTATIONS +} -internal fun namedAnnotationArguments(nameValuePairs: Array, sourceFactory: JavaElementSourceFactory): Collection = - nameValuePairs.convert { psi -> - val name = psi.name?.let(Name::identifier) - val value = psi.value ?: error("Annotation argument value cannot be null: $name") - JavaAnnotationArgumentImpl.create(value, name, sourceFactory) - } +internal fun namedAnnotationArguments( + nameValuePairs: Array, + sourceFactory: JavaElementSourceFactory, +): Collection = nameValuePairs.convert { psi -> + val name = psi.name?.let(Name::identifier) + val value = psi.value ?: error("Annotation argument value cannot be null: $name") + JavaAnnotationArgumentImpl.create(value, name, sourceFactory) +}