Make Kotlin light classes pass "element instanceof StubBasedPsiElement" in LocalSearchScope scope
This commit is contained in:
+8
-2
@@ -25,7 +25,9 @@ import com.intellij.psi.impl.light.LightClass
|
||||
import com.intellij.psi.impl.light.LightMethod
|
||||
import com.intellij.psi.scope.PsiScopeProcessor
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import com.intellij.psi.stubs.IStubElementType
|
||||
import com.intellij.psi.stubs.PsiClassHolderFileStub
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.psi.util.CachedValue
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
@@ -40,6 +42,7 @@ import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinClassOrObjectStub
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import javax.swing.Icon
|
||||
@@ -47,8 +50,8 @@ import javax.swing.Icon
|
||||
public open class KotlinLightClassForExplicitDeclaration(
|
||||
manager: PsiManager,
|
||||
private val classFqName: FqName, // FqName of (possibly inner) class
|
||||
protected val classOrObject: JetClassOrObject) : KotlinWrappingLightClass(manager), JetJavaMirrorMarker {
|
||||
|
||||
protected val classOrObject: JetClassOrObject)
|
||||
: KotlinWrappingLightClass(manager), JetJavaMirrorMarker, StubBasedPsiElement<KotlinClassOrObjectStub<out JetClassOrObject>> {
|
||||
private var delegate: PsiClass? = null
|
||||
|
||||
private fun getLocalClassParent(): PsiElement? {
|
||||
@@ -376,6 +379,9 @@ public open class KotlinLightClassForExplicitDeclaration(
|
||||
|
||||
override fun getUseScope(): SearchScope = getOrigin().useScope
|
||||
|
||||
override fun getElementType(): IStubElementType<out StubElement<*>, *>? = classOrObject.elementType
|
||||
override fun getStub(): KotlinClassOrObjectStub<out JetClassOrObject>? = classOrObject.stub
|
||||
|
||||
companion object {
|
||||
private val JAVA_API_STUB = Key.create<CachedValue<OutermostKotlinClassLightClassData>>("JAVA_API_STUB")
|
||||
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
public class ImplementJavaInnerInterface {
|
||||
interface Test {
|
||||
void foo();
|
||||
}
|
||||
|
||||
void test() {
|
||||
Test test = new Test() {
|
||||
@Override
|
||||
public void foo() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void usage(Test test) {
|
||||
test.<caret>foo();
|
||||
}
|
||||
}
|
||||
|
||||
// REF: (in KotlinTest).foo()
|
||||
// REF: <anonymous>.foo()
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class KotlinTest : ImplementJavaInnerInterface.Test {
|
||||
override fun foo() {}
|
||||
}
|
||||
+8
@@ -62,10 +62,18 @@ public class JetGotoImplementationMultifileTest extends JetLightCodeInsightFixtu
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaInnerInterface() throws Exception {
|
||||
doJavaKotlinTest();
|
||||
}
|
||||
|
||||
private void doKotlinJavaTest() throws Exception {
|
||||
doMultifileTest(getTestName(false) + ".kt", getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
private void doJavaKotlinTest() throws Exception {
|
||||
doMultifileTest(getTestName(false) + ".java", getTestName(false) + ".kt");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.test;
|
||||
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.NavigationItem;
|
||||
import com.intellij.psi.PsiAnonymousClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -49,6 +50,9 @@ public final class ReferenceUtils {
|
||||
|
||||
String presentableText = presentation.getPresentableText();
|
||||
String locationString = presentation.getLocationString();
|
||||
if (locationString == null && element.getParent() instanceof PsiAnonymousClass) {
|
||||
locationString = "<anonymous>";
|
||||
}
|
||||
return locationString == null || navigationElement instanceof PsiPackage
|
||||
// for PsiPackage, presentableText is FQ name of current package
|
||||
? presentableText
|
||||
|
||||
Reference in New Issue
Block a user