All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.resolve.jvm.SyntheticJavaPartsProvider.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2021 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.
 */

package org.jetbrains.kotlin.resolve.jvm

import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.name.Name

interface SyntheticJavaPartsProvider {

    companion object {
        val EMPTY = CompositeSyntheticJavaPartsProvider(emptyList())
    }

    fun getMethodNames(thisDescriptor: ClassDescriptor, c: LazyJavaResolverContext): List

    fun generateMethods(
        thisDescriptor: ClassDescriptor,
        name: Name,
        result: MutableCollection,
        c: LazyJavaResolverContext,
    )

    fun getStaticFunctionNames(thisDescriptor: ClassDescriptor, c: LazyJavaResolverContext): List

    fun generateStaticFunctions(
        thisDescriptor: ClassDescriptor,
        name: Name,
        result: MutableCollection,
        c: LazyJavaResolverContext,
    )

    fun generateConstructors(thisDescriptor: ClassDescriptor, result: MutableList, c: LazyJavaResolverContext)

    fun getNestedClassNames(thisDescriptor: ClassDescriptor, c: LazyJavaResolverContext): List

    fun generateNestedClass(thisDescriptor: ClassDescriptor, name: Name, result: MutableList, c: LazyJavaResolverContext)

    fun modifyField(
        thisDescriptor: ClassDescriptor,
        propertyDescriptor: PropertyDescriptorImpl,
        c: LazyJavaResolverContext,
    ): PropertyDescriptorImpl
}

@Suppress("IncorrectFormatting") // KTIJ-22227
class CompositeSyntheticJavaPartsProvider(private val inner: List) : SyntheticJavaPartsProvider {
    override fun getMethodNames(thisDescriptor: ClassDescriptor, c: LazyJavaResolverContext): List {
        return inner.flatMap { it.getMethodNames(thisDescriptor, c) }
    }

    override fun generateMethods(
        thisDescriptor: ClassDescriptor,
        name: Name,
        result: MutableCollection,
        c: LazyJavaResolverContext,
    ) {
        inner.forEach { it.generateMethods(thisDescriptor, name, result, c) }
    }

    override fun getStaticFunctionNames(thisDescriptor: ClassDescriptor, c: LazyJavaResolverContext): List =
        inner.flatMap { it.getStaticFunctionNames(thisDescriptor, c) }

    override fun generateStaticFunctions(
        thisDescriptor: ClassDescriptor,
        name: Name,
        result: MutableCollection,
        c: LazyJavaResolverContext,
    ) {
        inner.forEach { it.generateStaticFunctions(thisDescriptor, name, result, c) }
    }

    override fun generateConstructors(
        thisDescriptor: ClassDescriptor,
        result: MutableList,
        c: LazyJavaResolverContext,
    ) {
        inner.forEach { it.generateConstructors(thisDescriptor, result, c) }
    }

    override fun getNestedClassNames(thisDescriptor: ClassDescriptor, c: LazyJavaResolverContext): List {
        return inner.flatMap { it.getNestedClassNames(thisDescriptor, c) }
    }

    override fun generateNestedClass(
        thisDescriptor: ClassDescriptor,
        name: Name,
        result: MutableList,
        c: LazyJavaResolverContext,
    ) {
        inner.forEach { it.generateNestedClass(thisDescriptor, name, result, c) }
    }

    override fun modifyField(
        thisDescriptor: ClassDescriptor,
        propertyDescriptor: PropertyDescriptorImpl,
        c: LazyJavaResolverContext,
    ): PropertyDescriptorImpl {
        return inner.fold(propertyDescriptor) { property, provider -> provider.modifyField(thisDescriptor, property, c) }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy