Don't call getClassDescriptor for local declarations (KT-15259)
#KT-15259 Open
This commit is contained in:
@@ -747,7 +747,6 @@ public class KtPsiUtil {
|
||||
if (((KtParameter) declaration).hasValOrVar() && parent != null && parent.getParent() instanceof KtPrimaryConstructor) {
|
||||
return getEnclosingElementForLocalDeclaration(((KtPrimaryConstructor) parent.getParent()).getContainingClassOrObject(), skipParameters);
|
||||
}
|
||||
|
||||
else if (skipParameters && parent != null && parent.getParent() instanceof KtNamedFunction) {
|
||||
declaration = (KtNamedFunction) parent.getParent();
|
||||
}
|
||||
|
||||
+11
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.caches.resolve
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
|
||||
import org.jetbrains.kotlin.idea.project.ResolveElementCache
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
@@ -91,9 +92,17 @@ class CodeFragmentAnalyzer(
|
||||
val scopeForContextElement: LexicalScope?
|
||||
val dataFlowInfo: DataFlowInfo
|
||||
|
||||
fun getClassDescriptor(classOrObject: KtClassOrObject): ClassDescriptor? {
|
||||
if (!KtPsiUtil.isLocal(classOrObject)) {
|
||||
return resolveSession.getClassDescriptor(classOrObject, NoLookupLocation.FROM_IDE)
|
||||
}
|
||||
|
||||
return resolveToElement(classOrObject)[BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject] as ClassDescriptor?
|
||||
}
|
||||
|
||||
when (context) {
|
||||
is KtPrimaryConstructor -> {
|
||||
val descriptor = resolveSession.getClassDescriptor(context.getContainingClassOrObject(), NoLookupLocation.FROM_IDE) as ClassDescriptorWithResolutionScopes
|
||||
val descriptor = (getClassDescriptor(context.getContainingClassOrObject()) as? ClassDescriptorWithResolutionScopes) ?: return null
|
||||
|
||||
scopeForContextElement = descriptor.scopeForInitializerResolution
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
@@ -107,7 +116,7 @@ class CodeFragmentAnalyzer(
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
}
|
||||
is KtClassOrObject -> {
|
||||
val descriptor = resolveSession.getClassDescriptor(context, NoLookupLocation.FROM_IDE) as ClassDescriptorWithResolutionScopes
|
||||
val descriptor = (getClassDescriptor(context) as? ClassDescriptorWithResolutionScopes) ?: return null
|
||||
|
||||
scopeForContextElement = descriptor.scopeForMemberDeclarationResolution
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
val global = 2
|
||||
|
||||
fun makeFace() = object : ObjectFace {
|
||||
val inObject = 1
|
||||
<caret>}
|
||||
@@ -0,0 +1 @@
|
||||
global + inObject
|
||||
@@ -0,0 +1,16 @@
|
||||
fun test() {
|
||||
val local = 12
|
||||
|
||||
class A(
|
||||
a: Int
|
||||
<caret>) : Base(1) {
|
||||
val c = 1
|
||||
|
||||
init {
|
||||
val d = 1
|
||||
val e = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class Base(i: Int)
|
||||
@@ -0,0 +1 @@
|
||||
local + a + c + <error>d</error> + <error>e</error>
|
||||
+12
@@ -38,6 +38,12 @@ public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentH
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/checker/codeFragments"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, false);
|
||||
}
|
||||
|
||||
@TestMetadata("anonymousObject.kt")
|
||||
public void testAnonymousObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/codeFragments/anonymousObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("binaryExpression.kt")
|
||||
public void testBinaryExpression() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/codeFragments/binaryExpression.kt");
|
||||
@@ -104,6 +110,12 @@ public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentH
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primaryConstructorLocal.kt")
|
||||
public void testPrimaryConstructorLocal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/codeFragments/primaryConstructorLocal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("privateFunArgumentsResolve.kt")
|
||||
public void testPrivateFunArgumentsResolve() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/codeFragments/privateFunArgumentsResolve.kt");
|
||||
|
||||
Reference in New Issue
Block a user