Discover class objects for light class generation in the compiler
#KT-3337 In Progress LightClasses: class object's property getter unresolved in Java, but compiles OK
This commit is contained in:
+21
-3
@@ -33,10 +33,9 @@ import org.jetbrains.jet.asJava.LightClassGenerationSupport;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -95,6 +94,25 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
return Collections.singletonList((JetClassOrObject) element);
|
||||
}
|
||||
}
|
||||
|
||||
if (JvmAbi.isClassObjectFqName(fqName)) {
|
||||
Collection<JetClassOrObject> parentClasses = findClassOrObjectDeclarations(fqName.parent(), searchScope);
|
||||
return ContainerUtil.mapNotNull(parentClasses,
|
||||
new Function<JetClassOrObject, JetClassOrObject>() {
|
||||
@Override
|
||||
public JetClassOrObject fun(JetClassOrObject classOrObject) {
|
||||
if (classOrObject instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) classOrObject;
|
||||
JetClassObject classObject = jetClass.getClassObject();
|
||||
if (classObject != null) {
|
||||
return classObject.getObjectDeclaration();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public class JvmAbi {
|
||||
/**
|
||||
* This constant is used to identify binary format (class file) versions
|
||||
@@ -39,6 +43,10 @@ public class JvmAbi {
|
||||
public static final JvmClassName JETBRAINS_NOT_NULL_ANNOTATION =
|
||||
JvmClassName.byFqNameWithoutInnerClasses("org.jetbrains.annotations.NotNull");
|
||||
|
||||
public static boolean isClassObjectFqName(@NotNull FqName fqName) {
|
||||
return fqName.lastSegmentIs(Name.identifier(CLASS_OBJECT_CLASS_NAME));
|
||||
}
|
||||
|
||||
private JvmAbi() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
class WithClassObject {
|
||||
class object {
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,8 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Lists.newArrayList(
|
||||
new File("compiler/testData/asJava/lightClasses/Declared.kt"),
|
||||
new File("compiler/testData/asJava/lightClasses/Package.kt")
|
||||
new File("compiler/testData/asJava/lightClasses/Package.kt"),
|
||||
new File("compiler/testData/asJava/lightClasses/ClassObject.kt")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
||||
@NotNull
|
||||
protected PsiClass doTest(String qualifiedName) {
|
||||
KotlinLightClass psiClass = (KotlinLightClass) finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull(psiClass);
|
||||
assertNotNull("Class not found: " + qualifiedName, psiClass);
|
||||
|
||||
Asserter asserter = new Asserter();
|
||||
|
||||
@@ -203,4 +204,8 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
||||
public void testDeprecatedWithBracketsFQNSpaces() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassObject() throws Exception {
|
||||
doTest("test.WithClassObject.object");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user