Can be parameter inspection: use inside object literals is now handled as "property use"
This commit is contained in:
@@ -55,14 +55,13 @@ class CanBeParameterInspection : AbstractKotlinInspection() {
|
||||
do {
|
||||
parameterUser = PsiTreeUtil.getParentOfType(parameterUser, KtProperty::class.java, KtPropertyAccessor::class.java,
|
||||
KtClassInitializer::class.java, KtSecondaryConstructor::class.java,
|
||||
KtFunctionLiteral::class.java) ?: return true
|
||||
KtFunctionLiteral::class.java, KtObjectDeclaration::class.java) ?: return true
|
||||
} while (parameterUser is KtProperty && parameterUser.isLocal)
|
||||
return when (parameterUser) {
|
||||
is KtProperty -> parameterUser.containingClassOrObject !== klass
|
||||
is KtPropertyAccessor -> true
|
||||
is KtClassInitializer -> parameterUser.containingDeclaration !== klass
|
||||
is KtSecondaryConstructor -> parameterUser.getContainingClassOrObject() !== klass
|
||||
is KtFunctionLiteral -> true
|
||||
is KtFunctionLiteral, is KtObjectDeclaration, is KtPropertyAccessor -> true
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,10 @@ class UsedInDelegate(val x: Int) {
|
||||
// NO
|
||||
class UsedInParent(val x: UsedInParent?) {
|
||||
val y = x?.x
|
||||
}
|
||||
// NO
|
||||
class UsedInObjectLiteral(val x: Int) {
|
||||
val y = object: Any() {
|
||||
fun bar() = x
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user