Changes on code review

This commit is contained in:
Valentin Kipyatkov
2015-07-20 19:20:23 +03:00
parent 2ab8f9de8b
commit 4ec26de2a8
3 changed files with 9 additions and 10 deletions
@@ -104,14 +104,11 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
val memberScope = ownerClass.unsubstitutedMemberScope
val getMethod = possibleGetMethodNames(name)
.asSequence()
.flatMap { memberScope.getFunctions(it).asSequence() }
.singleOrNull {
isGoodGetMethod(it) && it.hasJavaOriginInHierarchy()
} ?: return null
// don't accept "uRL" for "getURL" etc
if (SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(getMethod.name) != name) return null
val setMethod = memberScope.getFunctions(setMethodName(getMethod.name))
.singleOrNull { isGoodSetMethod(it, getMethod) }
@@ -140,7 +137,7 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
private fun isGoodSetMethod(descriptor: FunctionDescriptor, getMethod: FunctionDescriptor): Boolean {
val propertyType = getMethod.returnType ?: 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 (descriptor.findOverridden {
val baseProperty = SyntheticJavaPropertyDescriptor.findByGetterOrSetter(it, this)
@@ -225,7 +222,7 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
//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 identifier = propertyName.identifier
@@ -239,7 +236,9 @@ class JavaSyntheticExtensionsScope(storageManager: StorageManager) : JetScope by
if (capitalize2 != capitalize1) {
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 {
@@ -9,7 +9,7 @@ fun foo(k: KotlinClass) {
if (<!SENSELESS_COMPARISON!>k.something == null<!>) return
k.setSomething("")
<!VAL_REASSIGNMENT!>k.something<!> = ""
k.something = ""
}
fun useString(<!UNUSED_PARAMETER!>i<!>: String) {}
@@ -62,9 +62,9 @@ sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpr
SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(newNameAsName)
}
else {
val propertyDescriptor = super.getTargetDescriptors(expression.analyze(BodyResolveMode.PARTIAL))
.singleOrNull { it.original is SyntheticJavaPropertyDescriptor } ?: return expression
SyntheticJavaPropertyDescriptor.propertyNameBySetMethodName(newNameAsName, withIsPrefix = propertyDescriptor.getName().asString().startsWith("is"))
//TODO: it's not correct
//TODO: setIsY -> setIsIsY bug
SyntheticJavaPropertyDescriptor.propertyNameBySetMethodName(newNameAsName, withIsPrefix = expression.getReferencedNameAsName().asString().startsWith("is"))
}
if (newName == null) return expression //TODO: handle the case when get/set becomes ordinary method