Moved methods
This commit is contained in:
+14
-16
@@ -49,6 +49,19 @@ interface SyntheticExtensionPropertyDescriptor : PropertyDescriptor {
|
||||
.filterIsInstance<SyntheticExtensionPropertyDescriptor>()
|
||||
.firstOrNull { getterOrSetter == it.getMethod || getterOrSetter == it.setMethod }
|
||||
}
|
||||
|
||||
fun propertyNameByGetMethodName(methodName: Name): Name? = propertyNameFromAccessorMethodName(methodName, "get")
|
||||
|
||||
fun propertyNameBySetMethodName(methodName: Name): Name? = propertyNameFromAccessorMethodName(methodName, "set")
|
||||
|
||||
private fun propertyNameFromAccessorMethodName(methodName: Name, prefix: String): Name? {
|
||||
if (methodName.isSpecial()) return null
|
||||
val identifier = methodName.getIdentifier()
|
||||
if (!identifier.startsWith(prefix)) return null
|
||||
val name = identifier.removePrefix(prefix).decapitalize()
|
||||
if (!Name.isValidIdentifier(name)) return null
|
||||
return Name.identifier(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +137,7 @@ class SyntheticExtensionsScope(storageManager: StorageManager) : JetScope by Jet
|
||||
if (classifier is JavaClassDescriptor) {
|
||||
for (descriptor in classifier.getMemberScope(type.getArguments()).getAllDescriptors()) {
|
||||
if (descriptor is FunctionDescriptor) {
|
||||
val propertyName = propertyNameByGetMethodName(descriptor.getName()) ?: continue
|
||||
val propertyName = SyntheticExtensionPropertyDescriptor.propertyNameByGetMethodName(descriptor.getName()) ?: continue
|
||||
addIfNotNull(syntheticPropertyInClass(Triple(classifier, type, propertyName)))
|
||||
}
|
||||
}
|
||||
@@ -151,21 +164,6 @@ class SyntheticExtensionsScope(storageManager: StorageManager) : JetScope by Jet
|
||||
return Name.identifier("set" + propertyName.getIdentifier().capitalize())
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun propertyNameByGetMethodName(methodName: Name): Name? = propertyNameFromAccessorMethodName(methodName, "get")
|
||||
|
||||
public fun propertyNameBySetMethodName(methodName: Name): Name? = propertyNameFromAccessorMethodName(methodName, "set")
|
||||
|
||||
private fun propertyNameFromAccessorMethodName(methodName: Name, prefix: String): Name? {
|
||||
if (methodName.isSpecial()) return null
|
||||
val identifier = methodName.getIdentifier()
|
||||
if (!identifier.startsWith(prefix)) return null
|
||||
val name = identifier.removePrefix(prefix).decapitalize()
|
||||
if (!Name.isValidIdentifier(name)) return null
|
||||
return Name.identifier(name)
|
||||
}
|
||||
}
|
||||
|
||||
private class MyPropertyDescriptor(
|
||||
javaClass: JavaClassDescriptor,
|
||||
override val getMethod: FunctionDescriptor,
|
||||
|
||||
+4
-4
@@ -40,7 +40,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticExtensionsScope
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.constant
|
||||
@@ -145,9 +144,10 @@ public class JetSimpleNameReference(
|
||||
if (Name.isValidIdentifier(newElementName)) {
|
||||
val newNameAsName = Name.identifier(newElementName)
|
||||
val newName = when (access()) {
|
||||
Access.READ -> SyntheticExtensionsScope.propertyNameByGetMethodName(newNameAsName)
|
||||
Access.WRITE -> SyntheticExtensionsScope.propertyNameBySetMethodName(newNameAsName)
|
||||
Access.READ_WRITE -> SyntheticExtensionsScope.propertyNameByGetMethodName(newNameAsName) ?: SyntheticExtensionsScope.propertyNameBySetMethodName(newNameAsName)
|
||||
Access.READ -> SyntheticExtensionPropertyDescriptor.propertyNameByGetMethodName(newNameAsName)
|
||||
Access.WRITE -> SyntheticExtensionPropertyDescriptor.propertyNameBySetMethodName(newNameAsName)
|
||||
Access.READ_WRITE -> SyntheticExtensionPropertyDescriptor.propertyNameByGetMethodName(newNameAsName)
|
||||
?: SyntheticExtensionPropertyDescriptor.propertyNameBySetMethodName(newNameAsName)
|
||||
} ?: return expression //TODO: handle the case when get/set becomes ordinary method
|
||||
newElementName = newName.getIdentifier()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user