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 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 {
@@ -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) {}
@@ -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