Do not return primary constructor as an analyzable parent, probably #EA-73679 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-05-13 19:06:56 +03:00
parent 60f23e9a7e
commit 79852e9912
2 changed files with 21 additions and 0 deletions
@@ -137,6 +137,8 @@ private object KotlinResolveDataProvider {
is KtParameter -> PsiTreeUtil.getParentOfType(topmostElement, KtClassOrObject::class.java, KtCallableDeclaration::class.java)
else -> topmostElement
}
// Primary constructor should never be returned
if (analyzableElement is KtPrimaryConstructor) return analyzableElement.getContainingClassOrObject()
return analyzableElement
// if none of the above worked, take the outermost declaration
?: PsiTreeUtil.getTopmostParentOfType(element, KtDeclaration::class.java)
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea
import com.intellij.psi.PsiDocumentManager
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
@@ -342,4 +343,22 @@ class C(param1: String = "", param2: Int = 0) {
private fun configureWithKotlin(@Language("kotlin") text: String): KtFile {
return myFixture.configureByText("Test.kt", text.trimIndent()) as KtFile
}
fun testPrimaryConstructorParameterFullAnalysis() {
val file = myFixture.configureByText("Test.kt", """
class My(param: Int = 0)
""") as KtFile
val defaultValue = ((file.declarations[0]) as KtClass).getPrimaryConstructor()!!.valueParameters[0].defaultValue!!
defaultValue.analyzeFullyAndGetResult()
}
fun testPrimaryConstructorAnnotationFullAnalysis() {
val file = myFixture.configureByText("Test.kt", """
class My @Deprecated("xyz") protected constructor(param: Int)
""") as KtFile
val annotationArguments = ((file.declarations[0]) as KtClass).getPrimaryConstructor()!!.annotationEntries[0].valueArgumentList!!
annotationArguments.analyzeFullyAndGetResult()
}
}