提交 6ca5ba36 编写于 作者: N Nikolay Krasko

Don't call getClassDescriptor for local declarations (KT-15259)

 #KT-15259 Open
上级 8fe9de1d
......@@ -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();
}
......
......@@ -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
......
val global = 2
fun makeFace() = object : ObjectFace {
val inObject = 1
<caret>}
\ No newline at end of file
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)
\ No newline at end of file
local + a + c + <error>d</error> + <error>e</error>
\ No newline at end of file
......@@ -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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册