Do not return primary constructor as an analyzable parent, probably #EA-73679 Fixed
This commit is contained in:
@@ -137,6 +137,8 @@ private object KotlinResolveDataProvider {
|
|||||||
is KtParameter -> PsiTreeUtil.getParentOfType(topmostElement, KtClassOrObject::class.java, KtCallableDeclaration::class.java)
|
is KtParameter -> PsiTreeUtil.getParentOfType(topmostElement, KtClassOrObject::class.java, KtCallableDeclaration::class.java)
|
||||||
else -> topmostElement
|
else -> topmostElement
|
||||||
}
|
}
|
||||||
|
// Primary constructor should never be returned
|
||||||
|
if (analyzableElement is KtPrimaryConstructor) return analyzableElement.getContainingClassOrObject()
|
||||||
return analyzableElement
|
return analyzableElement
|
||||||
// if none of the above worked, take the outermost declaration
|
// if none of the above worked, take the outermost declaration
|
||||||
?: PsiTreeUtil.getTopmostParentOfType(element, KtDeclaration::class.java)
|
?: PsiTreeUtil.getTopmostParentOfType(element, KtDeclaration::class.java)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea
|
|||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
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.caches.resolve.resolveToDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
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 {
|
private fun configureWithKotlin(@Language("kotlin") text: String): KtFile {
|
||||||
return myFixture.configureByText("Test.kt", text.trimIndent()) as 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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user