K2: introduce & use (for annotation creation) smartPlus for lists
This commit is contained in:
committed by
Space Team
parent
f33f87e3d4
commit
761a0f8248
+1
-6
@@ -2021,12 +2021,7 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
for (modifierList in allTypeModifiers) {
|
||||
if (modifierList.annotations.isNotEmpty()) {
|
||||
val replacementAnnotations =
|
||||
if (calculatedFirType.annotations.isNotEmpty()) calculatedFirType.annotations + modifierList.annotations
|
||||
else modifierList.annotations
|
||||
calculatedFirType.replaceAnnotations(replacementAnnotations)
|
||||
}
|
||||
calculatedFirType.replaceAnnotations(calculatedFirType.annotations.smartPlus(modifierList.annotations))
|
||||
}
|
||||
return calculatedFirType
|
||||
}
|
||||
|
||||
+1
-4
@@ -451,10 +451,7 @@ class ExpressionsConverter(
|
||||
|
||||
val result = firExpression ?: buildErrorExpression(null, ConeNotAnnotationContainer("???"))
|
||||
require(result is FirAnnotationContainer)
|
||||
if (firAnnotationList.isNotEmpty()) {
|
||||
val replacementAnnotations = if (result.annotations.isNotEmpty()) result.annotations + firAnnotationList else firAnnotationList
|
||||
result.replaceAnnotations(replacementAnnotations)
|
||||
}
|
||||
result.replaceAnnotations(result.annotations.smartPlus(firAnnotationList))
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -499,12 +499,7 @@ open class RawFirBuilder(
|
||||
if (this != null) {
|
||||
it.extractAnnotationsFrom(this)
|
||||
}
|
||||
val resultAnnotations = when {
|
||||
accessorAnnotationsFromProperty.isEmpty() -> it.annotations
|
||||
it.annotations.isEmpty() -> accessorAnnotationsFromProperty
|
||||
else -> it.annotations + accessorAnnotationsFromProperty
|
||||
}
|
||||
it.replaceAnnotations(resultAnnotations)
|
||||
it.replaceAnnotations(it.annotations.smartPlus(accessorAnnotationsFromProperty))
|
||||
it.status = status
|
||||
it.initContainingClassAttr()
|
||||
}
|
||||
@@ -704,7 +699,7 @@ open class RawFirBuilder(
|
||||
val annotations = buildList {
|
||||
addAll(container.annotations)
|
||||
for (annotationEntry in annotationEntries) {
|
||||
add(annotationEntry.convert<FirAnnotation>())
|
||||
add(annotationEntry.convert())
|
||||
}
|
||||
}
|
||||
container.replaceAnnotations(annotations)
|
||||
|
||||
+1
-7
@@ -958,13 +958,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
}
|
||||
return if (operation == FirOperation.ASSIGN) {
|
||||
val result = unwrappedLhs.convert()
|
||||
if (annotations.isNotEmpty()) {
|
||||
val annotationsToReplace = if (result.annotations.isEmpty()) annotations else mutableListOf<FirAnnotation>().apply {
|
||||
addAll(result.annotations)
|
||||
addAll(annotations)
|
||||
}
|
||||
result.replaceAnnotations(annotationsToReplace)
|
||||
}
|
||||
result.replaceAnnotations(result.annotations.smartPlus(annotations))
|
||||
result.pullUpSafeCallIfNecessary()
|
||||
} else {
|
||||
val receiver = unwrappedLhs.convert()
|
||||
|
||||
@@ -197,3 +197,14 @@ value class MutableOrEmptyList<T>(val list: MutableList<T>?) : List<T> {
|
||||
fun <T> empty(): MutableOrEmptyList<T> = EMPTY as MutableOrEmptyList<T>
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> List<T>.smartPlus(other: List<T>): List<T> = when {
|
||||
other.isEmpty() -> this
|
||||
this.isEmpty() -> other
|
||||
else -> {
|
||||
val result = ArrayList<T>(this.size + other.size)
|
||||
result.addAll(this)
|
||||
result.addAll(other)
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user