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(
|
||||
property, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||
components.visibilityConverter.convertToDescriptorVisibility(property.fieldVisibility),
|
||||
SpecialNames.propertyDelegateName(property.name), true, delegate
|
||||
NameUtils.propertyDelegateName(property.name), true, delegate
|
||||
)
|
||||
} else {
|
||||
val initializer = property.backingField?.initializer ?: property.initializer
|
||||
@@ -1230,7 +1230,7 @@ class Fir2IrDeclarationStorage(
|
||||
enterScope(this)
|
||||
delegate = declareIrVariable(
|
||||
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
|
||||
)
|
||||
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.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.util.isComposite
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.name.NameUtils
|
||||
|
||||
class Fir2IrLazyProperty(
|
||||
components: Fir2IrComponents,
|
||||
@@ -147,7 +147,7 @@ class Fir2IrLazyProperty(
|
||||
createBackingField(
|
||||
fir, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||
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
|
||||
*
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyGetterOrSetter
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parsePropertyComponent
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.toFirValueParameter
|
||||
*/
|
||||
private fun convertSetterParameter(
|
||||
@@ -1853,7 +1853,7 @@ class DeclarationsConverter(
|
||||
source = calculatedFirExpression.source?.fakeElement(KtFakeSourceElementKind.ClassDelegationField)
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Synthetic
|
||||
name = SpecialNames.delegateFieldName(delegateFieldsMap.size)
|
||||
name = NameUtils.delegateFieldName(delegateFieldsMap.size)
|
||||
returnTypeRef = firTypeRef
|
||||
symbol = FirFieldSymbol(CallableId(name))
|
||||
isVar = false
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.NameUtils
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
@@ -854,7 +855,7 @@ open class RawFirBuilder(
|
||||
source = delegateSource
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Synthetic
|
||||
name = SpecialNames.delegateFieldName(delegateFieldsMap.size)
|
||||
name = NameUtils.delegateFieldName(delegateFieldsMap.size)
|
||||
returnTypeRef = type
|
||||
symbol = FirFieldSymbol(CallableId(name))
|
||||
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.VariableDescriptorImpl
|
||||
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.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
@@ -98,7 +98,7 @@ class IrPropertyDelegateDescriptorImpl(
|
||||
) :
|
||||
IrDelegateDescriptorBase(
|
||||
correspondingProperty.containingDeclaration,
|
||||
SpecialNames.propertyDelegateName(correspondingProperty.name),
|
||||
NameUtils.propertyDelegateName(correspondingProperty.name),
|
||||
delegateType,
|
||||
correspondingProperty.delegateField?.annotations ?: Annotations.EMPTY
|
||||
),
|
||||
@@ -112,7 +112,7 @@ class IrImplementingDelegateDescriptorImpl(
|
||||
) :
|
||||
IrDelegateDescriptorBase(
|
||||
containingDeclaration,
|
||||
SpecialNames.delegateFieldName(number),
|
||||
NameUtils.delegateFieldName(number),
|
||||
delegateType
|
||||
),
|
||||
IrImplementingDelegateDescriptor
|
||||
@@ -125,7 +125,7 @@ class IrLocalDelegatedPropertyDelegateDescriptorImpl(
|
||||
VariableDescriptorImpl(
|
||||
correspondingLocalProperty.containingDeclaration,
|
||||
Annotations.EMPTY,
|
||||
SpecialNames.propertyDelegateName(correspondingLocalProperty.name),
|
||||
NameUtils.propertyDelegateName(correspondingLocalProperty.name),
|
||||
delegateType,
|
||||
SourceElement.NO_SOURCE
|
||||
) {
|
||||
|
||||
@@ -72,8 +72,8 @@ public final class B {
|
||||
@kotlin.Metadata
|
||||
public final class C {
|
||||
// source: 'delegating.kt'
|
||||
private synthetic final field <$$delegate_0-x>: int
|
||||
private synthetic final field <$$delegate_0-y>: int
|
||||
private synthetic final field $$delegate_0-x: int
|
||||
private synthetic final field $$delegate_0-y: int
|
||||
public method <init>(p0: int, p1: int): void
|
||||
public method getX(): int
|
||||
}
|
||||
|
||||
@@ -30,25 +30,35 @@ object NameUtils {
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getPackagePartClassNamePrefix(shortFileName: String): String =
|
||||
if (shortFileName.isEmpty())
|
||||
"_"
|
||||
else
|
||||
capitalizeAsJavaClassName(sanitizeAsJavaIdentifier(shortFileName))
|
||||
if (shortFileName.isEmpty())
|
||||
"_"
|
||||
else
|
||||
capitalizeAsJavaClassName(sanitizeAsJavaIdentifier(shortFileName))
|
||||
|
||||
@JvmStatic
|
||||
private fun capitalizeAsJavaClassName(str: String): String =
|
||||
// NB `uppercase` uses Locale.ROOT and is locale-independent.
|
||||
// See Javadoc on java.lang.String.toUpperCase() for more details.
|
||||
if (Character.isJavaIdentifierStart(str[0]))
|
||||
str[0].uppercase() + str.substring(1)
|
||||
else
|
||||
"_$str"
|
||||
// NB `uppercase` uses Locale.ROOT and is locale-independent.
|
||||
// See Javadoc on java.lang.String.toUpperCase() for more details.
|
||||
if (Character.isJavaIdentifierStart(str[0]))
|
||||
str[0].uppercase() + str.substring(1)
|
||||
else
|
||||
"_$str"
|
||||
|
||||
// "pkg/someScript.kts" -> "SomeScript"
|
||||
@JvmStatic
|
||||
fun getScriptNameForFile(filePath: String): Name =
|
||||
Name.identifier(NameUtils.getPackagePartClassNamePrefix(filePath.substringAfterLast('/').substringBeforeLast('.')))
|
||||
Name.identifier(NameUtils.getPackagePartClassNamePrefix(filePath.substringAfterLast('/').substringBeforeLast('.')))
|
||||
|
||||
@JvmStatic
|
||||
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 {
|
||||
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