diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java index 75c200c54ed..e1c0a330be2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java @@ -214,7 +214,8 @@ public class ResolveSession implements KotlinCodeAnalyzer { return (ClassDescriptor) declaration; } - /*package*/ LazyClassDescriptor getClassObjectDescriptor(JetClassObject classObject) { + @NotNull + /*package*/ LazyClassDescriptor getClassObjectDescriptor(@NotNull JetClassObject classObject) { JetClass aClass = PsiTreeUtil.getParentOfType(classObject, JetClass.class); final LazyClassDescriptor parentClassDescriptor; @@ -237,16 +238,18 @@ public class ResolveSession implements KotlinCodeAnalyzer { // It's possible that there are several class objects and another class object is taking part in lazy resolve. We still want to // build descriptors for such class objects. final JetClassLikeInfo classObjectInfo = parentClassDescriptor.getClassObjectInfo(classObject); - if (classObjectInfo != null) { - final Name name = SpecialNames.getClassObjectName(parentClassDescriptor.getName()); - return storageManager.compute(new Function0() { - @Override - public LazyClassDescriptor invoke() { - // Create under lock to avoid premature access to published 'this' - return new LazyClassDescriptor(ResolveSession.this, parentClassDescriptor, name, classObjectInfo); - } - }); - } + assert classObjectInfo != null : + String.format("Failed to find class object info for existent class object declaration: %s", + JetPsiUtil.getElementTextWithContext(classObject)); + + final Name name = SpecialNames.getClassObjectName(parentClassDescriptor.getName()); + return storageManager.compute(new Function0() { + @Override + public LazyClassDescriptor invoke() { + // Create under lock to avoid premature access to published 'this' + return new LazyClassDescriptor(ResolveSession.this, parentClassDescriptor, name, classObjectInfo); + } + }); } return (LazyClassDescriptor) declaration; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyClassDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyClassDescriptor.java index 34354e2dbdf..95079bdf496 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyClassDescriptor.java @@ -258,9 +258,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc @Nullable public JetClassLikeInfo getClassObjectInfo(JetClassObject classObject) { if (classObject != null) { - if (!DescriptorUtils.inStaticContext(this)) { - return null; - } JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration(); if (objectDeclaration != null) { return JetClassInfoUtil.createClassLikeInfo(objectDeclaration); @@ -269,6 +266,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc else if (getKind() == ClassKind.OBJECT || getKind() == ClassKind.ENUM_ENTRY || getKind() == ClassKind.ENUM_CLASS) { return new SyntheticClassObjectInfo(originalClassInfo, this); } + return null; } diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.kt b/compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.kt new file mode 100644 index 00000000000..855bb0bf351 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.kt @@ -0,0 +1,9 @@ +package test + +class A { + class B { + class object { + val TEST = 1 + } + } +} \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.txt b/compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.txt new file mode 100644 index 00000000000..ac74839e44e --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.txt @@ -0,0 +1,15 @@ +package test + +internal final class A { + /*primary*/ public constructor A() + + internal final class B { + /*primary*/ public constructor B() + + internal class object { + /*primary*/ private constructor () + internal final val TEST: jet.Int + internal final fun (): jet.Int + } + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java index 736ad84cfb2..9e5e2c6a374 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java @@ -1577,6 +1577,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObject.kt"); } + @TestMetadata("ClassObjectInStaticNestedClass.kt") + public void testClassObjectInStaticNestedClass() throws Exception { + doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.kt"); + } + @TestMetadata("Deprecated.kt") public void testDeprecated() throws Exception { doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/annotations/classes/Deprecated.kt"); diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java index 837b7b195af..ea880d7241e 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java @@ -105,6 +105,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObject.kt"); } + @TestMetadata("ClassObjectInStaticNestedClass.kt") + public void testClassObjectInStaticNestedClass() throws Exception { + doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/ClassObjectInStaticNestedClass.kt"); + } + @TestMetadata("Deprecated.kt") public void testDeprecated() throws Exception { doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/annotations/classes/Deprecated.kt"); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 33cf4c550b3..f9b570352e2 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -310,22 +310,6 @@ public class DescriptorUtils { return superClassDescriptor.equals(KotlinBuiltIns.getInstance().getAny()); } - public static boolean inStaticContext(@NotNull DeclarationDescriptor descriptor) { - DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration(); - if (containingDeclaration instanceof PackageFragmentDescriptor) { - return true; - } - if (containingDeclaration instanceof ClassDescriptor) { - ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration; - - if (classDescriptor.getKind().isSingleton()) { - return inStaticContext(classDescriptor.getContainingDeclaration()); - } - - } - return false; - } - public static boolean isEnumClassObject(@NotNull DeclarationDescriptor descriptor) { if (descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() == ClassKind.CLASS_OBJECT) { DeclarationDescriptor containing = descriptor.getContainingDeclaration(); diff --git a/idea/testData/codeInsight/lineMarker/ClassObjectInStaticNestedClass.kt b/idea/testData/codeInsight/lineMarker/ClassObjectInStaticNestedClass.kt new file mode 100644 index 00000000000..a0dac688db0 --- /dev/null +++ b/idea/testData/codeInsight/lineMarker/ClassObjectInStaticNestedClass.kt @@ -0,0 +1,12 @@ +trait TestTrait { + fun test() +} + +class A { + class B { + class object : TestTrait { // TODO: No line marker + override fun test() { + } + } + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/OverrideImplementLineMarkerTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/OverrideImplementLineMarkerTest.java index e44cbbd43d0..00f2ffb8fdf 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/OverrideImplementLineMarkerTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/OverrideImplementLineMarkerTest.java @@ -61,6 +61,10 @@ public class OverrideImplementLineMarkerTest extends JetLightCodeInsightFixtureT doTest(); } + public void testClassObjectInStaticNestedClass() throws Exception { + doTest(); + } + public void testFakeOverrideProperty() throws Exception { doTest(); }