Replace map { ... }.filterNotNull() with mapNotNull { ... }
This commit is contained in:
@@ -127,7 +127,7 @@ public class PropertyReferenceCodegen(
|
||||
StackValue.singleton(containingObject, typeMapper).put(typeMapper.mapClass(containingObject), this)
|
||||
}
|
||||
|
||||
for ((index, type) in listOf(dispatchReceiverType, extensionReceiverType).filterNotNull().withIndex()) {
|
||||
for ((index, type) in listOfNotNull(dispatchReceiverType, extensionReceiverType).withIndex()) {
|
||||
StackValue.local(index + 1, OBJECT_TYPE).put(typeMapper.mapType(type), this)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -40,10 +40,10 @@ class BuilderFactoryForDuplicateClassNameDiagnostics(
|
||||
}
|
||||
|
||||
private fun reportError(internalName: String, vararg another: JvmDeclarationOrigin) {
|
||||
val fromString = another.map { it.descriptor }.filterNotNull().
|
||||
val fromString = another.mapNotNull { it.descriptor }.
|
||||
joinToString { DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.render(it) }
|
||||
|
||||
another.map { it.element }.filterNotNull().forEach {
|
||||
another.mapNotNull { it.element }.forEach {
|
||||
diagnostics.report(ErrorsJvm.DUPLICATE_CLASS_NAMES.on(it, internalName, fromString))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -92,13 +92,13 @@ public class CliLightClassGenerationSupport(project: Project) : LightClassGenera
|
||||
}
|
||||
|
||||
override fun findClassOrObjectDeclarations(fqName: FqName, searchScope: GlobalSearchScope): Collection<KtClassOrObject> {
|
||||
return ResolveSessionUtils.getClassDescriptorsByFqName(module, fqName).map {
|
||||
return ResolveSessionUtils.getClassDescriptorsByFqName(module, fqName).mapNotNull {
|
||||
val element = DescriptorToSourceUtils.getSourceFromDescriptor(it)
|
||||
if (element is KtClassOrObject && PsiSearchScopeUtil.isInScope(searchScope, element)) {
|
||||
element
|
||||
}
|
||||
else null
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
override fun findFilesForPackage(fqName: FqName, searchScope: GlobalSearchScope): Collection<KtFile> {
|
||||
@@ -216,7 +216,7 @@ public class CliLightClassGenerationSupport(project: Project) : LightClassGenera
|
||||
override fun getFacadeClassesInPackage(packageFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> {
|
||||
return PackagePartClassUtils.getFilesWithCallables(findFilesForPackage(packageFqName, scope)).groupBy {
|
||||
JvmFileClassUtil.getFileClassInfoNoResolve(it).facadeClassFqName
|
||||
}.map { KtLightClassForFacade.createForFacade(psiManager, it.key, scope, it.value) }.filterNotNull()
|
||||
}.mapNotNull { KtLightClassForFacade.createForFacade(psiManager, it.key, scope, it.value) }
|
||||
}
|
||||
|
||||
override fun getFacadeNames(packageFqName: FqName, scope: GlobalSearchScope): Collection<String> {
|
||||
|
||||
@@ -28,9 +28,9 @@ public class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePar
|
||||
val roots by lazy {
|
||||
env.configuration.getList(CommonConfigurationKeys.CONTENT_ROOTS).
|
||||
filterIsInstance<JvmClasspathRoot>().
|
||||
map {
|
||||
mapNotNull {
|
||||
env.contentRootToVirtualFile(it);
|
||||
}.filter { it?.findChild("META-INF") != null }.filterNotNull()
|
||||
}.filter { it.findChild("META-INF") != null }
|
||||
}
|
||||
|
||||
override fun findPackageParts(packageFqName: String): List<String> {
|
||||
@@ -43,10 +43,10 @@ public class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePar
|
||||
else parent.findChild(part) ?: return@filter false
|
||||
}
|
||||
true
|
||||
}.map {
|
||||
}.mapNotNull {
|
||||
it.findChild("META-INF")
|
||||
}.filterNotNull().flatMap {
|
||||
it.children.filter { it.name.endsWith(ModuleMapping.MAPPING_FILE_EXT) }.toList<VirtualFile>()
|
||||
}.flatMap {
|
||||
it.children.filter<VirtualFile> { it.name.endsWith(ModuleMapping.MAPPING_FILE_EXT) }
|
||||
}.map {
|
||||
try {
|
||||
ModuleMapping.create(it.contentsToByteArray())
|
||||
@@ -55,6 +55,6 @@ public class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePar
|
||||
}
|
||||
}
|
||||
|
||||
return mappings.map { it.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }.distinct()
|
||||
return mappings.mapNotNull { it.findPackageParts(packageFqName) }.flatMap { it.parts }.distinct()
|
||||
}
|
||||
}
|
||||
@@ -49,10 +49,10 @@ public fun inlineFunctionsJvmNames(bytes: ByteArray): Set<String> {
|
||||
private fun inlineFunctionsJvmNames(functions: List<ProtoBuf.Function>, nameResolver: NameResolver, protoTypeTable: ProtoBuf.TypeTable): Set<String> {
|
||||
val typeTable = TypeTable(protoTypeTable)
|
||||
val inlineFunctions = functions.filter { Flags.IS_INLINE.get(it.flags) }
|
||||
val jvmNames = inlineFunctions.map {
|
||||
val jvmNames = inlineFunctions.mapNotNull {
|
||||
JvmProtoBufUtil.getJvmMethodSignature(it, nameResolver, typeTable)
|
||||
}
|
||||
return jvmNames.filterNotNull().toSet()
|
||||
return jvmNames.toSet()
|
||||
}
|
||||
|
||||
private fun readKotlinHeader(bytes: ByteArray): KotlinClassHeader {
|
||||
|
||||
+3
-5
@@ -119,10 +119,9 @@ public class IncrementalPackageFragmentProvider(
|
||||
} ?: emptyList<String>()
|
||||
|
||||
val scopes = actualPackagePartFiles
|
||||
.map {
|
||||
.mapNotNull {
|
||||
incrementalCache.getPackagePartData(it)
|
||||
}
|
||||
.filterNotNull()
|
||||
.map {
|
||||
IncrementalPackageScope(JvmProtoBufUtil.readPackageDataFrom(it.data, it.strings))
|
||||
}
|
||||
@@ -149,7 +148,7 @@ public class IncrementalPackageFragmentProvider(
|
||||
val partsNames: Collection<String>
|
||||
) : PackageFragmentDescriptorImpl(moduleDescriptor, multifileClassFqName.parent()) {
|
||||
val memberScope = storageManager.createLazyValue {
|
||||
val partsData = partsNames.map { incrementalCache.getPackagePartData(it) }.filterNotNull()
|
||||
val partsData = partsNames.mapNotNull { incrementalCache.getPackagePartData(it) }
|
||||
if (partsData.isEmpty())
|
||||
MemberScope.Empty
|
||||
else {
|
||||
@@ -182,8 +181,7 @@ public class IncrementalPackageFragmentProvider(
|
||||
|
||||
if (LOG.isDebugEnabled) {
|
||||
val allPackageParts = allMemberProtos
|
||||
.map(::getPackagePart)
|
||||
.filterNotNull()
|
||||
.mapNotNull(::getPackagePart)
|
||||
.toSet()
|
||||
val skippedPackageParts = allPackageParts.filter { shouldSkipPackagePart(it) }
|
||||
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ internal class IncrementalPackagePartProvider private constructor(
|
||||
val packagePartsFromParent = parent.findPackageParts(packageFqName)
|
||||
if (packageFqName in fqNamesToIgnore) return packagePartsFromParent
|
||||
|
||||
val packagePartsFromCompiled = moduleMappings().map { it.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }
|
||||
val packagePartsFromCompiled = moduleMappings().mapNotNull { it.findPackageParts(packageFqName) }.flatMap { it.parts }
|
||||
return (packagePartsFromCompiled + packagePartsFromParent).distinct()
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -77,8 +77,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : BaseImportingSc
|
||||
return receiverTypes.flatMapTo(LinkedHashSet<FunctionDescriptor>()) { type ->
|
||||
type.memberScope.getContributedDescriptors(DescriptorKindFilter.FUNCTIONS)
|
||||
.filterIsInstance<FunctionDescriptor>()
|
||||
.map { extensionForFunction(it.original) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { extensionForFunction(it.original) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +60,9 @@ fun getReceiverTypePredicate(resolvedCall: ResolvedCall<*>, receiverValue: Recei
|
||||
}
|
||||
resolvedCall.getDispatchReceiver() -> {
|
||||
val rootCallableDescriptors = callableDescriptor.findTopMostOverriddenDescriptors()
|
||||
return or(rootCallableDescriptors.map {
|
||||
return or(rootCallableDescriptors.mapNotNull {
|
||||
it.getDispatchReceiverParameter()?.getType()?.let { TypeUtils.makeNullableIfNeeded(it, resolvedCall.isSafeCall()) }?.getSubtypesPredicate()
|
||||
}.filterNotNull())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ public object PositioningStrategies {
|
||||
val visibilityTokens = listOf(KtTokens.PRIVATE_KEYWORD, KtTokens.PROTECTED_KEYWORD, KtTokens.PUBLIC_KEYWORD, KtTokens.INTERNAL_KEYWORD)
|
||||
val modifierList = element.getModifierList()
|
||||
|
||||
val result = visibilityTokens.map { modifierList?.getModifier(it)?.getTextRange() }.filterNotNull()
|
||||
val result = visibilityTokens.mapNotNull { modifierList?.getModifier(it)?.getTextRange() }
|
||||
if (!result.isEmpty()) return result
|
||||
|
||||
// Try to resolve situation when there's no visibility modifiers written before element
|
||||
|
||||
@@ -282,8 +282,8 @@ private object DebugTextBuildingVisitor : KtVisitor<String, Unit>() {
|
||||
}
|
||||
|
||||
fun renderChildren(element: KtElementImplStub<*>, separator: String, prefix: String = "", postfix: String = ""): String? {
|
||||
val childrenTexts = element.getStub()?.getChildrenStubs()?.map { (it?.getPsi() as? KtElement)?.getDebugText() }
|
||||
return childrenTexts?.filterNotNull()?.joinToString(separator, prefix, postfix) ?: element.getText()
|
||||
val childrenTexts = element.getStub()?.getChildrenStubs()?.mapNotNull { (it?.getPsi() as? KtElement)?.getDebugText() }
|
||||
return childrenTexts?.joinToString(separator, prefix, postfix) ?: element.getText()
|
||||
}
|
||||
|
||||
fun render(element: KtElementImplStub<*>, vararg relevantChildren: KtElement?): String? {
|
||||
|
||||
@@ -58,8 +58,7 @@ internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywo
|
||||
|
||||
val newModifier = KtPsiFactory(modifierList).createModifier(modifier)
|
||||
val modifierToReplace = MODIFIERS_TO_REPLACE[modifier]
|
||||
?.map { modifierList.getModifier(it) }
|
||||
?.filterNotNull()
|
||||
?.mapNotNull { modifierList.getModifier(it) }
|
||||
?.firstOrNull()
|
||||
|
||||
if (modifierToReplace != null) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public open class KotlinStubBaseImpl<T : KtElementImplStub<*>>(parent: StubEleme
|
||||
}
|
||||
|
||||
private fun renderPropertyValues(stubInterface: Class<out Any?>): List<String> {
|
||||
return collectProperties(stubInterface).map { property -> renderProperty(property) }.filterNotNull().sorted()
|
||||
return collectProperties(stubInterface).mapNotNull { property -> renderProperty(property) }.sorted()
|
||||
}
|
||||
|
||||
private fun collectProperties(stubInterface: Class<*>): Collection<Method> {
|
||||
|
||||
@@ -40,7 +40,7 @@ class AllUnderImportsScope(descriptor: DeclarationDescriptor) : BaseImportingSco
|
||||
= scopes.flatMap { it.getContributedDescriptors(kindFilter, nameFilter) }
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation)
|
||||
= scopes.asSequence().map { it.getContributedClassifier(name, location) }.filterNotNull().singleOrNull()
|
||||
= scopes.asSequence().mapNotNull { it.getContributedClassifier(name, location) }.singleOrNull()
|
||||
|
||||
override fun getContributedVariables(name: Name, location: LookupLocation)
|
||||
= scopes.flatMap { it.getContributedVariables(name, location) }
|
||||
|
||||
@@ -157,9 +157,9 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
?: return null
|
||||
val valueArguments = targetEntryDescriptor.allValueArguments
|
||||
val valueArgument = valueArguments.entrySet().firstOrNull()?.getValue() as? ArrayValue ?: return null
|
||||
return valueArgument.value.filterIsInstance<EnumValue>().map {
|
||||
return valueArgument.value.filterIsInstance<EnumValue>().mapNotNull {
|
||||
KotlinTarget.valueOrNull(it.value.name.asString())
|
||||
}.filterNotNull().toSet()
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
public fun getDeclarationSiteActualTargetList(annotated: KtElement, descriptor: ClassDescriptor?): List<KotlinTarget> {
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ public object NonExpansiveInheritanceRestrictionChecker {
|
||||
val bounds = hashSetOf<KotlinType>()
|
||||
|
||||
val substitutor = constituentType.substitution.buildSubstitutor()
|
||||
val adaptedUpperBounds = originalTypeParameter.upperBounds.map { substitutor.substitute(it, Variance.INVARIANT) }.filterNotNull()
|
||||
val adaptedUpperBounds = originalTypeParameter.upperBounds.mapNotNull { substitutor.substitute(it, Variance.INVARIANT) }
|
||||
bounds.addAll(adaptedUpperBounds)
|
||||
|
||||
if (!typeProjection.isStarProjection) {
|
||||
|
||||
@@ -237,8 +237,7 @@ public class TypeResolver(
|
||||
val modifierList = param.modifierList
|
||||
if (modifierList != null) {
|
||||
KtTokens.MODIFIER_KEYWORDS_ARRAY
|
||||
.map { modifierList.getModifier(it) }
|
||||
.filterNotNull()
|
||||
.mapNotNull { modifierList.getModifier(it) }
|
||||
.forEach { c.trace.report(Errors.UNSUPPORTED.on(it, "modifier on parameter in function type"))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -171,7 +171,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
|
||||
val candidateWithFreshVariables = FunctionDescriptorUtil.alphaConvertTypeParameters(candidateDescriptor)
|
||||
val conversion = candidateDescriptor.typeParameters.zip(candidateWithFreshVariables.typeParameters).toMap()
|
||||
|
||||
val freshVariables = returnType.getNestedTypeParameters().map { conversion[it] }.filterNotNull()
|
||||
val freshVariables = returnType.getNestedTypeParameters().mapNotNull { conversion[it] }
|
||||
builder.registerTypeVariables(resultingCall.call.toHandle(), freshVariables, external = true)
|
||||
|
||||
builder.addSubtypeConstraint(
|
||||
|
||||
+1
-3
@@ -58,9 +58,7 @@ public abstract class DeclarationProviderFactoryService {
|
||||
private class SyntheticFilesFilteringScope(syntheticFiles: Collection<KtFile>, baseScope: GlobalSearchScope)
|
||||
: DelegatingGlobalSearchScope(baseScope) {
|
||||
|
||||
private val originals = syntheticFiles
|
||||
.map { it.getOriginalFile().getVirtualFile() }
|
||||
.filterNotNullTo(HashSet<VirtualFile>())
|
||||
private val originals = syntheticFiles.mapNotNullTo(HashSet<VirtualFile>()) { it.getOriginalFile().getVirtualFile() }
|
||||
|
||||
override fun contains(file: VirtualFile) = super.contains(file) && file !in originals
|
||||
}
|
||||
|
||||
+4
-5
@@ -86,11 +86,10 @@ public class LazyAnnotations(
|
||||
|
||||
override fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget> {
|
||||
return annotationEntries
|
||||
.asSequence()
|
||||
.map {
|
||||
.mapNotNull {
|
||||
val (descriptor, target) = annotation(it)
|
||||
if (target == null) null else AnnotationWithTarget(descriptor, target)
|
||||
}.filterNotNull().toList()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAllAnnotations() = annotationEntries.map(annotation)
|
||||
@@ -98,10 +97,10 @@ public class LazyAnnotations(
|
||||
override fun iterator(): Iterator<AnnotationDescriptor> {
|
||||
return annotationEntries
|
||||
.asSequence()
|
||||
.map {
|
||||
.mapNotNull {
|
||||
val (descriptor, target) = annotation(it)
|
||||
if (target == null) descriptor else null // Filter out annotations with target
|
||||
}.filterNotNull().iterator()
|
||||
}.iterator()
|
||||
}
|
||||
|
||||
override fun forceResolveAllContents() {
|
||||
|
||||
+3
-3
@@ -365,13 +365,13 @@ public open class KtLightClassForExplicitDeclaration(
|
||||
override fun toString() = "${KtLightClass::class.java.simpleName}:$classFqName"
|
||||
|
||||
override fun getOwnInnerClasses(): List<PsiClass> {
|
||||
val result = ArrayList<PsiClass?>()
|
||||
classOrObject.declarations.filterIsInstance<KtClassOrObject>().mapTo(result) { create(it) }
|
||||
val result = ArrayList<PsiClass>()
|
||||
classOrObject.declarations.filterIsInstance<KtClassOrObject>().mapNotNullTo(result) { create(it) }
|
||||
|
||||
if (classOrObject.hasInterfaceDefaultImpls) {
|
||||
result.add(KtLightClassForInterfaceDefaultImpls(classFqName.defaultImplsChild(), classOrObject))
|
||||
}
|
||||
return result.filterNotNull()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getUseScope(): SearchScope = getOrigin().useScope
|
||||
|
||||
@@ -327,14 +327,17 @@ public object LightClassUtil {
|
||||
public val setter: PsiMethod?,
|
||||
public val backingField: PsiField?,
|
||||
additionalAccessors: List<PsiMethod>) : Iterable<PsiMethod> {
|
||||
private val allMethods = arrayListOf<PsiMethod>()
|
||||
val allDeclarations = arrayListOf<PsiNamedElement>()
|
||||
private val allMethods: List<PsiMethod>
|
||||
val allDeclarations: List<PsiNamedElement>
|
||||
|
||||
init {
|
||||
listOf(getter, setter).filterNotNullTo(allMethods)
|
||||
listOf<PsiNamedElement?>(getter, setter, backingField).filterNotNullTo(allDeclarations)
|
||||
allDeclarations.addAll(additionalAccessors)
|
||||
allMethods = arrayListOf<PsiMethod>()
|
||||
arrayOf(getter, setter).filterNotNullTo(allMethods)
|
||||
additionalAccessors.filterIsInstanceTo<PsiMethod, MutableList<PsiMethod>>(allMethods)
|
||||
|
||||
allDeclarations = arrayListOf<PsiNamedElement>()
|
||||
arrayOf<PsiNamedElement?>(getter, setter, backingField).filterNotNullTo(allDeclarations)
|
||||
allDeclarations.addAll(additionalAccessors)
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<PsiMethod> = allMethods.iterator()
|
||||
|
||||
@@ -45,9 +45,9 @@ public fun cliPluginUsageString(pluginId: String, options: Collection<CliOption>
|
||||
"\n" + " ".repeat(MAX_OPTION_WIDTH + LEFT_INDENT + 1)
|
||||
} else " ".repeat(1 + MAX_OPTION_WIDTH - name.length())
|
||||
|
||||
val modifiers = listOf(
|
||||
val modifiers = listOfNotNull(
|
||||
if (it.required) "required" else null,
|
||||
if (it.allowMultipleOccurrences) "multiple" else null).filterNotNull()
|
||||
if (it.allowMultipleOccurrences) "multiple" else null)
|
||||
val modifiersEnclosed = if (modifiers.isEmpty()) "" else " (${modifiers.joinToString()})"
|
||||
|
||||
" ".repeat(LEFT_INDENT) + name + margin + it.description + modifiersEnclosed
|
||||
|
||||
@@ -236,11 +236,10 @@ public object KotlinCompilerClient {
|
||||
?.split(File.pathSeparator)
|
||||
?.map { File(it).parentFile }
|
||||
?.distinct()
|
||||
?.map {
|
||||
?.mapNotNull {
|
||||
it?.walk()
|
||||
?.firstOrNull { it.name.equals(COMPILER_JAR_NAME, ignoreCase = true) }
|
||||
}
|
||||
?.filterNotNull()
|
||||
?.firstOrNull()
|
||||
?.let { listOf(it.absolutePath) }
|
||||
|
||||
@@ -266,7 +265,7 @@ public object KotlinCompilerClient {
|
||||
val daemons = registryDir.walk()
|
||||
.map { Pair(it, it.name.extractPortFromRunFilename(classPathDigest)) }
|
||||
.filter { it.second != 0 }
|
||||
.map {
|
||||
.mapNotNull {
|
||||
assert(it.second > 0 && it.second < 0xffff)
|
||||
reportingTargets.report(DaemonReportCategory.DEBUG, "found suitable daemon on port ${it.second}, trying to connect")
|
||||
val daemon = tryConnectToDaemon(it.second, reportingTargets)
|
||||
@@ -276,7 +275,6 @@ public object KotlinCompilerClient {
|
||||
}
|
||||
daemon
|
||||
}
|
||||
.filterNotNull()
|
||||
.toList()
|
||||
return when (daemons.size) {
|
||||
0 -> null
|
||||
|
||||
@@ -66,8 +66,8 @@ open class PropMapper<C, V, P : KMutableProperty1<C, V>>(val dest: C,
|
||||
open fun toArgs(prefix: String = COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX): List<String> =
|
||||
when {
|
||||
skipIf(prop.get(dest)) -> listOf<String>()
|
||||
mergeDelimiter != null -> listOf(listOf(prefix + names.first(), toString(prop.get(dest))).filterNotNull().joinToString(mergeDelimiter))
|
||||
else -> listOf(prefix + names.first(), toString(prop.get(dest))).filterNotNull()
|
||||
mergeDelimiter != null -> listOf(listOfNotNull(prefix + names.first(), toString(prop.get(dest))).joinToString(mergeDelimiter))
|
||||
else -> listOfNotNull(prefix + names.first(), toString(prop.get(dest)))
|
||||
}
|
||||
|
||||
open fun apply(s: String) = prop.set(dest, fromString(s))
|
||||
|
||||
@@ -66,8 +66,7 @@ public abstract class AbstractPseudoValueTest : AbstractPseudocodeTest() {
|
||||
|
||||
val elementToValues = getElementToValueMap(pseudocode)
|
||||
val unboundValues = pseudocode.getInstructions()
|
||||
.map { (it as? InstructionWithValue)?.outputValue }
|
||||
.filterNotNull()
|
||||
.mapNotNull { (it as? InstructionWithValue)?.outputValue }
|
||||
.filter { it.element == null }
|
||||
.sortedBy { it.debugName }
|
||||
val allValues = elementToValues.values() + unboundValues
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.io.File
|
||||
public interface AbstractSMAPBaseTest {
|
||||
|
||||
private fun extractSMAPFromClasses(outputFiles: Iterable<OutputFile>): List<SMAPAndFile> {
|
||||
return outputFiles.map { outputFile ->
|
||||
return outputFiles.mapNotNull { outputFile ->
|
||||
var debugInfo: String? = null
|
||||
ClassReader(outputFile.asByteArray()).accept(object : ClassVisitor(Opcodes.ASM5) {
|
||||
override fun visitSource(source: String?, debug: String?) {
|
||||
@@ -41,7 +41,7 @@ public interface AbstractSMAPBaseTest {
|
||||
}, 0)
|
||||
|
||||
SMAPAndFile.SMAPAndFile(debugInfo, outputFile.sourceFiles.single())
|
||||
}.filterNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
private fun extractSmapFromSource(file: KtFile): SMAPAndFile? {
|
||||
@@ -63,11 +63,11 @@ public interface AbstractSMAPBaseTest {
|
||||
return
|
||||
}
|
||||
|
||||
val sourceData = inputFiles.map { extractSmapFromSource(it) }.filterNotNull()
|
||||
val sourceData = inputFiles.mapNotNull { extractSmapFromSource(it) }
|
||||
val compiledData = extractSMAPFromClasses(outputFiles).groupBy {
|
||||
it.sourceFile
|
||||
}.map {
|
||||
val smap = it.getValue().map { replaceHash(it.smap) }.filterNotNull().joinToString("\n")
|
||||
val smap = it.getValue().mapNotNull { it.smap?.replaceHash() }.joinToString("\n")
|
||||
SMAPAndFile(if (smap.isNotEmpty()) smap else null, it.key)
|
||||
}.toMap { it.sourceFile }
|
||||
|
||||
@@ -77,17 +77,16 @@ public interface AbstractSMAPBaseTest {
|
||||
}
|
||||
}
|
||||
|
||||
fun replaceHash(data: String?): String? {
|
||||
if (data == null) return null
|
||||
|
||||
val fileSectionStart = data.indexOf("*F") + 3
|
||||
val lineSection = data.indexOf("*L") - 1
|
||||
private fun String.replaceHash(): String {
|
||||
val fileSectionStart = indexOf("*F") + 3
|
||||
val lineSection = indexOf("*L") - 1
|
||||
|
||||
val files = data.substring(fileSectionStart, lineSection).split("\n")
|
||||
val files = substring(fileSectionStart, lineSection).split("\n")
|
||||
|
||||
val cleaned = files.joinToString("\n")
|
||||
|
||||
return data.substring(0, fileSectionStart) + cleaned + data.substring(lineSection)
|
||||
return substring(0, fileSectionStart) + cleaned + substring(lineSection)
|
||||
}
|
||||
|
||||
class SMAPAndFile(val smap: String?, val sourceFile: String) {
|
||||
|
||||
Reference in New Issue
Block a user