Light Classes: Fix computation of base type in anonymous light class
This commit is contained in:
+16
-5
@@ -44,12 +44,10 @@ class KotlinLightClassForAnonymousDeclaration extends KotlinLightClassForExplici
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiJavaCodeReferenceElement getBaseClassReference() {
|
||||
Project project = classOrObject.getProject();
|
||||
return JavaPsiFacade.getElementFactory(project).createReferenceElementByFQClassName(
|
||||
getFirstSupertypeFQName(), GlobalSearchScope.allScope(project)
|
||||
);
|
||||
return JavaPsiFacade.getElementFactory(classOrObject.getProject()).createReferenceElementByType(getBaseClassType());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getFirstSupertypeFQName() {
|
||||
ClassDescriptor descriptor = getDescriptor();
|
||||
if (descriptor == null) return CommonClassNames.JAVA_LANG_OBJECT;
|
||||
@@ -77,7 +75,20 @@ class KotlinLightClassForAnonymousDeclaration extends KotlinLightClassForExplici
|
||||
if (cachedBaseType != null) type = cachedBaseType.get();
|
||||
if (type != null && type.isValid()) return type;
|
||||
|
||||
type = JavaPsiFacade.getInstance(classOrObject.getProject()).getElementFactory().createType(getBaseClassReference());
|
||||
String firstSupertypeFQName = getFirstSupertypeFQName();
|
||||
for (PsiClassType superType : getSuperTypes()) {
|
||||
PsiClass superClass = superType.resolve();
|
||||
if (superClass != null && firstSupertypeFQName.equals(superClass.getQualifiedName())) {
|
||||
type = superType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
Project project = classOrObject.getProject();
|
||||
type = PsiType.getJavaLangObject(PsiManager.getInstance(project), GlobalSearchScope.allScope(project));
|
||||
}
|
||||
|
||||
cachedBaseType = new SoftReference<PsiClassType>(type);
|
||||
return type;
|
||||
}
|
||||
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
interface X
|
||||
|
||||
interface A<D> {
|
||||
public fun <caret>bar(receiverTypes: Collection<X>): Collection<D>
|
||||
}
|
||||
|
||||
fun foo<D>(): A<D> {
|
||||
return object: A<D> {
|
||||
override fun bar(receiverTypes: Collection<X>): Collection<D> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
interface X
|
||||
|
||||
interface A<D> {
|
||||
public fun <caret>foo(receiverTypes: Collection<X>): Collection<D>
|
||||
}
|
||||
|
||||
fun foo<D>(): A<D> {
|
||||
return object: A<D> {
|
||||
override fun foo(receiverTypes: Collection<X>): Collection<D> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -1300,6 +1300,12 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
|
||||
doJavaTest(new JavaRefactoringProvider());
|
||||
}
|
||||
|
||||
public void testOverrideInAnonymousObjectWithTypeParameters() throws Exception {
|
||||
JetChangeInfo changeInfo = getChangeInfo();
|
||||
changeInfo.setNewName("bar");
|
||||
doTest(changeInfo);
|
||||
}
|
||||
|
||||
private List<Editor> editors = null;
|
||||
|
||||
private static final String[] EXTENSIONS = {".kt", ".java"};
|
||||
|
||||
Reference in New Issue
Block a user