FE: move delegate name functions to NameUtils
This commit is contained in:
committed by
Space Team
parent
a7ba081d22
commit
5cf1a88c42
+2
-2
@@ -897,7 +897,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
createBackingField(
|
createBackingField(
|
||||||
property, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
property, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||||
components.visibilityConverter.convertToDescriptorVisibility(property.fieldVisibility),
|
components.visibilityConverter.convertToDescriptorVisibility(property.fieldVisibility),
|
||||||
SpecialNames.propertyDelegateName(property.name), true, delegate
|
NameUtils.propertyDelegateName(property.name), true, delegate
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
val initializer = property.backingField?.initializer ?: property.initializer
|
val initializer = property.backingField?.initializer ?: property.initializer
|
||||||
@@ -1230,7 +1230,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
enterScope(this)
|
enterScope(this)
|
||||||
delegate = declareIrVariable(
|
delegate = declareIrVariable(
|
||||||
startOffset, endOffset, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
startOffset, endOffset, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||||
SpecialNames.propertyDelegateName(property.name), property.delegate!!.typeRef.toIrType(),
|
NameUtils.propertyDelegateName(property.name), property.delegate!!.typeRef.toIrType(),
|
||||||
isVar = false, isConst = false, isLateinit = false
|
isVar = false, isConst = false, isLateinit = false
|
||||||
)
|
)
|
||||||
delegate.parent = irParent
|
delegate.parent = irParent
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.fir.expressions.FirExpression
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.ir.util.isComposite
|
import org.jetbrains.kotlin.ir.util.isComposite
|
||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.NameUtils
|
||||||
|
|
||||||
class Fir2IrLazyProperty(
|
class Fir2IrLazyProperty(
|
||||||
components: Fir2IrComponents,
|
components: Fir2IrComponents,
|
||||||
@@ -147,7 +147,7 @@ class Fir2IrLazyProperty(
|
|||||||
createBackingField(
|
createBackingField(
|
||||||
fir, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
fir, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||||
components.visibilityConverter.convertToDescriptorVisibility(fir.visibility),
|
components.visibilityConverter.convertToDescriptorVisibility(fir.visibility),
|
||||||
SpecialNames.propertyDelegateName(fir.name), true, fir.delegate
|
NameUtils.propertyDelegateName(fir.name), true, fir.delegate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1536,7 +1536,7 @@ class DeclarationsConverter(
|
|||||||
/**
|
/**
|
||||||
* this is just a VALUE_PARAMETER_LIST
|
* this is just a VALUE_PARAMETER_LIST
|
||||||
*
|
*
|
||||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyGetterOrSetter
|
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyComponent
|
||||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.toFirValueParameter
|
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.toFirValueParameter
|
||||||
*/
|
*/
|
||||||
private fun convertSetterParameter(
|
private fun convertSetterParameter(
|
||||||
@@ -1853,7 +1853,7 @@ class DeclarationsConverter(
|
|||||||
source = calculatedFirExpression.source?.fakeElement(KtFakeSourceElementKind.ClassDelegationField)
|
source = calculatedFirExpression.source?.fakeElement(KtFakeSourceElementKind.ClassDelegationField)
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Synthetic
|
origin = FirDeclarationOrigin.Synthetic
|
||||||
name = SpecialNames.delegateFieldName(delegateFieldsMap.size)
|
name = NameUtils.delegateFieldName(delegateFieldsMap.size)
|
||||||
returnTypeRef = firTypeRef
|
returnTypeRef = firTypeRef
|
||||||
symbol = FirFieldSymbol(CallableId(name))
|
symbol = FirFieldSymbol(CallableId(name))
|
||||||
isVar = false
|
isVar = false
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl
|
|||||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||||
import org.jetbrains.kotlin.name.CallableId
|
import org.jetbrains.kotlin.name.CallableId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.name.NameUtils
|
||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.SpecialNames
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
@@ -854,7 +855,7 @@ open class RawFirBuilder(
|
|||||||
source = delegateSource
|
source = delegateSource
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Synthetic
|
origin = FirDeclarationOrigin.Synthetic
|
||||||
name = SpecialNames.delegateFieldName(delegateFieldsMap.size)
|
name = NameUtils.delegateFieldName(delegateFieldsMap.size)
|
||||||
returnTypeRef = type
|
returnTypeRef = type
|
||||||
symbol = FirFieldSymbol(CallableId(name))
|
symbol = FirFieldSymbol(CallableId(name))
|
||||||
isVar = false
|
isVar = false
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
import org.jetbrains.kotlin.descriptors.impl.VariableDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.VariableDescriptorImpl
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.NameUtils
|
||||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
@@ -98,7 +98,7 @@ class IrPropertyDelegateDescriptorImpl(
|
|||||||
) :
|
) :
|
||||||
IrDelegateDescriptorBase(
|
IrDelegateDescriptorBase(
|
||||||
correspondingProperty.containingDeclaration,
|
correspondingProperty.containingDeclaration,
|
||||||
SpecialNames.propertyDelegateName(correspondingProperty.name),
|
NameUtils.propertyDelegateName(correspondingProperty.name),
|
||||||
delegateType,
|
delegateType,
|
||||||
correspondingProperty.delegateField?.annotations ?: Annotations.EMPTY
|
correspondingProperty.delegateField?.annotations ?: Annotations.EMPTY
|
||||||
),
|
),
|
||||||
@@ -112,7 +112,7 @@ class IrImplementingDelegateDescriptorImpl(
|
|||||||
) :
|
) :
|
||||||
IrDelegateDescriptorBase(
|
IrDelegateDescriptorBase(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
SpecialNames.delegateFieldName(number),
|
NameUtils.delegateFieldName(number),
|
||||||
delegateType
|
delegateType
|
||||||
),
|
),
|
||||||
IrImplementingDelegateDescriptor
|
IrImplementingDelegateDescriptor
|
||||||
@@ -125,7 +125,7 @@ class IrLocalDelegatedPropertyDelegateDescriptorImpl(
|
|||||||
VariableDescriptorImpl(
|
VariableDescriptorImpl(
|
||||||
correspondingLocalProperty.containingDeclaration,
|
correspondingLocalProperty.containingDeclaration,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
SpecialNames.propertyDelegateName(correspondingLocalProperty.name),
|
NameUtils.propertyDelegateName(correspondingLocalProperty.name),
|
||||||
delegateType,
|
delegateType,
|
||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ public final class B {
|
|||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public final class C {
|
public final class C {
|
||||||
// source: 'delegating.kt'
|
// source: 'delegating.kt'
|
||||||
private synthetic final field <$$delegate_0-x>: int
|
private synthetic final field $$delegate_0-x: int
|
||||||
private synthetic final field <$$delegate_0-y>: int
|
private synthetic final field $$delegate_0-y: int
|
||||||
public method <init>(p0: int, p1: int): void
|
public method <init>(p0: int, p1: int): void
|
||||||
public method getX(): int
|
public method getX(): int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,25 +30,35 @@ object NameUtils {
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getPackagePartClassNamePrefix(shortFileName: String): String =
|
fun getPackagePartClassNamePrefix(shortFileName: String): String =
|
||||||
if (shortFileName.isEmpty())
|
if (shortFileName.isEmpty())
|
||||||
"_"
|
"_"
|
||||||
else
|
else
|
||||||
capitalizeAsJavaClassName(sanitizeAsJavaIdentifier(shortFileName))
|
capitalizeAsJavaClassName(sanitizeAsJavaIdentifier(shortFileName))
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private fun capitalizeAsJavaClassName(str: String): String =
|
private fun capitalizeAsJavaClassName(str: String): String =
|
||||||
// NB `uppercase` uses Locale.ROOT and is locale-independent.
|
// NB `uppercase` uses Locale.ROOT and is locale-independent.
|
||||||
// See Javadoc on java.lang.String.toUpperCase() for more details.
|
// See Javadoc on java.lang.String.toUpperCase() for more details.
|
||||||
if (Character.isJavaIdentifierStart(str[0]))
|
if (Character.isJavaIdentifierStart(str[0]))
|
||||||
str[0].uppercase() + str.substring(1)
|
str[0].uppercase() + str.substring(1)
|
||||||
else
|
else
|
||||||
"_$str"
|
"_$str"
|
||||||
|
|
||||||
// "pkg/someScript.kts" -> "SomeScript"
|
// "pkg/someScript.kts" -> "SomeScript"
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getScriptNameForFile(filePath: String): Name =
|
fun getScriptNameForFile(filePath: String): Name =
|
||||||
Name.identifier(NameUtils.getPackagePartClassNamePrefix(filePath.substringAfterLast('/').substringBeforeLast('.')))
|
Name.identifier(NameUtils.getPackagePartClassNamePrefix(filePath.substringAfterLast('/').substringBeforeLast('.')))
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun hasName(name: Name) = name != SpecialNames.NO_NAME_PROVIDED && name != SpecialNames.ANONYMOUS
|
fun hasName(name: Name) = name != SpecialNames.NO_NAME_PROVIDED && name != SpecialNames.ANONYMOUS
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun delegateFieldName(index: Int): Name {
|
||||||
|
return Name.identifier("\$\$delegate_$index")
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun propertyDelegateName(propertyName: Name): Name {
|
||||||
|
return Name.identifier("${propertyName.asString()}\$delegate")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,14 +101,4 @@ object SpecialNames {
|
|||||||
fun isSafeIdentifier(name: Name): Boolean {
|
fun isSafeIdentifier(name: Name): Boolean {
|
||||||
return name.asString().isNotEmpty() && !name.isSpecial
|
return name.asString().isNotEmpty() && !name.isSpecial
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun delegateFieldName(index: Int): Name {
|
|
||||||
return Name.identifier("\$\$delegate_$index")
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun propertyDelegateName(propertyName: Name): Name {
|
|
||||||
return Name.identifier("${propertyName.asString()}\$delegate")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user