[FIR] Allows use DSL for building FIR declarations from any FirExtension
This commit is contained in:
committed by
Space Team
parent
1248ee12d6
commit
a967a242c7
+13
-5
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildRegularClass
|
|||||||
import org.jetbrains.kotlin.fir.declarations.origin
|
import org.jetbrains.kotlin.fir.declarations.origin
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
||||||
import org.jetbrains.kotlin.fir.extensions.FirDeclarationGenerationExtension
|
import org.jetbrains.kotlin.fir.extensions.FirDeclarationGenerationExtension
|
||||||
|
import org.jetbrains.kotlin.fir.extensions.FirExtension
|
||||||
import org.jetbrains.kotlin.fir.moduleData
|
import org.jetbrains.kotlin.fir.moduleData
|
||||||
import org.jetbrains.kotlin.fir.scopes.kotlinScopeProvider
|
import org.jetbrains.kotlin.fir.scopes.kotlinScopeProvider
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||||
@@ -99,12 +100,13 @@ public class ClassBuildingContext(
|
|||||||
/**
|
/**
|
||||||
* Creates top-level class with given [classId]
|
* Creates top-level class with given [classId]
|
||||||
* All declarations in class should be generated using methods from [FirDeclarationGenerationExtension]
|
* All declarations in class should be generated using methods from [FirDeclarationGenerationExtension]
|
||||||
|
* Generation of top-level classes with [FirDeclarationsForMetadataProviderExtension] is prohibited
|
||||||
*
|
*
|
||||||
* If no supertypes added then [kotlin.Any] supertype will be added automatically
|
* If no supertypes added then [kotlin.Any] supertype will be added automatically
|
||||||
*
|
*
|
||||||
* Created class won't have a constructor; constructor can be added separately with [createConstructor] function
|
* Created class won't have a constructor; constructor can be added separately with [createConstructor] function
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createTopLevelClass(
|
public fun FirExtension.createTopLevelClass(
|
||||||
classId: ClassId,
|
classId: ClassId,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
classKind: ClassKind = ClassKind.CLASS,
|
classKind: ClassKind = ClassKind.CLASS,
|
||||||
@@ -115,7 +117,10 @@ public fun FirDeclarationGenerationExtension.createTopLevelClass(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates nested class for [owner] class with name [name]
|
* Creates nested class for [owner] class with name [name]
|
||||||
* All declarations in class should be generated using methods from [FirDeclarationGenerationExtension]
|
* If class is generated in [FirDeclarationGenerationExtension], all its declarations should be generated
|
||||||
|
* using methods from [FirDeclarationGenerationExtension]
|
||||||
|
* If class is generated in [FirDeclarationsForMetadataProviderExtension] all its declarations should be manually added right to
|
||||||
|
* FIR node of created class
|
||||||
*
|
*
|
||||||
* If no supertypes added then [kotlin.Any] supertype will be added automatically
|
* If no supertypes added then [kotlin.Any] supertype will be added automatically
|
||||||
*
|
*
|
||||||
@@ -123,7 +128,7 @@ public fun FirDeclarationGenerationExtension.createTopLevelClass(
|
|||||||
*
|
*
|
||||||
* By default, the class is only nested; to create an inner class, create nested class and add inner status via status()
|
* By default, the class is only nested; to create an inner class, create nested class and add inner status via status()
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createNestedClass(
|
public fun FirExtension.createNestedClass(
|
||||||
owner: FirClassSymbol<*>,
|
owner: FirClassSymbol<*>,
|
||||||
name: Name,
|
name: Name,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
@@ -135,13 +140,16 @@ public fun FirDeclarationGenerationExtension.createNestedClass(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates companion object for [owner] class
|
* Creates companion object for [owner] class
|
||||||
* All declarations in class should be generated using methods from [FirDeclarationGenerationExtension]
|
* If class is generated in [FirDeclarationGenerationExtension], all its declarations should be generated
|
||||||
|
* using methods from [FirDeclarationGenerationExtension]
|
||||||
|
* If class is generated in [FirDeclarationsForMetadataProviderExtension] all its declarations should be manually added right to
|
||||||
|
* FIR node of created class
|
||||||
*
|
*
|
||||||
* If no supertypes added then [kotlin.Any] supertype will be added automatically
|
* If no supertypes added then [kotlin.Any] supertype will be added automatically
|
||||||
*
|
*
|
||||||
* Created class won't have a constructor; constructor can be added separately with [createDefaultPrivateConstructor] function
|
* Created class won't have a constructor; constructor can be added separately with [createDefaultPrivateConstructor] function
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createCompanionObject(
|
public fun FirExtension.createCompanionObject(
|
||||||
owner: FirClassSymbol<*>,
|
owner: FirClassSymbol<*>,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
config: ClassBuildingContext.() -> Unit = {}
|
config: ClassBuildingContext.() -> Unit = {}
|
||||||
|
|||||||
+4
-4
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.origin
|
|||||||
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
||||||
import org.jetbrains.kotlin.fir.expressions.buildResolvedArgumentList
|
import org.jetbrains.kotlin.fir.expressions.buildResolvedArgumentList
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildDelegatedConstructorCall
|
import org.jetbrains.kotlin.fir.expressions.builder.buildDelegatedConstructorCall
|
||||||
import org.jetbrains.kotlin.fir.extensions.FirDeclarationGenerationExtension
|
import org.jetbrains.kotlin.fir.extensions.FirExtension
|
||||||
import org.jetbrains.kotlin.fir.getContainingClassLookupTag
|
import org.jetbrains.kotlin.fir.getContainingClassLookupTag
|
||||||
import org.jetbrains.kotlin.fir.moduleData
|
import org.jetbrains.kotlin.fir.moduleData
|
||||||
import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
|
||||||
@@ -115,7 +115,7 @@ public class ConstructorBuildingContext(
|
|||||||
*
|
*
|
||||||
* If you want to create custom delegated constructor call please do it in the [IrGenerationExtension]
|
* If you want to create custom delegated constructor call please do it in the [IrGenerationExtension]
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createConstructor(
|
public fun FirExtension.createConstructor(
|
||||||
owner: FirClassSymbol<*>,
|
owner: FirClassSymbol<*>,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
isPrimary: Boolean = false,
|
isPrimary: Boolean = false,
|
||||||
@@ -140,7 +140,7 @@ public fun FirDeclarationGenerationExtension.createConstructor(
|
|||||||
*
|
*
|
||||||
* If you want to create custom delegated constructor call please do it in the [IrGenerationExtension]
|
* If you want to create custom delegated constructor call please do it in the [IrGenerationExtension]
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createDefaultPrivateConstructor(
|
public fun FirExtension.createDefaultPrivateConstructor(
|
||||||
owner: FirClassSymbol<*>,
|
owner: FirClassSymbol<*>,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
generateDelegatedNoArgConstructorCall: Boolean = true
|
generateDelegatedNoArgConstructorCall: Boolean = true
|
||||||
@@ -150,7 +150,7 @@ public fun FirDeclarationGenerationExtension.createDefaultPrivateConstructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context(FirDeclarationGenerationExtension)
|
context(FirExtension)
|
||||||
private fun FirConstructor.generateNoArgDelegatingConstructorCall() {
|
private fun FirConstructor.generateNoArgDelegatingConstructorCall() {
|
||||||
val owner = returnTypeRef.coneType.toSymbol(session) as? FirClassSymbol<*>
|
val owner = returnTypeRef.coneType.toSymbol(session) as? FirClassSymbol<*>
|
||||||
requireNotNull(owner)
|
requireNotNull(owner)
|
||||||
|
|||||||
+5
-5
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildReceiverParameter
|
|||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyBackingField
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyBackingField
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||||
import org.jetbrains.kotlin.fir.extensions.FirDeclarationGenerationExtension
|
import org.jetbrains.kotlin.fir.extensions.FirExtension
|
||||||
import org.jetbrains.kotlin.fir.moduleData
|
import org.jetbrains.kotlin.fir.moduleData
|
||||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||||
@@ -117,7 +117,7 @@ public class PropertyBuildingContext(
|
|||||||
/**
|
/**
|
||||||
* Creates a member property for [owner] class with [returnType] return type
|
* Creates a member property for [owner] class with [returnType] return type
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createMemberProperty(
|
public fun FirExtension.createMemberProperty(
|
||||||
owner: FirClassSymbol<*>,
|
owner: FirClassSymbol<*>,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
name: Name,
|
name: Name,
|
||||||
@@ -133,7 +133,7 @@ public fun FirDeclarationGenerationExtension.createMemberProperty(
|
|||||||
* Creates a member property for [owner] class with return type provided by [returnTypeProvider]
|
* Creates a member property for [owner] class with return type provided by [returnTypeProvider]
|
||||||
* Use this overload when those types use type parameters of constructed property
|
* Use this overload when those types use type parameters of constructed property
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createMemberProperty(
|
public fun FirExtension.createMemberProperty(
|
||||||
owner: FirClassSymbol<*>,
|
owner: FirClassSymbol<*>,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
name: Name,
|
name: Name,
|
||||||
@@ -152,7 +152,7 @@ public fun FirDeclarationGenerationExtension.createMemberProperty(
|
|||||||
* If you create top-level extension property don't forget to set [hasBackingField] to false,
|
* If you create top-level extension property don't forget to set [hasBackingField] to false,
|
||||||
* since such properties never have backing fields
|
* since such properties never have backing fields
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createTopLevelProperty(
|
public fun FirExtension.createTopLevelProperty(
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
callableId: CallableId,
|
callableId: CallableId,
|
||||||
returnType: ConeKotlinType,
|
returnType: ConeKotlinType,
|
||||||
@@ -171,7 +171,7 @@ public fun FirDeclarationGenerationExtension.createTopLevelProperty(
|
|||||||
*
|
*
|
||||||
* Use this overload when those types use type parameters of constructed property
|
* Use this overload when those types use type parameters of constructed property
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createTopLevelProperty(
|
public fun FirExtension.createTopLevelProperty(
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
callableId: CallableId,
|
callableId: CallableId,
|
||||||
returnTypeProvider: (List<FirTypeParameterRef>) -> ConeKotlinType,
|
returnTypeProvider: (List<FirTypeParameterRef>) -> ConeKotlinType,
|
||||||
|
|||||||
+5
-5
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
|||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildReceiverParameter
|
import org.jetbrains.kotlin.fir.declarations.builder.buildReceiverParameter
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction
|
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction
|
||||||
import org.jetbrains.kotlin.fir.declarations.origin
|
import org.jetbrains.kotlin.fir.declarations.origin
|
||||||
import org.jetbrains.kotlin.fir.extensions.FirDeclarationGenerationExtension
|
import org.jetbrains.kotlin.fir.extensions.FirExtension
|
||||||
import org.jetbrains.kotlin.fir.moduleData
|
import org.jetbrains.kotlin.fir.moduleData
|
||||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||||
@@ -89,7 +89,7 @@ public class SimpleFunctionBuildingContext(
|
|||||||
*
|
*
|
||||||
* Type and value parameters can be configured with [config] builder lambda
|
* Type and value parameters can be configured with [config] builder lambda
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createMemberFunction(
|
public fun FirExtension.createMemberFunction(
|
||||||
owner: FirClassSymbol<*>,
|
owner: FirClassSymbol<*>,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
name: Name,
|
name: Name,
|
||||||
@@ -105,7 +105,7 @@ public fun FirDeclarationGenerationExtension.createMemberFunction(
|
|||||||
*
|
*
|
||||||
* Type and value parameters can be configured with [config] builder lambda
|
* Type and value parameters can be configured with [config] builder lambda
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createMemberFunction(
|
public fun FirExtension.createMemberFunction(
|
||||||
owner: FirClassSymbol<*>,
|
owner: FirClassSymbol<*>,
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
name: Name,
|
name: Name,
|
||||||
@@ -121,7 +121,7 @@ public fun FirDeclarationGenerationExtension.createMemberFunction(
|
|||||||
*
|
*
|
||||||
* Type and value parameters can be configured with [config] builder lambda
|
* Type and value parameters can be configured with [config] builder lambda
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createTopLevelFunction(
|
public fun FirExtension.createTopLevelFunction(
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
callableId: CallableId,
|
callableId: CallableId,
|
||||||
returnType: ConeKotlinType,
|
returnType: ConeKotlinType,
|
||||||
@@ -136,7 +136,7 @@ public fun FirDeclarationGenerationExtension.createTopLevelFunction(
|
|||||||
*
|
*
|
||||||
* Type and value parameters can be configured with [config] builder lambda
|
* Type and value parameters can be configured with [config] builder lambda
|
||||||
*/
|
*/
|
||||||
public fun FirDeclarationGenerationExtension.createTopLevelFunction(
|
public fun FirExtension.createTopLevelFunction(
|
||||||
key: GeneratedDeclarationKey,
|
key: GeneratedDeclarationKey,
|
||||||
callableId: CallableId,
|
callableId: CallableId,
|
||||||
returnTypeProvider: (List<FirTypeParameter>) -> ConeKotlinType,
|
returnTypeProvider: (List<FirTypeParameter>) -> ConeKotlinType,
|
||||||
|
|||||||
Reference in New Issue
Block a user