Fast implementation for KtLightClassForExplicitDeclaration#getContainingClass()

Prevent computing stubs for light classes for nested/inner classes when calling completion from java
This commit is contained in:
Pavel V. Talanov
2015-11-06 14:22:30 +03:00
parent 73cb94a3b2
commit ad87ec12cd
6 changed files with 39 additions and 0 deletions
@@ -47,6 +47,12 @@ class KtLightClassForAnonymousDeclaration extends KtLightClassForExplicitDeclara
return JavaPsiFacade.getElementFactory(getClassOrObject().getProject()).createReferenceElementByType(getBaseClassType());
}
@Nullable
@Override
public PsiClass getContainingClass() {
return getDelegate().getContainingClass();
}
@NotNull
private String getFirstSupertypeFQName() {
ClassDescriptor descriptor = getDescriptor();
@@ -230,6 +230,13 @@ public open class KtLightClassForExplicitDeclaration(
override fun getContainingClass(): PsiClass? {
if (classOrObject.parent === classOrObject.containingFile) return null
val containingClassOrObject = (classOrObject.parent as? KtClassBody)?.parent as? KtClassOrObject
if (containingClassOrObject != null) {
return create(containingClassOrObject)
}
// TODO: should return null
return super.getContainingClass()
}
@@ -46,4 +46,6 @@ public open class KtLightClassForInterfaceDefaultImpls(
override fun setName(name: String): PsiElement {
throw IncorrectOperationException("Impossible to rename DefaultImpls")
}
override fun getContainingClass() = KtLightClassForExplicitDeclaration.create(classOrObject)
}
@@ -0,0 +1,12 @@
package test;
import mockLib.foo
public class Testing {
public static void test() {
Nest<caret>
}
}
// EXIST: Nested
// EXIST: NestedObject
@@ -137,6 +137,12 @@ public class CompiledKotlinInJavaCompletionTestGenerated extends AbstractCompile
doTest(fileName);
}
@TestMetadata("NestedNoImport.java")
public void testNestedNoImport() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/injava/NestedNoImport.java");
doTest(fileName);
}
@TestMetadata("NestedObjectInstance.java")
public void testNestedObjectInstance() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/injava/NestedObjectInstance.java");
@@ -137,6 +137,12 @@ public class KotlinSourceInJavaCompletionTestGenerated extends AbstractKotlinSou
doTest(fileName);
}
@TestMetadata("NestedNoImport.java")
public void testNestedNoImport() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/injava/NestedNoImport.java");
doTest(fileName);
}
@TestMetadata("NestedObjectInstance.java")
public void testNestedObjectInstance() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/injava/NestedObjectInstance.java");