Don't show type hints for SAM constructors
#KT-22050 Fixed
This commit is contained in:
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
||||||
import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention
|
import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention
|
||||||
|
import org.jetbrains.kotlin.load.java.sam.SamConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.SpecialNames
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
@@ -82,9 +83,12 @@ private fun isUnclearType(type: KotlinType, element: KtCallableDeclaration): Boo
|
|||||||
if (initializer is KtCallExpression) {
|
if (initializer is KtCallExpression) {
|
||||||
val bindingContext = element.analyze()
|
val bindingContext = element.analyze()
|
||||||
val resolvedCall = initializer.getResolvedCall(bindingContext)
|
val resolvedCall = initializer.getResolvedCall(bindingContext)
|
||||||
val constructorDescriptor = resolvedCall?.candidateDescriptor as? ConstructorDescriptor
|
val resolvedDescriptor = resolvedCall?.candidateDescriptor
|
||||||
if (constructorDescriptor != null &&
|
if (resolvedDescriptor is SamConstructorDescriptor) {
|
||||||
(constructorDescriptor.constructedClass.declaredTypeParameters.isEmpty() || initializer.typeArgumentList != null)) {
|
return false
|
||||||
|
}
|
||||||
|
if (resolvedDescriptor is ConstructorDescriptor &&
|
||||||
|
(resolvedDescriptor.constructedClass.declaredTypeParameters.isEmpty() || initializer.typeArgumentList != null)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the license/LICENSE.txt file.
|
||||||
* 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.parameterInfo
|
package org.jetbrains.kotlin.idea.parameterInfo
|
||||||
@@ -116,4 +105,9 @@ class InlayTypeHintsTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
return Triple(<hint text="first:" />"A", <hint text="second:" />"B", <hint text="third:" />"C")
|
return Triple(<hint text="first:" />"A", <hint text="second:" />"B", <hint text="third:" />"C")
|
||||||
}""")
|
}""")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testSAMConstructor() {
|
||||||
|
HintType.PROPERTY_HINT.option.set(true)
|
||||||
|
check("""val x = Runnable { }""")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user