Supported loading named objects within named objects from compiled library.
This commit is contained in:
+8
-9
@@ -55,9 +55,7 @@ class JavaDescriptorResolverHelper {
|
||||
processFields();
|
||||
processMethods();
|
||||
}
|
||||
if (psiPackage != null) {
|
||||
processNeighborClasses();
|
||||
}
|
||||
processObjectClasses();
|
||||
}
|
||||
|
||||
private NamedMembers getNamedMembers(Name name) {
|
||||
@@ -210,17 +208,18 @@ class JavaDescriptorResolverHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private void processNeighborClasses() {
|
||||
for (PsiClass neighborPsiClass : psiPackage.getClasses()) {
|
||||
if (!neighborPsiClass.isPhysical()) { // to filter out JetLightClasses
|
||||
private void processObjectClasses() {
|
||||
PsiClass[] classes = psiPackage != null ? psiPackage.getClasses() : psiClass.getPsiClass().getInnerClasses();
|
||||
for (PsiClass psiClass : classes) {
|
||||
if (!psiClass.isPhysical()) { // to filter out JetLightClasses
|
||||
continue;
|
||||
}
|
||||
if (JetClassAnnotation.get(neighborPsiClass).kind() != JvmStdlibNames.FLAG_CLASS_KIND_OBJECT) {
|
||||
if (JetClassAnnotation.get(psiClass).kind() != JvmStdlibNames.FLAG_CLASS_KIND_OBJECT) {
|
||||
continue;
|
||||
}
|
||||
PsiField instanceField = neighborPsiClass.findFieldByName(JvmAbi.INSTANCE_FIELD, false);
|
||||
PsiField instanceField = psiClass.findFieldByName(JvmAbi.INSTANCE_FIELD, false);
|
||||
if (instanceField != null) {
|
||||
NamedMembers namedMembers = getNamedMembers(Name.identifier(neighborPsiClass.getName()));
|
||||
NamedMembers namedMembers = getNamedMembers(Name.identifier(psiClass.getName()));
|
||||
|
||||
TypeSource type = new TypeSource("", instanceField.getType(), instanceField);
|
||||
namedMembers.addPropertyAccessor(new PropertyAccessorData(new PsiFieldWrapper(instanceField), type, null));
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -27,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -366,11 +368,15 @@ public class DescriptorUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Collection<ClassDescriptor> getInnerClasses(ClassDescriptor classDescriptor) {
|
||||
Collection<DeclarationDescriptor> innerClasses = classDescriptor.getUnsubstitutedInnerClassesScope().getAllDescriptors();
|
||||
for (DeclarationDescriptor inner : innerClasses) {
|
||||
JetScope innerClassesScope = classDescriptor.getUnsubstitutedInnerClassesScope();
|
||||
Collection<DeclarationDescriptor> inners = innerClassesScope.getAllDescriptors();
|
||||
for (DeclarationDescriptor inner : inners) {
|
||||
assert inner instanceof ClassDescriptor
|
||||
: "Not a class in inner classes scope of " + classDescriptor + ": " + inner;
|
||||
}
|
||||
return (Collection) innerClasses;
|
||||
return new ImmutableList.Builder<ClassDescriptor>()
|
||||
.addAll((Collection) inners)
|
||||
.addAll(innerClassesScope.getObjectDescriptors())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
public object Outer {
|
||||
public object Obj {
|
||||
public val v: String = "val"
|
||||
public fun f(): String = "fun"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace test
|
||||
|
||||
public final object test.Outer : jet.Any {
|
||||
private final /*constructor*/ fun <init>(): test.Outer
|
||||
public final val Obj: test.Outer.Obj
|
||||
public final object test.Outer.Obj : jet.Any {
|
||||
private final /*constructor*/ fun <init>(): test.Outer.Obj
|
||||
public final fun f(): jet.String
|
||||
public final val v: jet.String
|
||||
}
|
||||
}
|
||||
public final val Outer: test.Outer
|
||||
@@ -140,6 +140,11 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
doTest("compiler/testData/loadKotlin/class/NamedObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NamedObjectInNamedObject.kt")
|
||||
public void testNamedObjectInNamedObject() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/class/NamedObjectInNamedObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NamedObjectWithAnotherTopLevelProperty.kt")
|
||||
public void testNamedObjectWithAnotherTopLevelProperty() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/class/NamedObjectWithAnotherTopLevelProperty.kt");
|
||||
|
||||
Reference in New Issue
Block a user