KT-15092 Suppress inspection "use property access syntax" for some getters and fix completion for them
#KT-15092 fixed
This commit is contained in:
+7
-3
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
@@ -49,7 +50,8 @@ class ReferenceVariantsHelper(
|
||||
private val bindingContext: BindingContext,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val moduleDescriptor: ModuleDescriptor,
|
||||
private val visibilityFilter: (DeclarationDescriptor) -> Boolean
|
||||
private val visibilityFilter: (DeclarationDescriptor) -> Boolean,
|
||||
private val notProperties: Set<FqNameUnsafe> = setOf()
|
||||
) {
|
||||
fun getReferenceVariants(
|
||||
expression: KtSimpleNameExpression,
|
||||
@@ -96,7 +98,9 @@ class ReferenceVariantsHelper(
|
||||
|
||||
fun filterOutJavaGettersAndSetters(variants: Collection<DeclarationDescriptor>): Collection<DeclarationDescriptor> {
|
||||
val accessorMethodsToRemove = HashSet<FunctionDescriptor>()
|
||||
for (variant in variants) {
|
||||
val filteredVariants = variants.filter { it !is SyntheticJavaPropertyDescriptor || !it.suppressedByNotPropertyList(notProperties) }
|
||||
|
||||
for (variant in filteredVariants) {
|
||||
if (variant is SyntheticJavaPropertyDescriptor) {
|
||||
accessorMethodsToRemove.add(variant.getMethod.original)
|
||||
|
||||
@@ -107,7 +111,7 @@ class ReferenceVariantsHelper(
|
||||
}
|
||||
}
|
||||
|
||||
return variants.filter { it !is FunctionDescriptor || it.original !in accessorMethodsToRemove }
|
||||
return filteredVariants.filter { it !is FunctionDescriptor || it.original !in accessorMethodsToRemove }
|
||||
}
|
||||
|
||||
// filters out variable inside its initializer
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.util
|
||||
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeUniqueAsSequence
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
|
||||
fun FunctionDescriptor.shouldNotConvertToProperty(notProperties: Set<FqNameUnsafe>): Boolean {
|
||||
if (fqNameUnsafe in notProperties) return true
|
||||
return this.overriddenTreeUniqueAsSequence(false).any { fqNameUnsafe in notProperties }
|
||||
}
|
||||
|
||||
fun SyntheticJavaPropertyDescriptor.suppressedByNotPropertyList(set: Set<FqNameUnsafe>) =
|
||||
getMethod.shouldNotConvertToProperty(set) || setMethod?.shouldNotConvertToProperty(set) ?: false
|
||||
Reference in New Issue
Block a user