Changes on code review
This commit is contained in:
+5
-6
@@ -104,14 +104,11 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
|
|||||||
|
|
||||||
val memberScope = ownerClass.unsubstitutedMemberScope
|
val memberScope = ownerClass.unsubstitutedMemberScope
|
||||||
val getMethod = possibleGetMethodNames(name)
|
val getMethod = possibleGetMethodNames(name)
|
||||||
.asSequence()
|
|
||||||
.flatMap { memberScope.getFunctions(it).asSequence() }
|
.flatMap { memberScope.getFunctions(it).asSequence() }
|
||||||
.singleOrNull {
|
.singleOrNull {
|
||||||
isGoodGetMethod(it) && it.hasJavaOriginInHierarchy()
|
isGoodGetMethod(it) && it.hasJavaOriginInHierarchy()
|
||||||
} ?: return null
|
} ?: return null
|
||||||
|
|
||||||
// don't accept "uRL" for "getURL" etc
|
|
||||||
if (SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(getMethod.name) != name) return null
|
|
||||||
|
|
||||||
val setMethod = memberScope.getFunctions(setMethodName(getMethod.name))
|
val setMethod = memberScope.getFunctions(setMethodName(getMethod.name))
|
||||||
.singleOrNull { isGoodSetMethod(it, getMethod) }
|
.singleOrNull { isGoodSetMethod(it, getMethod) }
|
||||||
@@ -140,7 +137,7 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
|
|||||||
private fun isGoodSetMethod(descriptor: FunctionDescriptor, getMethod: FunctionDescriptor): Boolean {
|
private fun isGoodSetMethod(descriptor: FunctionDescriptor, getMethod: FunctionDescriptor): Boolean {
|
||||||
val propertyType = getMethod.returnType ?: return false
|
val propertyType = getMethod.returnType ?: return false
|
||||||
val parameter = descriptor.valueParameters.singleOrNull() ?: return false
|
val parameter = descriptor.valueParameters.singleOrNull() ?: return false
|
||||||
if (parameter.type != propertyType) {
|
if (!TypeUtils.equalTypes(parameter.type, propertyType)) {
|
||||||
if (!propertyType.isSubtypeOf(parameter.type)) return false
|
if (!propertyType.isSubtypeOf(parameter.type)) return false
|
||||||
if (descriptor.findOverridden {
|
if (descriptor.findOverridden {
|
||||||
val baseProperty = SyntheticJavaPropertyDescriptor.findByGetterOrSetter(it, this)
|
val baseProperty = SyntheticJavaPropertyDescriptor.findByGetterOrSetter(it, this)
|
||||||
@@ -225,7 +222,7 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
|
|||||||
|
|
||||||
//TODO: reuse code with generation?
|
//TODO: reuse code with generation?
|
||||||
|
|
||||||
private fun possibleGetMethodNames(propertyName: Name): Collection<Name> {
|
private fun possibleGetMethodNames(propertyName: Name): Sequence<Name> {
|
||||||
val result = ArrayList<Name>(3)
|
val result = ArrayList<Name>(3)
|
||||||
val identifier = propertyName.identifier
|
val identifier = propertyName.identifier
|
||||||
|
|
||||||
@@ -239,7 +236,9 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
|
|||||||
if (capitalize2 != capitalize1) {
|
if (capitalize2 != capitalize1) {
|
||||||
result.add(Name.identifier("get" + capitalize2))
|
result.add(Name.identifier("get" + capitalize2))
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
return result.asSequence()
|
||||||
|
.filter { SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(it) == propertyName } // don't accept "uRL" for "getURL" etc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setMethodName(getMethodName: Name): Name {
|
private fun setMethodName(getMethodName: Name): Name {
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ fun foo(k: KotlinClass) {
|
|||||||
if (<!SENSELESS_COMPARISON!>k.something == null<!>) return
|
if (<!SENSELESS_COMPARISON!>k.something == null<!>) return
|
||||||
|
|
||||||
k.setSomething("")
|
k.setSomething("")
|
||||||
<!VAL_REASSIGNMENT!>k.something<!> = ""
|
k.something = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
fun useString(<!UNUSED_PARAMETER!>i<!>: String) {}
|
fun useString(<!UNUSED_PARAMETER!>i<!>: String) {}
|
||||||
|
|||||||
+3
-3
@@ -62,9 +62,9 @@ sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpr
|
|||||||
SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(newNameAsName)
|
SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(newNameAsName)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val propertyDescriptor = super.getTargetDescriptors(expression.analyze(BodyResolveMode.PARTIAL))
|
//TODO: it's not correct
|
||||||
.singleOrNull { it.original is SyntheticJavaPropertyDescriptor } ?: return expression
|
//TODO: setIsY -> setIsIsY bug
|
||||||
SyntheticJavaPropertyDescriptor.propertyNameBySetMethodName(newNameAsName, withIsPrefix = propertyDescriptor.getName().asString().startsWith("is"))
|
SyntheticJavaPropertyDescriptor.propertyNameBySetMethodName(newNameAsName, withIsPrefix = expression.getReferencedNameAsName().asString().startsWith("is"))
|
||||||
}
|
}
|
||||||
if (newName == null) return expression //TODO: handle the case when get/set becomes ordinary method
|
if (newName == null) return expression //TODO: handle the case when get/set becomes ordinary method
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user